Module: PWN::Plugins::BurpSuite

Defined in:
lib/pwn/plugins/burp_suite.rb

Overview

This plugin was created to interact w/ Burp Suite Pro in headless mode to kick off spidering/live scanning

Constant Summary collapse

@@logger =
Supported Method Parameters

burp_obj = PWN::Plugins::BurpSuite.start(

burp_jar_path: 'required - path of burp suite pro jar file',
headless: 'optional - run burp headless if set to true',
browser_type: 'optional - defaults to :firefox. See PWN::Plugins::TransparentBrowser.help for a list of types',

)

PWN::Plugins::PWNLogger.create

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



287
288
289
290
291
# File 'lib/pwn/plugins/burp_suite.rb', line 287

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.disable_proxy(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::BurpSuite.disable_proxy(

burp_obj: 'required - burp_obj returned by #start method'

)



91
92
93
94
95
96
97
98
99
100
# File 'lib/pwn/plugins/burp_suite.rb', line 91

public_class_method def self.disable_proxy(opts = {})
  burp_obj = opts[:burp_obj]
  rest_browser = burp_obj[:rest_browser]
  burpbuddy_api = burp_obj[:burpbuddy_api]

  disable_resp = rest_browser.post("http://#{burpbuddy_api}/proxy/intercept/disable", nil)
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.enable_proxy(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::BurpSuite.enable_proxy(

burp_obj: 'required - burp_obj returned by #start method'

)



75
76
77
78
79
80
81
82
83
84
# File 'lib/pwn/plugins/burp_suite.rb', line 75

public_class_method def self.enable_proxy(opts = {})
  burp_obj = opts[:burp_obj]
  rest_browser = burp_obj[:rest_browser]
  burpbuddy_api = burp_obj[:burpbuddy_api]

  enable_resp = rest_browser.post("http://#{burpbuddy_api}/proxy/intercept/enable", nil)
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.generate_scan_report(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::BurpSuite.generate_scan_report(

burp_obj: 'required - burp_obj returned by #start method',
target_url: 'required - target_url passed to #invoke_active_scan method',
report_type: :html|:xml|:both,
output_path: 'required - path to save report results'

)



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/pwn/plugins/burp_suite.rb', line 216

public_class_method def self.generate_scan_report(opts = {})
  burp_obj = opts[:burp_obj]
  target_url = opts[:target_url]
  rest_browser = burp_obj[:rest_browser]
  burpbuddy_api = burp_obj[:burpbuddy_api]
  report_type = opts[:report_type]
  # When burpbuddy begins to support XML report generation
  valid_report_types_arr = %i[
    html
    xml
  ]

  raise 'INVALID Report Type' unless valid_report_types_arr.include?(report_type)

  output_path = opts[:output_path].to_s.scrub

  scheme = URI.parse(target_url).scheme
  host = URI.parse(target_url).host
  port = URI.parse(target_url).port

  implicit_http_ports_arr = [
    80,
    443
  ]

  if implicit_http_ports_arr.include?(port)
    target_domain = "#{scheme}://#{host}"
  else
    target_domain = "#{scheme}://#{host}:#{port}"
  end

  report_url = Base64.strict_encode64(target_domain)
  # Ready scanreport API call in burpbuddy to support iHTML & XML report generation
  report_resp = rest_browser.get("http://#{burpbuddy_api}/scanreport/#{report_type.to_s.upcase}/#{report_url}")
  # report_resp = rest_browser.get("http://#{burpbuddy_api}/scanreport/#{report_url}")
  File.open(output_path, 'w') do |f|
    f.puts(report_resp.body)
  end
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.get_current_sitemap(opts = {}) ⇒ Object

Supported Method Parameters

json_sitemap = PWN::Plugins::BurpSuite.get_current_sitemap(

burp_obj: 'required - burp_obj returned by #start method'

)



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/pwn/plugins/burp_suite.rb', line 107

public_class_method def self.get_current_sitemap(opts = {})
  burp_obj = opts[:burp_obj]
  rest_browser = burp_obj[:rest_browser]
  burpbuddy_api = burp_obj[:burpbuddy_api]

  sitemap = rest_browser.get("http://#{burpbuddy_api}/sitemap", content_type: 'application/json; charset=UTF8')
  JSON.parse(sitemap)
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.get_scan_issues(opts = {}) ⇒ Object

Supported Method Parameters

json_scan_issues = PWN::Plugins::BurpSuite.get_scan_issues(

burp_obj: 'required - burp_obj returned by #start method'

)



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/pwn/plugins/burp_suite.rb', line 196

public_class_method def self.get_scan_issues(opts = {})
  burp_obj = opts[:burp_obj]
  rest_browser = burp_obj[:rest_browser]
  burpbuddy_api = burp_obj[:burpbuddy_api]

  scan_issues = rest_browser.get("http://#{burpbuddy_api}/scanissues")
  JSON.parse(scan_issues)
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.helpObject

Display Usage for this Module



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/pwn/plugins/burp_suite.rb', line 295

public_class_method def self.help
  puts "USAGE:
    burp_obj = #{self}.start(
      burp_jar_path: 'required - path of burp suite pro jar file',
      headless: 'optional - run headless if set to true',
      browser_type: 'optional - defaults to :firefox. See PWN::Plugins::TransparentBrowser.help for a list of types',
    )

    #{self}.enable_proxy(
      burp_obj: 'required - burp_obj returned by #start method'
    )

    #{self}.disable_proxy(
      burp_obj: 'required - burp_obj returned by #start method'
    )

    json_sitemap = #{self}.get_current_sitemap(
      burp_obj: 'required - burp_obj returned by #start method'
    )

    active_scan_url_arr = #{self}.invoke_active_scan(
      burp_obj: 'required - burp_obj returned by #start method',
      target_url: 'required - target url to scan in sitemap (should be loaded & authenticated w/ burp_obj[:burp_browser])'
    )

    json_scan_issues = #{self}.get_scan_issues(
      burp_obj: 'required - burp_obj returned by #start method'
    ).to_json

    #{self}.generate_scan_report(
      burp_obj: 'required - burp_obj returned by #start method',
      active_scan_url_arr: 'required - active_scan_url_arr returned by #invoke_active_scan method',
      report_type: :html|:xml,
      output_path: 'required - path to save report results'
    )

    #{self}.stop(
      burp_obj: 'required - burp_obj returned by #start method'
    )

    #{self}.authors
  "
end

.invoke_active_scan(opts = {}) ⇒ Object

Supported Method Parameters

active_scan_url_arr = PWN::Plugins::BurpSuite.invoke_active_scan(

burp_obj: 'required - burp_obj returned by #start method',
target_url: 'required - target url to scan in sitemap (should be loaded & authenticated w/ burp_obj[:burp_browser])'

)



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
163
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
# File 'lib/pwn/plugins/burp_suite.rb', line 125

public_class_method def self.invoke_active_scan(opts = {})
  burp_obj = opts[:burp_obj]
  rest_browser = burp_obj[:rest_browser]
  burpbuddy_api = burp_obj[:burpbuddy_api]
  target_url = opts[:target_url].to_s.scrub.strip.chomp
  target_scheme = URI.parse(target_url).scheme
  target_domain_name = URI.parse(target_url).host
  target_port = URI.parse(target_url).port.to_i
  if target_scheme == 'http'
    use_https = false
  else
    use_https = true
  end

  active_scan_url_arr = []
  json_sitemap = get_current_sitemap(burp_obj: burp_obj)
  json_sitemap.each do |site|
    json_http_svc = site['http_service']
    json_req = site['request']
    json_protocol = json_http_svc['protocol']
    json_host = json_http_svc['host'].to_s.scrub.strip.chomp
    json_port = json_http_svc['port'].to_i
    json_path = json_req['path']

    implicit_http_ports_arr = [
      80,
      443
    ]

    if implicit_http_ports_arr.include?(json_port)
      json_uri = "#{json_protocol}//#{json_host}#{json_path}"
    else
      json_uri = "#{json_protocol}//#{json_host}:#{json_port}#{json_path}"
    end

    next unless json_host == target_domain_name && json_port == target_port

    puts "Adding #{json_uri} to Active Scan"
    active_scan_url_arr.push(json_uri)
    post_body = "{ \"host\": \"#{json_host}\", \"port\": \"#{json_port}\", \"useHttps\": #{use_https}, \"request\": \"#{json_req['raw']}\" }"
    # Kick off an active scan for each given page in the json_sitemap results
    rest_browser.post("http://#{burpbuddy_api}/scan/active", post_body, content_type: 'application/json')
  end

  # Wait for scan completion
  scan_queue = rest_browser.get("http://#{burpbuddy_api}/scan/active")
  json_scan_queue = JSON.parse(scan_queue)
  scan_queue_total = json_scan_queue.count
  json_scan_queue.each do |scan_item|
    this_scan_item_id = scan_item['id']
    until scan_item['status'] == 'finished'
      scan_item_resp = rest_browser.get("http://#{burpbuddy_api}/scan/active/#{this_scan_item_id}")
      scan_item = JSON.parse(scan_item_resp)
      scan_status = scan_item['status']
      puts "Target ID ##{this_scan_item_id} of ##{scan_queue_total}| #{scan_status}"
      sleep 3
    end
    puts "Target ID ##{this_scan_item_id} of ##{scan_queue_total}| 100% complete\n"
  end

  active_scan_url_arr # Return array of targeted URIs to pass to #generate_scan_report method
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.start(opts = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pwn/plugins/burp_suite.rb', line 19

public_class_method def self.start(opts = {})
  burp_jar_path = opts[:burp_jar_path]
  raise 'Invalid path to burp jar file.  Please check your spelling and try again.' unless File.exist?(burp_jar_path)

  burp_root = File.dirname(burp_jar_path)

  browser_type = if opts[:browser_type].nil?
                   :firefox
                 else
                   opts[:browser_type]
                 end

  if opts[:headless]
    burp_cmd_string = "java -Xmx3G -Djava.awt.headless=true -classpath #{burp_root}/burpbuddy.jar:#{burp_jar_path} burp.StartBurp"
  else
    burp_cmd_string = "java -Xmx3G -classpath #{burp_root}/burpbuddy.jar:#{burp_jar_path} burp.StartBurp"
  end

  # Construct burp_obj
  burp_obj = {}
  burp_obj[:pid] = Process.spawn(burp_cmd_string)
  rest_browser = PWN::Plugins::TransparentBrowser.open(browser_type: :rest)
  burp_obj[:mitm_proxy] = '127.0.0.1:8080'
  burp_obj[:burpbuddy_api] = '127.0.0.1:8001'
  burp_obj[:rest_browser] = rest_browser

  # Proxy always listens on localhost...use SSH tunneling if remote access is required
  burp_browser = PWN::Plugins::TransparentBrowser.open(
    browser_type: browser_type,
    proxy: "http://#{burp_obj[:mitm_proxy]}"
  )

  burp_obj[:burp_browser] = burp_browser

  # Wait for TCP 8001 to open prior to returning burp_obj
  loop do
    s = TCPSocket.new('127.0.0.1', 8001)
    s.close
    break
  rescue Errno::ECONNREFUSED
    print '.'
    sleep 3
    next
  end

  burp_obj
rescue StandardError => e
  stop(burp_obj: burp_obj) unless burp_obj.nil?
  raise e
end

.stop(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::BurpSuite.stop(

burp_obj: 'required - burp_obj returned by #start method'

)



272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/pwn/plugins/burp_suite.rb', line 272

public_class_method def self.stop(opts = {})
  burp_obj = opts[:burp_obj]
  burp_browser = burp_obj[:burp_browser]
  burp_pid = burp_obj[:pid]

  burp_browser = PWN::Plugins::TransparentBrowser.close(browser_obj: burp_browser)
  Process.kill('TERM', burp_pid)

  burp_obj = nil
rescue StandardError => e
  raise e
end

.update_burp_jarObject

Supported Method Parameters

PWN::Plugins::BurpSuite.update_burp_jar( )



263
264
265
# File 'lib/pwn/plugins/burp_suite.rb', line 263

public_class_method def self.update_burp_jar
  # TODO: Do this if PortSwigger ever decides to includes this functionality as a CLI argument.
end