chmod -x chmod
  José Castro <cog@cpan.org>
          August 2010
During 2009
  we posed this problem
to several of our candidates
You’re in a Data Center
With absolutely
      no contact
with the outside world
There’s a machine
you must not reboot
And someone had
 the brilliant idea
  of performing a
`chmod -x chmod`
Solve the problem
The following is a list
   of 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 language
that implements chmod
Perl


perl -e ‘chmod 0755, “chmod”’
Python

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

                Node.js

require("fs").chmodSync("/bin/chmod", 0755);
Use existing executables
  or 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 );
}...
$ cat - > restore_chmod.c
#include <sys/types.h>
#include <sys/stat.h>

int main () {
   chmod( "/bin/chmod", 0000777 );
}...
$ cat - > restore_chmod.c
#include <sys/types.h>
#include <sys/stat.h>

int main () {
   chmod( "/bin/chmod", 0000777 );
}...
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 -
d
   un teste




$ tar -cvf chmod.tar chmod

edit the archive and alter the permissions
“You said I couldn’t
go to the internet...
“You said I couldn’t
   go to the internet...

but you said nothing about
    the 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...
cpio
cpio lets you
      copy files
to and from archives
bytes 19 to 24
are the file mode
(http://4bxf.sl.pt)
echo chmod |
 cpio -o |
 perl -pe 's/^(.{21}).../${1}755/' |
 cpio -i -u
Hardcore
alias chmod='/lib/ld-2.11.1.so ./chmod'
d
un teste



           • attrib or ls -@
           • force the inode into cache
           • check kcore for the VFS st...
Text editors
 sometimes need
to overwrite a file
Thus, some of them
  have 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)
Upcoming SlideShare
Loading in...5
×

chmod -x chmod

159,345

Published on

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.

Published in: Technology
15 Comments
82 Likes
Statistics
Notes
No Downloads
Views
Total Views
159,345
On Slideshare
0
From Embeds
0
Number of Embeds
34
Actions
Shares
0
Downloads
450
Comments
15
Likes
82
Embeds 0
No embeds

No notes for slide

chmod -x chmod

  1. 1. chmod -x chmod José Castro <cog@cpan.org> August 2010
  2. 2. During 2009 we posed this problem to several of our candidates
  3. 3. You’re in a Data Center
  4. 4. With absolutely no contact with the outside world
  5. 5. There’s a machine you must not reboot
  6. 6. And someone had the brilliant idea of performing a `chmod -x chmod`
  7. 7. Solve the problem
  8. 8. The following is a list of possible solutions proposed by my co-workers
  9. 9. If the package is in cache, reinstall it
  10. 10. On Debian: sudo apt-get install --reinstall coreutils
  11. 11. Use a language that implements chmod
  12. 12. Perl perl -e ‘chmod 0755, “chmod”’
  13. 13. Python python -c "import os;os.chmod('/bin/chmod', 0777)"
  14. 14. d un teste Node.js require("fs").chmodSync("/bin/chmod", 0755);
  15. 15. Use existing executables or create your own
  16. 16. $ cat - > chmod.c
  17. 17. $ cat - > chmod.c int main () { } ^D
  18. 18. $ cat - > chmod.c int main () { } ^D $ cc chmod.c
  19. 19. $ cat - > chmod.c int main () { } ^D $ cc chmod.c $ cat /bin/chmod > a.out
  20. 20. $ cp cat new_chmod $ cat chmod > new_chmod
  21. 21. $ cat - > restore_chmod.c
  22. 22. $ cat - > restore_chmod.c #include <sys/types.h> #include <sys/stat.h> int main () { chmod( "/bin/chmod", 0000777 ); } ^D
  23. 23. $ cat - > restore_chmod.c #include <sys/types.h> #include <sys/stat.h> int main () { chmod( "/bin/chmod", 0000777 ); } ^D $ cc restore_chmod.c
  24. 24. $ 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
  25. 25. launch BusyBox (it has a chmod inside)
  26. 26. GNU tar
  27. 27. $ tar --mode 0777 -cf chmod.tar /bin/chmod $ tar xvf chmod.tar
  28. 28. tar --mode 555 -cvf - chmod | tar xvf -
  29. 29. d un teste $ tar -cvf chmod.tar chmod edit the archive and alter the permissions
  30. 30. “You said I couldn’t go to the internet...
  31. 31. “You said I couldn’t go to the internet... but you said nothing about the other machines on the data center...”
  32. 32. Open a socket to another machine and do a: $ tar --preserve-permissions -cf chmod.tar chmod
  33. 33. 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
  34. 34. cpio
  35. 35. cpio lets you copy files to and from archives
  36. 36. bytes 19 to 24 are the file mode (http://4bxf.sl.pt)
  37. 37. echo chmod | cpio -o | perl -pe 's/^(.{21}).../${1}755/' | cpio -i -u
  38. 38. Hardcore
  39. 39. alias chmod='/lib/ld-2.11.1.so ./chmod'
  40. 40. d un teste • 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
  41. 41. Text editors sometimes need to overwrite a file
  42. 42. Thus, some of them have something resembling chmod
  43. 43. Emacs
  44. 44. Ctrl+x b > *scratch* (set-file-modes "/bin/chmod" (string-to-number "0755" 8)) Ctrl+j
  45. 45. There seem to be countless solutions
  46. 46. But one of the best answers I’ve seen...
  47. 47. Was from a guy who replied to my “Solve the problem” with...
  48. 48. “What problem? Isn’t the machine still running?”
  49. 49. The End (for now)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×