Browse Source

Merge branch 'sqlmap_plugin_json_parse_issue' of https://github.com/void-in/metasploit-framework into sqlmap_plugin_json_parse_issue

root 5 years ago
parent
commit
b47305ba4a
2 changed files with 39 additions and 38 deletions
  1. 3
    2
      lib/sqlmap/sqlmap_manager.rb
  2. 36
    36
      plugins/sqlmap.rb

+ 3
- 2
lib/sqlmap/sqlmap_manager.rb View File

@@ -50,14 +50,15 @@ module Sqlmap
50 50
 
51 51
     private
52 52
     def parse_response(res)
53
+      json = {}
53 54
       if res && res.body
54 55
         begin
55
-          res = JSON.parse(res.body)
56
+          json = JSON.parse(res.body)
56 57
         rescue JSON::ParserError
57 58
         end
58 59
       end
59 60
 
60
-      res
61
+      json
61 62
     end
62 63
   end
63 64
 end

+ 36
- 36
plugins/sqlmap.rb View File

@@ -28,14 +28,14 @@ module Msf
28 28
 
29 29
       def cmd_sqlmap_connect(*args)
30 30
         if args.length == 0
31
-          print_error("Need a host, and optionally a port")
31
+          print_error('Need a host, and optionally a port')
32 32
           return
33 33
         end
34 34
 
35 35
         @host, @port = args
36 36
 
37 37
         if !@port
38
-          @port = "8775"
38
+          @port = '8775'
39 39
         end
40 40
 
41 41
         @manager = Sqlmap::Manager.new(Sqlmap::Session.new(@host, @port))
@@ -44,13 +44,13 @@ module Msf
44 44
 
45 45
       def cmd_sqlmap_set_option(*args)
46 46
         unless args.length == 3
47
-          print_error("Usage:")
48
-          print_error("\tsqlmap_set_option <taskid> <option_name> <option_value>")
47
+          print_error('Usage:')
48
+          print_error('\tsqlmap_set_option <taskid> <option_name> <option_value>')
49 49
           return
50 50
         end
51 51
 
52 52
         unless @manager
53
-          print_error("Please run sqlmap_connect <host> first.")
53
+          print_error('Please run sqlmap_connect <host> first.')
54 54
           return
55 55
         end
56 56
 
@@ -62,8 +62,8 @@ module Msf
62 62
 
63 63
       def cmd_sqlmap_start_task(*args)
64 64
         if args.length == 0
65
-          print_error("Usage:")
66
-          print_error("\tsqlmap_start_task <taskid> [<url>]")
65
+          print_error('Usage:')
66
+          print_error('\tsqlmap_start_task <taskid> [<url>]')
67 67
           return
68 68
         end
69 69
 
@@ -76,7 +76,7 @@ module Msf
76 76
         end
77 77
 
78 78
         unless @manager
79
-          print_error("Please run sqlmap_connect <host> first.")
79
+          print_error('Please run sqlmap_connect <host> first.')
80 80
           return
81 81
         end
82 82
 
@@ -86,13 +86,13 @@ module Msf
86 86
 
87 87
       def cmd_sqlmap_get_log(*args)
88 88
         unless args.length == 1
89
-          print_error("Usage:")
90
-          print_error("\tsqlmap_get_log <taskid>")
89
+          print_error('Usage:')
90
+          print_error('\tsqlmap_get_log <taskid>')
91 91
           return
92 92
         end
93 93
 
94 94
         unless @manager
95
-          print_error("Please run sqlmap_connect <host> first.")
95
+          print_error('Please run sqlmap_connect <host> first.')
96 96
           return
97 97
         end
98 98
 
@@ -105,13 +105,13 @@ module Msf
105 105
 
106 106
       def cmd_sqlmap_get_status(*args)
107 107
         unless args.length == 1
108
-          print_error("Usage:")
109
-          print_error("\tsqlmap_get_status <taskid>")
108
+          print_error('Usage:')
109
+          print_error('\tsqlmap_get_status <taskid>')
110 110
           return
111 111
         end
112 112
 
113 113
         unless @manager
114
-          print_error("Please run sqlmap_connect <host> first.")
114
+          print_error('Please run sqlmap_connect <host> first.')
115 115
           return
116 116
         end
117 117
 
@@ -122,8 +122,8 @@ module Msf
122 122
 
123 123
       def cmd_sqlmap_get_data(*args)
124 124
         unless args.length == 1
125
-          print_error("Usage:")
126
-          print_error("\tsqlmap_get_data <taskid>")
125
+          print_error('Usage:')
126
+          print_error('\tsqlmap_get_data <taskid>')
127 127
           return
128 128
         end
129 129
 
@@ -131,14 +131,14 @@ module Msf
131 131
         @tasks ||= {}
132 132
 
133 133
         unless @manager
134
-          print_error("Please run sqlmap_connect <host> first.")
134
+          print_error('Please run sqlmap_connect <host> first.')
135 135
           return
136 136
         end
137 137
 
138 138
         @tasks[@hid_tasks[args[0]]] = @manager.get_options(@hid_tasks[args[0]])['options']
139 139
 
140 140
         print_line
141
-        print_status("URL: " + @tasks[@hid_tasks[args[0]]]['url'])
141
+        print_status('URL: ' + @tasks[@hid_tasks[args[0]]]['url'])
142 142
 
143 143
         res = @manager.get_task_data(@hid_tasks[args[0]])
144 144
 
@@ -162,13 +162,13 @@ module Msf
162 162
 
163 163
       def cmd_sqlmap_save_data(*args)
164 164
         unless args.length == 1
165
-          print_error("Usage:")
166
-          print_error("\tsqlmap_save_data <taskid>")
165
+          print_error('Usage:')
166
+          print_error('\tsqlmap_save_data <taskid>')
167 167
           return
168 168
         end
169 169
 
170 170
         unless framework.db && framework.db.usable
171
-          print_error("No database is connected or usable")
171
+          print_error('No database is connected or usable')
172 172
           return
173 173
         end
174 174
 
@@ -176,14 +176,14 @@ module Msf
176 176
         @tasks ||= {}
177 177
 
178 178
         unless @manager
179
-          print_error("Please run sqlmap_connect <host> first.")
179
+          print_error('Please run sqlmap_connect <host> first.')
180 180
           return
181 181
         end
182 182
 
183 183
         @tasks[@hid_tasks[args[0]]] = @manager.get_options(@hid_tasks[args[0]])['options']
184 184
 
185 185
         print_line
186
-        print_status("URL: " + @tasks[@hid_tasks[args[0]]]['url'])
186
+        print_status('URL: ' + @tasks[@hid_tasks[args[0]]]['url'])
187 187
 
188 188
         res = @manager.get_task_data(@hid_tasks[args[0]])
189 189
         web_vuln_info = {}
@@ -214,7 +214,7 @@ module Msf
214 214
             end
215 215
           end
216 216
         end
217
-        print_good("Saved vulnerabilities to database.")
217
+        print_good('Saved vulnerabilities to database.')
218 218
       end
219 219
 
220 220
       def cmd_sqlmap_get_option(*args)
@@ -222,12 +222,12 @@ module Msf
222 222
         @tasks ||= {}
223 223
 
224 224
         unless args.length == 2
225
-          print_error("Usage:")
226
-          print_error("\tsqlmap_get_option <taskid> <option_name>")
225
+          print_error('Usage:')
226
+          print_error('\tsqlmap_get_option <taskid> <option_name>')
227 227
         end
228 228
 
229 229
         unless @manager
230
-          print_error("Please run sqlmap_connect <host> first.")
230
+          print_error('Please run sqlmap_connect <host> first.')
231 231
           return
232 232
         end
233 233
 
@@ -247,14 +247,14 @@ module Msf
247 247
         @tasks ||= {}
248 248
 
249 249
         unless @manager
250
-          print_error("Please run sqlmap_connect <host> first.")
250
+          print_error('Please run sqlmap_connect <host> first.')
251 251
           return
252 252
         end
253
-        taskid = @manager.new_task
254
-        if taskid && taskid['taskid']
255
-          taskid = taskid['taskid']
256
-          @hid_tasks[(@hid_tasks.length + 1).to_s] = taskid
257
-          task_options = @manager.get_options(taskid)
253
+        task_id = @manager.new_task
254
+        if task_id['taskid']
255
+          t_id = task_id['taskid'].to_s
256
+          @hid_tasks[(@hid_tasks.length + 1).to_s] = t_id
257
+          task_options = @manager.get_options(t_id)
258 258
           @tasks[@hid_tasks[@hid_tasks.length]] = task_options['options']
259 259
           print_good("Created task: #{@hid_tasks.length}")
260 260
         else
@@ -276,7 +276,7 @@ module Msf
276 276
 
277 277
       add_console_dispatcher(SqlmapCommandDispatcher)
278 278
 
279
-      print_status("Sqlmap plugin loaded")
279
+      print_status('Sqlmap plugin loaded')
280 280
     end
281 281
 
282 282
     def cleanup
@@ -284,11 +284,11 @@ module Msf
284 284
     end
285 285
 
286 286
     def name
287
-      "Sqlmap"
287
+      'Sqlmap'
288 288
     end
289 289
 
290 290
     def desc
291
-      "sqlmap plugin for Metasploit"
291
+      'sqlmap plugin for Metasploit'
292 292
     end
293 293
   end
294 294
 end

Loading…
Cancel
Save