Lock
Recon
I started with an nmap scan. These are the open ports I found:
1
2
3
4
5
80/tcp HTTP IIS
445/tcp SMB
3000/tcp HTTP Gitea
3389/tcp RDP
5985/tcp WinRM
Port 3000 is a Gitea instance, and the user on it is ellen.freeman. Port 80 is a normal IIS site. I guessed the two might be connected, and they were.
Foothold
Leaked token in Gitea
Looking through the commit history on Gitea, I found a Personal Access Token. The token was removed from the current version of the code, but git history keeps old commits, so it was still there.
1
43ce39bb0bd6bc489284f2905f033ca467a6362f
I also found a .git-credentials file with a password for the same user:
1
ellen.freeman:YWFrWJk9uButLeqx
Webshell through auto-deploy
The repo is called website. A webhook script, Gitea_Webhook.ps1, copies every push into C:\inetpub\wwwroot. So anyone who can push to the repo can put files on the IIS server.
With the token I pushed an ASPX webshell into the website repo using the Gitea API. The webhook deployed it to IIS, and I got command execution as ellen.freeman.
User
In the AppData folder of ellen.freeman I found a confCons.xml file. This is the mRemoteNG config file, and it holds saved RDP credentials for gale.dekarios in encrypted form.
mRemoteNG uses AES-GCM, and the key comes from a default password, mR3m, run through PBKDF2 with 1000 iterations. Because most people never change the default, the saved passwords can be decrypted easily. I decrypted it and got:
1
gale.dekarios : ty8wnW9qCKDosXo6
Then I logged in over RDP as gale.dekarios and read the user flag.
1
cat user.txt
Root
Finding PDF24
While looking around the machine, I found an installer in C:\_install\:
1
C:\_install\pdf24-creator-11.15.1-x64.msi
PDF24 Creator 11.15.1 is vulnerable to CVE-2023-49147. When the MSI is repaired, it starts a process as SYSTEM, and we can freeze that process with an oplock so its console window stays open. From that console we can get to a browser running as SYSTEM.
Exploit steps
First I deleted the log file that the installer writes to:
1
del "C:\Program Files\PDF24\faxPrnInst.log"
Then I used SetOpLock.exe to set an oplock on that same file. When something tries to open it, the oplock holds it and the process waits.
Next I started the MSI repair:
1
msiexec /fa {B36652B8-9862-4A1E-83DE-4F3D52479DBB}
pdf24-PrinterInstall.exe started as SYSTEM and froze on the oplock, with its console window visible in my RDP session. From there:
- Right-click the title bar of the SYSTEM console and open Properties, then the Options tab.
- Click the “legacy console mode” link (it is a SysLink control).
- Since this was a fresh machine, SYSTEM had no default browser, so a “How do you want to open this?” dialog appeared.
- I picked Firefox. It opened as SYSTEM inside my interactive RDP session.
- In Firefox I pressed Ctrl+O to get a file dialog, went to my batch file, right-clicked it and chose Open. This ran the batch file as SYSTEM.
The batch file copied the root flag to a folder I could read:
1
type C:\Users\Administrator\Desktop\root.txt > C:\Users\Public\flag.txt
One thing matters here. If Edge is already the default browser, it opens in Session 0, which is not interactive, and the exploit fails. Firefox works because it opens in the current session, so I had to pick it in the dialog.
After that I read the copied file from C:\Users\Public\ and got the root flag.