无法运行ELF二进制文件house_of_force:文件不存在问题求助
无法运行house_of_force二进制文件:
bash: ./house_of_force: No such file or directory 尝试运行名为house_of_force的ELF二进制文件时,执行./house_of_force报错bash: ./house_of_force: No such file or directory,已执行chmod a+x house_of_force赋予执行权限,怀疑是共享对象或解释器链接问题,请求解决。
收集到的系统及二进制文件信息
1. ldd输出
pegasus@pegasus:~/Documents/Courses/heaplab-main/house_of_force$ ldd ./house_of_force linux-vdso.so.1 (0x00007fff7c6da000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3f879bd000) ../.glibc/glibc_2.28_no-tcache/ld.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f3f87bf9000)
2. file输出
pegasus@pegasus:~/Documents/Courses/heaplab-main/house_of_force$ file ./house_of_force ./house_of_force: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter ../.glibc/glibc_2.28_no-tcache/ld.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=278a2aec8b352ea120c49321ed3254eb15ca8ef5, with debug_info, not stripped
3. readelf -l输出
pegasus@pegasus:~/Documents/Courses/heaplab-main/house_of_force$ readelf -l house_of_force Elf file type is EXEC (Executable file) Entry point 0x400730 There are 9 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040 0x00000000000001f8 0x00000000000001f8 R 0x8 INTERP 0x0000000000000238 0x0000000000400238 0x0000000000400238 0x0000000000000027 0x0000000000000027 R 0x1 [Requesting program interpreter: ../.glibc/glibc_2.28_no-tcache/ld.so.2] LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x0000000000000d88 0x0000000000000d88 R E 0x200000 LOAD 0x0000000000001d70 0x0000000000601d70 0x0000000000601d70 0x00000000000002c0 0x00000000000002c8 RW 0x200000 DYNAMIC 0x0000000000001d80 0x0000000000601d80 0x0000000000601d80 0x0000000000000200 0x0000000000000200 RW 0x8 NOTE 0x0000000000000260 0x0000000000400260 0x0000000000400260 0x0000000000000044 0x0000000000000044 R 0x4 GNU_EH_FRAME 0x0000000000000c04 0x0000000000400c04 0x0000000000400c04 0x000000000000004c 0x000000000000004c R 0x4 GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RW 0x10 GNU_RELRO 0x0000000000001d70 0x0000000000601d70 0x0000000000601d70 0x0000000000000290 0x0000000000000290 R 0x1 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame 03 .init_array .fini_array .dynamic .got .data .bss 04 .dynamic 05 .note.ABI-tag .note.gnu.build-id 06 .eh_frame_hdr 07 08 .init_array .fini_array .dynamic .got
4. 系统信息
pegasus@pegasus:~/Documents/Courses/heaplab-main/house_of_force$ uname -a Linux pegasus 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux pegasus@pegasus:~/Documents/Courses/heaplab-main/house_of_force$ lsb_release -a LSB Version: core-11.1.0ubuntu4-noarch:printing-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy
解决方案
从file和readelf的输出可以看出,该二进制文件指定了自定义动态链接器../.glibc/glibc_2.28_no-tcache/ld.so.2,系统无法找到该路径对应的文件导致执行报错,可通过以下方式解决:
方法1:直接调用指定的动态链接器运行
先确认自定义链接器文件是否存在:
ls -la ../.glibc/glibc_2.28_no-tcache/ld.so.2
若文件存在,直接用该链接器启动二进制:
../.glibc/glibc_2.28_no-tcache/ld.so.2 ./house_of_force
方法2:修改二进制文件的动态链接器路径
使用patchelf工具修改二进制的解释器路径:
- 安装patchelf:
sudo apt install patchelf
- 修改为系统默认链接器或自定义链接器的绝对路径:
# 使用系统默认链接器 patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 ./house_of_force # 或使用自定义链接器的绝对路径(示例路径需根据实际情况调整) patchelf --set-interpreter /home/pegasus/Documents/Courses/heaplab-main/.glibc/glibc_2.28_no-tcache/ld.so.2 ./house_of_force
修改完成后直接运行./house_of_force即可。
方法3:通过环境变量指定链接器搜索路径
临时设置LD_LIBRARY_PATH指定自定义glibc的库路径:
LD_LIBRARY_PATH=../.glibc/glibc_2.28_no-tcache/ ./house_of_force
或临时添加到环境变量:
export LD_LIBRARY_PATH=../.glibc/glibc_2.28_no-tcache/:$LD_LIBRARY_PATH ./house_of_force
内容的提问来源于stack exchange,提问作者NobinPegasus
相关产品推荐
相关产品推荐

