Pwn cheatsheet
GDB
Many different useful commands to know to work with GDB
:
start
: start the program with a breakpoint atmain
orstart
ni
: next instructionsi
: step instructionx/[%d][ixdsb]{Address}
: display value at memory addressb {address}
sets breakpoint at the addressrun
: runs the binary, stops at breakpointdisassemble {disas}
: disassemble the current functionset {address} = {val}
: sets value at the addressheap bins
: shows current heapstack
: shows current stack
PWNTOOLS
Python library with simple socket/process control, has many features:
shellcode
- Address lookup
- Easy
GBD
interaction - …
Can also use the
cyclic
utility ofpwntools
to find out the size of the buffer we’re trying to overflow:
cyclic 100 # gives 100 random character
cyclic -l iaaa # finds the index of this sequence
Example
To overflow a buffer of 48 characters, we can use the following exploit.py
file:
from pwn import *
p = process('./a.out')
gdb.attach(p)
p.sendLine('a'*48 + p32(0xcafebabe))
p.interactive()
Buffer overflows
Either Stack
based or Heap
based –> occurs from miscalculations and can cause too much data to be read in.
–> We can check what security are enabled on a binary with:
checksec mc
[*] '/home/test/minio-binaries/mc'
Arch: amd64-64-little
RELRO: No RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
Format strings
Format specifiers
printf
-> argument basedscanf
-> dangerous if user controlled%p
displays the value in hex%n
writes amount of characters printed$
control which stack value to use
Global Offset Table
- Dynamically linked
- Need to look up function address because of
ASLR
got
command inGDB
PLT
= position lookup table –> location that is jumped to during a call, references the GOT
==> Sometimes we can write the GOT
–> allows us to control a function pointer, PLT
can be jumped directly
LIBC
Contains most functions called in a program, also includes functions such as system
or the string bin/sh\x00
–> Important to use correct version as it changes the functions offset
Can lookup the version at libc.blukat.me
==> To show where in memory files are loaded:
vmmap