question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heap inspection without libc debug symbols

See original GitHub issue

The commands for heap inspection currently requires libc debug symbols. However, when the binary is modified with patchelf to use a specific interpreter like this file:

$ file target
target: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter ./ld-2.27.so, for GNU/Linux 3.2.0, BuildID[sha1]=b722ce3ea0937340d3a56165c760ac5ef9ae0014, not stripped

$ ldd target
	linux-vdso.so.1 (0x00007fff3b7b4000)
	./libc-2.27.so (0x00007f774a9c4000)
	./ld-2.27.so => /lib64/ld-linux-x86-64.so.2 (0x00007f774afbd000

Then, pwndbg is unable to use heap commands even though libc6-dbg and libc6-dbg:i386 are installed:

pwndbg> heap
heap: This command only works with libc debug symbols.
They can probably be installed via the package manager of your choice.
See also: https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html

E.g. on Ubuntu/Debian you might need to do the following steps (for 64-bit and 32-bit binaries):
sudo apt-get install libc6-dbg
sudo dpkg --add-architecture i386
sudo apt-get install libc-dbg:i386

This is also mentioned in #924.

The solution I found is to use patchelf to change interpreter. However, when I try to use gef, I realized that it is able to run heap commands on this file without changing the interpreter:

image

GEF can simply work in all conditions without requiring debug symbols. I have investigated how they do this a little bit. Here is their heap_base function:

image

It looks like they are parsing the heap base address from the memory. I suggest implementing the same strategy.

This is also useful for systems like arch linux where there is no debug symbols package available and you have to build the package with debugging options yourself.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
disconnect3dcommented, Oct 3, 2022

Yes, this works now with set resolve-heap-via-heuristic on. There are still some improvements we can make to this, but it should generally work in more cases than in GEF afaik.

0reactions
gsingh93commented, Oct 3, 2022

@disconnect3d @lebr0nli can this be closed now? Or is there more work to be done on using heap commands without debug symbols?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using GDB without debugging symbols on x86?
Without debugging symbols, you can only debug at the ASM level. Ok you get a bit more information, but you're not going to...
Read more >
- Analyzing heap memory usage with libc allocator API
The libc library contains a data structure that you can read to retrieve statistics about the current heap memory usage. These statistics are...
Read more >
Diagnosing Memory Heap Corruption in glibc with ... - Support
If MALLOC_CHECK_ is set to 0 (zero), the memory management functions are simply most tolerant of errors and do not give warnings.
Read more >
Heap Safari - Thread Local Caching - Exploit Development
Source & Debug symbols – Even though this isn't a must, every Reverse Engineer wakes up and goes to bed wishing that there...
Read more >
Testing Linux Heap exploits on different Glibc version (with ...
Glibc is by default compiled with debug symbol ref so you don't have to worry about doing any special here. When the binaries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found