buby 1.3.3-java → 1.5.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README.rdoc +28 -14
  2. data/Rakefile +96 -6
  3. data/VERSION.yml +5 -0
  4. data/bin/buby +2 -0
  5. data/buby.gemspec +102 -17
  6. data/{java/src → ext/buby/burp}/BurpExtender.java +189 -29
  7. data/ext/burp_interfaces/burp/IBurpExtender.java +31 -0
  8. data/ext/burp_interfaces/burp/IBurpExtenderCallbacks.java +785 -0
  9. data/ext/burp_interfaces/burp/IContextMenuFactory.java +38 -0
  10. data/ext/burp_interfaces/burp/IContextMenuInvocation.java +156 -0
  11. data/ext/burp_interfaces/burp/ICookie.java +53 -0
  12. data/ext/burp_interfaces/burp/IExtensionHelpers.java +352 -0
  13. data/ext/burp_interfaces/burp/IExtensionStateListener.java +27 -0
  14. data/ext/burp_interfaces/burp/IHttpListener.java +37 -0
  15. data/ext/burp_interfaces/burp/IHttpRequestResponse.java +102 -0
  16. data/ext/burp_interfaces/burp/IHttpRequestResponsePersisted.java +26 -0
  17. data/ext/burp_interfaces/burp/IHttpRequestResponseWithMarkers.java +44 -0
  18. data/ext/burp_interfaces/burp/IHttpService.java +39 -0
  19. data/ext/burp_interfaces/burp/IInterceptedProxyMessage.java +116 -0
  20. data/ext/burp_interfaces/burp/IIntruderAttack.java +31 -0
  21. data/ext/burp_interfaces/burp/IIntruderPayloadGenerator.java +50 -0
  22. data/ext/burp_interfaces/burp/IIntruderPayloadGeneratorFactory.java +40 -0
  23. data/ext/burp_interfaces/burp/IIntruderPayloadProcessor.java +45 -0
  24. data/{java/src → ext/burp_interfaces}/burp/IMenuItemHandler.java +36 -40
  25. data/ext/burp_interfaces/burp/IMessageEditor.java +64 -0
  26. data/ext/burp_interfaces/burp/IMessageEditorController.java +49 -0
  27. data/ext/burp_interfaces/burp/IMessageEditorTab.java +102 -0
  28. data/ext/burp_interfaces/burp/IMessageEditorTabFactory.java +38 -0
  29. data/ext/burp_interfaces/burp/IParameter.java +104 -0
  30. data/ext/burp_interfaces/burp/IProxyListener.java +37 -0
  31. data/ext/burp_interfaces/burp/IRequestInfo.java +95 -0
  32. data/ext/burp_interfaces/burp/IResponseInfo.java +54 -0
  33. data/ext/burp_interfaces/burp/IScanIssue.java +120 -0
  34. data/ext/burp_interfaces/burp/IScanQueueItem.java +80 -0
  35. data/ext/burp_interfaces/burp/IScannerCheck.java +89 -0
  36. data/ext/burp_interfaces/burp/IScannerInsertionPoint.java +156 -0
  37. data/ext/burp_interfaces/burp/IScannerInsertionPointProvider.java +38 -0
  38. data/ext/burp_interfaces/burp/IScannerListener.java +30 -0
  39. data/ext/burp_interfaces/burp/IScopeChangeListener.java +25 -0
  40. data/ext/burp_interfaces/burp/ISessionHandlingAction.java +51 -0
  41. data/ext/burp_interfaces/burp/ITab.java +38 -0
  42. data/ext/burp_interfaces/burp/ITempFile.java +33 -0
  43. data/ext/burp_interfaces/burp/ITextEditor.java +90 -0
  44. data/lib/buby/burp_extender/console_frame.rb +33 -0
  45. data/lib/buby/burp_extender/console_pane.rb +26 -0
  46. data/lib/buby/burp_extender/console_tab.rb +15 -0
  47. data/lib/buby/burp_extender/context_menu.rb +29 -0
  48. data/lib/buby/burp_extender/context_menu_factory.rb +17 -0
  49. data/lib/buby/burp_extender/context_menu_item.rb +13 -0
  50. data/lib/buby/burp_extender/jcheck_box_menu_item.rb +12 -0
  51. data/lib/buby/burp_extender/jmenu.rb +11 -0
  52. data/lib/buby/burp_extender/jmenu_item.rb +12 -0
  53. data/lib/buby/burp_extender/menu.rb +11 -0
  54. data/lib/buby/burp_extender/menu_item.rb +12 -0
  55. data/lib/buby/burp_extender.rb +339 -0
  56. data/lib/buby/context_menu_factory.rb +35 -0
  57. data/lib/buby/cookie.rb +37 -0
  58. data/lib/buby/extender.rb +156 -0
  59. data/lib/buby/http_listener.rb +29 -0
  60. data/lib/buby/{extends → implants}/buby_array_wrapper.rb +0 -0
  61. data/lib/buby/implants/context_menu_invocation.rb +113 -0
  62. data/lib/buby/implants/cookie.rb +47 -0
  63. data/lib/buby/implants/extension_helpers.rb +286 -0
  64. data/lib/buby/{extends → implants}/http_request_response.rb +8 -1
  65. data/lib/buby/implants/intercepted_proxy_message.rb +53 -0
  66. data/lib/buby/implants/intruder_attack.rb +42 -0
  67. data/lib/buby/implants/jruby.rb +64 -0
  68. data/lib/buby/implants/message_editor.rb +70 -0
  69. data/lib/buby/implants/message_editor_controller.rb +60 -0
  70. data/lib/buby/implants/parameter.rb +84 -0
  71. data/lib/buby/implants/request_info.rb +47 -0
  72. data/lib/buby/implants/response_info.rb +44 -0
  73. data/lib/buby/{extends → implants}/scan_issue.rb +1 -2
  74. data/lib/buby/implants/scan_queue_item.rb +53 -0
  75. data/lib/buby/implants/scanner_insertion_point.rb +92 -0
  76. data/lib/buby/implants/temp_file.rb +43 -0
  77. data/lib/buby/implants/text_editor.rb +63 -0
  78. data/lib/buby/implants.rb +28 -0
  79. data/lib/buby/intruder_payload_generator.rb +60 -0
  80. data/lib/buby/intruder_payload_generator_factory.rb +32 -0
  81. data/lib/buby/intruder_payload_processor.rb +38 -0
  82. data/lib/buby/message_editor_controller.rb +41 -0
  83. data/lib/buby/message_editor_tab.rb +98 -0
  84. data/lib/buby/message_editor_tab_factory.rb +28 -0
  85. data/lib/buby/parameter/base.rb +40 -0
  86. data/lib/buby/parameter/body.rb +7 -0
  87. data/lib/buby/parameter/cookie.rb +7 -0
  88. data/lib/buby/parameter/url.rb +7 -0
  89. data/lib/buby/parameter.rb +15 -0
  90. data/lib/buby/proxy_listener.rb +26 -0
  91. data/lib/buby/scan_issue.rb +112 -0
  92. data/lib/buby/scanner_check.rb +84 -0
  93. data/lib/buby/scanner_insertion_point.rb +118 -0
  94. data/lib/buby/scanner_insertion_point_provider.rb +27 -0
  95. data/lib/buby/scanner_listener.rb +22 -0
  96. data/lib/buby/scope_change_listener.rb +19 -0
  97. data/lib/buby/session_handling_action.rb +43 -0
  98. data/lib/buby/tab.rb +37 -0
  99. data/lib/buby/version.rb +9 -0
  100. data/lib/buby.rb +892 -101
  101. metadata +118 -22
  102. data/VERSION +0 -1
  103. data/java/buby.jar +0 -0
  104. data/java/src/burp/IBurpExtender.java +0 -180
  105. data/java/src/burp/IBurpExtenderCallbacks.java +0 -373
  106. data/java/src/burp/IHttpRequestResponse.java +0 -156
  107. data/java/src/burp/IScanIssue.java +0 -106
  108. data/java/src/burp/IScanQueueItem.java +0 -76
  109. data/lib/buby/extends.rb +0 -4
@@ -0,0 +1,33 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class ConsoleFrame < Java::JavaxSwing::JFrame
4
+ attr_accessor :burp, :pane
5
+ def initialize(burp_extender, pane, opts = {}, &block)
6
+ @burp = burp_extender
7
+ @pane = pane
8
+
9
+ blck = lambda do |event|
10
+ if event.getID == Java::JavaAwtEvent::WindowEvent::WINDOW_CLOSING
11
+ @pane.tar.shutdown
12
+ self.dispose
13
+ end
14
+ end
15
+
16
+ super(opts[:title] || 'JRuby IRB Console (tab will autocomplete)')
17
+ set_size(*(opts[:size] || [700, 600]))
18
+ content_pane.add(@pane)
19
+ addWindowStateListener &blck
20
+ addWindowListener &blck
21
+
22
+ if block_given?
23
+ addWindowStateListener &block
24
+ addWindowListener &block
25
+ end
26
+
27
+ @burp.callbacks.customizeUiComponent self
28
+ Java::JavaAwt::EventQueue.invoke_later {
29
+ self.visible = true
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class ConsolePane < Java::JavaxSwing::JScrollPane
4
+ attr_accessor :text, :tar
5
+ def initialize
6
+ super
7
+ @text = Java::JavaxSwing::JTextPane.new
8
+ @text.font = find_font('Monospaced', Java::JavaAwt::Font::PLAIN, 14, 'Anonymous Pro', 'Anonymous', 'Monaco', 'Andale Mono')
9
+ @text.margin = Java::JavaAwt::Insets.new(8,8,8,8)
10
+ @text.caret_color = Java::JavaAwt::Color.new(0xa40000)
11
+ @text.background = Java::JavaAwt::Color.new(0xf2f2f2)
12
+ @text.foreground = Java::JavaAwt::Color.new(0xa40000)
13
+ 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
+ JRuby.objectspace = true # useful for code completion
16
+ @tar.hook_into_runtime_with_streams(JRuby.runtime)
17
+ end
18
+
19
+ # Try to find preferred font family, use otherwise -- err -- otherwise
20
+ def find_font(otherwise, style, size, *families)
21
+ avail_families = Java::JavaAwt::GraphicsEnvironment.local_graphics_environment.available_font_family_names
22
+ fontname = families.find(proc {otherwise}) { |name| avail_families.include? name }
23
+ Java::JavaAwt::Font.new(fontname, style, size)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'buby/version'
2
+
3
+ class BurpExtender
4
+ # @api private
5
+ class ConsoleTab
6
+ include Java::Burp::ITab
7
+ attr_accessor :ui_component, :tab_caption
8
+ CAPTION = "Buby v#{Buby::Version::STRING}"
9
+
10
+ def initialize component, caption = nil
11
+ @ui_component = component
12
+ @tab_caption = caption || CAPTION
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ require 'buby/burp_extender/context_menu_item'
2
+
3
+ # @api private
4
+ class BurpExtender
5
+ # @api private
6
+ class ContextMenu < Java::JavaxSwing::JMenu
7
+ attr_accessor :burp, :invocation
8
+ def initialize burp_extender, invocation
9
+ @burp = burp_extender
10
+ @invocation = invocation
11
+ super 'Buby'
12
+
13
+ if @burp.frame
14
+ self.add(ContextMenuItem.new('Move console to tab', @burp, @invocation) do |event|
15
+ burp = event.source.burp
16
+ invocation = event.source.invocation
17
+ burp.move_to_tab
18
+ end)
19
+ else
20
+ self.add(ContextMenuItem.new('Move console to window', @burp, @invocation) do |event|
21
+ burp = event.source.burp
22
+ invocation = event.source.invocation
23
+ burp.move_to_window
24
+ end)
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'buby/burp_extender/context_menu'
2
+
3
+ class BurpExtender
4
+ # @api private
5
+ class ContextMenuFactory
6
+ attr_accessor :burp
7
+ include Java::Burp::IContextMenuFactory
8
+ def initialize burp_extender
9
+ @burp = burp_extender
10
+ end
11
+
12
+ def createMenuItems invocation
13
+ pp [:createMenuItems, invocation] if $DEBUG
14
+ [BurpExtender::ContextMenu.new(@burp, invocation)]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class ContextMenuItem < Java::JavaxSwing::JMenuItem
4
+ attr_accessor :invocation, :burp
5
+ def initialize text, burp_extender, invocation, &block
6
+ super text
7
+ @invocation = invocation
8
+ @burp = burp_extender
9
+
10
+ addActionListener &block
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class BurpExtender
2
+ class JCheckBoxMenuItem < Java::JavaxSwing::JCheckBoxMenuItem
3
+ attr_accessor :burp
4
+ def initialize(burp_extender, *args, &block)
5
+ super *args
6
+ @burp = burp_extender
7
+ if block_given?
8
+ addActionListener &block
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class JMenu < Java::JavaxSwing::JMenu
4
+ attr_accessor :burp
5
+ def initialize burp_extender, name = nil
6
+ name ||= burp_extender.handler.class.name
7
+ @burp = burp_extender
8
+ super name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class JMenuItem < Java::JavaxSwing::JMenuItem
4
+ attr_accessor :burp
5
+ def initialize text, burp_extender, &block
6
+ super text
7
+ @burp = burp_extender
8
+
9
+ addActionListener &block
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class Menu < Java::JavaAwt::Menu
4
+ attr_accessor :burp
5
+ def initialize burp_extender, name = nil
6
+ name ||= burp_extender.handler.class.name
7
+ @burp = burp_extender
8
+ super name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class BurpExtender
2
+ # @api private
3
+ class MenuItem < Java::JavaAwt::MenuItem
4
+ attr_accessor :burp
5
+ def initialize text, burp_extender, &block
6
+ super text
7
+ @burp = burp_extender
8
+
9
+ addActionListener &block
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,339 @@
1
+ require 'buby'
2
+ require 'buby/extender'
3
+ require 'pp'
4
+ require 'buby/burp_extender/context_menu_factory'
5
+ require 'buby/burp_extender/jmenu_item'
6
+ require 'buby/burp_extender/jmenu'
7
+ require 'buby/burp_extender/jcheck_box_menu_item'
8
+
9
+
10
+ if ARGV.empty?
11
+ # default options, esp. useful for jrubyw
12
+ ARGV << '--readline' << '--prompt' << 'inf-ruby'
13
+ end
14
+
15
+ # This is the default JRuby implementation of IBurpExtender for use as a JRuby
16
+ # extension.
17
+ #
18
+ class BurpExtender
19
+ include Buby::Extender
20
+ include Java::Burp::IBurpExtender
21
+
22
+ @@handler ||= Buby.new
23
+
24
+ # ExtensionHelpers for internal reference
25
+ attr_reader :helpers
26
+ # BurpExtenderCallbacks for internal reference.
27
+ attr_reader :callbacks
28
+ # Start with an interactive session running. Defaults to IRB when +nil+ or unkown, can be +irb+, +none+ or +pry+.
29
+ attr_accessor :interactive
30
+ # Set $DEBUG on start.
31
+ attr_accessor :debug
32
+ # Run interactive session in a window instead of a tab.
33
+ attr_accessor :windowed
34
+ # Allow proxy interception on load.
35
+ attr_accessor :intercept
36
+ # Unload the extension when exiting irb. Defaults to nil. The values +exit+
37
+ # and +unload+ will close Burp and unload Buby, respectively.
38
+ attr_accessor :on_quit
39
+
40
+ attr_accessor :frame
41
+ attr_accessor :pane
42
+
43
+ # save the current BurpExtender settings to the preferences cache
44
+ def save_settings!
45
+ @callbacks.saveExtensionSetting('intercept', @intercept ? @intercept.to_s : nil)
46
+ case @interactive
47
+ when nil, 'irb', 'pry', 'none'
48
+ @callbacks.saveExtensionSetting('interactive', @interactive)
49
+ when false
50
+ @callbacks.saveExtensionSetting('interactive', 'none')
51
+ else
52
+ @callbacks.saveExtensionSetting('interactive', @interactive.to_s)
53
+ end
54
+ @callbacks.saveExtensionSetting('debug', @debug ? @debug.to_s : nil)
55
+ @callbacks.saveExtensionSetting('windowed', @windowed ? @windowed.to_s : nil)
56
+ case @on_quit
57
+ when 'exit', 'unload', nil
58
+ @callbacks.saveExtensionSetting('on_quit', @on_quit)
59
+ else
60
+ @callbacks.saveExtensionSetting('on_quit', @on_quit.to_s)
61
+ end
62
+ end
63
+
64
+ # @group Internals
65
+ # @see Buby::Extender#registerExtenderCallbacks
66
+ def registerExtenderCallbacks(callbacks)
67
+ @@handler.extender_initialize self
68
+ @interactive_sessions = 0
69
+ @callbacks = callbacks
70
+ @helpers = @callbacks.helpers
71
+ @callbacks.setExtensionName("Buby")
72
+
73
+ sys_properties = Java::JavaLang::System.getProperties
74
+
75
+ @intercept = sys_properties.getProperty("burp.buby.intercept", nil) || @callbacks.loadExtensionSetting('intercept')
76
+ @interactive = sys_properties.getProperty("burp.buby.interactive", nil) || @callbacks.loadExtensionSetting('interactive') || 'irb'
77
+ @debug = sys_properties.getProperty("burp.buby.debug", nil) || @callbacks.loadExtensionSetting('debug')
78
+ @windowed = sys_properties.getProperty("burp.buby.windowed", nil) || @callbacks.loadExtensionSetting('windowed') || 'false'
79
+ @on_quit = sys_properties.getProperty("burp.buby.on_quit", nil) || @callbacks.loadExtensionSetting('on_quit') || 'unload'
80
+
81
+ $DEBUG = @debug unless @debug && @debug.match(/\Afalse\Z/i)
82
+ @callbacks.setProxyInterceptionEnabled false unless @intercept && @intercept.match(/\A(?:false|f|n|no|off)\Z/i)
83
+
84
+ $burp = @@handler
85
+
86
+ super
87
+
88
+ @main_menu = Java::JavaAwt::Frame.getFrames.map{|x| x.getJMenuBar if x.respond_to?(:getJMenuBar)}.compact.find_all do |mb|
89
+ labels = mb.getMenuCount.times.map{|x| mb.getMenu(x).label}
90
+ !(labels & ["Burp", "Intruder", "Repeater", "Window", "Help"]).empty?
91
+ end.first
92
+
93
+ @menu = BurpExtender::JMenu.new self
94
+ @menu.add(tcm = BurpExtender::JMenuItem.new('Toggle console mode', self) do |event|
95
+ self.toggle_windowed
96
+ end)
97
+
98
+ pref_menu = BurpExtender::JMenu.new self, "Preferences.."
99
+
100
+ interact = BurpExtender::JMenu.new self, "Interactive..."
101
+
102
+ mode_group = Java::JavaxSwing::ButtonGroup.new
103
+
104
+ mode = BurpExtender::JMenu.new self, "Mode"
105
+ %w{irb pry none}.each do |md|
106
+ mode_item = Java::JavaxSwing::JRadioButtonMenuItem.new md
107
+ mode_item.action_command = md
108
+ # mode_item.selected = (@interactive == md)
109
+ mode_item.addActionListener do |event|
110
+ @callbacks.saveExtensionSetting('interactive', event.action_command)
111
+ @interactive = event.action_command
112
+ end
113
+ mode_group.add mode_item
114
+ mode.add mode_item
115
+ end
116
+ interact.add mode
117
+
118
+ quit_group = Java::JavaxSwing::ButtonGroup.new
119
+
120
+ oq = BurpExtender::JMenu.new self, "On quit"
121
+ %w{exit unload none}.each do |md|
122
+ menu_item = Java::JavaxSwing::JRadioButtonMenuItem.new md
123
+ menu_item.action_command = md
124
+ # menu_item.selected = (@on_quit == md)
125
+ menu_item.addActionListener do |event|
126
+ @callbacks.saveExtensionSetting('on_quit', event.action_command)
127
+ @on_quit = event.action_command
128
+ end
129
+ quit_group.add menu_item
130
+ oq.add menu_item
131
+ end
132
+ interact.add oq
133
+
134
+ windowd = BurpExtender::JCheckBoxMenuItem.new(self, "Windowed", (@windowed && (@windowed != 'false'))) do |event|
135
+ enabl = event.source.state
136
+
137
+ @windowed = enabl
138
+ if enabl
139
+ @callbacks.saveExtensionSetting('windowed', 'true')
140
+ self.move_to_window
141
+ else
142
+ @callbacks.saveExtensionSetting('windowed', nil)
143
+ self.move_to_tab
144
+ end
145
+ end
146
+
147
+ interact.add windowd
148
+ pref_menu.add interact
149
+
150
+ dbg = BurpExtender::JCheckBoxMenuItem.new self, "$DEBUG" do |event|
151
+ enabl = event.source.state
152
+ @debug = enabl
153
+ @callbacks.saveExtensionSetting('debug', enabl ? 'true' : nil)
154
+ $DEBUG = enabl ? 1 : nil
155
+ end
156
+
157
+ interc = BurpExtender::JCheckBoxMenuItem.new self, "Disable intercept on start" do |event|
158
+ enabl = event.source.state
159
+ if enabl
160
+ @intercept = nil
161
+ @callbacks.saveExtensionSetting('intercept', nil)
162
+ else
163
+ @intercept = true
164
+ @callbacks.saveExtensionSetting('intercept', 'true')
165
+ end
166
+ end
167
+ pref_menu.add interc
168
+
169
+ dbg.state = !!$DEBUG
170
+ pref_menu.add dbg
171
+
172
+ @menu.add pref_menu
173
+
174
+ @main_menu.add @menu
175
+
176
+ @menu.addChangeListener do |event|
177
+ if @menu.isSelected
178
+ mode.getMenuComponents.each do |menu|
179
+ menu.selected = (@interactive == menu.action_command)
180
+ end
181
+
182
+ oq.getMenuComponents.each do |menu|
183
+ menu.selected = (@on_quit == menu.action_command)
184
+ end
185
+
186
+ if @frame
187
+ tcm.text = 'Move console to tab'
188
+ elsif @interactive_running
189
+ tcm.text = 'Move console to window'
190
+ else
191
+ tcm.text = 'Start interactive session'
192
+ end
193
+
194
+ dbg.state = !!(@debug && (@debug != 'false'))
195
+ interc.state = !(@intercept && (@intercept != 'false'))
196
+ windowd.state = !!(@windowed && (@windowed != 'false'))
197
+ end
198
+ end
199
+
200
+ @callbacks.getStderr.flush
201
+ @callbacks.getStdout.flush
202
+ start_interactive unless @interactive == 'none'
203
+ end
204
+
205
+ def start_interactive(allow_multiple = false)
206
+ unless @interactive_sessions.nonzero? || allow_multiple
207
+ init_console
208
+ case @interactive
209
+ when 'irb', nil
210
+ start_irb
211
+ when 'pry'
212
+ start_pry
213
+ when 'none'
214
+ else
215
+ @callbacks.getStderr.write "Unknown interactive setting #{@interactive.dump}. Starting IRB".to_java_bytes
216
+ start_irb
217
+ end
218
+ end
219
+ end
220
+
221
+ def toggle_windowed
222
+ if @frame
223
+ move_to_tab
224
+ elsif @interactive_running
225
+ move_to_window
226
+ else
227
+ start_interactive
228
+ end
229
+ end
230
+
231
+ def move_to_tab
232
+ require 'buby/burp_extender/console_tab'
233
+ @tab = BurpExtender::ConsoleTab.new @pane
234
+ @callbacks.addSuiteTab @tab
235
+ if @frame
236
+ Java::JavaAwt::EventQueue.invoke_later {
237
+ @frame.dispose if @frame
238
+ @frame = nil
239
+ }
240
+ end
241
+ end
242
+
243
+ def move_to_window
244
+ @callbacks.removeSuiteTab @tab if @tab
245
+ create_frame
246
+ end
247
+
248
+ # Starts an IRB Session
249
+ def start_irb
250
+ require 'irb'
251
+ require 'irb/completion'
252
+
253
+ unless @interactive_running
254
+ @interactive_running = true
255
+ @interactive_sessions += 1
256
+ puts "Starting IRB: Global $burp is set to #{$burp.inspect}"
257
+ IRB.start(__FILE__)
258
+ quitting
259
+ end
260
+ end
261
+
262
+ def start_pry
263
+ require 'pry'
264
+
265
+ unless @interactive_running
266
+ @interactive_running = true
267
+ puts "Starting Pry: Global $burp is set to #{$burp.inspect}"
268
+ ENV['TERM'] = 'dumb'
269
+ Pry.color = false
270
+
271
+ # Pry makes a bunch of invalid assumptions. This seems to be the best we can do for now.
272
+ Pry.toplevel_binding.pry
273
+ quitting
274
+ end
275
+ end
276
+
277
+ def quitting
278
+ @interactive_running = false
279
+
280
+ case @on_quit
281
+ when 'exit'
282
+ @callbacks.exitSuite true
283
+ unload_ui # just in case closing is cancelled, we need to kill the frame and tab
284
+ when 'unload'
285
+ @callbacks.unloadExtension
286
+ else
287
+ unload_ui
288
+ end
289
+ end
290
+
291
+ def extensionUnloaded
292
+ super
293
+ unload_ui
294
+ unload_menu
295
+ end
296
+
297
+ def inspect
298
+ "<#{self.class}:0x#{self.hash.to_s(16)} @interactive=#{@interactive.inspect}, @windowed=#{@windowed.inspect}, @on_quit=#{@on_quit.inspect}, @intercept=#{@intercept.inspect}, @debug=#{@debug.inspect}, @callbacks=#{@callbacks.inspect}, @helpers=#{@helpers.inspect}>"
299
+ end
300
+
301
+ private
302
+ def unload_ui
303
+ if @frame
304
+ Java::JavaAwt::EventQueue.invoke_later {
305
+ @frame.dispose if @frame
306
+ @frame = nil
307
+ }
308
+ end
309
+ end
310
+
311
+ def unload_menu
312
+ @main_menu.remove @menu
313
+ @callbacks.removeSuiteTab @tab if @tab
314
+ @pane = nil
315
+ end
316
+
317
+ def init_console
318
+ require 'buby/burp_extender/console_pane'
319
+ @pane = ConsolePane.new
320
+
321
+ @callbacks.customizeUiComponent @pane
322
+ if @windowed && @windowed != 'false'
323
+ create_frame
324
+ else
325
+ require 'buby/burp_extender/console_tab'
326
+ @tab = BurpExtender::ConsoleTab.new @pane
327
+ @callbacks.addSuiteTab @tab
328
+ end
329
+ end
330
+
331
+ def create_frame
332
+ require 'buby/burp_extender/console_frame'
333
+ unless @frame
334
+ @frame = BurpExtender::ConsoleFrame.new self, @pane do |event|
335
+ @frame = nil if event.getID == Java::JavaAwtEvent::WindowEvent::WINDOW_CLOSED
336
+ end
337
+ end
338
+ end
339
+ end