Class: BurpExtender Private

Inherits:
Object show all
Includes:
Buby::Extender, Java::Burp::IBurpExtender
Defined in:
lib/buby/burp_extender.rb,
lib/buby/burp_extender/menu.rb,
lib/buby/burp_extender/jmenu.rb,
lib/buby/burp_extender/menu_item.rb,
lib/buby/burp_extender/jmenu_item.rb,
lib/buby/burp_extender/console_tab.rb,
lib/buby/burp_extender/console_pane.rb,
lib/buby/burp_extender/context_menu.rb,
lib/buby/burp_extender/console_frame.rb,
lib/buby/burp_extender/context_menu_item.rb,
lib/buby/burp_extender/context_menu_factory.rb,
lib/buby/burp_extender/jcheck_box_menu_item.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: ConsoleFrame, ConsolePane, ConsoleTab, ContextMenu, ContextMenuFactory, ContextMenuItem, JCheckBoxMenuItem, JMenu, JMenuItem, Menu, MenuItem

Instance Attribute Summary collapse

Internals collapse

Instance Method Summary collapse

Methods included from Buby::Extender

#createMenuItems, #handler, #handler=, included, #initialize, #newScanIssue, #processHttpMessage, #processProxyMessage, #scopeChanged

Instance Attribute Details

#callbacksObject (readonly)

BurpExtenderCallbacks for internal reference.



27
28
29
# File 'lib/buby/burp_extender.rb', line 27

def callbacks
  @callbacks
end

#debugObject

Set $DEBUG on start.



31
32
33
# File 'lib/buby/burp_extender.rb', line 31

def debug
  @debug
end

#frameObject

Returns the value of attribute frame.



40
41
42
# File 'lib/buby/burp_extender.rb', line 40

def frame
  @frame
end

#helpersObject (readonly)

ExtensionHelpers for internal reference



25
26
27
# File 'lib/buby/burp_extender.rb', line 25

def helpers
  @helpers
end

#interactiveObject

Start with an interactive session running. Defaults to IRB when nil or unkown, can be irb, none or pry.



29
30
31
# File 'lib/buby/burp_extender.rb', line 29

def interactive
  @interactive
end

#interceptObject

Allow proxy interception on load.



35
36
37
# File 'lib/buby/burp_extender.rb', line 35

def intercept
  @intercept
end

#on_quitObject

Unload the extension when exiting irb. Defaults to nil. The values exit

and +unload+ will close Burp and unload Buby, respectively.


38
39
40
# File 'lib/buby/burp_extender.rb', line 38

def on_quit
  @on_quit
end

#paneObject

Returns the value of attribute pane.



41
42
43
# File 'lib/buby/burp_extender.rb', line 41

def pane
  @pane
end

#windowedObject

Run interactive session in a window instead of a tab.



33
34
35
# File 'lib/buby/burp_extender.rb', line 33

def windowed
  @windowed
end

Instance Method Details

#extensionUnloadedObject



291
292
293
294
295
# File 'lib/buby/burp_extender.rb', line 291

def extensionUnloaded
  super
  unload_ui
  unload_menu
end

#inspectObject



297
298
299
# File 'lib/buby/burp_extender.rb', line 297

def inspect
  "<#{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}>"
end

#move_to_tabObject



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/buby/burp_extender.rb', line 231

def move_to_tab
  require 'buby/burp_extender/console_tab'
  @tab = BurpExtender::ConsoleTab.new @pane
  @callbacks.addSuiteTab @tab
  if @frame
    Java::JavaAwt::EventQueue.invoke_later {
      @frame.dispose if @frame
      @frame = nil
    }
  end
end

#move_to_windowObject



243
244
245
246
# File 'lib/buby/burp_extender.rb', line 243

def move_to_window
  @callbacks.removeSuiteTab @tab if @tab
  create_frame
end

#quittingObject



277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/buby/burp_extender.rb', line 277

def quitting
  @interactive_running = false

  case @on_quit
  when 'exit'
    @callbacks.exitSuite true
    unload_ui # just in case closing is cancelled, we need to kill the frame and tab
  when 'unload'
    @callbacks.unloadExtension
  else
    unload_ui
  end
end

#registerExtenderCallbacks(callbacks) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/buby/burp_extender.rb', line 66

def registerExtenderCallbacks(callbacks)
  @@handler.extender_initialize self
  @interactive_sessions = 0
  @callbacks = callbacks
  @helpers = @callbacks.helpers
  @callbacks.setExtensionName("Buby")

  sys_properties = Java::JavaLang::System.getProperties

  @intercept = sys_properties.getProperty("burp.buby.intercept", nil) || @callbacks.loadExtensionSetting('intercept')
  @interactive = sys_properties.getProperty("burp.buby.interactive", nil) || @callbacks.loadExtensionSetting('interactive') || 'irb'
  @debug = sys_properties.getProperty("burp.buby.debug", nil) || @callbacks.loadExtensionSetting('debug')
  @windowed = sys_properties.getProperty("burp.buby.windowed", nil) || @callbacks.loadExtensionSetting('windowed') || 'false'
  @on_quit = sys_properties.getProperty("burp.buby.on_quit", nil) || @callbacks.loadExtensionSetting('on_quit') || 'unload'

  $DEBUG = @debug unless @debug && @debug.match(/\Afalse\Z/i)
  @callbacks.setProxyInterceptionEnabled false unless @intercept &&  @intercept.match(/\A(?:false|f|n|no|off)\Z/i)

  $burp = @@handler

  super

  @main_menu = Java::JavaAwt::Frame.getFrames.map{|x| x.getJMenuBar if x.respond_to?(:getJMenuBar)}.compact.find_all do |mb|
    labels = mb.getMenuCount.times.map{|x| mb.getMenu(x).label}
    !(labels & ["Burp", "Intruder", "Repeater", "Window", "Help"]).empty?
  end.first

  @menu = BurpExtender::JMenu.new self
  @menu.add(tcm = BurpExtender::JMenuItem.new('Toggle console mode', self) do |event|
    self.toggle_windowed
  end)

  pref_menu = BurpExtender::JMenu.new self, "Preferences.."

  interact = BurpExtender::JMenu.new self, "Interactive..."

  mode_group = Java::JavaxSwing::ButtonGroup.new

  mode = BurpExtender::JMenu.new self, "Mode"
  %w{irb pry none}.each do |md|
    mode_item = Java::JavaxSwing::JRadioButtonMenuItem.new md
    mode_item.action_command = md
    # mode_item.selected = (@interactive == md)
    mode_item.addActionListener do |event|
      @callbacks.saveExtensionSetting('interactive', event.action_command)
      @interactive = event.action_command
    end
    mode_group.add mode_item
    mode.add mode_item
  end
  interact.add mode

  quit_group = Java::JavaxSwing::ButtonGroup.new

  oq = BurpExtender::JMenu.new self, "On quit"
  %w{exit unload none}.each do |md|
    menu_item = Java::JavaxSwing::JRadioButtonMenuItem.new md
    menu_item.action_command = md
    # menu_item.selected = (@on_quit == md)
    menu_item.addActionListener do |event|
      @callbacks.saveExtensionSetting('on_quit', event.action_command)
      @on_quit = event.action_command
    end
    quit_group.add menu_item
    oq.add menu_item
  end
  interact.add oq

  windowd = BurpExtender::JCheckBoxMenuItem.new(self, "Windowed", (@windowed && (@windowed != 'false'))) do |event|
    enabl = event.source.state

    @windowed = enabl
    if enabl
      @callbacks.saveExtensionSetting('windowed', 'true')
      self.move_to_window
    else
      @callbacks.saveExtensionSetting('windowed', nil)
      self.move_to_tab
    end
  end

  interact.add windowd
  pref_menu.add interact

  dbg = BurpExtender::JCheckBoxMenuItem.new self, "$DEBUG"  do |event|
    enabl = event.source.state
    @debug = enabl
    @callbacks.saveExtensionSetting('debug', enabl ? 'true' : nil)
    $DEBUG = enabl ? 1 : nil
  end

  interc = BurpExtender::JCheckBoxMenuItem.new self, "Disable intercept on start"  do |event|
    enabl = event.source.state
    if enabl
      @intercept = nil
      @callbacks.saveExtensionSetting('intercept', nil)
    else
      @intercept = true
      @callbacks.saveExtensionSetting('intercept', 'true')
    end
  end
  pref_menu.add interc

  dbg.state = !!$DEBUG
  pref_menu.add dbg

  @menu.add pref_menu

  @main_menu.add @menu

  @menu.addChangeListener do |event|
    if @menu.isSelected
      mode.getMenuComponents.each do |menu|
        menu.selected = (@interactive == menu.action_command)
      end

      oq.getMenuComponents.each do |menu|
        menu.selected = (@on_quit == menu.action_command)
      end

      if @frame
        tcm.text = 'Move console to tab'
      elsif @interactive_running
        tcm.text = 'Move console to window'
      else
        tcm.text = 'Start interactive session'
      end

      dbg.state = !!(@debug && (@debug != 'false'))
      interc.state = !(@intercept && (@intercept != 'false'))
      windowd.state = !!(@windowed && (@windowed != 'false'))
    end
  end

  @callbacks.getStderr.flush
  @callbacks.getStdout.flush
  start_interactive  unless @interactive == 'none'
end

#save_settings!Object

save the current BurpExtender settings to the preferences cache



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/buby/burp_extender.rb', line 44

def save_settings!
  @callbacks.saveExtensionSetting('intercept', @intercept ? @intercept.to_s : nil)
  case @interactive
  when nil, 'irb', 'pry', 'none'
    @callbacks.saveExtensionSetting('interactive', @interactive)
  when false
    @callbacks.saveExtensionSetting('interactive', 'none')
  else
    @callbacks.saveExtensionSetting('interactive', @interactive.to_s)
  end
  @callbacks.saveExtensionSetting('debug', @debug ? @debug.to_s : nil)
  @callbacks.saveExtensionSetting('windowed', @windowed ? @windowed.to_s : nil)
  case @on_quit
  when 'exit', 'unload', nil
    @callbacks.saveExtensionSetting('on_quit', @on_quit)
  else
    @callbacks.saveExtensionSetting('on_quit', @on_quit.to_s)
  end
end

#start_interactive(allow_multiple = false) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/buby/burp_extender.rb', line 205

def start_interactive(allow_multiple = false)
  unless @interactive_sessions.nonzero? || allow_multiple
    init_console
    case @interactive
    when 'irb', nil
      start_irb
    when 'pry'
      start_pry
    when 'none'
    else
      @callbacks.getStderr.write "Unknown interactive setting #{@interactive.dump}. Starting IRB".to_java_bytes
      start_irb
    end
  end
end

#start_irbObject

Starts an IRB Session



249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/buby/burp_extender.rb', line 249

def start_irb
  require 'irb'
  require 'irb/completion'

  unless @interactive_running
    @interactive_running = true
    @interactive_sessions += 1
    puts "Starting IRB: Global $burp is set to #{$burp.inspect}"
    IRB.start(__FILE__)
    quitting
  end
end

#start_pryObject



262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/buby/burp_extender.rb', line 262

def start_pry
  require 'pry'

  unless @interactive_running
    @interactive_running = true
    puts "Starting Pry: Global $burp is set to #{$burp.inspect}"
    ENV['TERM'] = 'dumb'
    Pry.color = false

    # Pry makes a bunch of invalid assumptions. This seems to be the best we can do for now.
    Pry.toplevel_binding.pry
    quitting
  end
end

#toggle_windowedObject



221
222
223
224
225
226
227
228
229
# File 'lib/buby/burp_extender.rb', line 221

def toggle_windowed
  if @frame
    move_to_tab
  elsif @interactive_running
    move_to_window
  else
    start_interactive
  end
end