PowerShellArsenal is a PowerShell module used to aid a reverse engineer. The module can be used to disassemble managed and unmanaged code, perform .NET malware analysis, analyze/scrape memory, parse file formats and memory structures, obtain internal system information, etc. PowerShellArsenal is comprised of the following tools:
Disassemble native and managed code.
Disassembles a byte array using the Capstone Engine disassembly framework.
Disassembles a raw MSIL byte array passed in from a MethodInfo object in a manner similar to that of Ildasm.
Useful tools when performing malware analysis.
Provides an executable wrapper for an X86 or X86_64 function.
Loads a DLL into the current PowerShell process.
Creates an executable wrapper delegate around an unmanaged, exported function.
Parses a HOSTS file.
Replace or append an entry to a HOSTS file.
Remove an entry or series of entries from a HOSTS file.
Output all strings from a .NET executable.
Extract managed resources from a .NET assembly
Strips a SuppressIldasmAttribute attribute from a .NET assembly.
Returns all methods in an assembly that are implemented in MSIL.
Inspect and analyze process memory
Outputs all printable strings from the user-mode memory of a process.
A wrapper for kernel32!VirtualQueryEx
Retrieve virtual memory information for every unique set of pages in user memory. This function is similar to the !vadump WinDbg command.
Marshals data from an unmanaged block of memory in an arbitrary process to a newly allocated managed object of the specified type.
Parse file formats and in-memory structures.
An on-disk and in-memory PE parser and process dumper.
Finds portable executables in memory regardless of whether or not they were loaded in a legitimate fashion.
Displays symbolic information from Windows LIB files.
Displays information about Windows object (OBJ) files.
Obtain and analyze low-level Windows OS information.
A utility that calls and parses the output of the ntdll!NtQuerySystemInformation function. This utility can be used to query internal OS information that is typically not made visible to a user.
Returns the process environment block (PEB) of a process.
Starts a trace of loaded process modules
Displays the process modules that have been loaded since the call to Register-ProcessModuleTrace
Stops the running process module trace
A wrapper for kernel32!GetSystemInfo
Miscellaneous helper functions
A proxy function used to extend the built-in Get-Member cmdlet. It adds the '-Private' parameter allowing you to display non-public .NET members
Dumps strings from files in both Unicode and Ascii. This cmdlet replicates the functionality of strings.exe from Sysinternals.
Converts the bytes of a file to a string that has a 1-to-1 mapping back to the file's original bytes. ConvertTo-String is useful for performing binary regular expressions.
Calculates the entropy of a file or byte array.
Libraries required by some of the RE functions.
The Capstone disassembly engine C# binding.
A powerful .NET deobfuscation and .NET PE parsing library.
A module used to easily define in-memory enums, structs, and Win32 functions.
ps1xml files used to format the output of various PowerShellArsenal functions.
The PowerShellArsenal module and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise.
Refer to the comment-based help in each individual script for detailed usage information.
To install this module, drop the entire PowerShellArsenal folder into one of your module directories. The default PowerShell module paths are listed in the $Env:PSModulePath environment variable.
The default per-user module path is: "$Env:HomeDrive$Env:HOMEPATH\Documents\WindowsPowerShell\Modules" The default computer-level module path is: "$Env:windir\System32\WindowsPowerShell\v1.0\Modules"
To use the module, type Import-Module PowerShellArsenal
To see the commands imported, type Get-Command -Module PowerShellArsenal
If you're running PowerShell v3 and you want to remove the annoying 'Do you really want to run scripts downloaded from the Internet' warning, once you've placed PowerShellArsenal into your module path, run the following one-liner:
$Env:PSModulePath.Split(';') | % { if ( Test-Path (Join-Path $_ PowerShellArsenal) ) {Get-ChildItem $_ -Recurse | Unblock-File} }
For help on each individual command, Get-Help is your friend.
Note: The tools contained within this module were all designed such that they can be run individually. Including them in a module simply lends itself to increased portability.
For all contributors and future contributors to PowerShellArsenal, I ask that you follow this style guide when writing your scripts/modules.
-
Avoid Write-Host at all costs. PowerShell functions/cmdlets are not command-line utilities! Pull requests containing code that uses Write-Host will not be considered. You should output custom objects instead. For more information on creating custom objects, read these articles:
-
If you want to display relevant debugging information to the screen, use Write-Verbose. The user can always just tack on '-Verbose'.
-
Always provide descriptive, comment-based help for every script. Also, be sure to include your name and a BSD 3-Clause license (unless there are extenuating circumstances that prevent the application of the BSD license).
-
Make sure all functions follow the proper PowerShell verb-noun agreement. Use Get-Verb to list the default verbs used by PowerShell. Exceptions to supported verbs will be considered on a case-by-case basis.
-
I prefer that variable names be capitalized and be as descriptive as possible.
-
Provide logical spacing in between your code. Indent your code to make it more readable.
-
If you find yourself repeating code, write a function.
-
Catch all anticipated errors and provide meaningful output. If you have an error that should stop execution of the script, use 'Throw'. If you have an error that doesn't need to stop execution, use Write-Error.
-
If you are writing a script that interfaces with the Win32 API, try to avoid compiling C# inline with Add-Type. Try to use the PSReflect module, if possible.
-
Do not use hardcoded paths. A script should be useable right out of the box. No one should have to modify the code unless they want to.
-
PowerShell v2 compatibility is highly desired.
-
Use positional parameters and make parameters mandatory when it makes sense to do so. For example, I'm looking for something like the following:
[Parameter(Position = 0, Mandatory = $True)]
-
Don't use any aliases unless it makes sense for receiving pipeline input. They make code more difficult to read for people who are unfamiliar with a particular alias.
-
Try not to let commands run on for too long. For example, a pipeline is a natural place for a line break.
-
Don't go overboard with inline comments. Only use them when certain aspects of the code might be confusing to a reader.
-
Rather than using Out-Null to suppress unwanted/irrelevant output, save the unwanted output to $null. Doing so provides a slight performance enhancement.
-
Use default values for your parameters when it makes sense. Ideally, you want a script that will work without requiring any parameters.
-
Explicitly state all required and optional dependencies in the comment-based help for your function. All library dependencies should reside in the 'Lib' folder.
-
If a script creates complex custom objects, include a ps1xml file that will properly format the object's output. ps1xml files are stored in Lib\Formatters.