Bastard Writeup - HackTheBox
Bastard is a Windows box running Drupal 7 on IIS. The chain runs: a changelog file that pins the exact Drupal version, unauthenticated remote code execution through Drupalgeddon2, and a Windows Server 2008 R2 install with zero hotfixes that falls to the MS15-051 kernel exploit for SYSTEM.
Reconnaissance
Port scan
Open $TARGET_IP:80 Open $TARGET_IP:135 Open $TARGET_IP:49154
Explain command
| -a $TARGET_IP | Address to sweep for open ports across the full range. |
PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 7.5 |_http-generator: Drupal 7 (http://drupal.org) | http-robots.txt: 36 disallowed entries (15 shown) | /includes/ /misc/ /modules/ /profiles/ /scripts/ | /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt | <snip> | http-methods: |_ Potentially risky methods: TRACE |_http-title: Welcome to Bastard | Bastard 135/tcp open msrpc Microsoft Windows RPC 49154/tcp open msrpc Microsoft Windows RPC Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Explain command
| -sCV | Run the default script set and probe service versions. |
| -T4 | Faster timing template, safe against a lab target. |
| -p80,135,49154 | Limit the scan to the ports rustscan already found open. |
Drupal 7 on IIS 7.5, with RPC on 135 and 49154 offering nothing without credentials. The interesting part is in the robots.txt listing: Drupal ships a CHANGELOG.txt in the webroot and it names the exact release.
Vulnerability Discovery
Pinning the Drupal version
Drupal 7.54, 2017-02-01 ----------------------- - Modules are now able to define theme engines (API addition) <snip>
Drupal 7.54 sits below the 7.58 fix for CVE-2018-7600, better known as Drupalgeddon2. The bug is in the Form API: render array keys starting with # arrive from user input and are processed as callbacks, so a crafted parameter on an anonymous form such as the user registration form executes PHP without any authentication.
Exploitation
Drupalgeddon2
[*] Targeting: http://$TARGET_IP [*] Got Build ID: form-Rj1d3tYsD9CI4euGExLT-BAVH3qC1BFV-VuDyySslOI [*] Executing command: whoami --- Command Output --- nt authority\iusr ----------------------
Command execution as nt authority\iusr, the IIS anonymous identity. Feeding the same exploit a Base64 encoded PowerShell reverse shell makes it interactive.
Interactive shell
connect to [$ATTACKER_IP] from (UNKNOWN) [$TARGET_IP] 49211 whoami nt authority\iusr
Explain command
| rlwrap | Wrap the listener so the caught shell gets line editing and history. |
| -lvnp $ATTACKER_PORT | Listen verbosely on the callback port without resolving names. |
Foothold as the web identity. The first question on an old Windows target is how far behind the patch level is.
Privilege Escalation
Patch level
Host Name: BASTARD OS Name: Microsoft Windows Server 2008 R2 Datacenter OS Version: 6.1.7600 N/A Build 7600 <snip> Domain: HTB Hotfix(s): N/A
Build 7600 is the original 2008 R2 release with no service pack, and Hotfix(s): N/A means nothing has ever been patched. That makes public kernel exploits the shortest path, and MS15-051, CVE-2015-1701, is a reliable one on this build. It abuses a win32k.sys flaw to run code in kernel context and hand SYSTEM to a chosen command.
Delivering the exploit
Instead of finding an upload primitive on the target, an SMB server on the attacking machine serves the exploit and a netcat binary straight from the working directory.
Explain command
| myshare | Share name the target will use in the UNC path. |
| `pwd` | Serve the current directory, holding the exploit and nc64.exe. |
| -smb2 | Speak SMB2, which Windows Server 2008 R2 requires here. |
The exploit takes the command to run as its argument, so the first run just confirms the context it produces.
[#] ms15-051 fixed by zcgonvh [!] process with pid: 1744 created. ============================== nt authority\system
SYSTEM confirmed. Swapping the argument for a netcat callback turns it into a shell on a second listener.
connect to [$ATTACKER_IP] from (UNKNOWN) [$TARGET_IP] 49170 Microsoft Windows [Version 6.1.7600] C:\inetpub\drupal-7.54>whoami nt authority\system
SYSTEM shell on the box. Both the web identity and the highest local context are covered.
Related
References
-
Drupal SA-CORE-2018-002LINK: Drupal SA-CORE-2018-002, www.drupal.org/sa-core-2018-002 (opens in new tab)
Official advisory for CVE-2018-7600, the Form API flaw behind Drupalgeddon2.
-
windows-kernel-exploitsREPO: windows-kernel-exploits, github.com/SecWiki/windows-kernel-exploits (opens in new tab)
Source of the compiled MS15-051 binary used for the SYSTEM escalation.
-
Microsoft advisory for CVE-2015-1701CVE: Microsoft advisory for CVE-2015-1701, msrc.microsoft.com/update-guide/vulnerability/CVE-2015-1701 (opens in new tab)
Details the win32k.sys elevation of privilege fixed by MS15-051.