Alright, so things have slowed down for me enough to post a long rambling (rough week had interop testing, presentations, etc). Let's take a 50K foot view and review with what I'll call "I haz shell now what?!"
What steps did you go through to get a shell account. For those reading this, it will be a part intro, part explanation and so on. Typically the penetration tester will go through phases to access a machine. These phases include a variation of the following:
- Recon
Enumeration of services
Enumeration of accounts if possible
Collection of exploits against the services (where vulnerable)
etc., etc
When you set out to test the security of this machine from a penetration tester's point of view, you at some point had to run some form of "mapping" software to determine what services were running on the machine in order to circumvent slash exploit one to work your way in. You've made your way in but have determined, it's not where you need to be. You need to escalate for one reason or another.
Sidetrack: In most cases, getting in is enough period (believe it or not) and anyone who tells you otherwise is off their rockers. Analogy time: Imagine coming home from dinner one day to find your apartment was burglarized. Nothing was stolen, but someone ransacked through all your belongings. Do you sit there and say: "
So what! Nothing was taken, no harm no foul." Highly doubtful. There is the entire concept of someone going through your personal belongings. Not to mention the fact of insecurity you will feel. "
Will they come back again", "
will they clean me out next time" and so on.
Forwardtrack: So you've managed to get access... How did you get access again? Through a process. You now need to go through that same process using a different approach. The procedures are the same:
- Recon
Enumeration of services
Enumeration of accounts if possible
Collection of exploits against the system you're on
On *nix
Where am I first of allgary7:~$ pwd
/home/mail
Who am I and what groups am I in?
gary7:~$ id
uid=8(mail) gid=8(mail) groups=8(mail)
I can't read shadow, maybe I can find an account I can escalate to
gary7:~$ more /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:11:11:proxy:/bin:/bin/sh
backup:x:12:12:backup:/var/backups:/bin/sh
Debian-exim:x:100:102::/var/spool/exim4:/bin/false
statd:x:101:65534::/var/lib/nfs:/bin/false
identd:x:102:65534::/var/run/identd:/bin/false
sshd:x:103:65534::/var/run/sshd:/usr/sbin/nologin
postfix:x:107:107::/var/spool/postfix:/bin/false
snort:x:108:109:Snort IDS:/var/log/snort:/bin/false
ossec:x:1003:1003::/var/ossec:/bin/false
mysql:x:110:111:MySQL Server,,,:/var/lib/mysql:/bin/false
ntop:x:111:112::/var/lib/ntop:/bin/false
nagios:x:112:113::/var/log/nagios:/bin/false
arpwatch:x:113:114:ARP Watcher,,,:/var/lib/arpwatch:/bin/sh
osirismd:x:114:115:Osiris management daemon,,,:/var/lib/osirismd:/bin/false
postgres:x:1000:1000:,,,:/home/postgres:/bin/bash
In some cases, this file could be really large especially in an enterprise. Let's see only accounts worth seeing (get rid of nologin and false):
gary7:~$ awk '!/false|nologin/{print}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:11:11:proxy:/bin:/bin/sh
backup:x:12:12:backup:/var/backups:/bin/sh
arpwatch:x:113:114:ARP Watcher,,,:/var/lib/arpwatch:/bin/sh
postgres:x:1000:1000:,,,:/home/postgres:/bin/bash
I see there are mechanisms/programs in place to potentially see/monitor what is going on (snort, ossec, osiris, arpwatch, nagios). Better play it safe and keep things silent (non-noisy as snort will see it)
man sleep Meaning, if I need to do something network related, I want to keep my intervals high to avoid tripping IPS/IDS alarms. If an interval command is not available, I'll use sleep for N amount of seconds, e.g.:
HEAD 10.20.30.2 ; sleep 180 ; nextCommand
Anyhow, Let me see what other networks I'm on...
gary7:~$ /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 00:14:22:0F:BE:EF
inet addr:208.47.125.33 Bcast:208.47.125.255 Mask:255.255.255.0
inet6 addr: fe80::214:22ff:fe0f:8019/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:530490559 errors:45 dropped:5036 overruns:0 frame:23
TX packets:849641363 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3489730358 (3.2 GiB) TX bytes:2252362147 (2.0 GiB)
Base address:0xdcc0 Memory:dfbe0000-dfc00000
eth1 Link encap:Ethernet HWaddr 00:14:22:0F:BA:BE
inet addr:10.20.30.40 Bcast:10.20.30.255 Mask:255.255.255.0
inet6 addr: fe80::214:22ff:fe0f:801a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:313524793 errors:35 dropped:119137 overruns:0 frame:17
TX packets:257953444 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2316259519 (2.1 GiB) TX bytes:49064241 (46.7 MiB)
Base address:0xccc0 Memory:df9e0000-dfa00000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:105669960 errors:0 dropped:0 overruns:0 frame:0
TX packets:105669960 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:632006627 (602.7 MiB) TX bytes:632006627 (602.7 MiB)
Now that I see a private address, let's see what is visible on the private side. Forget nmap since it may NOT be on the machine and there is no way in hell I'm setting off alarms. Hello good old faithful netcat, I need you as a scanner today. You come preinstalled on just about everything nowadays:
gary7:~$ nc -v -z 10.20.30.40 1-20000
gary7 [10.20.30.40] 5038 (?) open
gary7 [10.20.30.40] 3128 (?) open
gary7 [10.20.30.40] 3000 (?) open
gary7 [10.20.30.40] 2266 (?) open
gary7 [10.20.30.40] 113 (auth) open
gary7 [10.20.30.40] 80 (www) open
gary7 [10.20.30.40] 25 (smtp) open
gary7 [10.20.30.40] 22 (ssh) open
Strange, these weren't visible to me from the outside world when I ran nmap. Let me keep note, find a potential matching program and see if I can find any potential working exploits against these services....
gary7:~$ nc -v 10.20.30.40 5038 -q 1
gary7 [10.20.30.40] 5038 (?) open
Asterisk Call Manager/1.0
gary7:~$
I can go Google exploits against this later. Right now, just jotting down what's visible slash accessible to me. Get the picture? It pays to understand systems from a systems administrator perspective otherwise one will always ask the question: "
I haz shell now what?" Hopefully this made sense to those who've been asking themselves that same question. The remainder is sort of elementary. Much similar to gathering data from the outside view, gather it now from the inside view. This could mean finding services, finding an account with better privileges (more /etc/group), finding any errors with file permissions. Finding any potential TOCTOU issues and so on.
It's good practice to build a "dossier" of the system your own instead of trying to hack it wildly. The time you spend doing so (hacking wildly) could lead to you being detected and or kicked/blocked off the system rendering your test moot (to a degree... After all you did get in). Practice, patience and understanding allow you to go far. I can't stress it enough, one needs to truly understand a system from even a junior admin level as it makes things easier and allows one to streamline processes to make things quicker, more effective and more stealthy sometimes.
For anyone with an OMFG on this in regards to gary7, take note, I replaced my system information with gary7. I wouldn't go fiddling with that machine if I were you. (No really I wouldn't)