$ python poc.py
objdump: test: File format not recognized
$ file test
test: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
$ readelf -h test | grep program
readelf: Error: Out of memory reading 536870912 program headers
Start of program headers: 0 (bytes into file)
Size of program headers: 0 (bytes)
Number of program headers: 65535 (536870912)
gdb-peda$ r -x test
gdb-peda$ bt
#0 0xb7fd9ce5 in __kernel_vsyscall ()
#1 0xb7e2eea9 in __GI_raise (sig=0x6) at ../sysdeps/unix/sysv/linux/raise.c:54
#2 0xb7e30407 in __GI_abort () at abort.c:89
#3 0xb7e6a37c in __libc_message (do_abort=0x2,
fmt=0xb7f62e54 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/posix/libc_fatal.c:175
#4 0xb7e702f7 in malloc_printerr (action=<optimized out>,
str=0xb7f5f943 "free(): invalid pointer", ptr=<optimized out>,
ar_ptr=0xb7fb5780 <main_arena>) at malloc.c:5006
#5 0xb7e70c31 in _int_free (av=0xb7fb5780 <main_arena>, p=<optimized out>,
have_lock=0x0) at malloc.c:3867
#6 0x0814feab in objalloc_free (o=0x8250800) at ./objalloc.c:187
#7 0x08096c10 in bfd_hash_table_free (table=0x8250a4c) at hash.c:426
#8 0x080985fc in _bfd_delete_bfd (abfd=abfd@entry=0x8250a08) at opncls.c:125
#9 0x08099257 in bfd_close_all_done (abfd=0x8250a08) at opncls.c:773
#10 0x08052791 in display_file (filename=0xbffff136 "test", target=<optimized out>,
last_file=0x1) at ./objdump.c:3726
#11 0x0804c1af in main (argc=0x3, argv=0xbfffef04) at ./objdump.c:4015
#12 0xb7e1b637 in __libc_start_main (main=0x804ba50 <main>, argc=0x3, argv=0xbfffef04,
init=0x8150fd0 <__libc_csu_init>, fini=0x8151030 <__libc_csu_fini>,
rtld_fini=0xb7fea880 <_dl_fini>, stack_end=0xbfffeefc) at ../csu/libc-start.c:291
#13 0x0804c3ca in _start ()
// binutils/objdump.c
static void
display_any_bfd (bfd *file, int level)
{
/* Decompress sections unless dumping the section contents. */
if (!dump_section_contents)
file->flags |= BFD_DECOMPRESS;
/* If the file is an archive, process all of its elements. */
if (bfd_check_format (file, bfd_archive))
{
[...]
}
else
display_object_bfd (file);
}
// binutils/objdump.c
/* Read in the program headers. */
if (i_ehdrp->e_phnum == 0)
elf_tdata (abfd)->phdr = NULL;
else
{
Elf_Internal_Phdr *i_phdr;
unsigned int i;
#ifndef BFD64
if (i_ehdrp->e_phnum > ((bfd_size_type) -1) / sizeof (*i_phdr))
goto got_wrong_format_error;
#endif
amt = i_ehdrp->e_phnum * sizeof (*i_phdr); // <-- 整型溢出点
elf_tdata (abfd)->phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt);
if (elf_tdata (abfd)->phdr == NULL)
goto got_no_match;
if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0)
goto got_no_match;
i_phdr = elf_tdata (abfd)->phdr;
for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++)
{
Elf_External_Phdr x_phdr;
if (bfd_bread (&x_phdr, sizeof x_phdr, abfd) != sizeof x_phdr)
goto got_no_match;
elf_swap_phdr_in (abfd, &x_phdr, i_phdr);
}
}