chmod -x chmod

  • 157,578 views
Uploaded on

Video at http://www.youtube.com/watch?v=DTWZqh64RcQ. …

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
157,578
On Slideshare
0
From Embeds
0
Number of Embeds
34

Actions

Shares
Downloads
442
Comments
15
Likes
79

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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