Always been wondering about this, I figure some hackers out there probably know. I did it on a VM and couldn't figure out what to do for the life of me.
4 Answers
perl -e 'chmod 0755, "/bin/chmod";'
This will fix it if you are root. Most unix and linux based OS's have perl installed and available by default.
Boring option: mount that partition from a live CD/different machine and chmod your chmod...
If you have python installed, intact and have some already executable python script you can edit, you could hijack it to call os.chmod. Or similar call in any still executable thing that can do system calls.
-
you wouldn't even need an executable python script; you can just run
python -c ...
. (if python won't execute, an executable script won't help you either.)– EeveeJan 16, 2013 at 8:33 -
cp /bin/ls new-chmod && cp /bin/chmod new-chmod && ./new-chmod +x /bin/chmod
First, make a new (must be new, so cp will copy permissions) file, which is a copy of an existing executable file (/bin/ls). Then copy the contents of chmod over the new executable file (cp won't copy permissions to an existing file). Then use this new executable chmod to make /bin/chmod executable.
Switch to Single User Mode (init 1
) and you should be able to restore your permissions.
In effect (though not exactly true), this logging is as a "super-root" user.