Module: PWN::Plugins::TransparentBrowser
- Defined in:
- lib/pwn/plugins/transparent_browser.rb
Overview
This plugin rocks. Chrome, Firefox, headless, REST Client, all from the comfort of one plugin. Proxy support (e.g. Burp Suite Professional) is completely available for all browsers except for limited functionality within IE (IE has interesting protections in place to prevent this). This plugin also supports taking screenshots :)
Constant Summary collapse
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.close(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj1 = PWN::Plugins::TransparentBrowser.close( browser_obj: ‘required - browser_obj returned from #open method)’ ).
-
.find_element_by_text(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.find_element_by_text( browser_obj: browser_obj1, text: ‘required - text to search for in the DOM’ ).
-
.help ⇒ Object
Display Usage for this Module.
-
.linkout(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.linkout( browser_obj: browser_obj1 ).
-
.open(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj1 = PWN::Plugins::TransparentBrowser.open( browser_type: :firefox|:chrome|:headless|:rest|:websocket, proxy: ‘optional - scheme://proxy_host:port || tor’, with_devtools: ‘optional - boolean (defaults to false)’ ).
-
.type_as_human(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.type_as_human( string: ‘required - string to type as human’, rand_sleep_float: ‘optional - float timing in between keypress (defaults to 0.09)’ ).
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
347 348 349 350 351 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 347 public_class_method def self. "AUTHOR(S): 0day Inc. <[email protected]> " end |
.close(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj1 = PWN::Plugins::TransparentBrowser.close(
browser_obj: 'required - browser_obj returned from #open method)'
)
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 328 public_class_method def self.close(opts = {}) browser_obj = opts[:browser_obj] unless browser_obj[:tor_obj].nil? tor_obj = browser_obj[:tor_obj] PWN::Plugins::Tor.stop(tor_obj: browser_obj[:tor_obj]) end unless browser_obj[:browser].to_s.include?('RestClient') # Close the browser unless this_browser_obj.nil? (thus the &) browser_obj[:browser]&.close end nil rescue StandardError => e raise e end |
.find_element_by_text(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.find_element_by_text(
browser_obj: browser_obj1, text: 'required - text to search for in the DOM'
)
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 283 public_class_method def self.find_element_by_text(opts = {}) browser_obj = opts[:browser_obj] text = opts[:text].to_s elements_found = browser_obj[:browser].elements.select do |element| element.text == text end elements_found.each do |element_found| @@logger.info("#{element_found.html}\n\n\n") end browser_obj rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 355 public_class_method def self.help puts "USAGE: browser_obj1 = #{self}.open( browser_type: :firefox|:chrome|:headless_chrome|:headless_firefox|:rest|:websocket, proxy: 'optional scheme://proxy_host:port || tor', with_devtools: 'optional - boolean (defaults to false)' ) puts browser_obj1.public_methods ******************************************************** * DevTools Interaction Only works w/ Chrome * All DevTools Commands can be found here: * https://chromedevtools.github.io/devtools-protocol/ * Examples devtools = browser_obj1.driver.devtools puts devtools.public_methods puts devtools.instance_variables puts devtools.instance_variable_get('@messages') * Tracing devtools.send_cmd('Tracing.start') devtools.send_cmd('Tracing.requestMemoryDump') devtools.send_cmd('Tracing.end') puts devtools.instance_variable_get('@messages') * Network devtools.send_cmd('Network.enable') last_ws_resp = devtools.instance_variable_get('@messages').last if devtools.instance_variable_get('@messages').last['method'] == 'Network.webSocketFrameReceived' puts last_ws_resp devtools.send_cmd('Network.disable') * Debugging DOM and Sending JavaScript to Console devtools.send_cmd('Runtime.enable') devtools.send_cmd('Console.enable') devtools.send_cmd('DOM.enable') devtools.send_cmd('Page.enable') devtools.send_cmd('Log.enable') devtools.send_cmd('Debugger.enable') devtools.send_cmd('Debugger.pause') step = 1 next_step = 60 loop do devtools.send_cmd('Console.clearMessages') devtools.send_cmd('Log.clear') console_events = [] b.driver.on_log_event(:console) { |event| console_events.push(event) } devtools.send_cmd('Debugger.stepInto') puts \"Step: \#{step}\" this_document = devtools.send_cmd('DOM.getDocument') puts \"This #document:\\n\#{this_document}\\n\\n\\n\" console_cmd = { expression: 'for(var pop_var in window) { if (window.hasOwnProperty(pop_var) && window[pop_var] != null) console.log(pop_var + \" = \" + window[pop_var]); }' } puts devtools.send_cmd('Runtime.evaluate', **console_cmd) print '-' * 180 print \"\\n\" console_events.each do |event| puts event.args end puts \"Console Response Length: \#{console_events.length}\" console_events_digest = OpenSSL::Digest::SHA256.hexdigest( console_events.inspect ) puts \"Console Events Array SHA256 Digest: \#{console_events_digest}\" print '-' * 180 puts \"\\n\\n\\n\" print \"Next Step in \" next_step.downto(1) {|n| print \"\#{n} \"; sleep 1 } puts 'READY!' step += 1 end devtools.send_cmd('Debugger.disable') devtools.send_cmd('Log.disable') devtools.send_cmd('Page.disable') devtools.send_cmd('DOM.disable') devtools.send_cmd('Console.disable') devtools.send_cmd('Runtime.disable') * End of DevTools Examples ******************************************************** browser_obj1 = #{self}.linkout( browser_obj: 'required - browser_obj returned from #open method)' ) browser_obj1 = #{self}.find_element_by_text( browser_obj: 'required - browser_obj returned from #open method)', text: 'required - text to search for in the DOM' ) #{self}.type_as_human( string: 'required - string to type as human', rand_sleep_float: 'optional - float timing in between keypress (defaults to 0.09)' ) {|char| browser_obj1.text_field(name: \"search\").send_keys(char) } browser_obj1 = #{self}.close( browser_obj: 'required - browser_obj returned from #open method)' ) #{self}.authors " end |
.linkout(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.linkout(
browser_obj: browser_obj1
)
265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 265 public_class_method def self.linkout(opts = {}) browser_obj = opts[:browser_obj] browser_obj[:browser].links.each do |link| @@logger.info("#{link.text} => #{link.href}\n\n\n") unless link.text == '' end browser_obj rescue StandardError => e raise e end |
.open(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj1 = PWN::Plugins::TransparentBrowser.open(
browser_type: :firefox|:chrome|:headless|:rest|:websocket, proxy: 'optional - scheme://proxy_host:port || tor', with_devtools: 'optional - boolean (defaults to false)'
)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 30 public_class_method def self.open(opts = {}) browser_type = opts[:browser_type] proxy = opts[:proxy].to_s unless opts[:proxy].nil? browser_obj = {} tor_obj = nil if opts[:proxy] == 'tor' tor_obj = PWN::Plugins::Tor.start proxy = "socks5://#{tor_obj[:ip]}:#{tor_obj[:port]}" browser_obj[:tor_obj] = tor_obj end opts[:with_devtools] ? (with_devtools = true) : (with_devtools = false) # Let's crank up the default timeout from 30 seconds to 15 min for slow sites Watir.default_timeout = 900 case browser_type when :firefox this_profile = Selenium::WebDriver::Firefox::Profile.new # Increase Web Assembly Verbosity this_profile['javascript.options.wasm_verbose'] = true # Downloads reside in ~/Downloads this_profile['browser.download.folderList'] = 1 this_profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/pdf' # disable Firefox's built-in PDF viewer this_profile['pdfjs.disabled'] = true # disable Adobe Acrobat PDF preview plugin this_profile['plugin.scan.plid.all'] = false this_profile['plugin.scan.Acrobat'] = '99.0' # ensure localhost proxy capabilities are enabled this_profile['network.proxy.no_proxies_on'] = '' # allow scripts to run a bit longer # this_profile['dom.max_chrome_script_run_time'] = 180 # this_profile['dom.max_script_run_time'] = 180 # disable browser cache this_profile['browser.cache.disk.enable'] = false this_profile['browser.cache.disk_cache_ssl.enable'] = false this_profile['browser.cache.memory.enable'] = false this_profile['browser.cache.offline.enable'] = false this_profile['devtools.cache.disabled'] = true this_profile['dom.caches.enabled'] = false # caps = Selenium::WebDriver::Remote::Capabilities.firefox # caps[:acceptInsecureCerts] = true if proxy this_profile['network.proxy.type'] = 1 this_profile['network.proxy.allow_hijacking_localhost'] = true if tor_obj this_profile['network.proxy.socks_version'] = 5 this_profile['network.proxy.socks'] = tor_obj[:ip] this_profile['network.proxy.socks_port'] = tor_obj[:port] else this_profile['network.proxy.ftp'] = URI(proxy).host this_profile['network.proxy.ftp_port'] = URI(proxy).port this_profile['network.proxy.http'] = URI(proxy).host this_profile['network.proxy.http_port'] = URI(proxy).port this_profile['network.proxy.ssl'] = URI(proxy).host this_profile['network.proxy.ssl_port'] = URI(proxy).port end end args = [] args.push('--devtools') if with_devtools = Selenium::WebDriver::Firefox::Options.new(args: args, accept_insecure_certs: true) .profile = this_profile # driver = Selenium::WebDriver.for(:firefox, capabilities: options) driver = Selenium::WebDriver.for(:firefox, options: ) browser_obj[:browser] = Watir::Browser.new(driver) when :chrome this_profile = Selenium::WebDriver::Chrome::Profile.new this_profile['download.prompt_for_download'] = false this_profile['download.default_directory'] = '~/Downloads' switches = [] switches.push('--start-maximized') switches.push('--disable-notifications') if proxy switches.push("--host-resolver-rules='MAP * 0.0.0.0 , EXCLUDE #{tor_obj[:ip]}'") if tor_obj switches.push("--proxy-server=#{proxy}") end if with_devtools switches.push('--auto-open-devtools-for-tabs') switches.push('--disable-hang-monitor') end = Selenium::WebDriver::Chrome::Options.new( args: switches, accept_insecure_certs: true ) .profile = this_profile # driver = Selenium::WebDriver.for(:chrome, capabilities: options) driver = Selenium::WebDriver.for(:chrome, options: ) browser_obj[:browser] = Watir::Browser.new(driver) when :headless, :headless_firefox this_profile = Selenium::WebDriver::Firefox::Profile.new # Increase Web Assembly Verbosity this_profile['javascript.options.wasm_verbose'] = true # Downloads reside in ~/Downloads this_profile['browser.download.folderList'] = 1 this_profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/pdf' # disable Firefox's built-in PDF viewer this_profile['pdfjs.disabled'] = true # disable Adobe Acrobat PDF preview plugin this_profile['plugin.scan.plid.all'] = false this_profile['plugin.scan.Acrobat'] = '99.0' # ensure localhost proxy capabilities are enabled this_profile['network.proxy.no_proxies_on'] = '' # allow scripts to run a bit longer # this_profile['dom.max_chrome_script_run_time'] = 180 # this_profile['dom.max_script_run_time'] = 180 # disable browser cache this_profile['browser.cache.disk.enable'] = false this_profile['browser.cache.disk_cache_ssl.enable'] = false this_profile['browser.cache.memory.enable'] = false this_profile['browser.cache.offline.enable'] = false this_profile['devtools.cache.disabled'] = true this_profile['dom.caches.enabled'] = false # caps = Selenium::WebDriver::Remote::Capabilities.firefox # caps[:acceptInsecureCerts] = true if proxy this_profile['network.proxy.type'] = 1 this_profile['network.proxy.allow_hijacking_localhost'] = true if tor_obj this_profile['network.proxy.socks_version'] = 5 this_profile['network.proxy.socks'] = tor_obj[:ip] this_profile['network.proxy.socks_port'] = tor_obj[:port] else this_profile['network.proxy.ftp'] = URI(proxy).host this_profile['network.proxy.ftp_port'] = URI(proxy).port this_profile['network.proxy.http'] = URI(proxy).host this_profile['network.proxy.http_port'] = URI(proxy).port this_profile['network.proxy.ssl'] = URI(proxy).host this_profile['network.proxy.ssl_port'] = URI(proxy).port end end = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'], accept_insecure_certs: true) .profile = this_profile driver = Selenium::WebDriver.for(:firefox, options: ) browser_obj[:browser] = Watir::Browser.new(driver) when :headless_chrome this_profile = Selenium::WebDriver::Chrome::Profile.new this_profile['download.prompt_for_download'] = false this_profile['download.default_directory'] = '~/Downloads' switches = [] switches.push('--headless') switches.push('--start-maximized') switches.push('--disable-notifications') if proxy switches.push("--host-resolver-rules='MAP * 0.0.0.0 , EXCLUDE #{tor_obj[:ip]}'") if tor_obj switches.push("--proxy-server=#{proxy}") end = Selenium::WebDriver::Chrome::Options.new( args: switches, accept_insecure_certs: true ) .profile = this_profile driver = Selenium::WebDriver.for(:chrome, options: ) browser_obj[:browser] = Watir::Browser.new(driver) when :rest browser_obj[:browser] = RestClient if proxy if tor_obj TCPSocket.socks_server = tor_obj[:ip] TCPSocket.socks_port = tor_obj[:port] else browser_obj[:browser].proxy = proxy end end when :websocket if proxy if tor_obj TCPSocket.socks_server = tor_obj[:ip] TCPSocket.socks_port = tor_obj[:port] end proxy_opts = { origin: proxy } tls_opts = { verify_peer: false } browser_obj[:browser] = Faye::WebSocket::Client.new( '', [], { tls: tls_opts, proxy: proxy_opts } ) else browser_obj[:browser] = Faye::WebSocket::Client.new('') end else puts 'Error: browser_type only supports :firefox, :chrome, :headless, :rest, or :websocket' return nil end browser_obj rescue StandardError => e raise e end |
.type_as_human(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.type_as_human(
string: 'required - string to type as human', rand_sleep_float: 'optional - float timing in between keypress (defaults to 0.09)'
)
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 306 public_class_method def self.type_as_human(opts = {}) string = opts[:string].to_s rand_sleep_float = if opts[:rand_sleep_float] opts[:rand_sleep_float].to_f else 0.09 end string.each_char do |char| yield char sleep Random.rand(rand_sleep_float) end rescue StandardError => e raise e end |