chmod -x chmod
DESCRIPTION
Video at http://www.youtube.com/watch?v=DTWZqh64RcQ. You're in a Data Center, with absolutely no contact with the outside world, with a machine that you must not restart, and someone performed a `chmod -x chmod`. This is a problem we used in interviews during 2009, and this presentation is a list of some of the possible solutions that my co-workers at SAPO have suggested.TRANSCRIPT
chmod -x chmod
José Castro <[email protected]>August 2010
During 2009we posed this problem
to several of our candidates
You’re in a Data Center
With absolutelyno contact
with the outside world
There’s a machineyou must not reboot
And someone hadthe brilliant ideaof performing a
`chmod -x chmod`
Solve the problem
The following is a listof possible solutions
proposed by my co-workers
If the package is in cache, reinstall it
On Debian:
sudo apt-get install --reinstall coreutils
Use a languagethat implements chmod
perl -e ‘chmod 0755, “chmod”’
Perl
python -c "import os;os.chmod('/bin/chmod', 0777)"
Python
Node.js
require("fs").chmodSync("/bin/chmod", 0755);
untested
Use existing executablesor create your own
$ cat - > chmod.c
$ cat - > chmod.c int main () { }^D
$ cat - > chmod.c int main () { }^D$ cc chmod.c
$ cat - > chmod.c int main () { }^D$ cc chmod.c
$ cat /bin/chmod > a.out
$ cp cat new_chmod
$ cat chmod > new_chmod
$ cat - > restore_chmod.c
$ cat - > restore_chmod.c #include <sys/types.h>#include <sys/stat.h>
int main () { chmod( "/bin/chmod", 0000777 );}^D
$ cat - > restore_chmod.c #include <sys/types.h>#include <sys/stat.h>
int main () { chmod( "/bin/chmod", 0000777 );}^D$ cc restore_chmod.c
$ cat - > restore_chmod.c #include <sys/types.h>#include <sys/stat.h>
int main () { chmod( "/bin/chmod", 0000777 );}^D$ cc restore_chmod.c
$ ./a.out
launch BusyBox(it has a chmod inside)
GNU tar
$ tar --mode 0777 -cf chmod.tar /bin/chmod
$ tar xvf chmod.tar
tar --mode 555 -cvf - chmod | tar xvf -
$ tar -cvf chmod.tar chmod
edit the archive and alter the permissions
untested
“You said I couldn’tgo to the internet...
“You said I couldn’tgo to the internet...
but you said nothing aboutthe other machines
on the data center...”
Open a socket to another machine and do a:
$ tar --preserve-permissions -cf chmod.tar chmod
Open a socket to another machine and do a:
$ tar --preserve-permissions -cf chmod.tar chmod
Get this tar to your machine and:
$ tar xvf chmod.tar
cpio
cpio lets youcopy files
to and from archives
echo chmod | -o |
cpio -i -u
cpio 21 ... 755perl -pe 's/^(.{ }) /${1} /' |
Hardcore
alias chmod='/lib/ld-2.11.1.so ./chmod'
• attrib or ls -@
• force the inode into cache
• check kcore for the VFS structures
• use sed to alter the execution bit without the kernel realizing it
• run chmod +x chmod
untested
Text editorssometimes need
to overwrite a file
Thus, some of themhave something
resembling chmod
Emacs
Ctrl+x b > *scratch* (set-file-modes "/bin/chmod" (string-to-number "0755" 8))Ctrl+j
There seem to be countless solutions
But one of the best answers I’ve seen...
Was from a guy who replied to my“Solve the problem”
with...
“What problem?Isn’t the machine still
running?”
The End(for now)