chmod -x chmod

49
chmod -x chmod José Castro <[email protected] > August 2010

Upload: jose-castro

Post on 08-Sep-2014

161.726 views

Category:

Technology


3 download

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

Page 1: chmod -x chmod

chmod -x chmod

José Castro <[email protected]>August 2010

Page 2: chmod -x chmod

During 2009we posed this problem

to several of our candidates

Page 3: chmod -x chmod

You’re in a Data Center

Page 4: chmod -x chmod

With absolutelyno contact

with the outside world

Page 5: chmod -x chmod

There’s a machineyou must not reboot

Page 6: chmod -x chmod

And someone hadthe brilliant ideaof performing a

`chmod -x chmod`

Page 7: chmod -x chmod

Solve the problem

Page 8: chmod -x chmod

The following is a listof possible solutions

proposed by my co-workers

Page 9: chmod -x chmod

If the package is in cache, reinstall it

Page 10: chmod -x chmod

On Debian:

sudo apt-get install --reinstall coreutils

Page 11: chmod -x chmod

Use a languagethat implements chmod

Page 12: chmod -x chmod

perl -e ‘chmod 0755, “chmod”’

Perl

Page 13: chmod -x chmod

python -c "import os;os.chmod('/bin/chmod', 0777)"

Python

Page 14: chmod -x chmod

Node.js

require("fs").chmodSync("/bin/chmod", 0755);

untested

Page 15: chmod -x chmod

Use existing executablesor create your own

Page 16: chmod -x chmod

$ cat - > chmod.c

Page 17: chmod -x chmod

$ cat - > chmod.c int main () { }^D

Page 18: chmod -x chmod

$ cat - > chmod.c int main () { }^D$ cc chmod.c

Page 19: chmod -x chmod

$ cat - > chmod.c int main () { }^D$ cc chmod.c

$ cat /bin/chmod > a.out

Page 20: chmod -x chmod

$ cp cat new_chmod

$ cat chmod > new_chmod

Page 21: chmod -x chmod

$ cat - > restore_chmod.c

Page 22: chmod -x chmod

$ cat - > restore_chmod.c #include <sys/types.h>#include <sys/stat.h>

int main () { chmod( "/bin/chmod", 0000777 );}^D

Page 23: chmod -x chmod

$ cat - > restore_chmod.c #include <sys/types.h>#include <sys/stat.h>

int main () { chmod( "/bin/chmod", 0000777 );}^D$ cc restore_chmod.c

Page 24: chmod -x chmod

$ 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

Page 25: chmod -x chmod

launch BusyBox(it has a chmod inside)

Page 26: chmod -x chmod

GNU tar

Page 27: chmod -x chmod

$ tar --mode 0777 -cf chmod.tar /bin/chmod

$ tar xvf chmod.tar

Page 28: chmod -x chmod

tar --mode 555 -cvf - chmod | tar xvf -

Page 29: chmod -x chmod

$ tar -cvf chmod.tar chmod

edit the archive and alter the permissions

untested

Page 30: chmod -x chmod

“You said I couldn’tgo to the internet...

Page 31: chmod -x chmod

“You said I couldn’tgo to the internet...

but you said nothing aboutthe other machines

on the data center...”

Page 32: chmod -x chmod

Open a socket to another machine and do a:

$ tar --preserve-permissions -cf chmod.tar chmod

Page 33: chmod -x 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

Page 34: chmod -x chmod

cpio

Page 35: chmod -x chmod

cpio lets youcopy files

to and from archives

Page 36: chmod -x chmod

bytes 19 to 24are the file mode(http://4bxf.sl.pt)

Page 37: chmod -x chmod

echo chmod | -o |

cpio -i -u

cpio 21 ... 755perl -pe 's/^(.{ }) /${1} /' |

Page 38: chmod -x chmod

Hardcore

Page 39: chmod -x chmod

alias chmod='/lib/ld-2.11.1.so ./chmod'

Page 40: chmod -x 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

Page 41: chmod -x chmod

Text editorssometimes need

to overwrite a file

Page 42: chmod -x chmod

Thus, some of themhave something

resembling chmod

Page 43: chmod -x chmod

Emacs

Page 44: chmod -x chmod

Ctrl+x b > *scratch* (set-file-modes "/bin/chmod" (string-to-number "0755" 8))Ctrl+j

Page 45: chmod -x chmod

There seem to be countless solutions

Page 46: chmod -x chmod

But one of the best answers I’ve seen...

Page 47: chmod -x chmod

Was from a guy who replied to my“Solve the problem”

with...

Page 48: chmod -x chmod

“What problem?Isn’t the machine still

running?”

Page 49: chmod -x chmod

The End(for now)