InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Follow publication

Member-only story

Vanilla PowerShell Reverse Shell Using SMTP

Pampuna
InfoSec Write-ups
Published in
6 min read6 days ago

Lately, as you may have noticed, I’ve been delving into the world of custom PowerShell reverse shells. I’ve been challenging myself to create tools that don’t rely on external dependencies, especially on the client side. Instead, my focus has been on using unconventional protocols and methods to establish remote connections.

My most recent experiment led to the creation of a reverse shell that communicates through custom headers and response messages in SMTP (Simple Mail Transfer Protocol). By embedding data the data, I was able to craft a working reverse shell. It’s a method that aims to fly under the radar a bit, and I’m excited to test how security measures will handle this.

Not a member? Read this article for free on my site.

In this article, I’ll walk you through the theory and share the proof of concept code that achieves a ping-pong exchange between the client and the server.

Visualizing SMTP (DALL·E 3)

Note that this article is written for educational purposes and is intended only for legal penetration testing and red teaming activities, where explicit permission has been granted. If you wish to test any of the scripts provided, please refer to the disclaimer at the end of this article.

But before we dive into the proof of concept code, let’s take a quick look at the final result: a functional reverse shell, powered by embedding data within SMTP communication using headers and status codes.

Demonstrating the full reverse shell code running in PowerShell

The Theory

Before I could start writing code I had to figure out where to embed my data, as I didn’t want to use the e-mail subject or body. After all, the client is the one initiating the connection and also needs to be able to receive data.

As stated in the SMTP RFC, it’s possible to embed a lot of data in each header line:

The maximum total length of a text line including the is 1000 octets (not counting the leading dot duplicate for transparency). This number may be increased by the use of SMTP Service Extensions.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Written by Pampuna

Ethical Hacker & Security Researcher. Crafting offensive tools with Python & PowerShell, emphasizing defensive strategies. Passionate about digital security.

No responses yet

Write a response