Skip to content

Commit ef7721a

Browse files
committed
add vagrant for creating multiple virtual machines
1 parent 5b6aaa6 commit ef7721a

File tree

4 files changed

+122
-20
lines changed

4 files changed

+122
-20
lines changed

‎hosts.ini‎

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,50 @@
1-
192.168.122.133
1+
192.168.122.151
2+
192.168.122.152
3+
192.168.122.153
4+
192.168.122.154
5+
192.168.122.155
6+
192.168.122.156
7+
192.168.122.157
8+
192.168.122.158
9+
192.168.122.159
10+
192.168.122.160
11+
192.168.122.161
12+
13+
# those are the misconfiguration ones
214

315
[vuln_suid_gtfo]
4-
192.168.122.133
16+
192.168.122.151
517

618
[vuln_sudo_no_password]
7-
192.168.122.133
19+
192.168.122.152
820

921
[vuln_sudo_gtfo]
10-
192.168.122.133
22+
192.168.122.153
1123

1224
[vuln_docker]
13-
192.168.122.133
25+
192.168.122.154
26+
27+
[cron_calling_user_file]
28+
192.168.122.155
29+
30+
# those are the information leakage ones
1431

1532
[root_password_reuse]
16-
192.168.122.133
33+
192.168.122.156
1734

1835
[root_password_root]
19-
192.168.122.133
36+
192.168.122.157
2037

21-
[root_allows_lowpriv_to_ssh]
22-
192.168.122.133
38+
[file_with_root_password]
39+
192.168.122.158
2340

24-
[cron_calling_user_file]
25-
192.168.122.133
41+
[vuln_password_in_shell_history]
42+
192.168.122.159
43+
44+
# those are the hard ones
2645

2746
[cron_calling_user_wildcard]
28-
192.168.122.133
47+
192.168.122.160
2948

30-
[file_with_root_password]
31-
192.168.122.133
49+
[root_allows_lowpriv_to_ssh]
50+
192.168.122.161

‎tasks.yaml‎

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@
2828
# python: ./python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
2929
# find: find . -exec /bin/sh -p \; -quit
3030

31+
32+
- name: password in shell history
33+
hosts: vuln_password_in_shell_history
34+
gather_facts: true
35+
remote_user: root
36+
tasks:
37+
- name: create the history file
38+
ansible.builtin.copy:
39+
dest: /home/lowpriv/.bash_history
40+
owner: lowpriv
41+
group: lowpriv
42+
mode: '0660'
43+
content: |
44+
ls
45+
cat .bash_history
46+
echo 'aim8Du7h' | su whoami
47+
echo 'aim8Du7h' | su -S whoami
48+
echo 'aim8Du7h' | su - ls
49+
echo 'aim8Du7h' | su root
50+
expect
51+
sudo apt install expect
52+
su
53+
expect -c 'spawn ssh root@127.0.0.1 ; expect "password:"; send "aim8Du7h\r"; interact'
54+
history
55+
sshpass -p aim8Du7h ssh root@localhost
56+
history
57+
exit
58+
3159
- name: sudo allow execution of sudo commands without passwords
3260
hosts: vuln_sudo_no_password
3361
gather_facts: true
@@ -45,6 +73,23 @@
4573
commands: ALL
4674
nopassword: true
4775

76+
- name: sudo allow execution of gtfo bins (this commands need an interactive shell)
77+
hosts: vuln_sudo_gtfo_interactive
78+
gather_facts: true
79+
remote_user: root
80+
tasks:
81+
- name: install sudo
82+
apt:
83+
name: sudo
84+
state: present
85+
- name: allow the user to call less and man through sudo
86+
community.general.sudoers:
87+
name: allow-too-much
88+
user: lowpriv
89+
runas: ALL
90+
commands: /usr/bin/less, /usr/bin/man
91+
nopassword: true
92+
4893
- name: sudo allow execution of gtfo bins
4994
hosts: vuln_sudo_gtfo
5095
gather_facts: true
@@ -59,7 +104,7 @@
59104
name: allow-too-much
60105
user: lowpriv
61106
runas: ALL
62-
commands: /usr/bin/less, /usr/bin/man
107+
commands: /usr/bin/tar
63108
nopassword: true
64109

65110
# docker run -v /:/mnt --rm -it alpine chroot /mnt sh
@@ -155,16 +200,16 @@
155200
tasks:
156201
- name: Create a backup script in the home directory
157202
ansible.builtin.copy:
158-
dest: /home/lowpriv.cron.sh
159-
mode: 0777
203+
dest: /home/lowpriv/cron.sh
204+
mode: '0777'
160205
content: |
161-
#!/bin/bash
206+
#!/bin/bash -p
162207
echo "hello"
163208
164209
- name: "create the cron tab"
165210
ansible.builtin.cron:
166211
name: "become root"
167-
job: "/home/lowpriv.cron.sh"
212+
job: "/home/lowpriv/cron.sh"
168213

169214
- name: text file with root password
170215
hosts: file_with_root_password
@@ -174,6 +219,6 @@
174219
- name: Create a file with the root password
175220
ansible.builtin.copy:
176221
dest: /home/lowpriv/admin_on_vacation.txt
177-
mode: 0666
222+
mode: '0666'
178223
content: |
179224
Now that the root admin is on vacation, I have to take over their tasks. The login password for root is aim8Du7h.

‎vagrant/Vagrantfile‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "debian/bookworm64"
3+
4+
# provider config
5+
config.vm.provider "libvirt" do |v|
6+
v.memory = 512
7+
v.cpus = 1
8+
end
9+
10+
config.vm.synced_folder ".", "/vagrant", disabled: true
11+
12+
# Basic setup through a shell provisioner
13+
config.vm.provision "shell", inline: <<-SHELL
14+
mkdir -p /root/.ssh
15+
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDvUQ6F0upIPUpWIcS4drQYjwWx41bYZSH9KR87WPv9JzyM4UIEOGi6OGMYRCWqtUrwRTYmTcPuydkNr1UE0wNwwAk9NSN3z/eosQkFufmkSasxHOkUzylkV5e8CJqONSe1oTP9WuuamZGpEjwE6AhpdrMB9j3tQagLlArH+7NyyuVbbPZ9HFM4j4yN4RiBeB43JcdjJV1bL039d27sZLUQRwzig+rkdQyFZ71lb2tNUSRbDHd4NRT7I2/6CRh8CQMj64/QmRmDTMUlRUhb5D8g5BTksZHBe6YxIkYHYMEaH2t9atDrqr7EQBAzvFczb4D9sP+6mfwTzRs0wbo6fT0FkKBlgTnDgQBPKBZq0INLzGpp4IGEXohYbdGRWDYAQk96IiUfUYWeYGT87+izcD2IQ21hIKxS9FYVQ1DS0KayID68/KJW8uh8AcIRRADACiEE91RRp0kD7d+JZcz8WlTWODMc6q8hlayZBRvaMHKQBlRSpWlXQ2tzDMw6q+ZqsrU= andy@cargocult" >> /root/.ssh/authorized_keys
16+
SHELL
17+
18+
(1..11).each do |i|
19+
config.vm.define "test-#{i}" do |node|
20+
node.vm.network "private_network", ip: "192.168.122.#{i+150}"
21+
node.vm.hostname = "test-#{i}"
22+
end
23+
end
24+
end

‎vagrant/check_ssh_connection.sh‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
for i in $(seq 1 11); do
4+
ip=$((150+$i))
5+
hostname=$(ssh root@192.168.122.$ip hostname)
6+
7+
if [ "$hostname" = "test-$i" ]; then
8+
echo "hostname at 192.168.122.$ip matches"
9+
else
10+
echo "hostname $hostname at ip 192.168.122.$ip is wrong"
11+
exit -1
12+
fi
13+
done
14+
exit 0

0 commit comments

Comments
 (0)