Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

single patchelf command corrupts symbols #297

Closed
j4k0xb opened this issue Oct 18, 2023 · 1 comment · Fixed by #299
Closed

single patchelf command corrupts symbols #297

j4k0xb opened this issue Oct 18, 2023 · 1 comment · Fixed by #299

Comments

@j4k0xb
Copy link

j4k0xb commented Oct 18, 2023

binary/libc: Archive.zip
OS: Manjaro
patchelf: 0.18.0

Gdb can't find any symbols anymore after running pwninit:

$ pwninit --bin rpsls --libc libc.so.6 --no-template
bin: rpsls
libc: libc.so.6
ld: ./ld-2.31.so

unstripping libc
https://launchpad.net/ubuntu/+archive/primary/+files//libc6-dbg_2.31-0ubuntu9.2_amd64.deb
eu-unstrip: cannot find matching section for [16] '.text'
eu-unstrip: cannot find matching section for [17] '__libc_freeres_fn'
eu-unstrip: cannot find matching section for [18] '.rodata'
eu-unstrip: cannot find matching section for [19] '.stapsdt.base'
eu-unstrip: cannot find matching section for [20] '.interp'
eu-unstrip: cannot find matching section for [21] '.eh_frame_hdr'
eu-unstrip: cannot find matching section for [22] '.eh_frame'
eu-unstrip: cannot find matching section for [23] '.gcc_except_table'
eu-unstrip: cannot find matching section for [24] '.tdata'
eu-unstrip: cannot find matching section for [25] '.tbss'
eu-unstrip: cannot find matching section for [26] '.init_array'
eu-unstrip: cannot find matching section for [27] '.data.rel.ro'
eu-unstrip: cannot find matching section for [28] '.dynamic'
eu-unstrip: cannot find matching section for [29] '.got'
eu-unstrip: cannot find matching section for [30] '.got.plt'
eu-unstrip: cannot find matching section for [31] '.data'
eu-unstrip: cannot find matching section for [32] '__libc_subfreeres'
eu-unstrip: cannot find matching section for [33] '__libc_IO_vtables'
eu-unstrip: cannot find matching section for [34] '__libc_atexit'
eu-unstrip: cannot find matching section for [35] '.bss'
eu-unstrip: cannot find matching section for [36] '__libc_freeres_ptrs'
warning: failed unstripping libc: eu-unstrip exited with failure: exit status: 1
copying rpsls to rpsls_patched
running patchelf on rpsls_patched

$ ldd rpsls_patched
        linux-vdso.so.1 (0x00007ffff7fc8000)
        libc.so.6 => ./libc.so.6 (0x00007ffff7dc9000)
        ./ld-2.31.so => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fca000)

$ gdb rpsls_patched
GNU gdb (GDB) 13.1
...
gef➤  b main
Function "main" not defined.

Same behavior when manually running patchelf with both args:

$ cp rpsls rpsls_patched
$ patchelf --set-interpreter ./ld-2.31.so --set-rpath . rpsls_patched
$ gdb rpsls_patched
GNU gdb (GDB) 13.1
...
gef➤  b main
Function "main" not defined.

Only with 2 separate commands it works as expected:

$ cp rpsls rpsls_patched
$ patchelf --set-interpreter ./ld-2.31.so rpsls_patched
$ patchelf --set-rpath . rpsls_patched

$ ldd rpsls_patched
        linux-vdso.so.1 (0x00007ffff7fc8000)
        libc.so.6 => ./libc.so.6 (0x00007ffff7dc9000)
        ./ld-2.31.so => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fca000)

$ gdb
GNU gdb (GDB) 13.1
...
gef➤  b main
Breakpoint 1 at 0x153a
@anthraxx
Copy link
Contributor

I've been hit by this issue as well and opened #299 to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants