Skip to content

Commit a7a5319

Browse files
authored
Merge pull request #1 from SourceCode-AI/stratus
Stratus
2 parents c95dcd3 + 4c9e526 commit a7a5319

8 files changed

Lines changed: 130 additions & 97 deletions

File tree

README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,23 @@ NOTICE: this repository also contains malware samples, it is possible your AV so
99
Instructions & prerequisites:
1010
-----------------------------
1111

12-
- [docker compose](https://docs.docker.com/compose/)
13-
- copy of this repository
14-
- all the commands should be run in the same directory hwere you cloned the repository. docker compose will pick up the configuration file automatically
15-
- run `docker compose pull` to pull the dependencies
16-
- run `docker compose build` to build the custom container with preinstalled tools
12+
- Access to Stratus (stratus.fi.muni.cz)
13+
- make sure to configure your SSH key under Settings -> Auth -> Public SSH Key
1714

18-
- if there are updates, you need to re-run this step, run `docker compose down` first to remove any previous work
15+
![sshkey.png](sshkey.png)
1916

20-
- run `docker compose up -d` to start the containers. You should see containers `postgres` and `vault` as running in logs.
2117

22-
- Check that there is no error in those two containers!
23-
- run `docker compose down` to shutdown the running containers
2418

25-
- shutting down all containers will also remove all data, all work/modifications you have done will be reset
26-
- you can use this to reset your environment if you misconfigure something
19+
Installation:
20+
---
2721

28-
- you are now ready for the exercise!
22+
Create a Debian12 VM machine with the default options:
2923

24+
![vm_creation.png](vm_creation.png)
3025

31-
Manual installation
32-
-------------------
3326

34-
If there is a problem with the docker compose containers or you wish to not use the docker then the following software is required:
35-
36-
- password protected PostgreSQL instance + postgres client
37-
- [Hashicorp Vault](https://www.vaultproject.io)
38-
- python3 with venv, build and pip modules installed
39-
- [diffoscope & strip-nondeterminism tools](https://reproducible-builds.org/tools/)
40-
- gcc
41-
42-
You can also refer to the included docker configuration files which basically contains installation instructions of all dependencies into ubuntu
27+
When the VM boots up, login via ssh and run the following command:
4328

29+
```shell
30+
curl "https://raw.githubusercontent.com/SourceCode-AI/secure_coding/refs/heads/master/install_debian.sh"|bash
31+
```

cheat_sheet.md

Lines changed: 77 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,3 @@
1-
Reproducible builds exercise
2-
============================
3-
4-
Reproducing a package ~ 20min
5-
6-
Exec inside the container `docker compose run --rm -ti secure_coding /bin/bash`
7-
8-
```shell
9-
root@7ccad3d01d39:/# cd /local_data/python_package/
10-
11-
root@7ccad3d01d39:/local_data/python_package# ls
12-
pyproject.toml secure_coding_demo_package
13-
14-
root@7ccad3d01d39:/local_data/python_package# python3 -m build
15-
...
16-
Successfully built secure_coding_demo_package-0.0.1.tar.gz and secure_coding_demo_package-0.0.1-py3-none-any.whl
17-
18-
19-
root@7ccad3d01d39:/local_data/python_package# diffoscope dist/secure_coding_demo_package-0.0.1-py3-none-any.whl /local_data/prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
20-
21-
root@7ccad3d01d39:/local_data/python_package# mkdir /local_data/html
22-
root@7ccad3d01d39:/local_data/python_package# diffoscope dist/secure_coding_demo_package-0.0.1-py3-none-any.whl /local_data/prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl --html-dir /local_data/html
23-
24-
root@7ccad3d01d39:/local_data/python_package# strip-nondeterminism dist/secure_coding_demo_package-0.0.1-py3-none-any.whl
25-
root@7ccad3d01d39:/local_data/python_package# diffoscope dist/secure_coding_demo_package-0.0.1-py3-none-any.whl /local_data/prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
26-
root@7ccad3d01d39:/local_data/python_package# md5sum dist/secure_coding_demo_package-0.0.1-py3-none-any.whl /local_data/prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
27-
28-
e11a303eef41e70032b4130652e740be dist/secure_coding_demo_package-0.0.1-py3-none-any.whl
29-
e11a303eef41e70032b4130652e740be /local_data/prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
30-
```
31-
32-
33-
compare compiled code ~5 min
34-
```shell
35-
root@8157f590f783:/# cd /local_data/
36-
root@8157f590f783:/local_data# diff hello_world.c malwaretest.c
37-
4c4
38-
< printf("Hello world\n");
39-
---
40-
> printf("malwaretest\n");
41-
42-
43-
gcc hello_world.c -o a.out
44-
gcc malwaretest.c -o b.out
45-
46-
diffoscope a.out b.out
47-
48-
```
49-
50-
CTX Malware exercise ~ 15 min
51-
521

532
Vault
543
=====
@@ -60,13 +9,8 @@ Vault KV
609

6110
```bash
6211
# verify creds
63-
64-
docker compose logs vault
65-
66-
docker compose exec -ti vault /bin/sh
67-
68-
6912
vault status
13+
# vault operator unseal
7014
vault login
7115

7216
# Store secret
@@ -99,25 +43,11 @@ curl -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" http://
9943
```
10044

10145

102-
10346
Vault PostgresQL Integration
10447
============================
10548

10649
~ 20 min
10750

108-
Setup DB
109-
```shell
110-
docker compose exec -ti vault /bin/sh
111-
apk add postgresql-client
112-
113-
/ # psql -h postgres -U postgres
114-
Password for user postgres: not_so_secure_default_password
115-
postgres=# create database secure_data;
116-
postgres=# \c secure_data;
117-
secure_data=# create table users (name VARCHAR(255));
118-
secure_data=# \q
119-
120-
```
12151

12252
Configure vault
12353
```shell
@@ -129,8 +59,8 @@ Success! Enabled the database secrets engine at: database/
12959
/ # vault write database/config/secure_db \
13060
plugin_name="postgresql-database-plugin" \
13161
allowed_roles="secure_coding_role" \
132-
connection_url="postgresql://{{username}}:{{password}}@postgres:5432/secure_data" \
133-
username="postgres" \
62+
connection_url="postgresql://{{username}}:{{password}}@<YOUR_IP>:5432/secure_db?sslmode=disable" \
63+
username="vault" \
13464
password="not_so_secure_default_password"
13565
Success! Data written to: database/config/secure_db
13666

@@ -156,3 +86,77 @@ secure_data=> INSERT INTO users VALUES ('ratata');
15686
ERROR: permission denied for table users
15787
```
15888

89+
90+
91+
Reproducible builds exercise
92+
============================
93+
94+
Reproducing a package ~ 20min
95+
96+
```shell
97+
root@debian12:/secure_coding# cd /secure_coding/local_data/
98+
root@debian12:/secure_coding/local_data# tree
99+
.
100+
├── hello_world.c
101+
├── malwaretest.c
102+
├── prebuild_package
103+
│   └── secure_coding_demo_package-0.0.1-py3-none-any.whl
104+
└── python_package
105+
├── pyproject.toml
106+
└── secure_coding_demo_package
107+
├── __init__.py
108+
└── sneaky_package
109+
└── __init__.py
110+
111+
5 directories, 6 files
112+
113+
114+
root@debian12:/secure_coding/local_data# cd python_package/
115+
root@debian12:/secure_coding/local_data/python_package# python3 -m build
116+
...
117+
Successfully built secure_coding_demo_package-0.0.1.tar.gz and secure_coding_demo_package-0.0.1-py3-none-any.whl
118+
119+
120+
root@debian12:/secure_coding/local_data/python_package# strip-nondeterminism dist/secure_coding_demo_package-0.0.1-py3-none-any.whl
121+
root@debian12:/secure_coding/local_data/python_package# strip-nondeterminism dist/secure_coding_demo_package-0.0.1-py3-none-any.whl
122+
root@debian12:/secure_coding/local_data/python_package# diffoscope dist/secure_coding_demo_package-0.0.1-py3-none-any.whl ../prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
123+
root@debian12:/secure_coding/local_data/python_package# md5sum dist/secure_coding_demo_package-0.0.1-py3-none-any.whl ../prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
124+
81cab8eab03f8255a8c05bb014c40824 dist/secure_coding_demo_package-0.0.1-py3-none-any.whl
125+
81cab8eab03f8255a8c05bb014c40824 ../prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl
126+
127+
root@7ccad3d01d39:/secure_coding/python_package# mkdir /secure_coding/html
128+
root@7ccad3d01d39:/secure_coding/python_package# diffoscope dist/secure_coding_demo_package-0.0.1-py3-none-any.whl /secure_coding/prebuild_package/secure_coding_demo_package-0.0.1-py3-none-any.whl --html-dir /local_data/html
129+
130+
131+
```
132+
133+
134+
compare compiled code ~5 min
135+
```shell
136+
root@debian12:/secure_coding/local_data# cd /secure_coding/local_data/
137+
root@debian12:/secure_coding/local_data# ls
138+
hello_world.c malwaretest.c prebuild_package python_package
139+
root@debian12:/secure_coding/local_data# cat hello_world.c
140+
root@debian12:/secure_coding/local_data# cat malwaretest.c
141+
142+
root@debian12:/secure_coding/local_data# gcc hello_world.c -o a.out
143+
root@debian12:/secure_coding/local_data# gcc malwaretest.c -o b.out
144+
root@debian12:/secure_coding/local_data# ls
145+
a.out b.out hello_world.c malwaretest.c prebuild_package python_package
146+
root@debian12:/secure_coding/local_data# diffoscope a.out b.out
147+
148+
```
149+
150+
CTX Malware exercise ~ 15 min
151+
---
152+
153+
154+
```shell
155+
root@debian12:/secure_coding/local_data# mkdir /var/www/html/diffoscope
156+
root@debian12:/secure_coding/local_data# diffoscope a.out wannabe_ransomware --html-dir /var/www/html/diffoscope
157+
158+
root@debian12:/secure_coding# cd /secure_coding/malware/
159+
root@debian12:/secure_coding/malware# ls
160+
b40297af54e3f99b02e105f013265fd8d0a1b1e1f7f0b05bcb5dbdc9125b3bb5.gz ctx-0.1.2.tar.gz
161+
root@debian12:/secure_coding/malware# diffoscope ctx-0.1.2.tar.gz b40297af54e3f99b02e105f013265fd8d0a1b1e1f7f0b05bcb5dbdc9125b3bb5.gz
162+
```

install_debian.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
4+
if [ "$EUID" -ne 0 ]
5+
then echo "Please run as root"
6+
exit
7+
fi
8+
9+
10+
cd /
11+
apt-get update
12+
apt-get install -y gpg
13+
14+
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
15+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
16+
17+
apt-get update
18+
apt-get install -y nano gcc wget jq screen python3-venv python3-pip strip-nondeterminism tree postgresql postgresql-client vault git python3-pip xxd binutils-multiarch openssl nginx
19+
20+
apt-get install -y diffoscope-minimal --no-install-suggests --no-install-recommends
21+
pip install build==1.2.1 wheel==0.43.0 setuptools==61.0 --break-system-packages
22+
23+
git clone https://github.com/SourceCode-AI/secure_coding.git /secure_coding
24+
25+
echo "listen_addresses='*'">>/etc/postgresql/15/main/postgresql.conf
26+
27+
echo "host all all 0.0.0.0/0 scram-sha-256">>/etc/postgresql/15/main/pg_hba.conf
28+
echo "host all all ::/0 scram-sha-256">>/etc/postgresql/15/main/pg_hba.conf
29+
30+
#PG_PASSWD=$(openssl rand -hex 16)
31+
sudo -u postgres createdb secure_db
32+
sudo -u postgres psql -c "create role vault with login superuser password 'not_so_secure_default_password'";
33+
sudo -u postgres psql --db secure_db -c "create table users (name VARCHAR(255));";
34+
sudo -u postgres psql --db secure_db -c "insert into users values ('john doe');";
35+
systemctl restart postgresql
36+
37+
#pip3 install build --break-system-packages
38+
echo "export VAULT_SKIP_VERIFY=true">>/etc/bash.bashrc
39+
echo "export VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200">>/etc/bash.bashrc
40+
echo "export VAULT_ADDR=http://127.0.0.1:8200">>/etc/bash.bashrc
41+
touch /tmp/automation_finished
Binary file not shown.

local_data/python_package/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ requires-python = ">=3.9"
1313

1414

1515
[build-system]
16-
requires = ["setuptools>=61.0"]
16+
requires = ["setuptools==61.0", "wheel==0.43.0"]
1717
build-backend = "setuptools.build_meta"

local_data/wannabe_ransomware

15.7 KB
Binary file not shown.

sshkey.png

191 KB
Loading

vm_creation.png

366 KB
Loading

0 commit comments

Comments
 (0)