惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

Black Hills Information Security, Inc.

Same Problem, Different Angles: When Red Team and Blue Team Actually Talk to Each Other How to Identify and Exploit New Vulnerabilities Swapper – A Pure Regex Match/Replace Burp Extension A Practical Guide to BloodHound Data Collection Network Engineering Basics Signed, Trusted, and Abused: Proxy Execution via WebView2 Getting Started In Pentesting – Advice From The BHIS Pentest Lead Cloud Security: Tips and Resources for Securing the Cloud Lessons From A Chatbot Incident How to Lead Effective Tabletops Understanding GRC: How to Navigate Risks and Compliance Standards The “P” in PAM is for Persistence: Linux Persistence Technique Malware Analysis: How to Analyze and Understand Malware OSINT: How to Find, Use, and Control Open-Source Intelligence What to Do with Your First Home Lab When the SOC Goes to Deadwood: A Night to Remember Social Engineering and Microsoft SSPR: The Road to Pwnage is Paved with Good Intentions Common Cyber Threats Finding the Right Penetration Testing Company Deceptive-Auditing: An Active Directory Honeypots Tool The Curious Case of the Comburglar How to Set Smart Goals (That Actually Work For You) Inside the BHIS SOC: A Conversation with Hayden Covington Abusing Delegation with Impacket (Part 3): Resource-Based Constrained Delegation Why You Got Hacked – 2025 Super Edition Abusing Delegation with Impacket (Part 2): Constrained Delegation Abusing Delegation with Impacket (Part 1): Unconstrained Delegation GoSpoof – Turning Attacks into Intel Model Context Protocol (MCP) Bypassing WAFs Using Oversized Requests Getting Started with AI Hacking Part 2: Prompt Injection Wrangling Windows Event Logs with Hayabusa & SOF-ELK (Part 2) DomCat: A Domain Categorization Tool Wrangling Windows Event Logs with Hayabusa & SOF-ELK (Part 1) Microsoft Store and WinGet: Security Risks for Corporate Environments Default Web Content MailFail Commonly Abused Administrative Utilities: A Hidden Risk to Enterprise Security Stop Spoofing Yourself! Disabling M365 Direct Send Bypassing CSP with JSONP: Introducing JSONPeek and CSP B Gone Offensive Tooling Cheatsheets: An Infosec Survival Guide Resource DNS Triage Cheatsheet GraphRunner Cheatsheet Burp Suite Cheatsheet Impacket Cheatsheet Wireshark Cheatsheet Hashcat Cheatsheet EyeWitness Cheatsheet Nmap Cheatsheet Netcat (nc) Cheatsheet Hunt for Weak Spots in Your Wireless Network with Airodump-ng from the Aircrack-ng Suite Detecting ADCS Privilege Escalation Vulnerability Scanning with Nmap Getting Started with NetExec: Streamlining Network Discovery and Access How to Use Dirsearch Augmenting Penetration Testing Methodology with Artificial Intelligence – Part 3: Arcanum Cyber Security Bot How to Design and Execute Effective Social Engineering Attacks by Phone Abusing S4U2Self for Active Directory Pivoting Why Use a Macro Pad? Espanso: Text Replacement, the Easy Way Caging Copilot: Lessons Learned in LLM Security Augmenting Penetration Testing Methodology with Artificial Intelligence – Part 2: Copilot Augmenting Penetration Testing Methodology with Artificial Intelligence – Part 1: Burpference Intercepting Traffic for Mobile Applications that Bypass the System Proxy How to Root Android Phones Communicating Security to the C-Suite: A Strategic Approach Offline Memory Forensics With Volatility Getting Started with AI Hacking: Part 1 Go-Spoof: A Tool for Cyber Deception How to Test Adversary-in-the-Middle Without Hacking Tools Canary in the Code: Alert()-ing on XSS Exploits How to Hack Wi-Fi with No Wi-Fi Why Your Org Needs a Penetration Test Program Burp Suite Extension: Copy For Light at the End of the Dark Web Wi-Fi Forge: Practice Wi-Fi Security Without Hardware Avoiding Dirty RAGs: Retrieval-Augmented Generation with Ollama and LangChain Gone Phishing: Installing GoPhish and Creating a Campaign 5 Things We Are Going to Continue to Ignore in 2025 John Strand’s 5 Phase Plan For Starting in Computer Security Questions From a Beginner Threat Hunter GRC for Security Managers: From Checklists to Influence AI Large Language Models and Supervised Fine Tuning Attack Tactics 9: Shadow Creds for PrivEsc w/ Kent & Jordan One Active Directory Account Can Be Your Best Early Warning Introduction to Zeek Log Analysis Indecent Exposure: Your Secrets are Showing Creating Burp Extensions: A Beginner’s Guide Pitting AI Against AI: Using PyRIT to Assess Large Language Models (LLMs) The Top Ten List of Why You Got Hacked This Year (2023/2024) ICS Hard Knocks: Mitigations to Scenarios Found in ICS/OT Backdoors & Breaches Intro to Data Analytics Using SQL Finding Access Control Vulnerabilities with Autorize The Detection Engineering Process Cyber Risk Lessons We Can Learn From Hurricane Preparedness Intro to Desktop Application Testing Methodology What Is Penetration Testing? Adversary in the Middle (AitM): Post-Exploitation Pentesting, Threat Hunting, and SOC: An Overview QEMU, MSYS2, and Emacs: Open-Source Solutions to Run Virtual Machines on Windows
Adding Egress Brute Force to PowerShell Payloads
2016-09-19 · via Black Hills Information Security, Inc.

Philosoraptor - If my reverse shell never reaches the listener was the payload ever even executed?

We’ve all been there. You craft the perfect phishing email, register a great domain name, your multi handler is set up ever so perfectly. And then you wait and nothing happens. Egress packet filtering has destroyed all your hard work.

Now there are payloads and listeners designed specifically for this sort of thing, and they usually work well. But if you’re like me you want to have options. PowerShell has been my bread and butter as of late, so I decided to write a few lines of script that would allow me to try every port out towards my listener until I found an open one, and then use that port in my payload.

Be sure to set your own host address for your listener, also note the $wait variable has 2000 set as the timeout, you can increase this number to ensure you have enough time between client and server, but then it takes longer to get through all the ports so tweak as needed.

On the server side I wanted to have just as many options. No matter the listener; metasploit multi/handler, or any of the various cats (nc, ncat, PowerCat, gcat, dnscat, etc), I wanted a solution that could handle my reverse shells coming in on any port. IPtables to the rescue! This little one liner forwards all ports 65k and change to one of my choosing. (4444 in this case)

After setting the IPtables, fire up the metasploit reverse tcp listener.
Remember to use the port you specified in the iptables command (4444)

Throw the first bit of code in front of your favorite PowerShell reverse tcp payload. I generated mine with the Social Engineering Toolkit (SET). I simply had to modify the code to use the IP address I set in the Egress loop ($address = $Computername) and comment out  the line below that that is setting the port as I already set the variable named $port in my Egress loop.

Watching the PowerShell in action it fires the shell when it hits port 25 as this is the first open port to the listener.

That Is Nothing New

I am aware that Metasploit has an multi/shell/reverse_tcp_allports payload to listen on all ports. But like I said, we want flexibility. We aren’t always going to be in a situation where we can use a fancy pants Metasploit reverse tcp listener. Maybe you got root access to an old unused development web server on the DMZ and you want to use that as the landing place for your payloads? There are often constraints in place that can get in the way of installing all the tools of the trade. Perhaps you popped a box that has ncat already running on it because the user installed it with Nmap. Whatever your reason for not having the multi/shell/reverse_tcp_allports payload, this technique may be able to help.

The Same Concept with a Powercat Payload

I got Powercat up and rolling, so I generate a payload.

This spits out a ton of code but at the bottom there is the execution of the main function.

This looks like as good of a place as any to stick some variables.

So I throw my loop in there right above the call to the Main function so it executes before everything else. And I change the IP address and port number in the function call to their respective variables from my loop. (Powercat Payload didn’t like PS ISE, so I used Notepad++)

I save this script as payload.ps1  and start my PERSISTENT netcat listener. Again I use port 4444. We must be persistent as the payload hits the port twice and will kill the listener.

Then I execute payload.ps1

Once it hits port 25 (first open port)…. Success!

Conclusion

So there you have it. A few lines of PowerShell, and some iptables, and you have a way to potentially brute force your way out of some networks that are attempting to block egress traffic. If you are going to take the time to get code on a system, why not add a few more lines to increase your chances of getting that shell out? Even if you are in a situation where you can use theallports flavors of Metasploit Multi/Handler listeners, adding a simple loop to your PowerShell payload can greatly increase the odds of success.

Research Limitations

I tested this against iptables using both REJECT and DROP on the packets and it worked. You may or may not experience different results behind enterprise firewalls.

There are other ways to test for open ports with PowerShell. During my research, the method I used allowed me to make full connections with a timeout, which seemed to work the best.

*We love guest posts! Want to write for us? Use our contact form to let us know your title, and brief summary of your idea.