-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreinforce-v9.yaml
1544 lines (1513 loc) · 51.4 KB
/
reinforce-v9.yaml
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: This template creates the two VPCs for an isolated testing
environment. It will deploy tow EC2 hosts running docker which will run an 'attacker and 'victim'.
The environment will demontrate how cloud security requires multiple approaches including cloud native and third party
Services.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Tagging Information
Parameters:
- CSAccounting
- CSDepartment
- CSOwner
- CSBusiness
- Label:
default: Jenkins Network Configuration
Parameters:
- JenkinsVPCCIDR
- JenkinsPrivateSubnetCIDR1
- JenkinsPrivateSubnetCIDR2
- JenkinsPublicSubnetCIDR1
- JenkinsPublicSubnetCIDR2
- Label:
default: Network Configuration
Parameters:
- AvailabilityZones
- VPCCIDR
- PrivateSubnetCIDR
- PublicSubnetCIDR
- RemoteAccessCIDR
- Label:
default: Amazon EC2 Configuration
Parameters:
- KeyPairName
- AvailabilityZones
- KeyPairName
ParameterLabels:
AvailabilityZones:
default: Availability Zones
KeyPairName:
default: Key Pair Name
PrivateSubnetCIDR:
default: Private Subnet CIDR
PublicSubnetCIDR:
default: Public Subnet CIDR
RemoteAccessCIDR:
default: Allowed Bastion External Access CIDR
VPCCIDR:
default: VPC CIDR
Parameters:
CSOwner:
Type: String
Description: Owner/Creator of resource
MaxLength: 20
Default: Justin Harris
CSBusiness:
Type: String
Description: Department
MaxLength: 20
Default: Sales - 310000
CSAccounting:
Type: String
Description: Billing Account
MaxLength: 20
Default: dev
CSDepartment:
Type: String
Description: Department
MaxLength: 20
Default: Sales
stackPrefix:
Type: String
Description: The prefix to use when naming resources in this stack. Normally we would use the stack name, but since this template can be used as a resource in other stacks we want to keep the naming consistent. No symbols allowed.
ConstraintDescription: Alphanumeric characters only, maximum 10 characters
AllowedPattern: ^[a-zA-z0-9]+$
MaxLength: 10
Default: waf
stackScope:
Type: String
Description: You can deploy this stack at a regional level, for regional WAF targets like Application Load Balancers, or for global targets, such as Amazon CloudFront distributions.
AllowedValues:
- Global
- Regional
Default: Regional
ruleAction:
Type: String
Description: The type of action you want to iplement for the rules in this set. Valid options are COUNT or BLOCK.
AllowedValues:
- BLOCK
- COUNT
Default: BLOCK
includesPrefix:
Type: String
Description: This is the URI path prefix (starting with '/') that identifies any files in your webroot that are server-side included components, and should not be invoked directly via URL. These can be headers, footers, 3rd party server side libraries or components. You can add additional prefixes later directly in the set.
Default: /includes
adminUrlPrefix:
Type: String
Description: This is the URI path prefix (starting with '/') that identifies your administrative sub-site. You can add additional prefixes later directly in the set.
Default: /admin
adminRemoteCidr:
Type: String
Description: This is the IP address allowed to access your administrative interface. Use CIDR notation. You can add additional ones later directly in the set.
Default: 127.0.0.1/32
maxExpectedURISize:
Type: Number
Description: Maximum number of bytes allowed in the URI component of the HTTP request. Generally the maximum possible value is determined by the server operating system (maps to file system paths), the web server software, or other middleware components. Choose a value that accomodates the largest URI segment you use in practice in your web application.
Default: 512
maxExpectedQueryStringSize:
Type: Number
Description: Maximum number of bytes allowed in the query string component of the HTTP request. Normally the of query string parameters following the "?" in a URL is much larger than the URI , but still bounded by the of the parameters your web application uses and their values.
Default: 1024
maxExpectedBodySize:
Type: Number
Description: Maximum number of bytes allowed in the body of the request. If you do not plan to allow large uploads, set it to the largest payload value that makes sense for your web application. Accepting unnecessarily large values can cause performance issues, if large payloads are used as an attack vector against your web application.
Default: 4096
maxExpectedCookieSize:
Type: Number
Description: Maximum number of bytes allowed in the cookie header. The maximum size should be less than 4096, the size is determined by the amount of information your web application stores in cookies. If you only pass a session token via cookies, set the size to no larger than the serialized size of the session token and cookie metadata.
Default: 4093
csrfExpectedHeader:
Type: String
Description: The custom HTTP request header, where the CSRF token value is expected to be encountered
Default: x-csrf-token
csrfExpectedSize:
Type: Number
Description: The size in bytes of the CSRF token value. For example if it's a canonically formatted UUIDv4 value the expected size would be 36 bytes/ASCII characters
Default: 36
AvailabilityZones:
Description: Availability Zone to use for the subnets in the VPC. You should select
two so that we can deploy the ALB, but we just use 1 (the first).
Type: List<AWS::EC2::AvailabilityZone::Name>
KeyPairName:
Description: Public/private key pairs allow you to securely connect to your instance
after it launches
Type: AWS::EC2::KeyPair::KeyName
PrivateSubnetCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.128.32/28
Description: CIDR block for isolated private subnet.
Type: String
PublicSubnetCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.128.0/28
Description: CIDR Block for the public DMZ subnet for secure administrative entry
Type: String
JenkinsPrivateSubnetCIDR1:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.64.16/28
Description: CIDR block for isolated private subnet.
Type: String
JenkinsPublicSubnetCIDR1:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.64.0/28
Description: CIDR Block for the public DMZ subnet for secure administrative entry
Type: String
JenkinsPrivateSubnetCIDR2:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.64.48/28
Description: CIDR block for isolated private subnet.
Type: String
JenkinsPublicSubnetCIDR2:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.64.32/28
Description: CIDR Block for the public DMZ subnet for secure administrative entry
Type: String
JenkinsVPCCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.64.0/24
Description: CIDR Block for the VPC
Type: String
RemoteAccessCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/x
Default: '0.0.0.0/0'
Description: CIDR from which access to bastion is to be permitted
Type: String
VPCCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 172.16.128.0/24
Description: CIDR Block for the VPC
Type: String
trustedSource:
Default: 86.146.158.174/32
Description: Trusted Source IP
Type: String
LatestLinuxAMI:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
Mappings:
AWSUbuntuRegionMap:
us-east-1:
Ubuntu16: ami-d15a75c7
us-west-2:
Ubuntu16: ami-746aba14
us-west-1:
Ubuntu16: ami-a9a8e4c9
eu-west-1:
Ubuntu16: ami-844e0bf7
eu-central-1:
Ubuntu16: ami-a9a557c6
ap-northeast-1:
Ubuntu16: ami-d82efcb9
ap-southeast-1:
Ubuntu16: ami-d554f1b6
ap-southeast-2:
Ubuntu16: ami-0bc1f168
AWSAMIRegionMap:
NATAMI:
AWSNATHVM: amzn-ami-vpc-nat-hvm-2017.03.0.20170401-x86_64-ebs
us-gov-west-1:
AWSNATHVM: ami-3f0a8f5e
Resources:
JenkinsVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref 'JenkinsVPCCIDR'
InstanceTenancy: default
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref 'AWS::StackName'
- Jenkins-VPC
- Key: CreatedBy
Value: GuardDuty Test Script
JenkinsNATGateway:
DependsOn: VPCGatewayAttachment
Type: AWS::EC2::NatGateway
Properties:
AllocationId:
Fn::GetAtt:
- JenkinsNatEip
- AllocationId
SubnetId:
Ref: JenkinsPublicSubnet1
JenkinsInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: CreatedBy
Value: GuardDuty Test Script
JenkinsVPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref 'JenkinsVPC'
InternetGatewayId: !Ref 'JenkinsInternetGateway'
JenkinsPrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: JenkinsVPC
CidrBlock: !Ref 'JenkinsPrivateSubnetCIDR1'
AvailabilityZone: !Select
- '0'
- !Ref 'AvailabilityZones'
Tags:
- Key: Name
Value: Private subnet
JenkinsPublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref 'JenkinsVPC'
CidrBlock: !Ref 'JenkinsPublicSubnetCIDR1'
AvailabilityZone: !Select
- '0'
- !Ref 'AvailabilityZones'
Tags:
- Key: Name
Value: Public subnet
- Key: Network
Value: Public
- Key: CreatedBy
Value: GuardDuty Test Script
MapPublicIpOnLaunch: true
JenkinsPublicSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: JenkinsVPC
CidrBlock: !Ref 'JenkinsPublicSubnetCIDR2'
AvailabilityZone: !Select
- '1'
- !Ref 'AvailabilityZones'
Tags:
- Key: Name
Value: Public subnet
- Key: Network
Value: Public
- Key: CreatedBy
Value: GuardDuty Test Script
MapPublicIpOnLaunch: true
JenkinsPrivateSubnetRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: JenkinsVPC
Tags:
- Key: Name
Value: Private subnet
- Key: Network
Value: Private
JenkinsPrivateSubnetRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref 'JenkinsPrivateSubnetRouteTable'
DestinationCidrBlock: '0.0.0.0/0'
NatGatewayId: !Ref 'JenkinsNATGateway'
JenkinsPrivateSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref 'JenkinsPrivateSubnet'
RouteTableId: !Ref 'JenkinsPrivateSubnetRouteTable'
JenkinsPublicSubnetRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: JenkinsVPC
Tags:
- Key: Name
Value: Public Subnets
- Key: Network
Value: Public
JenkinsPublicSubnetRoute:
DependsOn: JenkinsVPCGatewayAttachment
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref 'JenkinsPublicSubnetRouteTable'
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !Ref 'JenkinsInternetGateway'
JenkinsPublicSubnetRouteTableAssociation1:
DependsOn:
- JenkinsPublicSubnet1
- JenkinsPublicSubnetRouteTable
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref 'JenkinsPublicSubnet1'
RouteTableId: !Ref 'JenkinsPublicSubnetRouteTable'
JenkinsPublicSubnetRouteTableAssociation2:
DependsOn:
- JenkinsPublicSubnet2
- JenkinsPublicSubnetRouteTable
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref 'JenkinsPublicSubnet2'
RouteTableId: !Ref 'JenkinsPublicSubnetRouteTable'
JenkinsNatEip:
DependsOn: VPCGatewayAttachment
Type: AWS::EC2::EIP
Properties:
Domain: vpc
JenkinsServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ALB Security Group with HTTP access on port 80
VpcId:
Ref: JenkinsVPC
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref 'AWS::StackName'
- alb-sg
SecurityGroupIngress:
- IpProtocol: '-1'
FromPort: '8080'
ToPort: '8080'
CidrIp: !Ref 'JenkinsPublicSubnetCIDR1'
- IpProtocol: '-1'
FromPort: '8080'
ToPort: '8080'
CidrIp: !Ref 'JenkinsPublicSubnetCIDR2'
SecurityGroupEgress:
- IpProtocol: '-1'
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
- IpProtocol: '-1'
FromPort: '53'
ToPort: '53'
CidrIp: 0.0.0.0/0
WebServerGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: !Join
- '-'
- - !Ref 'AWS::StackName'
- Jenkins-ASG
Cooldown: 60
DesiredCapacity: '1'
VPCZoneIdentifier:
- !Ref 'JenkinsPrivateSubnet'
LaunchConfigurationName: !Ref 'LaunchConfig'
MinSize: '0'
MaxSize: '1'
Tags:
- Key: Name
PropagateAtLaunch: true
Value: Jenkins
- Key: CRWD_MANAGED
PropagateAtLaunch: true
Value: YES
- Key: cstag-accounting
PropagateAtLaunch: true
Value: !Ref CSAccounting
- Key: cstag-business
PropagateAtLaunch: true
Value: !Ref CSBusiness
- Key: cstag-department
PropagateAtLaunch: true
Value: !Ref CSDepartment
- Key: cstag-owner
PropagateAtLaunch: true
Value: !Ref CSOwner
TargetGroupARNs:
- !Ref 'PublicLoadBalancerTargetGroup'
LaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
Comment: Install a simple application
Properties:
KeyName: !Ref 'KeyPairName'
ImageId: !Ref 'LatestLinuxAMI'
SecurityGroups:
- !Ref 'JenkinsServerSecurityGroup'
IamInstanceProfile: !Ref JenkinsBootstrapInstanceProfile
InstanceType: m4.large
UserData:
Fn::Base64: !Sub |
#! /bin/bash
# version 2
# Added ssm role
exec > /tmp/part-001.log 2>&1
sudo cd /var/tmp
sudo wget -O initialize_webserver_aws_ami.sh https://raw.githubusercontent.com/jhseceng/secframework/master/scripts/initialize_webserver_aws_ami.sh
sudo wget -O dns-exfil.sh https://raw.githubusercontent.com/jhseceng/secframework/master/scripts/dns-exfil.sh
sudo chmod 755 initialize_webserver_aws_ami.sh
sudo chmod 755 dns-exfil.sh
sudo bash ./initialize_webserver_aws_ami.sh
JenkinsBootstrapRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: JenkinslBootstrapRolePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- cloudwatch:*
Resource:
- '*'
- Effect: Allow
Action:
- ssm:DescribeAssociation
- ssm:GetDeployablePatchSnapshotForInstance
- ssm:GetDocument
- ssm:DescribeDocument
- ssm:GetManifest
- ssm:GetParameter
- ssm:GetParameters
- ssm:ListAssociations
- ssm:ListInstanceAssociations
- ssm:PutInventory
- ssm:PutComplianceItems
- ssm:PutConfigurePackageResult
- ssm:UpdateAssociationStatus
- ssm:UpdateInstanceAssociationStatus
- ssm:UpdateInstanceInformation
Resource: '*'
- Effect: Allow
Action:
- ssmmessages:CreateControlChannel
- ssmmessages:CreateDataChannel
- ssmmessages:OpenControlChannel
- ssmmessages:OpenDataChannel
Resource: '*'
- Effect: Allow
Action:
- ec2messages:AcknowledgeMessage
- ec2messages:DeleteMessage
- ec2messages:FailMessage
- ec2messages:GetEndpoint
- ec2messages:GetMessages
- ec2messages:SendReply
Resource: '*'
JenkinsBootstrapInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref 'JenkinsBootstrapRole'
DependsOn:
- JenkinsBootstrapRole
AttackerBootstrapInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref 'AttackerIAMRole'
DependsOn:
- AttackerIAMRole
AttackerVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref 'VPCCIDR'
InstanceTenancy: default
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
Tags:
- Key: Name
Value: !Ref 'AWS::StackName'
- Key: CreatedBy
Value: GuardDuty Test Script
AttackerInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Network
Value: Public
VPCGatewayAttachment:
DependsOn:
- AttackerVPC
- AttackerInternetGateway
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: AttackerVPC
InternetGatewayId: !Ref 'AttackerInternetGateway'
AttackerPrivateSubnet:
DependsOn:
- AttackerVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: AttackerVPC
CidrBlock: !Ref 'PrivateSubnetCIDR'
AvailabilityZone: !Select
- '0'
- !Ref 'AvailabilityZones'
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref 'AWS::StackName'
- Attacker-VPC
- Key: Network
Value: Private
- Key: CreatedBy
Value: GuardDuty Test Script
AttackerPublicSubnet:
DependsOn: AttackerVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: AttackerVPC
CidrBlock: !Ref 'PublicSubnetCIDR'
AvailabilityZone: !Select
- '0'
- !Ref 'AvailabilityZones'
Tags:
- Key: Name
Value: Public subnet
- Key: Network
Value: Public
- Key: CreatedBy
Value: GuardDuty Test Script
MapPublicIpOnLaunch: true
AttackerPublicSubnetRouteTable:
DependsOn: AttackerVPC
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: AttackerVPC
Tags:
- Key: Name
Value: Public Subnets
- Key: Network
Value: Public
AttackerPublicSubnetRoute:
DependsOn:
- VPCGatewayAttachment
- AttackerVPC
Type: AWS::EC2::Route
Properties:
RouteTableId:
Ref: AttackerPublicSubnetRouteTable
DestinationCidrBlock: '0.0.0.0/0'
GatewayId:
Ref: AttackerInternetGateway
AttackerPublicSubnetRouteTableAssociation:
DependsOn: AttackerVPC
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: AttackerPublicSubnet
RouteTableId:
Ref: AttackerPublicSubnetRouteTable
AttackerSecurityGroup:
DependsOn: AttackerVPC
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enables Admin Access to basic linux hosts
VpcId:
Ref: AttackerVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'trustedSource'
- IpProtocol: tcp
FromPort: '5000'
ToPort: '5000'
CidrIp: '0.0.0.0/0'
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: '0.0.0.0/0'
AttackerIAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: JenkinslBootstrapRolePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: sts:*
Resource: "*"
- Sid: VisualEditor0
Effect: Allow
Action:
- ec2:DescribeInstances
- ssm:ListCommands
- logs:Describe*
- logs:StartQuery
- ssm:DescribeInstancePatches
- ssm:ListInstanceAssociations
- securityhub:BatchUpdateFindings
- ssm:ListInstanceAssociations
- securityhub:ListEnabledProductsForImport
- ssm:GetParameter
- guardduty:ListInvitations
- ssm:GetMaintenanceWindowExecutionTaskInvocation
- ssm:UpdateAssociationStatus
- ssm:DescribeAutomationExecutions
- ssm:GetMaintenanceWindowTask
- ssm:DescribeAutomationStepExecutions
- ssm:UpdateInstanceInformation
- logs:FilterLogEvents
- ssm:PutComplianceItems
- ssm:GetConnectionStatus
- ssm:GetMaintenanceWindowExecutionTask
- logs:List*
- ssm:GetOpsItem
- ssm:GetMaintenanceWindowExecution
- ec2messages:AcknowledgeMessage
- logs:StopQuery
- ssm:GetParameters
- logs:Get*
- ssm:DescribeOpsItems
- ssm:DescribeEffectivePatchesForPatchBaseline
- ssm:GetServiceSetting
- ssm:DescribeAssociationExecutions
- ec2messages:SendReply
- ssm:DescribeDocumentPermission
- ssm:ListCommandInvocations
- ssm:GetAutomationExecution
- ssm:GetDefaultPatchBaseline
- ssm:DescribeDocument
- ec2messages:GetEndpoint
- ssmmessages:OpenControlChannel
- ec2messages:GetMessages
- ssm:GetPatchBaselineForPatchGroup
- ssm:PutConfigurePackageResult
- ssm:DescribePatchGroupState
- ssm:GetManifest
- ec2messages:DeleteMessage
- ec2messages:FailMessage
- ssm:DescribeInstancePatchStates
- ssm:DescribeInstancePatchStatesForPatchGroup
- ssmmessages:OpenDataChannel
- ssm:GetDocument
- ssm:GetInventorySchema
- ssm:GetParametersByPath
- ssm:GetMaintenanceWindow
- ssm:DescribeInstanceAssociationsStatus
- ssm:DescribeAssociationExecutionTargets
- ssm:DescribeInstanceProperties
- ssm:GetPatchBaseline
- ssm:DescribeAssociation
- guardduty:ListDetectors
- ssm:GetDeployablePatchSnapshotForInstance
- ssm:GetParameterHistory
- logs:TestMetricFilter
- ssmmessages:CreateControlChannel
- ssm:DescribeEffectiveInstanceAssociations
- ssm:DescribeInventoryDeletions
- ssm:GetInventory
- ssm:GetOpsSummary
- ssm:DescribeActivations
- ssm:GetCommandInvocation
- ssmmessages:CreateDataChannel
- ssm:PutInventory
- ssm:DescribeInstanceInformation
- ssm:ListTagsForResource
- ssm:DescribeDocumentParameters
- guardduty:ListOrganizationAdminAccounts
- ssm:ListAssociations
- ssm:UpdateInstanceAssociationStatus
- ssm:DescribeAvailablePatches
Resource: "*"
- Sid: VisualEditor1
Effect: Allow
Action:
- ssm:SendCommand
- guardduty:GetFindings
- guardduty:ListThreatIntelSets
- ssm:ListDocumentVersions
- ssm:DescribeDocument
- guardduty:ListFindings
- ssm:GetParameters
- guardduty:GetDetector
- ssm:GetParameter
- ssm:StartSession
- ssm:PutParameter
- ssm:RemoveTagsFromResource
- ssm:AddTagsToResource
- ssm:ListTagsForResource
- ssm:DescribeDocumentParameters
- ssm:DescribeDocumentPermission
- guardduty:ListFilters
- guardduty:ListPublishingDestinations
- guardduty:GetFilter
- guardduty:ListTagsForResource
- guardduty:ListMembers
Resource:
- arn:aws:guardduty:*:*:detector/*
- arn:aws:ssm:*:*:document/*
- arn:aws:ec2:*:*:instance/*
- arn:aws:ssm:*:*:parameter/*
- arn:aws:ssm:*:*:patchbaseline/*
- arn:aws:ssm:*:*:maintenancewindow/*
- Sid: VisualEditor2
Effect: Allow
Action:
- ssm:SendCommand
- ssm:PutParameter
- ssm:ListDocumentVersions
- ssm:DescribeDocument
- ssm:RemoveTagsFromResource
- ssm:AddTagsToResource
- ssm:ListTagsForResource
- ssm:DescribeDocumentParameters
- ssm:DescribeDocumentPermission
- ssm:GetParameters
- ssm:GetParameter
- ssm:StartSession
Resource: arn:aws:ssm:*:*:managed-instance/*
FigEIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
AssociateFigEIP:
Type: AWS::EC2::EIPAssociation
DependsOn: FigEIP
Properties:
AllocationId: !GetAtt FigEIP.AllocationId
NetworkInterfaceId: !Ref 'FigNetInt'
FigNetInt:
DependsOn: AttackerVPC
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref 'AttackerPublicSubnet'
GroupSet:
- !Ref 'AttackerSecurityGroup'
Fig:
DependsOn:
- "FigNetInt"
Type: AWS::EC2::Instance
Properties:
KeyName: !Ref 'KeyPairName'
NetworkInterfaces:
- NetworkInterfaceId: !Ref 'FigNetInt'
DeviceIndex: '0'
UserData:
Fn::Base64: !Sub |
#! /bin/bash
# version 3.0
# export account id and region on instance startup
# Added region and cloudwatch log group
exec > /tmp/part-001.log 2>&1
cat > /etc/profile.d/load_env.sh << 'EOF'
export ATTACKER=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
export VICTIM=${PublicLoadBalancer.DNSName}
export REGION=${AWS::Region}
export LOG_GROUP=${LogGroup}
EOF
sudo cd /var/tmp
sudo wget -O initialize_fig.sh https://raw.githubusercontent.com/jhseceng/secframework/master/scripts/initialize_fig_aws_ami.sh
sudo wget -O dns-exfil.sh https://raw.githubusercontent.com/jhseceng/secframework/master/scripts/dns-exfil.sh
sudo chmod 755 initialize_fig.sh
sudo chmod 755 dns-exfil.sh
sudo bash ./initialize_fig.sh -r ${AWS::Region}
InstanceType: m4.large
AvailabilityZone: !Select
- '0'
- !Ref 'AvailabilityZones'
IamInstanceProfile: !Ref AttackerBootstrapInstanceProfile
ImageId: !Ref 'LatestLinuxAMI'
Tags:
- Key: Name
Value: Fig
- Key: CRWD_MANAGED
Value: YES
- Key: cstag-accounting
Value: !Ref CSAccounting
- Key: cstag-business
Value: !Ref CSBusiness
- Key: cstag-department
Value: !Ref CSDepartment
- Key: cstag-owner
Value: !Ref CSOwner
AttackerEIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
AssociateAttackerEIP:
DependsOn: AttackerEIP
Type: AWS::EC2::EIPAssociation
Properties:
AllocationId: !GetAtt AttackerEIP.AllocationId
NetworkInterfaceId: !Ref 'AttackerNetInt'
AttackerNetInt:
DependsOn: AttackerVPC
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref 'AttackerPublicSubnet'
GroupSet:
- !Ref 'AttackerSecurityGroup'
Attacker:
DependsOn:
- "AttackerNetInt"
Type: AWS::EC2::Instance
Properties:
KeyName: !Ref 'KeyPairName'
NetworkInterfaces:
- NetworkInterfaceId: !Ref 'AttackerNetInt'
DeviceIndex: '0'
UserData:
Fn::Base64: !Sub |
#! /bin/bash
# version 3.0
# export account id and region on instance startup
# Added region and cloudwatch log group
exec > /tmp/part-001.log 2>&1
cat > /etc/profile.d/load_env.sh << 'EOF'
export ATTACKER=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
export VICTIM=${PublicLoadBalancer.DNSName}
export REGION=${AWS::Region}
export LOG_GROUP=${LogGroup}
EOF
sudo cd /var/tmp
sudo wget -O initialize_attacker.sh https://raw.githubusercontent.com/jhseceng/secframework/master/scripts/initialize_attacker_aws_ami.sh
sudo wget -O dns-exfil.sh https://raw.githubusercontent.com/jhseceng/secframework/master/scripts/dns-exfil.sh
sudo chmod 755 initialize_attacker.sh
sudo chmod 755 dns-exfil.sh
sudo bash ./initialize_attacker.sh -v ${PublicLoadBalancer.DNSName} -r ${AWS::Region} -l ${LogGroup}
InstanceType: m4.large
AvailabilityZone: !Select
- '0'
- !Ref 'AvailabilityZones'
IamInstanceProfile: !Ref AttackerBootstrapInstanceProfile
ImageId: !Ref 'LatestLinuxAMI'
Tags:
- Key: Name
Value: Attacker
- Key: CRWD_MANAGED
Value: YES
- Key: cstag-accounting
Value: !Ref CSAccounting
- Key: cstag-business
Value: !Ref CSBusiness
- Key: cstag-department
Value: !Ref CSDepartment
- Key: cstag-owner
Value: !Ref CSOwner
PublicLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Join
- ''
- - !Ref 'AWS::StackName'
- Jenkins-ALB
SecurityGroups:
- !Ref 'PublicLoadBalancerSecurityGroup'
Subnets:
- !Ref 'JenkinsPublicSubnet1'
- !Ref 'JenkinsPublicSubnet2'
Scheme: internet-facing
DependsOn:
- JenkinsVPC
- JenkinsInternetGateway
- PublicLoadBalancerSecurityGroup
- JenkinsPublicSubnet1
- JenkinsPublicSubnet2
PublicLoadBanlancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref 'PublicLoadBalancerTargetGroup'
LoadBalancerArn: !Ref 'PublicLoadBalancer'
Port: '80'
Protocol: HTTP
PublicLoadBalancerTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 60
UnhealthyThresholdCount: 10
HealthCheckProtocol: HTTP
HealthCheckPort: '8080'
HealthCheckPath: /
Matcher:
HttpCode: '200'
Port: 8080
Protocol: HTTP
VpcId:
Ref: JenkinsVPC
PublicLoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Public ALB Security Group with HTTP access on port 80 from
the internet
VpcId:
Ref: JenkinsVPC
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref 'AWS::StackName'
- PublicLoadBalancerSecurityGroup
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'