Module: Buby::Implants::ExtensionHelpers
- Defined in:
- lib/buby/implants/extension_helpers.rb
Overview
This interface contains a number of helper methods, which extensions can use to assist with various common tasks that arise for Burp extensions.
Extensions can call IBurpExtenderCallbacks.getHelpers() to obtain an instance of this interface. This module is used to extend the JRuby proxy class returned by Burp.
Class Method Summary collapse
-
.implant(helpers) ⇒ Object
Install ourselves into the current
IExtensionHelpers
java class.
Instance Method Summary collapse
-
#addParameter(request, parameter) ⇒ String
This method adds a new parameter to an HTTP request, and if appropriate updates the Content-Length header.
-
#analyzeRequest(*args) ⇒ IRequestInfo
This method can be used to analyze an HTTP request, and obtain various key details about it.
-
#analyzeResponse(response) ⇒ IResponseInfo
This method can be used to analyze an HTTP response, and obtain various key details about it.
-
#buildHttpMessage(headers, body) ⇒ String
This method builds an HTTP message containing the specified headers and message body.
-
#buildHttpRequest(url) ⇒ String
This method creates a GET request to the specified URL.
-
#buildHttpService(host, port, protocol) ⇒ IHttpService
This method constructs an
IHttpService
object based on the details provided. -
#buildParameter(name, value, type) ⇒ IParameter
This method constructs an
IParameter
object based on the details provided. -
#getRequestParameter(request, parameter_name) ⇒ IParameter
This method can be used to retrieve details of a specified parameter within an HTTP request.
-
#indexOf(data, pattern, case_sensitive, from, to) ⇒ Object
This method searches a piece of data for the first occurrence of a specified pattern.
-
#makeScannerInsertionPoint(insertion_point_name, base_request, from, to) ⇒ IScannerInsertionPoint
This method constructs an
IScannerInsertionPoint
object based on the details provided. -
#removeParameter(request, parameter) ⇒ String
This method removes a parameter from an HTTP request, and if appropriate updates the Content-Length header.
-
#toggleRequestMethod(request) ⇒ String
This method can be used to toggle a request’s method between GET and POST.
-
#updateParameter(request, parameter) ⇒ String
This method updates the value of a parameter within an HTTP request, and if appropriate updates the Content-Length header.
Class Method Details
.implant(helpers) ⇒ Object
Install ourselves into the current IExtensionHelpers
java class
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/buby/implants/extension_helpers.rb', line 251 def self.implant(helpers) unless helpers.implanted? || helpers.nil? pp [:implanting, helpers, helpers.class] if $DEBUG helpers.class.class_exec(helpers) do |helpers| a_methods = %w{ analyzeRequest analyzeResponse getRequestParameter indexOf buildHttpMessage buildHttpRequest addParameter removeParameter updateParameter toggleRequestMethod buildHttpService buildParameter makeScannerInsertionPoint } a_methods.each do |meth| alias_method "__"+meth.to_s, meth end include Buby::Implants::ExtensionHelpers a_methods.each do |meth| java_class.ruby_names_for_java_method(meth).each do |ruby_meth| define_method ruby_meth, Buby::Implants::ExtensionHelpers.instance_method(meth) end end include Buby::Implants::Proxy end end helpers end |
Instance Method Details
#addParameter(request, parameter) ⇒ String
Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
This method adds a new parameter to an HTTP request, and if appropriate updates the Content-Length header.
126 127 128 129 130 131 132 |
# File 'lib/buby/implants/extension_helpers.rb', line 126 def addParameter(request, parameter) pp [:got_addParameter, parameter, request] if $DEBUG request = request.request if request.kind_of? Java::Burp::IHttpRequestResponse request = request.to_java_bytes if request.respond_to? :to_java_bytes parameter = Buby::Parameter::Base.new parameter if parameter.kind_of? Hash String.from_java_bytes(__addParameter(request, parameter)) end |
#analyzeRequest(request) ⇒ IRequestInfo #analyzeRequest(httpService, request) ⇒ IRequestInfo #analyzeRequest(request) ⇒ IRequestInfo
This method can be used to analyze an HTTP request, and obtain various key details about it. The resulting IRequestInfo
object will not include the full request URL.
of the other overloaded #analyzeRequest methods.
@param [String, Array<byte>] request The request to be analyzed
30 31 32 33 34 |
# File 'lib/buby/implants/extension_helpers.rb', line 30 def analyzeRequest(*args) pp [:got_analyze_request, *args] if $DEBUG args[-1] = args[-1].to_java_bytes if args[-1].respond_to? :to_java_bytes Buby::Implants::RequestInfo.implant(__analyzeRequest(*args)) end |
#analyzeResponse(response) ⇒ IResponseInfo
This method can be used to analyze an HTTP response, and obtain various key details about it.
43 44 45 46 47 |
# File 'lib/buby/implants/extension_helpers.rb', line 43 def analyzeResponse(response) pp [:got_analyze_response, response] if $DEBUG response = response.to_java_bytes if response.respond_to? :to_java_bytes Buby::Implants::ResponseInfo.implant(__analyzeResponse(response)) end |
#buildHttpMessage(headers, body) ⇒ String
This method builds an HTTP message containing the specified headers and message body. If applicable, the Content-Length header will be added or updated, based on the length of the body.
94 95 96 97 98 |
# File 'lib/buby/implants/extension_helpers.rb', line 94 def buildHttpMessage(headers, body) pp [:got_build_http_message, headers, body] if $DEBUG body = body.to_java_bytes if body.respond_to?(:to_java_bytes) String.from_java_bytes(__buildHttpMessage(headers, body)) end |
#buildHttpRequest(url) ⇒ String
This method creates a GET request to the specified URL. The headers used in the request are determined by the Request headers settings as configured in Burp Spider’s options.
107 108 109 110 111 |
# File 'lib/buby/implants/extension_helpers.rb', line 107 def buildHttpRequest(url) pp [:got_build_http_request, url] if $DEBUG url = Java::JavaNet::URL.new url.to_s unless url.kind_of?(Java::JavaNet::URL) String.from_java_bytes __buildHttpRequest(url) end |
#buildHttpService(host, port, protocol) ⇒ IHttpService #buildHttpService(host, port, use_https) ⇒ IHttpService
This method constructs an IHttpService
object based on the details provided.
211 212 213 214 |
# File 'lib/buby/implants/extension_helpers.rb', line 211 def buildHttpService(host, port, protocol) pp [:got_buildHttpService, host, port, protocol] if $DEBUG Buby::Implants::HttpService.implant(__buildHttpService(host, port, protocol)) end |
#buildParameter(name, value, type) ⇒ IParameter
This method constructs an IParameter
object based on the details
provided.
224 225 226 227 |
# File 'lib/buby/implants/extension_helpers.rb', line 224 def buildParameter(name, value, type) pp [:got_buildParameter, name, value, type] if $DEBUG Buby::Implants::Parameter.implant(__buildParameter(name, value, type)) end |
#getRequestParameter(request, parameter_name) ⇒ IParameter
This method can be used to retrieve details of a specified parameter within an HTTP request. Note: Use #analyzeRequest to obtain details of all parameters within the request.
59 60 61 62 63 |
# File 'lib/buby/implants/extension_helpers.rb', line 59 def getRequestParameter(request, parameter_name) pp [:got_get_request_parameter, parameter_name, request] if $DEBUG request = request.to_java_bytes if request.respond_to? :to_java_bytes Buby::Implants::Parameter.implant(__getRequestParameter(request, parameter_name)) end |
#indexOf(data, pattern, case_sensitive, from, to) ⇒ Object
This method is only wrapped for testing purposes. There are better ways to do this in the JRuby runtime.
This method searches a piece of data for the first occurrence of a specified pattern. It works on byte-based data in a way that is similar to the way the native Java method String.indexOf() works on String-based data.
78 79 80 81 82 83 84 |
# File 'lib/buby/implants/extension_helpers.rb', line 78 def indexOf(data, pattern, case_sensitive, from, to) pp [:got_index_of, case_sensitive, from, to, data, pattern] if $DEBUG data = data.to_java_bytes if data.respond_to?(:to_java_bytes) pattern = pattern.to_java_bytes if data.respond_to?(:to_java_bytes) ret = __indexOf(data, pattern, case_sensitive, from, to) ret == -1 ? nil : ret end |
#makeScannerInsertionPoint(insertion_point_name, base_request, from, to) ⇒ IScannerInsertionPoint
Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
This method constructs an IScannerInsertionPoint
object based on the
details provided. It can be used to quickly create a simple insertion
point based on a fixed payload location within a base request.
241 242 243 244 245 246 |
# File 'lib/buby/implants/extension_helpers.rb', line 241 def makeScannerInsertionPoint(insertion_point_name, base_request, from, to) pp [:got_makeScannerInsertionPoint, insertion_point_name, base_request, from, to] if $DEBUG base_request = base_request.request if base_request.kind_of? Java::Burp::IHttpRequestResponse base_request = base_request.to_java_bytes if base_request.respond_to? :to_java_bytes Buby::Implants::ScannerInsertionPoint.implant(__makeScannerInsertionPoint(insertion_point_name, base_request, from, to)) end |
#removeParameter(request, parameter) ⇒ String
Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
This method removes a parameter from an HTTP request, and if appropriate updates the Content-Length header.
147 148 149 150 151 152 153 |
# File 'lib/buby/implants/extension_helpers.rb', line 147 def removeParameter(request, parameter); pp [:got_addParameter, parameter, request] if $DEBUG request = request.request if request.kind_of? Java::Burp::IHttpRequestResponse request = request.to_java_bytes if request.respond_to? :to_java_bytes parameter = Buby::Parameter::Base.new parameter if parameter.kind_of? Hash String.from_java_bytes(__removeParameter(request, parameter)) end |
#toggleRequestMethod(request) ⇒ String
Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
This method can be used to toggle a request’s method between GET and POST. Parameters are relocated between the URL query string and message body as required, and the Content-Length header is created or removed as applicable.
191 192 193 194 195 196 |
# File 'lib/buby/implants/extension_helpers.rb', line 191 def toggleRequestMethod(request) pp [:got_toggleRequestMethod, request] if $DEBUG request = request.request if request.kind_of? Java::Burp::IHttpRequestResponse request = request.to_java_bytes if request.respond_to? :to_java_bytes String.from_java_bytes(__toggleRequestMethod(request)) end |
#updateParameter(request, parameter) ⇒ String
Switch IHttpRequestResponse to new Buby::Implants functionality (2.0)
This method updates the value of a parameter within an HTTP request, and if appropriate updates the Content-Length header. @note: This method can only be used to update the value of an existing
parameter of a specified type. If you need to change the type of an
existing parameter, you should first call {#removeParameter} to remove
the parameter with the old type, and then call {#addParameter} to add
a parameter with the new type.
173 174 175 176 177 178 179 |
# File 'lib/buby/implants/extension_helpers.rb', line 173 def updateParameter(request, parameter) pp [:got_updateParameter, parameter, request] if $DEBUG request = request.request if request.kind_of? Java::Burp::IHttpRequestResponse request = request.to_java_bytes if request.respond_to? :to_java_bytes parameter = Buby::Parameter::Base.new parameter if parameter.kind_of? Hash String.from_java_bytes(__updateParameter(request, parameter)) end |