
HeapInfo
As pwn lovers, while playing CTF with heap exploitation, we always need a debugger (e.g. gdb) for tracking memory layout. But we don't really need gdb if we want to see whether the heap layout same as our imagine or not. Hope this small tool helps us exploit easier ;).
Why
HeapInfo is very helpful when binary has somehow anti-debugger limitations, e.g. being ptraced.
HeapInfo still works because it doesn't use ptrace.
Implement with Ruby because I love Ruby :P. But might implement with Python (if no others did) in the future.
If you prefer pwntools for exploiting, you can still use HeapInfo in irb/pry as a small debugger.
Any suggestion of features or bug issues are welcome.
Install
HeapInfo is still under developing for more features, so the version might change frequently :p
$ gem install heapinfo
Features
- Can use in your ruby exploit script or in irb/pry.
- HeapInfo works when
victim
is being traced! i.e. you can use ltrace/strace/gdb and HeapInfo simultaneously!
dump
- Dump arbitrarily address memory.
layouts
- Show the current bin layouts, very useful for heap exploitation.
offset
- Show the offset between given address and segment. Very useful for calculating relative offset.
canary
- Fetch the value of stack guard!
x
- Provide gdb-like command.
s
- Provide gdb-like command.
find
- Provide gdb-like command.
- More features and details can be found in RDoc
Usage
Load
require 'heapinfo'
h = heapinfo('victim')
"%#x" % h.libc.base
h.libc.name
"%#x" % h.elf.base
"%#x" % h.heap.base
NOTICE: While the process is not found, most methods will return nil
. One way to prevent some error happend is to wrapper methods within debug
, the block will be ignored while doing remote exploitation.
h = heapinfo('remote')
h.pid
h.debug { fail unless leak_libc_base == h.libc.base }
Dump
Query content of specific address.
NOTICE: You MUST have permission of attaching a program, otherwise dump will fail.
i.e. /proc/sys/kernel/yama/ptrace_scope
set to 0 or run as root.
h.debug do
p h.dump(:libc, 8)
p h.dump(:heap, 16)
p h.dump('heap+0x30', 16)
p h.dump('heap+0x30 * 3 + 0x8', 16)
p h.dump(:program, 8)
p h.dump(0x400000, 8)
end
layouts
h.layouts :fast

h.layouts :unsorted, :small

h.layouts :tcache

offset
h.offset(0x7fda86fe8670)
h.offset(0x1839cd0, :heap)
h.offset(0x1839cd0)

canary
h.canary.to_s(16)
x - gdb-like command
h.x 8, :heap

find - gdb-like command
Provide a searcher of memory, easier to use than in (naive) gdb.
Support search integer, string, and even regular expression.
h.find(0xdeadbeef, 'heap+0x10', 0x1000)
h.find(/E.F/, 0x400000, 4)
h.find(/E.F/, 0x400000, 3)
h.find('/bin/sh', :libc, rel: true)
h.offset(h.find('/bin/sh', :libc))
Tests
HeapInfo currently only run tests on ubuntu, followings are tested glibc versions:
- libc-2.19
- libc-2.23
- libc-2.24
- libc-2.25
- libc-2.26
- libc-2.27