emonti-buby 1.0.0

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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2009-05-08
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/README.rdoc ADDED
@@ -0,0 +1,278 @@
1
+ buby
2
+ by Eric Monti
3
+ http://github.com/emonti/buby
4
+
5
+ == DESCRIPTION:
6
+
7
+ Buby is a mashup of JRuby with the popular commercial web security testing tool Burp Suite from PortSwigger. Burp is driven from and tied to JRuby with a Java extension using the BurpExtender API. This extension aims to add Ruby scriptability to Burp Suite with an interface comparable to the Burp's pure Java extension interface.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Intercept and log proxied requests and responses via Burp into Ruby and
12
+ perform arbitrary processing on them.
13
+
14
+ * Modify requests and responses in-line using Ruby scripts.
15
+
16
+ * Pass requests and other information from JRuby to various sub-interfaces in
17
+ Burp
18
+
19
+ * Use the Burp framework for active and passive scanning using arbitrary
20
+ requests and responses.
21
+
22
+ * Use the Burp framework for making arbitrary HTTP requests
23
+
24
+
25
+ Buby is implemented using an abstract Ruby event handler and interface class. The Buby Ruby class is back-ended with a minimal BurpExtender class implemented in Java. The java code is required to conform to nuances in the Burp extension interface and while it's in the pure Java runtime, it acts as 'glue' where deemed appropriate, but otherwise tries to stay out of the way.
26
+
27
+ The java BurpExtender included with Buby is an implementation of IBurpExtender which is the interface API supplied by PortSwigger for writing extensions to Burp Suite. It mostly acts as a method proxy between Ruby and Java, doing very little except event handler proxying between the java and ruby runtimes with run-time type conversion as needed.
28
+
29
+
30
+ == REQUIREMENTS:
31
+
32
+ Buby requires a copy of Burp Suite. Not sure if this will work with the unlicensed trial version. Point is, you'll need to get this separately since it's a trade-marked commercial product of PortSwigger Ltd.
33
+
34
+ See http://portswigger.net/
35
+
36
+
37
+ == BUILD/INSTALLATION:
38
+
39
+ === Gem
40
+ You should be able to get up and running with just the gem and a copy of Burp.
41
+ I've packaged up a pre-built buby.jar file containing the required classes
42
+ minus ofcourse, Burp itself.
43
+
44
+ gem install emonti-buby
45
+
46
+ See manual step #5 below. For best results, you'll still want to make your
47
+ burp.jar available in the ruby runtime library path.
48
+
49
+
50
+ === Manual
51
+ Here are manual instructions if you want or need to build things yourself:
52
+
53
+ 1. Download buby from github
54
+ git clone git://github.com/emonti/buby.git
55
+
56
+ 2. Compile BurpExtender.java. Include jruby.jar in the classpath:
57
+
58
+ cd buby/java/src
59
+ javac -classpath (.../jruby/root)/lib/jruby.jar:. BurpExtender.java
60
+
61
+ 3. Create a new lib/buby.jar
62
+
63
+ jar cvf ../../lib/buby.jar .
64
+
65
+ 4. Copy the buby library to your JRuby library path. Your location may vary:
66
+
67
+ cp buby.jar buby.rb (.../jruby)/lib/site_ruby/1.8/
68
+
69
+ 5. The last part is a bit tricky. Burp Suite itself is obviously not packaged
70
+ with buby. You'll need to somehow put your 'burp.jar' in a place where
71
+ it is visible in the JRuby RUBY-LIB paths. While there are a few other
72
+ methods added for pulling in 'burp.jar' during run-time, this one is by far
73
+ the least amount of hassle in the long run.
74
+
75
+ Here's a quick way to see jruby's runtime lib-path:
76
+
77
+ jruby -e 'puts $:'
78
+
79
+ There is usually a '.../jruby/lib/1.8/java' directory reference in there,
80
+ though the directory may not exist in your set-up yet and you may need to
81
+ create it.
82
+
83
+ Note: I keep my jruby installation under my home directory. Also, I think
84
+ my jruby version is out of date at the time of writing. But your configuration
85
+ should still be relatively close to this.
86
+
87
+ Here's how I have mine set up.
88
+
89
+ mkdir ~/jruby-1.1.5/lib/ruby/1.8/java
90
+ ln -s ~/tools/burp.jar ~/jruby-1.1.5/lib/ruby/1.8/java/burp.jar
91
+
92
+ Once this is done, everything should be ready to go.
93
+
94
+ == TEST AND USAGE EXAMPLE:
95
+
96
+ The gem includes a command-line tool called 'buby' but it doesn't do much right
97
+ now. You can, however use this as a minimal test to confirm whether Burp can be
98
+ launched from ruby and whether Buby and Burp are connected.
99
+
100
+ Here are some really simple test examples using Buby through IRB:
101
+
102
+ $ jruby -S irb
103
+
104
+ require 'buby'
105
+ $DEBUG = true
106
+
107
+ # Here's one way to explicitely add burp.jar into the runtime if its not
108
+ # already.
109
+ Buby.load_burp("/path/to/burp.jar") if not Buby.burp_loaded?
110
+ buby = Buby.start_burp()
111
+
112
+ At this point, you should see Burp starting and with the $DEBUG flag, you'll
113
+ also see several debug messages in IRB coming from Buby as various events are
114
+ generated by the BurpExtender java implementation. Once Burp is running, click
115
+ on the alerts tab.
116
+
117
+ You should see now something like the following in alerts:
118
+
119
+ 2:46:01 PM suite method BurpExtender.processProxyMessage() found
120
+ 2:46:01 PM suite method BurpExtender.registerExtenderCallbacks() found
121
+ 2:46:01 PM suite method BurpExtender.setCommandLineArgs() found
122
+ 2:46:01 PM suite method BurpExtender.applicationClosing() found
123
+ 2:46:01 PM proxy proxy service started on port 8080
124
+ 2:46:01 PM suite [BurpExtender] registering JRuby handler callbacks
125
+ 2:46:01 PM suite [JRuby::Buby] registered callback
126
+
127
+ To confirm you are connected back to Burp in IRB, do the following:
128
+
129
+ buby.alert("hello Burp!")
130
+
131
+ Which should produce a new alert:
132
+
133
+ 2:47:00 PM suite hello Burp!
134
+
135
+
136
+ Next, lets make an HTTP request through the proxy. We'll use Net:HTTP right
137
+ in IRB for illustration purposes. However, you can just as easily perform this
138
+ test through a browser configured to use Burp as its proxy.
139
+
140
+ require 'net/http'
141
+ p = Net::HTTP::Proxy("localhost", 8080).start("www.example.com")
142
+ p.get("/")
143
+
144
+
145
+ With $DEBUG = true, you should see the debugging output from Ruby as the proxy
146
+ passes your request back to your Ruby runtime.
147
+
148
+ It will look something like the following in IRB:
149
+
150
+ >> p.get("/")
151
+ [:got_proxy_request,
152
+ [:msg_ref, 1],
153
+ [:is_req, true],
154
+ [:rhost, "www.example.com"],
155
+ [:rport, 80],
156
+ [:is_https, false],
157
+ [:http_meth, "GET"],
158
+ [:url, "/"],
159
+ [:resourceType, nil],
160
+ [:status, nil],
161
+ [:req_content_type, nil],
162
+ [:message, "GET / HTTP/1.1\r\nAccept:..."],
163
+ [:action, 0]]
164
+
165
+ You may also see the response right away depending on your intercept settings
166
+ in Burp. Back the in Burp proxy's intercept window, turn off interception if
167
+ it hasn't already been disabled. Now you should definitely see the response
168
+ in IRB as it passes back through the Burp proxy.
169
+
170
+ [:got_proxy_response,
171
+ [:msg_ref, 1],
172
+ [:is_req, false],
173
+ [:rhost, "www.example.com"],
174
+ [:rport, 80],
175
+ [:is_https, false],
176
+ [:http_meth, "GET"],
177
+ [:url, "/"],
178
+ [:resourceType, nil],
179
+ [:status, "200"],
180
+ [:req_content_type, "text/html; charset=utf-8"],
181
+ [:message, "HTTP/1.1 200 OK\r\n..."],
182
+ [:action, 0]]
183
+ => #<Net::HTTPOK 200 OK readbody=true>
184
+ >>
185
+
186
+ Note also, the Net::HTTP request should have returned the same result as shown in the proxy.
187
+
188
+ Now, lets try something mildly interesting with the proxy. This contrived example will implement a proxy request manipulator to do HTTP request verb tampering on every GET request that goes through the proxy.
189
+
190
+ # Note: I'm using 'instance_eval' here only to stay with the flow of the
191
+ # existing IRB session. Normally, you'd probably want to implement this as
192
+ # an override in your Buby-derived class.
193
+
194
+ buby.instance_eval do
195
+
196
+ def evt_proxy_message(*param)
197
+ msg_ref, is_req, rhost, rport, is_https, http_meth, url, resourceType,
198
+ status, req_content_type, message, action = param
199
+
200
+ if is_req and http_meth=="GET"
201
+ # Change the HTTP request verb to something silly
202
+ message[0,3] = "PET"
203
+
204
+ # Forcibly disable interception in the Burp UI
205
+ action[0] = Buby::ACTION_DONT_INTERCEPT
206
+
207
+ # Return a new instance and still get $DEBUG info
208
+ return super(*param).dup
209
+ else
210
+ # Just get $DEBUG info for all other requests
211
+ return super(*param)
212
+ end
213
+ end
214
+
215
+ end
216
+
217
+ # Now, make another request using the Net::HTTP client
218
+ p.get("/")
219
+
220
+
221
+ This should produce a request that looks like the following in IRB:
222
+
223
+ [:got_proxy_request,
224
+ ...
225
+ [:message,
226
+ "PET / HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Ruby..."],
227
+ [:action, 2]]
228
+
229
+ And, assuming 'www.example.com' checks for valid request verbs, you should see something like the following response:
230
+
231
+ [:got_proxy_response,
232
+ ...
233
+ [:http_meth, "PET"],
234
+ [:url, "/"],
235
+ [:resourceType, nil],
236
+ [:status, "400"],
237
+ ...
238
+ [:message,
239
+ "HTTP/1.1 400 Bad Request\r\nContent-Type:..."],
240
+ [:action, 0]]
241
+ => #<Net::HTTPBadRequest 400 Bad Request readbody=true>
242
+
243
+
244
+ == CREDIT:
245
+ * Burp and Burp Suite are trademarks of PortSwigger(ltd)
246
+ Copyright 2008 PortSwigger Ltd. All rights reserved.
247
+ See http://portswigger.net for license terms.
248
+
249
+ * This ruby library and the accompanying BurpExtender.java implementation are
250
+ written by Eric Monti @ Matasano Security. Matasano Security claims no
251
+ professional or legal affiliation with PortSwigger LTD.
252
+
253
+ However, the author would like to express his personal and professional
254
+ respect and admiration to Burp's authors and appreciation to PortSwigger for
255
+ the availability of the IBurpExtender extension API.
256
+
257
+ The availability of this interface goes a long way to helping make Burp Suite
258
+ a truly first-class application.
259
+
260
+ == LICENSE:
261
+
262
+ * Burp and Burp Suite are trademarks of PortSwigger Ltd.
263
+ Copyright 2008 PortSwigger Ltd. All rights reserved.
264
+ See http://portswigger.net for license terms.
265
+
266
+ * The Buby Ruby library and its accompanying BurpExtender implementation are
267
+ both freely available under the terms of the MIT public license:
268
+
269
+ (The MIT License)
270
+
271
+ Copyright (C) 2009 Eric Monti, Matasano Security
272
+
273
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
274
+
275
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
276
+
277
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
278
+
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ ensure_in_path 'java'
18
+ require 'buby'
19
+
20
+ task :default => 'spec:run'
21
+
22
+ PROJ.name = 'buby'
23
+ PROJ.authors = 'Eric Monti - Matasano Security'
24
+ PROJ.email = 'emonti@matasano.com'
25
+ PROJ.url = 'http://github.com/emonti/buby'
26
+ PROJ.version = Buby::VERSION
27
+ PROJ.rubyforge.name = 'buby'
28
+ PROJ.readme_file = 'README.rdoc'
29
+ PROJ.libs << "java"
30
+
31
+ PROJ.spec.opts << '--color'
32
+
33
+ # EOF
data/bin/buby ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib buby]))
4
+ require 'irb'
5
+
6
+ unless Buby.burp_loaded?
7
+ begin
8
+ raise "You must specify the path to your burp.jar" unless jar=ARGV.shift
9
+ raise "#{jar} did not provide burp.StartBurp" unless Buby.load_burp(jar)
10
+ rescue
11
+ STDERR.puts "Error: #{$!}"
12
+ exit 1
13
+ end
14
+ end
15
+ $burp = Buby.start_burp()
16
+ IRB.start if $DEBUG
data/buby.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{buby}
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Eric Monti - Matasano Security"]
9
+ s.date = %q{2009-05-08}
10
+ s.default_executable = %q{buby}
11
+ s.description = %q{Buby is a mashup of JRuby with the popular commercial web security testing tool Burp Suite from PortSwigger. Burp is driven from and tied to JRuby with a Java extension using the BurpExtender API. This extension aims to add Ruby scriptability to Burp Suite with an interface comparable to the Burp's pure Java extension interface.}
12
+ s.email = %q{emonti@matasano.com}
13
+ s.executables = ["buby"]
14
+ s.extra_rdoc_files = ["History.txt", "README.rdoc", "bin/buby"]
15
+ s.files = ["History.txt", "README.rdoc", "Rakefile", "bin/buby", "buby.gemspec", "java/buby.jar", "java/src/BurpExtender.java", "java/src/burp/IBurpExtender.java", "java/src/burp/IBurpExtenderCallbacks.java", "lib/buby.rb", "samples/basic.rb", "spec/buby_spec.rb", "spec/spec_helper.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "tasks/zentest.rake", "test/test_buby.rb"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/emonti/buby}
18
+ s.rdoc_options = ["--main", "README.rdoc"]
19
+ s.require_paths = ["lib", "java"]
20
+ s.rubyforge_project = %q{buby}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{Buby is a mashup of JRuby with the popular commercial web security testing tool Burp Suite from PortSwigger}
23
+ s.test_files = ["test/test_buby.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_development_dependency(%q<bones>, [">= 2.5.0"])
31
+ else
32
+ s.add_dependency(%q<bones>, [">= 2.5.0"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<bones>, [">= 2.5.0"])
36
+ end
37
+ end
data/java/buby.jar ADDED
Binary file
@@ -0,0 +1,247 @@
1
+ //import javax.annotation.PostConstruct;
2
+
3
+ import burp.IBurpExtender;
4
+ import burp.IBurpExtenderCallbacks;
5
+
6
+ import org.jruby.*;
7
+ import org.jruby.javasupport.JavaUtil;
8
+ import org.jruby.runtime.ThreadContext;
9
+ import org.jruby.runtime.builtin.IRubyObject;
10
+
11
+ /**
12
+ * This is an implementation of the BurpExtender/IBurpExtender interface
13
+ * for Burp Suite which provides glue between a Ruby runtime and Burp.
14
+ *
15
+ * This is a complete implementation of the Burp Extender interfaces available
16
+ * as of Burp Suite 1.2/1.2.05
17
+ */
18
+ public class BurpExtender implements IBurpExtender {
19
+ public final static String INIT_METH = "evt_extender_init";
20
+ public final static String PROXY_METH = "evt_proxy_message";
21
+ public final static String MAINARGS_METH = "evt_commandline_args";
22
+ public final static String REG_METH = "evt_register_callbacks";
23
+ public final static String CLOSE_METH = "evt_application_closing";
24
+
25
+ // Internal reference to hold the ruby Burp handler
26
+ private static IRubyObject r_obj = null;
27
+
28
+ /**
29
+ * Sets an internal reference to the ruby handler class or module to use
30
+ * for proxied BurpExtender events into a ruby runtime.
31
+ *
32
+ * Generally, this should probably be called before burp.StartBurp.main.
33
+ * However, it is also possible to set this afterwards and even swap in
34
+ * new objects during runtime.
35
+ */
36
+ public static void set_handler(IRubyObject hnd) { r_obj = hnd; }
37
+
38
+ /**
39
+ * Returns the internal Ruby handler reference.
40
+ *
41
+ * The handler is the ruby class or module used for proxying BurpExtender
42
+ * events into a ruby runtime.
43
+ */
44
+ public static IRubyObject get_handler() { return r_obj; }
45
+
46
+
47
+ /**
48
+ * This constructor is invoked from Burp's extender framework.
49
+ *
50
+ * This implementation invokes the <code>INIT_METH</code> method
51
+ * from the Ruby handler object if one is defined passing it Ruby
52
+ * usable reference to the instance.
53
+ *
54
+ */
55
+ public BurpExtender() {
56
+ if (r_obj !=null && r_obj.respondsTo(INIT_METH))
57
+ r_obj.callMethod(ctx(r_obj), INIT_METH, to_ruby(rt(r_obj), this));
58
+ }
59
+
60
+
61
+ /**
62
+ * This method is invoked immediately after the implementation's constructor
63
+ * to pass any command-line arguments that were passed to Burp Suite on
64
+ * startup.
65
+ *
66
+ * This implementation invokes the method defined by
67
+ * <code>MAINARGS_METH</code> in the Ruby handler if both the handler
68
+ * and its ruby method are defined.
69
+ *
70
+ * It allows Ruby implementations to control aspects of their behaviour at
71
+ * runtime by defining their own command-line arguments.
72
+ *
73
+ * WARNING: Burp appears to have a bug (as of 1.2 and 1.2.05) which causes
74
+ * Burp to exit immediately if arguments are supplied regardless whether
75
+ * this handler is used.
76
+ *
77
+ * @param args The command-line arguments passed to Burp Suite on startup.
78
+ */
79
+ public void setCommandLineArgs(String[] args) {
80
+ if(r_obj != null && r_obj.respondsTo(MAINARGS_METH))
81
+ r_obj.callMethod(ctx(r_obj), MAINARGS_METH, to_ruby(rt(r_obj), args));
82
+ }
83
+
84
+ /**
85
+ * This method is invoked on startup. It registers an instance of the
86
+ * <code>burp.IBurpExtenderCallbacks</code> interface, providing methods
87
+ * that may be invoked by the implementation to perform various actions.
88
+ *
89
+ * The call to registerExtenderCallbacks need not return, and
90
+ * implementations may use the invoking thread for any purpose.<p>
91
+ *
92
+ * This implementation simply passes a ruby-usable "callbacks" instance to
93
+ * the Ruby handler using the method defined by <code>REG_METH</code> if
94
+ * both the handler and its ruby method are defined.
95
+ *
96
+ * @param callbacks An implementation of the
97
+ * <code>IBurpExtenderCallbacks</code> interface.
98
+ */
99
+ public void registerExtenderCallbacks(IBurpExtenderCallbacks cb) {
100
+ if(r_obj != null && r_obj.respondsTo(REG_METH)) {
101
+ cb.issueAlert("[BurpExtender] registering JRuby handler callbacks");
102
+ r_obj.callMethod(ctx(r_obj), REG_METH, to_ruby(rt(r_obj), cb));
103
+ }
104
+ }
105
+
106
+ /**
107
+ * This method is invoked by Burp Proxy whenever a client request or server
108
+ * response is received.
109
+ *
110
+ * This implementation simply passes all arguments to the Ruby handler's
111
+ * method defined by <code>PROXY_METH</code> if both the handler and
112
+ * its ruby method are defined.
113
+ *
114
+ * This allows Ruby implementations to perform logging functions, modify
115
+ * the message, specify an action (intercept, drop, etc.) and perform any
116
+ * other arbitrary processing.
117
+ *
118
+ * @param messageReference An identifier which is unique to a single
119
+ * request/response pair. This can be used to correlate details of requests
120
+ * and responses and perform processing on the response message accordingly.
121
+ * @param messageIsRequest Flags whether the message is a client request or
122
+ * a server response.
123
+ * @param remoteHost The hostname of the remote HTTP server.
124
+ * @param remotePort The port of the remote HTTP server.
125
+ * @param serviceIsHttps Flags whether the protocol is HTTPS or HTTP.
126
+ * @param httpMethod The method verb used in the client request.
127
+ * @param url The requested URL.
128
+ * @param resourceType The filetype of the requested resource, or a
129
+ * zero-length string if the resource has no filetype.
130
+ * @param statusCode The HTTP status code returned by the server. This value
131
+ * is <code>null</code> for request messages.
132
+ * @param responseContentType The content-type string returned by the
133
+ * server. This value is <code>null</code> for request messages.
134
+ * @param message The full HTTP message.
135
+ * @param action An array containing a single integer, allowing the
136
+ * implementation to communicate back to Burp Proxy a non-default
137
+ * interception action for the message. The default value is
138
+ * <code>ACTION_FOLLOW_RULES</code>. Set <code>action[0]</code> to one of
139
+ * the other possible values to perform a different action.
140
+ * @return Implementations should return either (a) the same object received
141
+ * in the <code>message</code> paramater, or (b) a different object
142
+ * containing a modified message.
143
+ */
144
+ public byte[] processProxyMessage(
145
+ int messageReference,
146
+ boolean messageIsRequest,
147
+ String remoteHost,
148
+ int remotePort,
149
+ boolean serviceIsHttps,
150
+ String httpMethod,
151
+ String url,
152
+ String resourceType,
153
+ String statusCode,
154
+ String responseContentType,
155
+ byte[] message,
156
+ int[] action
157
+ ) {
158
+
159
+ if (r_obj != null && r_obj.respondsTo(PROXY_METH)) {
160
+ Ruby rt = rt(r_obj);
161
+ // prepare an alternate action value to present to ruby
162
+ IRubyObject r_action = to_ruby(rt, action);
163
+
164
+ // prepare an alternate message value to present to ruby
165
+ IRubyObject r_msg = to_ruby(rt, RubyString.bytesToString(message));
166
+
167
+ IRubyObject pxy_msg[] = {
168
+ to_ruby(rt, messageReference),
169
+ to_ruby(rt, messageIsRequest),
170
+ to_ruby(rt, remoteHost),
171
+ to_ruby(rt, remotePort),
172
+ to_ruby(rt, serviceIsHttps),
173
+ to_ruby(rt, httpMethod),
174
+ to_ruby(rt, url),
175
+ to_ruby(rt, resourceType),
176
+ to_ruby(rt, statusCode),
177
+ to_ruby(rt, responseContentType),
178
+ r_msg,
179
+ r_action
180
+ };
181
+
182
+ // slurp back in the action value in-case it's been changed
183
+ action[0] = ((int[]) JavaUtil.convertRubyToJava(r_action))[0];
184
+
185
+ IRubyObject ret = r_obj.callMethod(ctx(r_obj), PROXY_METH, pxy_msg);
186
+ if(ret != r_msg)
187
+ return ((RubyString) ret).getBytes();
188
+ }
189
+
190
+ return message;
191
+ }
192
+
193
+ /**
194
+ * This method is invoked immediately before Burp Suite exits.
195
+ * This implementation simply invokes the Ruby handler's method defined
196
+ * by <code>CLOSE_METH</code> if both the handler and its ruby method are
197
+ * defined.
198
+ *
199
+ * This allows implementations to carry out any clean-up actions necessary
200
+ * (e.g. flushing log files or closing database resources, etc.).
201
+ */
202
+ public void applicationClosing() {
203
+ if (r_obj != null && r_obj.respondsTo(CLOSE_METH))
204
+ r_obj.callMethod(ctx(r_obj), CLOSE_METH);
205
+ }
206
+
207
+ // Private method to return the ThreadContext for a given ruby object.
208
+ // This is used in the various event proxies
209
+ private ThreadContext ctx(IRubyObject obj) {
210
+ return rt(obj).getThreadService().getCurrentContext();
211
+ }
212
+
213
+ // Private method to return the ruby runtime for a given ruby object.
214
+ // This is used in the various event proxies
215
+ private Ruby rt(IRubyObject obj) {
216
+ return obj.getRuntime();
217
+ }
218
+
219
+ // private method to transfer arbitrary java objects into a ruby runtime.
220
+ // This is used in the various event proxies to pass arguments to the
221
+ // ruby handler object.
222
+ private IRubyObject to_ruby(Ruby rt, Object obj) {
223
+ return JavaUtil.convertJavaToUsableRubyObject(rt, obj);
224
+ }
225
+
226
+
227
+ /**
228
+ * Causes Burp Proxy to follow the current interception rules to determine
229
+ * the appropriate action to take for the message.
230
+ */
231
+ public final static int ACTION_FOLLOW_RULES = 0;
232
+ /**
233
+ * Causes Burp Proxy to present the message to the user for manual
234
+ * review or modification.
235
+ */
236
+ public final static int ACTION_DO_INTERCEPT = 1;
237
+ /**
238
+ * Causes Burp Proxy to forward the message to the remote server or client.
239
+ */
240
+ public final static int ACTION_DONT_INTERCEPT = 2;
241
+ /**
242
+ * Causes Burp Proxy to drop the message and close the client connection.
243
+ */
244
+ public final static int ACTION_DROP = 3;
245
+
246
+ }
247
+