Issue
This was an interview question. Let's say you revoked the execute permission of chmod binary -- i.e., you cannot run "chmod u+x chmod" because chmod doesn't have +x. Without obtaining a copy of chmod's binary file outside of the local file system, how can you recover chmod's execute permission?
Solution
1) Use install
:
install -m +rx /bin/chmod /tmp/chmod
/tmp/chmod 755 /bin/chmod # or just copy it back.
2) Use busybox's chmod
/bin/busybox chmod 755 /bin/chmod
3) Use cp
and cat
(dd
can work as well):
cp -a /bin/sh /tmp/chmod
cat /bin/chmod > /tmp/chmod
/tmp/chmod 755 /bin/chmod
Answered By - konsolebox