I was sure you couldn’t change permission of a file without using /bin/chmod – I was wrong.

I recently got asked a question that I ‘m sure I had the right answer.

What if someone changed the permissions of /bin/chmod and removed the execute bits?

-r–r–r–. 1 root root 52472 Oct 15 2014 /bin/chmod

You cant ‘execute’ /bin/chmod because the execute bit is no longer set.  I immediately thought.  OK.. Reinstall the RPM  (rpm -qf /bin/chmod  – coreutils package)  or copy the chmod bin from another host.

Well it turns out that in perl you can use the ‘chmod’ call from a ‘one-liner’ to set the permissions. As root.

perl -e ‘chmod 0755, “/bin/chmod”‘

-rwxr-xr-x. 1 root root 52472 Oct 15  2014 /bin/chmod

Guess I need to learn more about the system calls themselves instead of just executing binaries.

This entry was posted in Uncategorized. Bookmark the permalink.