/
5-VPN-IKEv2.yml
1549 lines (1506 loc) · 61 KB
/
5-VPN-IKEv2.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
AWSTemplateFormatVersion: '2010-09-09'
Description: VPN instance in this region
Parameters:
Environment:
Type: String
Description: Name of the environment to bring up.
StrongswanVersion:
Type: String
Default: 5.7.1
SourceId:
Type: String
Date:
Type: String
Description: MMDDYY date of last machine bringup
CertAccessSecret:
Type: String
NoEcho: true
# Optional
UbuntuAMI:
Type: String
Description: AMI
Default: ""
InstanceType:
Type: String
Description: Instance Type
Default: t3.small
Conditions:
OverrideInstanceType: !Not [!Equals [!Ref InstanceType, ""]]
OverrideAMI: !Not [!Equals [!Ref UbuntuAMI, ""]]
Mappings:
RegionMap:
us-east-1:
AMI: ami-0747bdcabd34c712a
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
us-east-2:
AMI: ami-0b9064170e32bde34
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
us-west-1:
AMI: ami-07b068f843ec78e72
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
us-west-2:
AMI: ami-090717c950a5c34d3
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
ap-south-1:
AMI: ami-04bde106886a53080
InstanceType: t2.small
EbsOptimized: false
FsDevice: xvda1
ap-northeast-2:
AMI: ami-0ba5cd124d7a79612
InstanceType: t2.small
EbsOptimized: false
FsDevice: xvda1
ap-southeast-1:
AMI: ami-055147723b7bca09a
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
ap-southeast-2:
AMI: ami-0f39d06d145e9bb63
InstanceType: t2.small
EbsOptimized: false
FsDevice: nvme0n1p1
ap-northeast-1:
AMI: ami-0fe22bffdec36361c
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
ca-central-1:
AMI: ami-0e28822503eeedddc
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
eu-central-1:
AMI: ami-0b1deee75235aa4bb
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
eu-west-1:
AMI: ami-0943382e114f188e8
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
eu-west-2:
AMI: ami-09a56048b08f94cdf
InstanceType: t3.small
EbsOptimized: true
FsDevice: nvme0n1p1
eu-west-3:
AMI: ami-06602da18c878f98d
InstanceType: t2.small
EbsOptimized: false
FsDevice: xvda1
sa-east-1:
AMI: ami-05aa753c043f1dcd3
InstanceType: t2.small
EbsOptimized: false
FsDevice: nvme0n1p1
Resources:
VpnInstance:
Type: AWS::EC2::Instance
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT20M
Properties:
InstanceType: !If [OverrideInstanceType, !Ref InstanceType, !FindInMap [RegionMap, !Ref "AWS::Region", InstanceType]]
InstanceInitiatedShutdownBehavior: stop
DisableApiTermination: false
EbsOptimized: !FindInMap [RegionMap, !Ref "AWS::Region", EbsOptimized]
CreditSpecification:
CPUCredits: unlimited
ImageId: !If [OverrideAMI, !Ref UbuntuAMI, !FindInMap [RegionMap, !Ref "AWS::Region", AMI]]
NetworkInterfaces:
- DeleteOnTermination: true
Description: Primary network interface
DeviceIndex: 0
SubnetId:
Fn::ImportValue:
!Join [ '-', [ !Ref Environment, VpnSubnetId ] ]
GroupSet:
- Fn::ImportValue:
!Join [ '-', [ !Ref Environment, VpnSecurityGroupId ] ]
Monitoring: false
Tags:
- Key: Name
Value: !Join [ '-', [ !Ref Environment, VPN-IKEv2 ] ]
- Key: Environment
Value: !Ref Environment
IamInstanceProfile:
Fn::ImportValue:
!Join [ '-', [ !Ref Environment, VpnInstanceProfile ] ]
UserData:
"Fn::Base64":
!Sub |
#!/bin/bash -ex
# Install Updates and Python3
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get dist-upgrade -yq
apt-get -yq install python3.8-distutils python3-pip python3 python3-setuptools
# Install CloudFormation Bootstrap
wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
tar -xvzf aws-cfn-bootstrap-py3-latest.tar.gz
cd aws-cfn-bootstrap-2.0
python3 setup.py install
# Run CloudFormation Init
cfn-init -c default --stack ${AWS::StackName} --resource VpnInstance --region ${AWS::Region}
# Signal success to CloudFormation on reboot
echo "@reboot root /usr/local/bin/cfn-signal --success true --stack ${AWS::StackName} --resource VpnInstance --region ${AWS::Region} 2>&1 | /usr/bin/logger -t cfn_success" >> /etc/cron.d/success_on_reboot
# Reboot to pick up latest patches
reboot
Metadata:
AWS::CloudFormation::Init:
configSets:
default:
- "unattended-upgrades"
- "set-region-and-environment"
- "install-aws-cloudwatch-and-cli"
- "enable-swap"
- "load-network-config"
- "install-node"
- "install-suricata"
- "install-strongswan"
- "copy-certs"
- "install-aws-codedeploy"
updateable:
- "fix-suricata-check"
- "update-suricata-yaml"
fix-suricata-check:
files:
'/etc/cron.d/suricata_check':
content: "*/15 * * * * root /home/ubuntu/suricata-check.sh 2>&1 | /usr/bin/logger -t suricata_check\n"
mode: '000644'
owner: root
group: root
update-suricata-yaml:
files:
'/home/ubuntu/suricata-check.sh':
content: !Sub
- |
#!/bin/bash
set -ex
printf "Suricata Rules Conf Check\n";
if pgrep suricata-update >/dev/null 2>&1
then
echo "suricata-update already running. Quitting.";
exit 0;
fi
printf "Updating Rules from S3\n";
LOWERCASED_BUCKET=`echo ${SuricataBucket} | awk '{print tolower($0)}'`;
REGION=`aws s3api get-bucket-location --bucket $LOWERCASED_BUCKET --output text`;
if [ "$REGION" = "None" ]; then
REGION="us-east-1"
fi
aws s3 cp s3://$LOWERCASED_BUCKET/confirmed.rules /etc/suricata/local-rules/confirmed.rules --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/drop.conf /etc/suricata/drop.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/disable.conf /etc/suricata/disable.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/enable.conf /etc/suricata/enable.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/modify.conf /etc/suricata/modify.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/update.yaml /etc/suricata/update.yaml --region $REGION
printf "Running update\n";
/usr/bin/suricata-update --no-test \
--ignore *deleted.rules \
--ignore *app-layer-events.rules \
--ignore *tls-events.rules \
--ignore *http-events.rules \
--ignore *emerging-icmp_info.rules \
--ignore *emerging-trojan.rules \
--ignore *emerging-malware.rules \
--ignore *emerging-mobile_malware.rules \
--ignore *botcc.rules \
--ignore *stream-events.rules \
--ignore *tor.rules \
--ignore *emerging-policy.rules;
- SuricataBucket:
Fn::ImportValue:
!Join [ '-', [ !Ref Environment, SuricataBucketVpn ] ]
mode: '000544'
owner: ubuntu
group: ubuntu
unattended-upgrades:
files:
'/etc/apt/apt.conf.d/10periodic':
content: |
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
mode: '000644'
owner: root
group: root
'/etc/apt/apt.conf.d/50unattended-upgrades':
content: |
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESM:${distro_codename}";
};
mode: '000644'
owner: root
group: root
set-region-and-environment:
commands:
0_set_region:
command: !Sub echo AWS_DEFAULT_REGION=${AWS::Region} >> /etc/environment
1_set_environment:
command: !Sub |
echo ENVIRONMENT=${Environment} >> /etc/environment
printf "${Environment}" > /home/ubuntu/environment
2_set_eth_device:
command: !Sub |
ETHDEVICE=$(ifconfig -s | grep BMRU | head -n 1 | cut -d" " -f1)
printf "$ETHDEVICE" > /home/ubuntu/ethdevice
echo ETHDEVICE=$ETHDEVICE >> /etc/environment
install-aws-cloudwatch-and-cli:
packages:
apt:
awscli: []
files:
'/home/ubuntu/cloudwatch.config':
content: !Sub |
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-cloudwatch-logs"
},
{
"file_path": "/var/log/auth.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-authlog"
},
{
"file_path": "/var/log/amazon/ssm/amazon-ssm-agent.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-aws-ssm"
},
{
"file_path": "/var/log/cfn-init.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-cfn-init"
},
{
"file_path": "/var/log/cfn-init-cmd.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-cfn-init-cmd"
},
{
"file_path": "/var/log/cloud-init.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-cloud-init"
},
{
"file_path": "/var/log/cloud-init-output.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-cloud-init-output"
},
{
"file_path": "/var/log/aws/codedeploy-agent/codedeploy-agent.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-aws-codedeploy-agent"
},
{
"file_path": "/opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-aws-codedeploy-deployments"
},
{
"file_path": "/home/ubuntu/bandwidth-node.log",
"log_group_name": "${Environment}-VPN-Node",
"log_stream_name": "${AWS::StackName}-{instance_id}"
},
{
"file_path": "/var/log/suricata/fast.log",
"log_group_name": "${Environment}-VPN-Suricata",
"log_stream_name": "${AWS::StackName}-{instance_id}-fast"
},
{
"file_path": "/var/log/suricata/suricata.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-suricata-log"
},
{
"file_path": "/var/log/syslog",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-syslog"
},
{
"file_path": "/var/log/unattended-upgrades/unattended-upgrades.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-unattended-upgrades"
},
{
"file_path": "/var/log/unattended-upgrades/unattended-upgrades-dpkg.log",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-unattended-upgrades-dpkg"
},
{
"file_path": "/var/run/reboot-required.pkgs",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-reboot-required"
},
{
"file_path": "/tmp/CURRENT_NODE_VERSION",
"log_group_name": "${Environment}-VPN",
"log_stream_name": "${AWS::StackName}-{instance_id}-current-node-version"
}
]
}
}
},
"metrics": {
"append_dimensions": {
"InstanceId": "${!aws:InstanceId}"
},
"metrics_collected": {
"cpu": {
"measurement": [
"cpu_usage_active",
"cpu_usage_iowait",
"cpu_usage_user",
"cpu_usage_system"
],
"metrics_collection_interval": 60,
"totalcpu": true
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"/"
]
},
"diskio": {
"measurement": [
"io_time"
],
"metrics_collection_interval": 60,
"resources": [
"/"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
mode: '000644'
owner: root
group: root
commands:
0_install_cloudwatch:
command: |
apt-get -yq install unzip
wget -q https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip -P /tmp
unzip /tmp/AmazonCloudWatchAgent.zip -d /home/ubuntu/cloudwatch_agent
cd /home/ubuntu/cloudwatch_agent
./install.sh
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/home/ubuntu/cloudwatch.config -s
enable-swap:
commands:
0_enable_swap:
command: |
dd if=/dev/zero of=/var/spool/swap bs=1M count=1k
mkswap /var/spool/swap
chmod 0600 /var/spool/swap
swapon /var/spool/swap
1_persist_on_reboot:
command: |
echo "/var/spool/swap swap swap defaults 0 0" >> /etc/fstab
load-network-config:
packages:
apt:
iptables-persistent: []
files:
'/etc/iptables/rules.v4':
content: |
*mangle
# Ensure all "mangle" chains default to ACCEPT, essentially a no-op.
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
*nat
# Ensure NAT chains default to ACCEPT to let packets through
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# For traffic coming from VPN clients that's *not* IPSec encrypted (because it's been decrypted by this VPN server),
# apply "MASQUERADE" NAT to give it a source IP of this host, instead of its private Virtual IP. Without this rule,
# remote hosts wouldn't be able to get responses back to the right VPN server (this one).
-A POSTROUTING -s 10.0.0.0/8 -m policy --pol none --dir out -j MASQUERADE
COMMIT
*filter
# Default to dropping everything coming into or being forwarded by this host. A safe default that we then add exceptions to.
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
# For output traffic, just let it through so we don't have to go crazy figuring out what services on this host need
# access to the public internet.
:OUTPUT ACCEPT [0:0]
# Accept all loopback traffic
-A INPUT -i lo -j ACCEPT
# Accept all traffic from established connections. For example, TCP connections, DNS replies, ICMP ping replies, etc.
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# Accept all IPSec VPN traffic using IP protocols 50, 51.
-A INPUT -p esp -j ACCEPT
-A INPUT -p ah -j ACCEPT
# rate limit ICMP traffic per source
-A INPUT -p icmp --icmp-type echo-request -m hashlimit --hashlimit-upto 5/s --hashlimit-mode srcip --hashlimit-srcmask 32 --hashlimit-name icmp-echo-drop -j ACCEPT
# Accept all IKE traffic and IPSec NAT-T UDP encapsulation
-A INPUT -p udp -m multiport --dports 500,4500 -j ACCEPT
# Do not accept incoming SSH connections
# -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT
# Accept traffic from VPN clients intended for this host
-A INPUT -p ipencap -m policy --dir in --pol ipsec --proto esp -j ACCEPT
# Send all traffic from and to VPN clients to Suricata for analysis
-A FORWARD -s 10.0.0.0/8 -j NFQUEUE --queue-num 0
-A FORWARD -d 10.0.0.0/8 -j NFQUEUE --queue-num 0
# Block traffic *between* VPN clients
-A FORWARD -s 10.0.0.0/8 -d 10.0.0.0/8 -j DROP
# Forward all traffic from established connections. For example, TCP connections, DNS replies, ICMP ping replies, etc.
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# Block CIFS (MS LAN file sharing), because it's probably up to no good
-A FORWARD -p tcp --dport 445 -j DROP
# Block NETBIOS, because it's probably up to no good
-A FORWARD -p udp -m multiport --ports 137,138 -j DROP
-A FORWARD -p tcp -m multiport --ports 137,139 -j DROP
# Allow new connections from VPN clients to remote hosts
-A FORWARD -m conntrack --ctstate NEW -s 10.0.0.0/8 -m policy --pol ipsec --dir in -j ACCEPT
COMMIT
'/etc/sysctl.conf':
content: |
net.ipv4.ip_forward=1
net.ipv4.conf.all.forwarding=1
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.all.send_redirects=0
commands:
0_reload_network:
command: |
ifdown lo:100 && ifup lo:100
sysctl -p
echo 1 > /proc/sys/net/ipv4/route/flush
services:
sysvinit:
netfilter-persistent:
ensureRunning: true
enabled: true
install-node:
commands:
1_setup:
command: curl -sL https://deb.nodesource.com/setup_16.x | bash -
2_install:
command: apt-get install -yq nodejs
3_update_npm:
command: npm install -g npm@8
4_install_n:
command: npm install -g n
install-suricata:
files:
'/etc/default/suricata':
content: |
# start the server in the init.d script
RUN=yes
# user that will run suricata in the init.d script (used for dropping privileges only)
RUN_AS_USER=
SURCONF=/etc/suricata/suricata.yaml
LISTENMODE=nfqueue
NFQUEUE="-q 0"
PIDFILE=/var/run/suricata.pid
'/etc/modules-load.d/suricata.conf':
content: |
nfnetlink
nfnetlink_queue
'/etc/suricata/suricata.yaml':
content: |
%YAML 1.1
---
vars:
address-groups:
CLIENT_NET: '[10.0.0.0/8]'
HOME_NET: '[10.0.0.0/8]'
EXTERNAL_NET: any
HTTP_SERVERS: any
SMTP_SERVERS: any
SQL_SERVERS: any
DNS_SERVERS: any
TELNET_SERVERS: any
AIM_SERVERS: any
DNP3_SERVER: any
DNP3_CLIENT: any
MODBUS_CLIENT: any
MODBUS_SERVER: any
ENIP_CLIENT: any
ENIP_SERVER: any
port-groups:
HTTP_PORTS: '[80,81,311,591,593,901,1220,1414,1830,2301,2381,2809,3128,3702,4343,5250,7001,7145,7510,7777,7779,8000,8008,8014,8028,8080,8088,8118,8123,8180,8181,8243,8280,8800,8888,8899,9080,9090,9091,9443,9999,11371,55555]'
ORACLE_PORTS: 1521
SHELLCODE_PORTS: '!80'
SSH_PORTS: 22
DNP3_PORTS: 20000
MODBUS_PORTS: 502
FILE_DATA_PORTS: '[$HTTP_PORTS,110,143]'
FTP_PORTS: 21
default-rule-path: /var/lib/suricata/rules
rule-files:
- suricata.rules
default-log-dir: /var/log/suricata/
stats:
enabled: no
interval: 8
outputs:
-
fast:
enabled: yes
filename: fast.log
append: yes
-
eve-log:
enabled: no
filetype: unix_stream
filename: /tmp/eve.sock
types: [{alert: {metadata: yes, tagged-packets: yes}}]
-
alert-debug:
enabled: no
filename: alert-debug.log
append: yes
-
stats:
enabled: no
filename: stats.log
append: yes
totals: yes
threads: no
-
drop:
enabled: no
filename: drop.log
append: yes
logging:
default-log-level: notice
default-output-filter: null
outputs:
-
console: {enabled: yes}
-
file: {enabled: yes, level: info, filename: /var/log/suricata/suricata.log}
-
syslog: {enabled: no, facility: local5, format: '[%i] <%d> -- '}
af-packet:
-
interface: eth0
cluster-id: 99
cluster-type: cluster_flow
defrag: yes
-
interface: default
cluster-id: 99
cluster-type: cluster_flow
defrag: yes
pcap:
-
interface: eth0
-
interface: default
pcap-file:
checksum-checks: auto
app-layer:
protocols:
tls:
enabled: yes
detection-ports: {dp: 443}
dcerpc:
enabled: yes
ftp:
enabled: yes
ssh:
enabled: yes
smtp:
enabled: yes
mime: {decode-mime: yes, decode-base64: yes, decode-quoted-printable: yes, header-value-depth: 2000, extract-urls: yes, body-md5: no}
inspected-tracker: {content-limit: 100000, content-inspect-min-size: 32768, content-inspect-window: 4096}
imap:
enabled: detection-only
msn:
enabled: detection-only
smb:
enabled: yes
detection-ports: {dp: '139, 445'}
nfs:
enabled: no
dns:
tcp: {enabled: yes, detection-ports: {dp: 53}}
udp: {enabled: yes, detection-ports: {dp: 53}}
http:
enabled: yes
libhtp: {default-config: {personality: IDS, request-body-limit: 100kb, response-body-limit: 100kb, request-body-minimal-inspect-size: 32kb, request-body-inspect-window: 4kb, response-body-minimal-inspect-size: 40kb, response-body-inspect-window: 16kb, response-body-decompress-layer-limit: 2, http-body-inline: auto, double-decode-path: no, double-decode-query: no}, server-config: null}
modbus:
enabled: no
detection-ports: {dp: 502}
stream-depth: 0
dnp3:
enabled: no
detection-ports: {dp: 20000}
enip:
enabled: no
detection-ports: {dp: 44818, sp: 44818}
ntp:
enabled: no
asn1-max-frames: 256
coredump:
max-dump: unlimited
host-mode: auto
unix-command:
enabled: auto
legacy:
uricontent: enabled
engine-analysis:
rules-fast-pattern: yes
rules: yes
pcre:
match-limit: 3500
match-limit-recursion: 1500
host-os-policy:
windows:
- 0.0.0.0/0
bsd: []
bsd-right: []
old-linux: []
linux: []
old-solaris: []
solaris: []
hpux10: []
hpux11: []
irix: []
macos: []
vista: []
windows2k3: []
defrag:
memcap: 32mb
hash-size: 65536
trackers: 65535
max-frags: 65535
prealloc: yes
timeout: 60
flow:
memcap: 128mb
hash-size: 65536
prealloc: 10000
emergency-recovery: 30
vlan:
use-for-tracking: true
flow-timeouts:
default:
new: 30
established: 300
closed: 0
bypassed: 100
emergency-new: 10
emergency-established: 100
emergency-closed: 0
emergency-bypassed: 50
tcp:
new: 60
established: 600
closed: 60
bypassed: 100
emergency-new: 5
emergency-established: 100
emergency-closed: 10
emergency-bypassed: 50
udp:
new: 30
established: 300
bypassed: 100
emergency-new: 10
emergency-established: 100
emergency-bypassed: 50
icmp:
new: 30
established: 300
bypassed: 100
emergency-new: 10
emergency-established: 100
emergency-bypassed: 50
stream:
memcap: 64mb
checksum-validation: yes
inline: auto
reassembly:
memcap: 256mb
depth: 1mb
toserver-chunk-size: 2560
toclient-chunk-size: 2560
randomize-chunk-size: yes
host:
hash-size: 4096
prealloc: 1000
memcap: 32mb
decoder:
teredo:
enabled: true
detect:
profile: medium
custom-values:
toclient-groups: 3
toserver-groups: 25
sgh-mpm-context: auto
inspection-recursion-limit: 3000
prefilter:
default: mpm
grouping: null
profiling:
grouping:
dump-to-disk: false
include-rules: false
include-mpm-stats: false
mpm-algo: auto
spm-algo: auto
threading:
set-cpu-affinity: no
cpu-affinity:
-
management-cpu-set: {cpu: [0]}
-
receive-cpu-set: {cpu: [0]}
-
worker-cpu-set: {cpu: [all], mode: exclusive, prio: {low: [0], medium: [1-2], high: [3], default: medium}}
detect-thread-ratio: 1
luajit:
states: 128
profiling:
rules:
enabled: yes
filename: rule_perf.log
append: yes
limit: 10
json: yes
keywords:
enabled: yes
filename: keyword_perf.log
append: yes
rulegroups:
enabled: yes
filename: rule_group_perf.log
append: yes
packets:
enabled: yes
filename: packet_stats.log
append: yes
csv:
enabled: no
filename: packet_stats.csv
locks:
enabled: no
filename: lock_stats.log
append: yes
pcap-log:
enabled: no
filename: pcaplog_stats.log
append: yes
nfq: null
nflog:
-
group: 2
buffer-size: 18432
-
group: default
qthreshold: 1
qtimeout: 100
max-size: 20000
capture: null
pfring:
-
interface: eth0
threads: 1
cluster-id: 99
cluster-type: cluster_flow
-
interface: default
threads: 1
cluster-id: 99
cluster-type: cluster_flow
'/etc/suricata/update.yaml':
content: !Sub |
disable-conf: /etc/suricata/disable.conf
enable-conf: /etc/suricata/enable.conf
drop-conf: /etc/suricata/drop.conf
modify-conf: /etc/suricata/modify.conf
ignore:
- "*deleted.rules"
sources:
- https://rules.emergingthreats.net/open/suricata-%(__version__)s/emerging.rules.tar.gz
- https://sslbl.abuse.ch/blacklist/sslblacklist.rules
local:
- /etc/suricata/local-rules/confirmed.rules
reload-command: sudo suricatasc -c reload-rules
'/home/ubuntu/suricata-check.sh':
content: !Sub
- |
#!/bin/bash
set -ex
printf "Suricata Rules Conf Check\n";
if pgrep suricata-update >/dev/null 2>&1
then
echo "suricata-update already running. Quitting.";
exit 0;
fi
printf "Updating Rules from S3\n";
LOWERCASED_BUCKET=`echo ${SuricataBucket} | awk '{print tolower($0)}'`;
REGION=`aws s3api get-bucket-location --bucket $LOWERCASED_BUCKET --output text`;
if [ "$REGION" = "None" ]; then
REGION="us-east-1"
fi
aws s3 cp s3://$LOWERCASED_BUCKET/confirmed.rules /etc/suricata/local-rules/confirmed.rules --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/drop.conf /etc/suricata/drop.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/disable.conf /etc/suricata/disable.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/enable.conf /etc/suricata/enable.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/modify.conf /etc/suricata/modify.conf --region $REGION
aws s3 cp s3://$LOWERCASED_BUCKET/update.yaml /etc/suricata/update.yaml --region $REGION
printf "Running update\n";
/usr/bin/suricata-update --no-test \
--ignore *deleted.rules \
--ignore *app-layer-events.rules \
--ignore *tls-events.rules \
--ignore *http-events.rules \
--ignore *emerging-icmp_info.rules \
--ignore *emerging-trojan.rules \
--ignore *emerging-malware.rules \
--ignore *emerging-mobile_malware.rules \
--ignore *botcc.rules \
--ignore *stream-events.rules \
--ignore *tor.rules \
--ignore *emerging-policy.rules;
- SuricataBucket:
Fn::ImportValue:
!Join [ '-', [ !Ref Environment, SuricataBucketVpn ] ]
mode: '000544'
owner: ubuntu
group: ubuntu
'/etc/cron.d/suricata_check':
content: "*/15 * * * * root /home/ubuntu/suricata-check.sh 2>&1 | /usr/bin/logger -t suricata_check\n"
mode: '000644'
owner: root
group: root
commands:
0_replace_eth_device:
command: |
ETHDEVICE=$(cat /home/ubuntu/ethdevice)
sed -i "s/eth0/$ETHDEVICE/g" /etc/suricata/suricata.yaml
1_load_nfqueue:
command: |
/sbin/modprobe nfnetlink_queue
2_apt_get:
command: |
add-apt-repository ppa:oisf/suricata-5.0 --yes
apt-get update
apt-get install -yq --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" suricata=5.0.8-0ubuntu0
apt-get install -yq python-pip
pip install suricata-update
3_do_update:
command: /home/ubuntu/suricata-check.sh
env:
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
install-strongswan:
packages:
apt:
libgmp3-dev: []
libssl-dev: []
files:
'/etc/ipsec.conf':
content: !Sub
- |
config setup
uniqueids=never
conn %default
fragmentation=yes
rekey=no
dpdaction=clear
keyexchange=ikev2
compress=yes
dpddelay=35s
ike=aes128gcm16-prfsha512-ecp256,aes128-sha2_512-prfsha512-ecp256,aes128-sha2_384-prfsha384-ecp256!
esp=aes128gcm16-ecp256,aes128-sha2_512-prfsha512-ecp256!
left=%any
leftauth=pubkey
leftid=www-${SourceId}.${Domain}
leftcert=www-${SourceId}.${Domain}.crt
leftsendcert=always
leftsubnet=0.0.0.0/0
right=%any
rightauth=pubkey
rightsourceip=10.0.0.0/8
rightdns=1.1.1.1,1.0.0.1
conn ikev2-pubkey
auto=add
- Domain:
Fn::ImportValue:
!Sub ${Environment}-Domain
SourceId: !Ref SourceId
'/etc/strongswan.conf':
content: |
charon {
load_modular = yes