Pivoting
For this lab, I had access to a machine with a public facing IP address and I knew that it was able to connect to another network using IPSec.
The first job was to scan the machine which had a public IP address:
I could see that ports 139 and 445 were open. Port 139 uses NetBIOS over a TCP connection. NetBIOS allows machines to communicate with each other and share resources on a Local Area Network. It can also be used with the Service Message Block protocol and a TCP/IP stack to facilitate remote sharing of resources over the internet. Port 445 is used by SMB on its own in order to share resources. SMB has a number of security vulnerabilities, so I decided to take a closer look using nmblookup
The -A flag shows us the NetBIOS names in the name table. NetBIOS names refer to resources and are made up of 16 bytes. The first 15 bytes can be specified by the user (15 characters) while the last one is reserved as a hexadecimal (00 to FF) byte to specify what type of resource it is. The interesting resource type in the screenshot above is the one listed as 20 as 20 indicates a server service. This meant that the machine @ 10.130.40.70 was serving resources. I therefore decided to try to list the shares using smbclient with -N for no password.
Even though an anonymous login was allowed, I did not have permission to view any data, so I moved to msfconsole to use a module which brute forces account details for smb.
As well as the usual RHOSTS parameter, we also need to specify a path to a username file and a password file.
This module found test:12345 but this was not listed as an admin account.
It went on to find administrator:password and this was listed as an admin account!
I used an nmap script to enumerate the SMB shares further, but this was not really a necessary step.
I now tried to connect once more using smbclient with the discovered username and password. This time I was able to view the shares but not access them.
The next step was to attempt to gain a meterpreter shell using the /smb/psexec module in msfconsole. The username and password I discovered earlier were set as the SMBUSER and SMBPASS parameters along with the usual RHOSTS, LHOST and LPORT.
This successfully established a reverse meterpreter shell! The next step was to attempt to use the compromised machine to pivot onto the network which it was using IPSec to connect to. This network was unreachable from the public internet, so it would be great if this pivoting attempt could work.
I used meterpreter's autoroute module. I did not specify the netmask as it was /24 which is a default as far as I know. If it had been using a different subnet mask, I could have specified it with NETMASK=x.x.x.x where x.x.x.x would have been the netmask in decimal notation
I then used background on the session and ran msfconsole's portscan/tcp module against the network I had just pivoted to. This scan discovered a machine with ports 139 and 445 open which was unreachable from the public internet!
My next job was to get access to the resources being shared by the machine @ 170.30.111.10 so I went back into the meterpreter session. I opened a regular shell and checked the user ID.
I needed to be a different user so I used ctrl + z to background the channel before launching the incognito extension. From here, I listed the tokens I could use and then I impersonated eLS-Win7\Administrator. I had to escape the \
I was now able to use net view to see the shares @ 172.30.111.10 and then net use to map one of them to a drive. Again, I had to escape the first \
Finally, I had a look at the Confidential.txt file and then downloaded the shared directory to my local machine. This concluded a compromise of a machine on a network which was not accessible directly from the public internet. This lab proved to me the importance of pivoting and further enumerating newly discovered networks.