buby 1.5.2-java → 1.6.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  class BurpExtender
2
2
  # @api private
3
3
  class ConsolePane < Java::JavaxSwing::JScrollPane
4
+ HEADER = " Welcome to the Burp JRuby IRB Console [#{JRUBY_VERSION} (#{RUBY_VERSION})]\n\n"
4
5
  attr_accessor :text, :tar
5
6
  def initialize
6
7
  super
@@ -11,7 +12,13 @@ class BurpExtender
11
12
  @text.background = Java::JavaAwt::Color.new(0xf2f2f2)
12
13
  @text.foreground = Java::JavaAwt::Color.new(0xa40000)
13
14
  self.viewport_view = @text
14
- @tar = Java::OrgJrubyDemo::TextAreaReadline.new(@text, " Welcome to the Burp JRuby IRB Console [#{JRUBY_VERSION} (#{RUBY_VERSION})]\n\n")
15
+ @tar = begin
16
+ Java::OrgJrubyDemo::TextAreaReadline.new(@text, HEADER)
17
+ rescue NameError
18
+ require 'readline'
19
+ Java::OrgJrubyDemoReadline::TextAreaReadline.new(text, HEADER)
20
+ end
21
+
15
22
  JRuby.objectspace = true # useful for code completion
16
23
  @tar.hook_into_runtime_with_streams(JRuby.runtime)
17
24
  end
@@ -18,6 +18,7 @@ class Buby
18
18
  # sub-menus, checkbox menu items, etc.) that should be displayed.
19
19
  # Extensions may return +nil+ from this method, to indicate that no menu
20
20
  # items are required.
21
+ # @deprecated
21
22
  #
22
23
  def self.createMenuItems invocation
23
24
  pp [:got_create_menu_items, invocation] if $DEBUG
@@ -25,10 +26,38 @@ class Buby
25
26
  nil
26
27
  end
27
28
 
28
- # (see ContextMenuFactory.createMenuItems)
29
+ # This method will be called by Burp when the user invokes a context menu
30
+ # anywhere within Burp. The factory can then provide any custom context
31
+ # menu items that should be displayed in the context menu, based on the
32
+ # details of the menu invocation.
33
+ # This method calls create_menu_items after implanting the invocation class.
34
+ # Redefine to bypass this behavior
35
+ #
36
+ # @param [IContextMenuInvocation] invocation An object the extension can
37
+ # query to obtain details of the context menu invocation.
38
+ # @return [Array<JMenuItem>] A list of custom menu items (which may include
39
+ # sub-menus, checkbox menu items, etc.) that should be displayed.
40
+ # Extensions may return +nil+ from this method, to indicate that no menu
41
+ # items are required.
42
+ #
29
43
  def createMenuItems invocation
30
44
  pp [:got_create_menu_items, invocation] if $DEBUG
31
- Buby::Implants::ContextMenuInvocation.implant invocation
45
+ create_menu_items Buby::Implants::ContextMenuInvocation.implant(invocation)
46
+ end
47
+
48
+ # This method will be called by Burp when the user invokes a context menu
49
+ # anywhere within Burp. The factory can then provide any custom context
50
+ # menu items that should be displayed in the context menu, based on the
51
+ # details of the menu invocation.
52
+ #
53
+ # @param [IContextMenuInvocation] invocation An object the extension can
54
+ # query to obtain details of the context menu invocation.
55
+ # @return [Array<JMenuItem>] A list of custom menu items (which may include
56
+ # sub-menus, checkbox menu items, etc.) that should be displayed.
57
+ # Extensions may return +nil+ from this method, to indicate that no menu
58
+ # items are required.
59
+ #
60
+ def create_menu_items invocation
32
61
  nil
33
62
  end
34
63
  end
@@ -138,6 +138,8 @@ class Buby
138
138
  end
139
139
 
140
140
  module ExtenderMethods
141
+ @@handler = nil
142
+
141
143
  # Returns the internal Ruby handler reference.
142
144
  #
143
145
  # The handler is the ruby class or module used for proxying BurpExtender
@@ -1,4 +1,5 @@
1
1
  class Buby
2
+ # @todo document
2
3
  module Implants
3
4
  module Proxy
4
5
  def implanted?
@@ -1,5 +1,6 @@
1
1
 
2
2
  class Buby
3
+ # @deprecated
3
4
  class BubyArrayWrapper
4
5
  include Enumerable
5
6
 
@@ -8,38 +8,53 @@ class Buby
8
8
  # This module is used to extend the JRuby proxy class returned by Burp.
9
9
  #
10
10
  module ContextMenuInvocation
11
+
11
12
  # Context menu is being invoked in a request editor.
12
- CONTEXT_MESSAGE_EDITOR_REQUEST = 0;
13
+ CONTEXT_MESSAGE_EDITOR_REQUEST = 0
13
14
 
14
15
  # Context menu is being invoked in a response editor.
15
- CONTEXT_MESSAGE_EDITOR_RESPONSE = 1;
16
+ CONTEXT_MESSAGE_EDITOR_RESPONSE = 1
16
17
 
17
18
  # Context menu is being invoked in a non-editable request viewer.
18
- CONTEXT_MESSAGE_VIEWER_REQUEST = 2;
19
+ CONTEXT_MESSAGE_VIEWER_REQUEST = 2
19
20
 
20
21
  # Context menu is being invoked in a non-editable response viewer.
21
- CONTEXT_MESSAGE_VIEWER_RESPONSE = 3;
22
+ CONTEXT_MESSAGE_VIEWER_RESPONSE = 3
22
23
 
23
24
  # Context menu is being invoked in the Target site map tree.
24
- CONTEXT_TARGET_SITE_MAP_TREE = 4;
25
+ CONTEXT_TARGET_SITE_MAP_TREE = 4
25
26
 
26
27
  # Context menu is being invoked in the Target site map table.
27
- CONTEXT_TARGET_SITE_MAP_TABLE = 5;
28
+ CONTEXT_TARGET_SITE_MAP_TABLE = 5
28
29
 
29
30
  # Context menu is being invoked in the Proxy history.
30
- CONTEXT_PROXY_HISTORY = 6;
31
+ CONTEXT_PROXY_HISTORY = 6
31
32
 
32
33
  # Context menu is being invoked in the Scanner results.
33
- CONTEXT_SCANNER_RESULTS = 7;
34
+ CONTEXT_SCANNER_RESULTS = 7
34
35
 
35
36
  # Context menu is being invoked in the Intruder payload positions editor.
36
- CONTEXT_INTRUDER_PAYLOAD_POSITIONS = 8;
37
+ CONTEXT_INTRUDER_PAYLOAD_POSITIONS = 8
37
38
 
38
39
  # Context menu is being invoked in an Intruder attack results.
39
- CONTEXT_INTRUDER_ATTACK_RESULTS = 9;
40
+ CONTEXT_INTRUDER_ATTACK_RESULTS = 9
40
41
 
41
42
  # Context menu is being invoked in a search results window.
42
- CONTEXT_SEARCH_RESULTS = 10;
43
+ CONTEXT_SEARCH_RESULTS = 10
44
+
45
+ CONTEXTS = {
46
+ CONTEXT_MESSAGE_EDITOR_REQUEST => "message_editor_request",
47
+ CONTEXT_MESSAGE_EDITOR_RESPONSE => "message_editor_response",
48
+ CONTEXT_MESSAGE_VIEWER_REQUEST => "message_viewer_request",
49
+ CONTEXT_MESSAGE_VIEWER_RESPONSE => "message_viewer_response",
50
+ CONTEXT_TARGET_SITE_MAP_TREE => "target_site_map_tree",
51
+ CONTEXT_TARGET_SITE_MAP_TABLE => "target_site_map_table",
52
+ CONTEXT_PROXY_HISTORY => "proxy_history",
53
+ CONTEXT_SCANNER_RESULTS => "scanner_results",
54
+ CONTEXT_INTRUDER_PAYLOAD_POSITIONS => "intruder_payload_positions",
55
+ CONTEXT_INTRUDER_ATTACK_RESULTS => "intruder_attack_results",
56
+ CONTEXT_SEARCH_RESULTS => "search_results"
57
+ }
43
58
 
44
59
  # This method can be used to retrieve details of the HTTP requests /
45
60
  # responses that were shown or selected by the user when the context menu
@@ -57,30 +72,39 @@ class Buby
57
72
  # +IBurpExtenderCallbacks.saveBuffersToTempFiles()+ to create a
58
73
  # persistent read-only copy of the +IHttpRequestResponse+.
59
74
  #
60
- # @return [Array<IHttpRequestResponse>,nil] An array of objects
75
+ # @return [HttpRequestResponseList,nil] An array of objects
61
76
  # representing the items that were shown or selected by the user when
62
77
  # the context menu was invoked. This method returns +nil+ if no messages
63
78
  # are applicable to the invocation.
64
79
  #
65
80
  def getSelectedMessages
66
81
  pp [:got_get_selected_messages] if $DEBUG
67
- hrrl = __getSelectedMessages
68
- HttpRequestResponseHelper.implant(hrrl.first)
69
- hrrl
82
+ HttpRequestResponseList.new(__getSelectedMessages)
70
83
  end
71
84
 
72
85
  # This method can be used to retrieve details of the Scanner issues that
73
86
  # were selected by the user when the context menu was invoked.
74
87
  #
75
- # @return [Array<IScanIssue>,nil] The issues that were selected by the
88
+ # @return [ScanIssuesList,nil] The issues that were selected by the
76
89
  # user when the context menu was invoked. This method returns +nil+ if
77
90
  # no Scanner issues are applicable to the invocation.
78
91
  #
79
92
  def getSelectedIssues
80
93
  pp [:got_get_selected_issues] if $DEBUG
81
- sil = __getSelectedIssues
82
- ScanIssueHelper.implant(sil.first)
83
- sil
94
+ ScanIssuesList.new(__getSelectedIssues)
95
+ end
96
+
97
+ # Get the name of the tool invoking a context menu
98
+ # @return [String] Tool name
99
+ def tool_name
100
+ $burp.getToolName getToolFlag
101
+ end
102
+
103
+ # This method can be used to retrieve the context within which the menu
104
+ # was invoked.
105
+ # @return [String] Context name
106
+ def context_name
107
+ CONTEXTS[getInvocationContext]
84
108
  end
85
109
 
86
110
  # Install ourselves into the current +IContextMenuInvocation+ java class
@@ -8,6 +8,16 @@ class Buby
8
8
  # This module is used to extend the JRuby proxy class returned by Burp.
9
9
  #
10
10
  module ExtensionHelpers
11
+ PARAM_TYPES = {
12
+ 'url' => 0,
13
+ 'body' => 1,
14
+ 'cookie' => 2,
15
+ 'xml' => 3,
16
+ 'xml_attr' => 4,
17
+ 'multipart_attr' => 5,
18
+ 'json' => 6
19
+ }
20
+
11
21
  # This method can be used to analyze an HTTP request, and obtain various
12
22
  # key details about it. The resulting +IRequestInfo+ object
13
23
  # will not include the full request URL.
@@ -21,9 +31,10 @@ class Buby
21
31
  # @param [IHttpService] http_service HTTP service description
22
32
  # @param [String, Array<byte>] request The request to be analyzed
23
33
  # @overload analyzeRequest(request)
24
- # Analyze a +String+ or +byte[]+ request. To obtain the full URL, use one
25
- # of the other overloaded {#analyzeRequest} methods.
34
+ # Analyze a +String+ or +byte[]+ request. To obtain the full URL, use
35
+ # one of the other overloaded {#analyzeRequest} methods.
26
36
  # @param [String, Array<byte>] request The request to be analyzed
37
+ #
27
38
  # @return [IRequestInfo] object (wrapped with Ruby goodness)
28
39
  # that can be queried to obtain details about the request.
29
40
  #
@@ -36,44 +47,57 @@ class Buby
36
47
  # This method can be used to analyze an HTTP response, and obtain various
37
48
  # key details about it.
38
49
  #
39
- # @param [String, Array<byte>] response The response to be analyzed.
40
- # @return [IResponseInfo] object (wrapped with Ruby goodness) that can be
41
- # queried to obtain details about the response.
50
+ # @overload analyzeResponse(response)
51
+ # @param [String, Array<byte>] response The response to be analyzed.
52
+ # @return [IResponseInfo] object (wrapped with Ruby goodness) that
53
+ # can be queried to obtain details about the response.
54
+ # @overload analyzeResponse(response)
55
+ # @param [IHttpRequestResponse] response The response to be analyzed.
56
+ # @return [IResponseInfo, nil] Object (wrapped with Ruby goodness) that
57
+ # can be queried to obtain details about the response. Returns +nil+
58
+ # when +response+ is +nil+.
42
59
  #
43
60
  def analyzeResponse(response)
44
61
  pp [:got_analyze_response, response] if $DEBUG
62
+ response = response.response if response.respond_to? :response
45
63
  response = response.to_java_bytes if response.respond_to? :to_java_bytes
46
- Buby::Implants::ResponseInfo.implant(__analyzeResponse(response))
64
+ Buby::Implants::ResponseInfo.implant(__analyzeResponse(response)) if response
47
65
  end
48
66
 
49
67
  # This method can be used to retrieve details of a specified parameter
50
- # within an HTTP request. <b>Note:</b> Use {#analyzeRequest} to obtain
51
- # details of all parameters within the request.
68
+ # within an HTTP request. Use {#analyzeRequest} to obtain details of all
69
+ # parameters within the request.
52
70
  #
53
- # @param [String, Array<byte>] request The request to be inspected for the
54
- # specified parameter.
55
- # @param [String] parameter_name The name of the parameter to retrieve.
56
- # @return [IParameter] object that can be queried to obtain details
71
+ # @param [IHttpRequestResponse, String, Array<byte>] request The request
72
+ # to be inspected for the specified parameter.
73
+ # @param [#to_s] parameter_name The name of the parameter to retrieve.
74
+ # @return [IParameter, nil] object that can be queried to obtain details
57
75
  # about the parameter, or +nil+ if the parameter was not found.
58
76
  #
59
77
  def getRequestParameter(request, parameter_name)
60
78
  pp [:got_get_request_parameter, parameter_name, request] if $DEBUG
79
+ request = request.request if request.kind_of?(Java::Burp::IHttpRequestResponse)
61
80
  request = request.to_java_bytes if request.respond_to? :to_java_bytes
62
- Buby::Implants::Parameter.implant(__getRequestParameter(request, parameter_name))
81
+ Buby::Implants::Parameter.implant(__getRequestParameter(request, parameter_name.to_s))
63
82
  end
64
83
 
65
84
  # This method searches a piece of data for the first occurrence of a
66
85
  # specified pattern. It works on byte-based data in a way that is similar
67
86
  # to the way the native Java method +String.indexOf()+ works on
68
87
  # String-based data.
69
- # @note This method is only wrapped for testing purposes. There are better ways to do this in the JRuby runtime.
88
+ #
89
+ # @note This method is only wrapped for testing purposes. There are better
90
+ # ways to do this in the JRuby runtime.
70
91
  #
71
92
  # @param [String, Array<byte>] data The data to be searched.
72
93
  # @param [String, Array<byte>] pattern The pattern to be searched for.
73
- # @param [Boolean] case_sensitive Flags whether or not the search is case-sensitive.
74
- # @param [Fixnum] from The offset within +data+ where the search should begin.
94
+ # @param [Boolean] case_sensitive Flags whether or not the search is
95
+ # case-sensitive.
96
+ # @param [Fixnum] from The offset within +data+ where the search should
97
+ # begin.
75
98
  # @param [Fixnum] to The offset within +data+ where the search should end.
76
- # @return The offset of the first occurrence of the pattern within the specified bounds, or nil if no match is found.
99
+ # @return [Fixnum, nil] The offset of the first occurrence of the pattern
100
+ # within the specified bounds, or +nil+ if no match is found.
77
101
  #
78
102
  def indexOf(data, pattern, case_sensitive, from, to)
79
103
  pp [:got_index_of, case_sensitive, from, to, data, pattern] if $DEBUG
@@ -87,11 +111,13 @@ class Buby
87
111
  # message body. If applicable, the Content-Length header will be added or
88
112
  # updated, based on the length of the body.
89
113
  #
90
- # @param [Array<String>] headers A list of headers to include in the message.
91
- # @param [String, Array<byte>] body The body of the message, or +nil+ if the message has an empty body.
114
+ # @param [Array<String>] headers A list of headers to include in the
115
+ # message.
116
+ # @param [String, Array<byte>] body The body of the message, or +nil+ if
117
+ # the message has an empty body.
92
118
  # @return [String] The resulting full HTTP message.
93
119
  #
94
- def buildHttpMessage(headers, body)
120
+ def buildHttpMessage(headers, body = nil)
95
121
  pp [:got_build_http_message, headers, body] if $DEBUG
96
122
  body = body.to_java_bytes if body.respond_to?(:to_java_bytes)
97
123
  String.from_java_bytes(__buildHttpMessage(headers, body))
@@ -101,7 +127,8 @@ class Buby
101
127
  # in the request are determined by the Request headers settings as
102
128
  # configured in Burp Spider's options.
103
129
  #
104
- # @param [URL, #to_s] url The URL to which the request should be made.
130
+ # @param [java.net.URL, URI, #to_s] url The URL to which the request
131
+ # should be built.
105
132
  # @return [String] A request to the specified URL.
106
133
  #
107
134
  def buildHttpRequest(url)
@@ -185,7 +212,7 @@ class Buby
185
212
  #
186
213
  # @param [String, Array<byte>, IHttpRequestResponse] request The HTTP
187
214
  # request whose method should be toggled.
188
- # @return [String} A new HTTP request using the toggled method.
215
+ # @return [String] A new HTTP request using the toggled method.
189
216
  #
190
217
  # @todo Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
191
218
  def toggleRequestMethod(request)
@@ -199,18 +226,43 @@ class Buby
199
226
  # details provided.
200
227
  #
201
228
  # @overload buildHttpService(host, port, protocol)
202
- # @param [String] host The HTTP service host.
229
+ # @param [Java::JavaNet::URL, URI,String] host The HTTP service host.
203
230
  # @param [Fixnum] port The HTTP service port.
204
231
  # @param [String] protocol The HTTP service protocol.
205
232
  # @overload buildHttpService(host, port, use_https)
206
- # @param [String] host The HTTP service host.
233
+ # @param [Java::JavaNet::URL, URI,String] host The HTTP service host.
207
234
  # @param [Fixnum] port The HTTP service port.
208
235
  # @param [Boolean] use_https Flags whether the HTTP service protocol is HTTPS or HTTP.
236
+ # @overload buildHttpService(url)
237
+ # @param [Java::JavaNet::URL, URI, String] url URL specifying host, port
238
+ # and protocol. Will automatically set port to 80/443 if http(s) url
239
+ # is passed. Defaults to 80 for other URL schemes.
209
240
  # @return [IHttpService] object based on the details provided.
210
241
  #
211
- def buildHttpService(host, port, protocol)
212
- pp [:got_buildHttpService, host, port, protocol] if $DEBUG
213
- Buby::Implants::HttpService.implant(__buildHttpService(host, port, protocol))
242
+ def buildHttpService(host, *args)
243
+ pp [:got_buildHttpService, host, *args] if $DEBUG
244
+ port, protocol = *args
245
+ case host
246
+ when URI, Java::JavaNet::URL
247
+ port ||= host.port
248
+ protocol ||= host.protocol
249
+ host = host.host
250
+ else
251
+ thost = host.kind_of?(String) ? Java::JavaNet::URL.new(host) : host
252
+ port ||= thost.port
253
+ protocol ||= thost.protocol
254
+ end
255
+ port ||= case protocol
256
+ when TrueClass, /^https$/i
257
+ 443
258
+ else
259
+ 80
260
+ end
261
+
262
+ port = https ? 443 : 80 if port < 0
263
+ host = host.host if host.respond_to? :host
264
+
265
+ __buildHttpService(host, port, protocol)
214
266
  end
215
267
 
216
268
  # This method constructs an +IParameter+ object based on the details
@@ -223,6 +275,7 @@ class Buby
223
275
  # @return [IParameter] object based on the details provided.
224
276
  def buildParameter(name, value, type)
225
277
  pp [:got_buildParameter, name, value, type] if $DEBUG
278
+ ptype = TYPE_HASH[ptype.to_s] unless ptype.kind_of?(Fixnum)
226
279
  Buby::Implants::Parameter.implant(__buildParameter(name, value, type))
227
280
  end
228
281
 
@@ -231,8 +284,8 @@ class Buby
231
284
  # point based on a fixed payload location within a base request.
232
285
  #
233
286
  # @param [String] insertion_point_name The name of the insertion point.
234
- # @param [String, Array<byte>, IHttpRequestResponse] base_request The request from which to
235
- # build scan requests.
287
+ # @param [String, Array<byte>, IHttpRequestResponse] base_request The
288
+ # request from which to build scan requests.
236
289
  # @param [Fixnum] from The offset of the start of the payload location.
237
290
  # @param [Fixnum] to The offset of the end of the payload location.
238
291
  # @return [IScannerInsertionPoint] object based on the details provided.
@@ -240,7 +293,7 @@ class Buby
240
293
  # @todo Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
241
294
  def makeScannerInsertionPoint(insertion_point_name, base_request, from, to)
242
295
  pp [:got_makeScannerInsertionPoint, insertion_point_name, base_request, from, to] if $DEBUG
243
- base_request = base_request.request if base_request.kind_of? Java::Burp::IHttpRequestResponse
296
+ base_request = base_request.request if base_request.respond_to? :request
244
297
  base_request = base_request.to_java_bytes if base_request.respond_to? :to_java_bytes
245
298
  Buby::Implants::ScannerInsertionPoint.implant(__makeScannerInsertionPoint(insertion_point_name, base_request, from, to))
246
299
  end
@@ -263,9 +316,8 @@ class Buby
263
316
  removeParameter
264
317
  updateParameter
265
318
  toggleRequestMethod
266
- buildHttpService
267
319
  buildParameter
268
- makeScannerInsertionPoint
320
+ makeScannerInsertionPoint
269
321
  }
270
322
  a_methods.each do |meth|
271
323
  alias_method "__"+meth.to_s, meth
@@ -45,6 +45,16 @@ class Buby
45
45
  end
46
46
  end
47
47
  end
48
+
49
+ module URL
50
+ def inspect
51
+ if $DEBUG
52
+ super.insert(-2, ": #{self.to_s} ")
53
+ else
54
+ self.to_s
55
+ end
56
+ end
57
+ end
48
58
  end
49
59
  end
50
60
 
@@ -57,6 +67,12 @@ module Enumerable
57
67
  end
58
68
 
59
69
  module Java
70
+ module JavaNet
71
+ class URL
72
+ include Buby::Implants::URL
73
+ end
74
+ end
75
+
60
76
  class JavaClass
61
77
  include Buby::Implants::JavaClass
62
78
  end