"bash: ./2: No such file or directory" how to fix this on ubuntu while trying to run a file

Viewed 74

So, i have been working on a reverse engineering challenge using gdb. I have this file which can be debugged using gdb but when i try running it with two arguments it shows no such file or directory even though it is there. Details about the file: It is a 32 bit file so i have installed the gdb-multiarch extension. I have given it permission using chmod. But it is showing no such file or directory. Any idea how to solve this. When i give the two arguments, the file gives a output. That is what i want.

gani@gun-gani-PC:~/Downloads$ ./2 a b
bash: ./2: No such file or directory

But the file is present

2  3  4  5_alt  peda-session-2.txt  peda-session-3.txt

The terminal Screenshot for better understanding

1 Answers

But it is showing no such file or directory

The problem is (was) that:

  1. The binary is dynamically linked (use readelf -Wl ./2 to observe that it has PT_INTERP pointing to /lib/ld-linux.so.2) and
  2. With the 32-bit GLIBC missing, the interpreter was also missing.

When the kernel tries to start a new ELF executable, it performs the following steps:

  1. mmap the file itself according to its PT_LOAD segments
  2. IFF PT_INTERP segment is present, mmaps the interpreter (this is the step which was failing with ENOENT error) and
  3. Passes control to the interpreter (which is responsible for mmaping all required libraries and then running the executable itself).

It should now be clear why you were getting "no such file".

Here is a trivial repro:

$ echo "int main() { return 0; }" | gcc -xc - -o /tmp/3 -Wl,--dynamic-linker=/no/such/file
$ ls -l /tmp/3
-rwxr-x--- 1 user group 15976 Sep  6 19:55 /tmp/3
$ /tmp/3
-bash: /tmp/3: No such file or directory
Related