forked from pwndbg/pwndbg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added plt and gotplt commands to print the .plt and .got.plt sections…
…, and cleaned up elfheader command (pwndbg#43) * Added plt and gotplt commands to print the .plt and .got.plt sections, and cleaned up elfheader command * Use pwndbg.proc.exe and sort sections * Removed checksec file * Handle the case where the file is on a remote system
- Loading branch information
1 parent
6c484b3
commit 6e0fec8
Showing
4 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import gdb | ||
import pwndbg.commands | ||
from elftools.elf.elffile import ELFFile | ||
|
||
@pwndbg.commands.Command | ||
def elfheader(): | ||
""" | ||
Prints the section mappings contained in the ELF header. | ||
""" | ||
local_path = pwndbg.file.get_file(pwndbg.proc.exe) | ||
with open(local_path, 'rb') as f: | ||
elffile = ELFFile(f) | ||
load_segment = elffile.get_segment(3) | ||
segment_base = load_segment['p_vaddr'] | ||
sections = [] | ||
for section in elffile.iter_sections(): | ||
start = section['sh_addr'] | ||
|
||
# Don't print sections that aren't mapped into memory | ||
if start == 0: | ||
continue | ||
|
||
size = section['sh_size'] | ||
sections.append((start, start + size, section.name.decode('ascii'))) | ||
|
||
sections.sort() | ||
for start, end, name in sections: | ||
print('%#x - %#x %s' % (start, end, name)) | ||
|
||
@pwndbg.commands.Command | ||
def gotplt(): | ||
""" | ||
Prints any symbols found in the .got.plt section if it exists. | ||
""" | ||
print_symbols_in_section('.got.plt', '@got.plt') | ||
|
||
@pwndbg.commands.Command | ||
def plt(): | ||
""" | ||
Prints any symbols found in the .plt section if it exists. | ||
""" | ||
print_symbols_in_section('.plt', '@plt') | ||
|
||
def get_section_bounds(section_name): | ||
section_name = section_name.encode('ascii') | ||
with open(pwndbg.proc.exe, 'rb') as f: | ||
elffile = ELFFile(f) | ||
|
||
section = elffile.get_section_by_name(section_name) | ||
start = section['sh_addr'] | ||
size = section['sh_size'] | ||
return (start, start + size) | ||
|
||
def print_symbols_in_section(section_name, filter_text=''): | ||
start, end = get_section_bounds(section_name) | ||
if start == None: | ||
print(pwndbg.color.red('Could not find section')) | ||
return | ||
|
||
symbols = get_symbols_in_region(start, end, filter_text) | ||
for symbol, addr in symbols: | ||
print(hex(addr) + ': ' + symbol) | ||
|
||
def get_symbols_in_region(start, end, filter_text=''): | ||
symbols = [] | ||
ptr_size = pwndbg.typeinfo.pvoid.sizeof | ||
addr = start | ||
while addr < end: | ||
name = pwndbg.symbol.get(addr) | ||
if name != '' and '+' not in name and filter_text in name: | ||
symbols.append((name, addr)) | ||
addr += ptr_size | ||
|
||
return symbols |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters