Yes, it is possiblepossible to execexecute a file by its inode. The method is fiddly:
find / -inum 242 -exec {} \;
Performance motivated the question, inefficientthough, and the above is not guaranteed to work in all environments. Thusperformant: under the hood, if your motivationthe inode number is efficiencyresolved to a path, this method isn't desirable. But if your motivationand the path is malicious,given to the calculus changeskernel to execute. But why?
Before discussing execution by inode, let's talk about how the kernel does path-based execution. The kernel exposes the exec family of functions (execl, execvp, etc), which all wrap the kernel function execve. That function replaces the current process image with a new process image, one that's been bootstrapped by reading the contents fromfrom a given file path. So every way the kernel gives to execute a program requires it be given fileby path. By using the file path as the entry point, we get all the access control benefits associated with file paths and, for this reason, there is no otherthe "by path" API is the only one in Linux for executing a program.
HoweverSince performance motivated the question, there exists a fiddly and not guaranteed to work in all environments mechanism, but allows you to invoke a program from within memory. Since anything in memory is necessary faster than anything on disk, this drives to the heart of the question.
In early 2002 a (famous) hacker known as grugq introduced the concept of userland exec. This is not a shell's exec function: it's an emulation of every step the kernel's execve function performs, just written in userland. This is ideal for hackers who want to hide their activity because it allows the execution of a program outside the usual access control mechanism of execve.
The implementation for this mechanism is not efficient -- and it need not be for the use case it solves. The mechanismmethod requires numerous helpers that can clean the address space, load the dynamic linker if needed, initialize the stack and so on. The mechanism also requires the desired code be loaded in certain kinds of memory.
So, finally, if your Linux system meets the requirements above, then the two things you need to do are:
- Load the inodecode into memory somewhere. HintMalicious actors will have already side-loaded the desired code into memory as part of the initial drop, but if you wanted to do it along the lines of inode, you could do
find / -inodeinum 242 -exec cat {} \;
- Invoke the userland exec mechanism, setting its entry point to the address of memory where you stored your program from step 1
- Profit