Skip to content

Commit 4c9e526

Browse files
committed
lab updates
1 parent d92f653 commit 4c9e526

6 files changed

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

512
Vault
523
=====
@@ -59,6 +10,7 @@ Vault KV
5910
```bash
6011
# verify creds
6112
vault status
13+
# vault operator unseal
6214
vault login
6315

6416
# Store secret
@@ -91,36 +43,11 @@ curl -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" http://
9143
```
9244

9345

94-
9546
Vault PostgresQL Integration
9647
============================
9748

9849
~ 20 min
9950

100-
Setup DB
101-
```shell
102-
root@debian12:~# sudo -u postgres psql -c "create role vault with login superuser password 'insecure'";
103-
could not change directory to "/root": Permission denied
104-
CREATE ROLE
105-
106-
root@debian12:~# psql --user vault --password --host 172.26.7.80 --db secure_db
107-
Password:
108-
psql (15.12 (Debian 15.12-0+deb12u2))
109-
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
110-
Type "help" for help.
111-
112-
secure_db=# create table users (name VARCHAR(255));
113-
CREATE TABLE
114-
secure_db=# insert into users values ('john doe');
115-
INSERT 0 1
116-
secure_db=# select * from users;
117-
name
118-
----------
119-
john doe
120-
(1 row)
121-
122-
secure_db=# exit
123-
```
12451

12552
Configure vault
12653
```shell
@@ -159,3 +86,77 @@ secure_data=> INSERT INTO users VALUES ('ratata');
15986
ERROR: permission denied for table users
16087
```
16188

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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3+
4+
if [ "$EUID" -ne 0 ]
5+
then echo "Please run as root"
6+
exit
7+
fi
8+
9+
310
cd /
411
apt-get update
512
apt-get install -y gpg
@@ -8,7 +15,7 @@ wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/sh
815
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
916

1017
apt-get update
11-
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
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
1219

1320
apt-get install -y diffoscope-minimal --no-install-suggests --no-install-recommends
1421
pip install build==1.2.1 wheel==0.43.0 setuptools==61.0 --break-system-packages
@@ -23,8 +30,8 @@ echo "host all all ::/0 s
2330
#PG_PASSWD=$(openssl rand -hex 16)
2431
sudo -u postgres createdb secure_db
2532
sudo -u postgres psql -c "create role vault with login superuser password 'not_so_secure_default_password'";
26-
sudo -u postgres psql -c --db secure_db "create table users (name VARCHAR(255));";
27-
sudo -u postgres psql -c --db secure_db "insert into users values ('john doe');";
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');";
2835
systemctl restart postgresql
2936

3037
#pip3 install build --break-system-packages

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)