Class: Msf::Plugin::Sqlmap::SqlmapCommandDispatcher
Instance Attribute Summary
#driver
#shell, #tab_complete_items
Instance Method Summary
collapse
#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #initialize, #load_config, #log_error, #remove_lines
#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt
Instance Method Details
#cmd_sqlmap_connect(*args) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'plugins/sqlmap.rb', line 29
def cmd_sqlmap_connect(*args)
if args.empty?
print_error('Need a host, and optionally a port')
return
end
@host, @port = args
if !@port
@port = '8775'
end
@manager = Sqlmap::Manager.new(Sqlmap::Session.new(@host, @port))
print_good("Set connection settings for host #{@host} on port #{@port}")
end
|
#cmd_sqlmap_get_data(*args) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'plugins/sqlmap.rb', line 123
def cmd_sqlmap_get_data(*args)
unless args.length == 1
print_error('Usage:')
print_error('\tsqlmap_get_data <taskid>')
return
end
@hid_tasks ||= {}
@tasks ||= {}
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
@tasks[@hid_tasks[args[0]]] = @manager.get_options(@hid_tasks[args[0]])['options']
print_line
print_status("URL: #{@tasks[@hid_tasks[args[0]]]['url']}")
res = @manager.get_task_data(@hid_tasks[args[0]])
tbl = Rex::Text::Table.new(
'Columns' => ['Title', 'Payload']
)
res['data'].each do |d|
d['value'].each do |v|
v['data'].each do |i|
title = i[1]['title'].split('-')[0]
payload = i[1]['payload']
tbl << [title, payload]
end
end
end
print_line
print_line tbl.to_s
print_line
end
|
#cmd_sqlmap_get_log(*args) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'plugins/sqlmap.rb', line 87
def cmd_sqlmap_get_log(*args)
unless args.length == 1
print_error('Usage:')
print_error('\tsqlmap_get_log <taskid>')
return
end
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
res = @manager.get_task_log(@hid_tasks[args[0]])
res['log'].each do |message|
print_status("[#{message['time']}] #{message['level']}: #{message['message']}")
end
end
|
#cmd_sqlmap_get_option(*args) ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'plugins/sqlmap.rb', line 221
def cmd_sqlmap_get_option(*args)
@hid_tasks ||= {}
@tasks ||= {}
unless args.length == 2
print_error('Usage:')
print_error('\tsqlmap_get_option <taskid> <option_name>')
end
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
arg = args.first
task_options = @manager.get_options(@hid_tasks[arg])
@tasks[@hid_tasks[arg]] = task_options['options']
if @tasks[@hid_tasks[arg]]
print_good("#{args[1]} : #{@tasks[@hid_tasks[arg]][args[1]]}")
else
print_error("Option #{arg} doesn't exist")
end
end
|
#cmd_sqlmap_get_status(*args) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'plugins/sqlmap.rb', line 106
def cmd_sqlmap_get_status(*args)
unless args.length == 1
print_error('Usage:')
print_error('\tsqlmap_get_status <taskid>')
return
end
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
res = @manager.get_task_status(@hid_tasks[args[0]])
print_status("Status: #{res['status']}")
end
|
#cmd_sqlmap_list_tasks ⇒ Object
266
267
268
269
270
271
272
|
# File 'plugins/sqlmap.rb', line 266
def cmd_sqlmap_list_tasks
@hid_tasks ||= {}
@tasks ||= {}
@hid_tasks.each_key do |task|
print_good("Task ID: #{task}")
end
end
|
#cmd_sqlmap_new_task ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'plugins/sqlmap.rb', line 246
def cmd_sqlmap_new_task
@hid_tasks ||= {}
@tasks ||= {}
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
task_id = @manager.new_task
if task_id['taskid']
t_id = task_id['taskid'].to_s
@hid_tasks[(@hid_tasks.length + 1).to_s] = t_id
task_options = @manager.get_options(t_id)
@tasks[@hid_tasks[@hid_tasks.length]] = task_options['options']
print_good("Created task: #{@hid_tasks.length}")
else
print_error("Error connecting to the server. Please make sure the sqlmapapi server is running at #{@host}:#{@port}")
end
end
|
#cmd_sqlmap_save_data(*args) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'plugins/sqlmap.rb', line 164
def cmd_sqlmap_save_data(*args)
unless args.length == 1
print_error('Usage:')
print_error('\tsqlmap_save_data <taskid>')
return
end
unless framework.db && framework.db.usable
print_error('No database is connected or usable')
return
end
@hid_tasks ||= {}
@tasks ||= {}
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
@tasks[@hid_tasks[args[0]]] = @manager.get_options(@hid_tasks[args[0]])['options']
print_line
print_status('URL: ' + @tasks[@hid_tasks[args[0]]]['url'])
res = @manager.get_task_data(@hid_tasks[args[0]])
web_vuln_info = {}
url = @tasks[@hid_tasks[args[0]]]['url']
proto = url.split(':')[0]
host = url.split('/')[2]
port = 80
host, port = host.split(':') if host.include?(':')
path = '/' + url.split('/')[3..(url.split('/').length - 1)].join('/')
query = url.split('?')[1]
web_vuln_info[:web_site] = url
web_vuln_info[:path] = path
web_vuln_info[:query] = query
web_vuln_info[:host] = host
web_vuln_info[:port] = port
web_vuln_info[:ssl] = (proto =~ /https/)
web_vuln_info[:category] = 'imported from sqlmap'
res['data'].each do |d|
d['value'].each do |v|
web_vuln_info[:pname] = v['parameter']
web_vuln_info[:method] = v['place']
web_vuln_info[:payload] = v['suffix']
v['data'].each_value do |i|
web_vuln_info[:name] = i['title']
web_vuln_info[:description] = res.to_json
web_vuln_info[:proof] = i['payload']
framework.db.report_web_vuln(web_vuln_info)
end
end
end
print_good('Saved vulnerabilities to database.')
end
|
#cmd_sqlmap_set_option(*args) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'plugins/sqlmap.rb', line 45
def cmd_sqlmap_set_option(*args)
unless args.length == 3
print_error('Usage:')
print_error('\tsqlmap_set_option <taskid> <option_name> <option_value>')
return
end
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
val = args[2] =~ /^\d+$/ ? args[2].to_i : args[2]
res = @manager.set_option(@hid_tasks[args[0]], args[1], val)
print_status("Success: #{res['success']}")
end
|
#cmd_sqlmap_start_task(*args) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'plugins/sqlmap.rb', line 63
def cmd_sqlmap_start_task(*args)
if args.empty?
print_error('Usage:')
print_error('\tsqlmap_start_task <taskid> [<url>]')
return
end
options = {}
options['url'] = args[1] if args.length == 2
if !options['url'] && @tasks[@hid_tasks[args[0]]]['url'] == ''
print_error('You need to specify a URL either as an argument to sqlmap_start_task or sqlmap_set_option')
return
end
unless @manager
print_error('Please run sqlmap_connect <host> first.')
return
end
res = @manager.start_task(@hid_tasks[args[0]], options)
print_status("Started task: #{res['success']}")
end
|
#commands ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'plugins/sqlmap.rb', line 14
def commands
{
'sqlmap_new_task' => 'Create a new task',
'sqlmap_connect' => 'sqlmap_connect <host> [<port>]',
'sqlmap_list_tasks' => 'List the knows tasks. New tasks are not stored in DB, so lives as long as the console does',
'sqlmap_get_option' => 'Get an option for a task',
'sqlmap_set_option' => 'Set an option for a task',
'sqlmap_start_task' => 'Start the task',
'sqlmap_get_status' => 'Get the status of a task',
'sqlmap_get_log' => 'Get the running log of a task',
'sqlmap_get_data' => 'Get the resulting data of the task',
'sqlmap_save_data' => 'Save the resulting data as web_vulns'
}
end
|
#name ⇒ Object
10
11
12
|
# File 'plugins/sqlmap.rb', line 10
def name
'Sqlmap'
end
|