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)’ ).
-
.close_tab(opts = {}) ⇒ Object
- Supported Method Parameters
-
tab = PWN::Plugins::TransparentBrowser.close_tab( browser_obj: ‘required - browser_obj returned from #open method)’, keyword: ‘required - keyword in title or url used to close tabs’ ).
-
.console(opts = {}) ⇒ Object
- Supported Method Parameters
-
console_resp = PWN::Plugins::TransparentBrowser.console( browser_obj: browser_obj1, js: ‘required - JavaScript expression to evaluate’ ).
-
.debugger(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.debugger( browser_obj: ‘required - browser_obj returned from #open method)’, action: ‘optional - action to take :pause|:resume (Defaults to :pause)’, url: ‘optional - URL to navigate to after pausing debugger (Defaults to nil)’ ).
-
.dom(opts = {}) ⇒ Object
- Supported Method Parameters
-
current_dom = PWN::Plugins::TransparentBrowser.dom( browser_obj: ‘required - browser_obj returned from #open method)’ ).
-
.dump_links(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.dump_links( browser_obj: browser_obj1 ).
-
.find_elements_by_text(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.find_elements_by_text( browser_obj: browser_obj1, text: ‘required - text to search for in the DOM’ ).
-
.help ⇒ Object
Display Usage for this Module.
-
.jmp_devtools_panel(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.jmp_devtools_panel( browser_obj: ‘required - browser_obj returned from #open method)’, panel: ‘optional - panel to switch to :elements|:inspector|:console|:debugger|:sources|:network ).
-
.jmp_tab(opts = {}) ⇒ Object
- Supported Method Parameters
-
tab = PWN::Plugins::TransparentBrowser.jmp_tab( browser_obj: ‘required - browser_obj returned from #open method)’, keyword: ‘required - keyword in title or url used to switch tabs’, explicit: ‘optional - boolean to indicate if the keyword is an exact match (Defaults to false)’ ).
-
.list_tabs(opts = {}) ⇒ Object
- Supported Method Parameters
-
tabs = PWN::Plugins::TransparentBrowser.list_tabs( browser_obj: ‘required - browser_obj returned from #open method)’ ).
-
.new_tab(opts = {}) ⇒ Object
- Supported Method Parameters
-
tab = PWN::Plugins::TransparentBrowser.new_tab( browser_obj: ‘required - browser_obj returned from #open method)’, first_tab: ‘optional - boolean to indicate if this is the first tab (Defaults to false)’ ).
-
.open(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj1 = PWN::Plugins::TransparentBrowser.open( browser_type: ‘optional - :firefox|:chrome|:headless|:rest|:websocket (defaults to :chrome)’, proxy: ‘optional - scheme://proxy_host:port || tor (defaults to nil)’, devtools: ‘optional - boolean (defaults to true)’, ).
-
.step_into(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.step_into( browser_obj: ‘required - browser_obj returned from #open method)’, steps: ‘optional - number of steps taken (Defaults to 1)’ ).
-
.step_out(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.step_out( browser_obj: ‘required - browser_obj returned from #open method)’, steps: ‘optional - number of steps taken (Defaults to 1)’ ).
-
.step_over(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.step_over( browser_obj: ‘required - browser_obj returned from #open method)’, steps: ‘optional - number of steps taken (Defaults to 1)’ ).
-
.toggle_devtools(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.toggle_devtools( browser_obj: ‘required - browser_obj returned from #open method)’, first_tab: ‘optional - boolean to indicate if this is the first tab (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)’ ).
-
.update_about_config(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.update_about_config( browser_obj: browser_obj1, key: ‘required - key to update in about:config’, value: ‘required - value to set for key in about:config’ ).
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
961 962 963 964 965 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 961 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)'
)
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 941 public_class_method def self.close(opts = {}) browser_obj = opts[:browser_obj] return nil unless browser_obj.is_a?(Hash) browser = browser_obj[:browser] tor_obj = browser_obj[:tor_obj] PWN::Plugins::Tor.stop(tor_obj: browser_obj[:tor_obj]) if tor_obj # Close the browser unless browser.nil? (thus the &) browser&.close unless browser.to_s == 'RestClient' nil rescue StandardError => e raise e end |
.close_tab(opts = {}) ⇒ Object
- Supported Method Parameters
-
tab = PWN::Plugins::TransparentBrowser.close_tab(
browser_obj: 'required - browser_obj returned from #open method)', keyword: 'required - keyword in title or url used to close tabs'
)
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 612 public_class_method def self.close_tab(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) keyword = opts[:keyword] raise 'ERROR: keyword parameter is required' if keyword.nil? browser = browser_obj[:browser] # Switch to an inactive tab before closing the active tab if it's currently active tab_list = list_tabs(browser_obj: browser_obj) active_tab = tab_list.find { |tab| tab[:state] == :active } if active_tab[:url].include?(keyword) inactive_tabs = tab_list.reject { |tab| tab[:url] == browser.url } if inactive_tabs.any? tab_to_activate = inactive_tabs.last[:url] jmp_tab(browser_obj: browser_obj, keyword: tab_to_activate) end end all_tabs = browser.windows tabs_to_close = all_tabs.select { |tab| tab.title.include?(keyword) || tab.url.include?(keyword) } tabs_closed = tabs_to_close.map do |tab| { title: tab.title, url: tab.url, state: :closed } end tabs_to_close.each(&:close) tabs_closed rescue StandardError => e raise e end |
.console(opts = {}) ⇒ Object
- Supported Method Parameters
-
console_resp = PWN::Plugins::TransparentBrowser.console(
browser_obj: browser_obj1, js: 'required - JavaScript expression to evaluate'
)
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 463 public_class_method def self.console(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) js = opts[:js] ||= "alert('ACK from => #{self}')" browser = browser_obj[:browser] case js when 'clear', 'clear;', 'clear()', 'clear();' script = 'console.clear()' else script = "console.log(#{js})" end console_resp = nil begin Timeout.timeout(1) { console_resp = browser.execute_script(script) } rescue Timeout::Error, Timeout::ExitException console_resp rescue Selenium::WebDriver::Error::JavascriptError script = js retry end console_resp rescue StandardError => e raise e end |
.debugger(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.debugger(
browser_obj: 'required - browser_obj returned from #open method)', action: 'optional - action to take :pause|:resume (Defaults to :pause)', url: 'optional - URL to navigate to after pausing debugger (Defaults to nil)'
)
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 652 public_class_method def self.debugger(opts = {}) browser_obj = opts[:browser_obj] supported = %i[chrome headless_chrome] verify_devtools_browser(browser_obj: browser_obj, supported: supported) browser = browser_obj[:browser] action = opts[:action] ||= :pause url = opts[:url] devtools = browser_obj[:devtools] case action.to_s.downcase.to_sym when :pause devtools.send_cmd( 'EventBreakpoints.setInstrumentationBreakpoint', eventName: 'scriptFirstStatement' ) # devtools.send_cmd('Debugger.enable') # devtools.send_cmd( # 'Debugger.setInstrumentationBreakpoint', # instrumentation: 'beforeScriptExecution' # ) # devtools.send_cmd( # 'EventBreakpoints.setInstrumentationBreakpoint', # eventName: 'load' # ) # devtools.send_cmd( # 'Debugger.setPauseOnExceptions', # state: 'all' # ) begin Timeout.timeout(1) do browser.refresh if url.nil? browser.goto(url) unless url.nil? end rescue Timeout::Error url end when :resume devtools.send_cmd( 'EventBreakpoints.removeInstrumentationBreakpoint', eventName: 'scriptFirstStatement' ) devtools.send_cmd('Debugger.resume') else raise 'ERROR: action parameter must be :pause or :resume' end rescue StandardError => e raise e end |
.dom(opts = {}) ⇒ Object
- Supported Method Parameters
-
current_dom = PWN::Plugins::TransparentBrowser.dom(
browser_obj: 'required - browser_obj returned from #open method)'
)
710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 710 public_class_method def self.dom(opts = {}) browser_obj = opts[:browser_obj] supported = %i[chrome headless_chrome] verify_devtools_browser(browser_obj: browser_obj, supported: supported) devtools = browser_obj[:devtools] computed_styles = %i[display color font-size font-family] devtools.send_cmd( 'DOMSnapshot.captureSnapshot', computedStyles: computed_styles ).transform_keys(&:to_sym) rescue StandardError => e raise e end |
.dump_links(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.dump_links(
browser_obj: browser_obj1
)
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 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 374 public_class_method def self.dump_links(opts = {}) browser_obj = opts[:browser_obj] links = browser_obj[:browser].links dump_links_arr = [] links.each do |link| link_hash = {} link_hash[:text] = link.text link_hash[:href] = link.href link_hash[:id] = link.id link_hash[:name] = link.name link_hash[:class_name] = link.class_name link_hash[:html] = link.html link_hash[:target] = link.target dump_links_arr.push(link_hash) yield link if block_given? end dump_links_arr rescue StandardError => e raise e end |
.find_elements_by_text(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj = PWN::Plugins::TransparentBrowser.find_elements_by_text(
browser_obj: browser_obj1, text: 'required - text to search for in the DOM'
)
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 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 406 public_class_method def self.find_elements_by_text(opts = {}) browser_obj = opts[:browser_obj] text = opts[:text].to_s elements = browser_obj[:browser].elements elements_found_arr = [] elements.each do |element| begin if element.text == text || element.value == text element_hash = {} element_hash[:tag_name] = element.tag_name element_hash[:html] = element.html elements_found_arr.push(element_hash) yield element if block_given? end rescue NoMethodError next end end elements_found_arr rescue StandardError => e puts e.backtrace raise e end |
.help ⇒ Object
Display Usage for this Module
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 969 public_class_method def self.help puts "USAGE: browser_obj1 = #{self}.open( browser_type: 'optional - :firefox|:chrome|:headless|:rest|:websocket (defaults to :chrome)', proxy: 'optional scheme://proxy_host:port || tor (defaults to nil)', devtools: 'optional - boolean (defaults to true)' ) browser = browser_obj1[:browser] puts browser.public_methods ******************************************************** * DevTools Interaction * All DevTools Commands can be found here: * https://chromedevtools.github.io/devtools-protocol/ * Examples devtools = browser.driver.devtools puts devtools.public_methods puts devtools.instance_variables puts devtools.instance_variable_get('@session_id') websocket = devtools.instance_variable_get('@ws') puts websocket.public_methods puts websocket.instance_variables puts websocket.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 = [] browser.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}.dump_links( browser_obj: 'required - browser_obj returned from #open method)' ) browser_obj1 = #{self}.find_elements_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) } console_resp = #{self}.console( browser_obj: 'required - browser_obj returned from #open method)', js: 'required - JavaScript expression to evaluate' ) #{self}.update_about_config( browser_obj: 'required - browser_obj returned from #open method)', key: 'required - key to update in about:config', value: 'required - value to set for key in about:config' ) tabs = #{self}.list_tabs( browser_obj: 'required - browser_obj returned from #open method)' ) tab = #{self}.jmp_tab( browser_obj: 'required - browser_obj returned from #open method)', keyword: 'required - keyword in title or url used to switch tabs' ) tab = #{self}.new_tab( browser_obj: 'required - browser_obj returned from #open method)', first_tab: 'optional - boolean to indicate if this is the first tab (Defaults to false)' ) tab = #{self}.close_tab( browser_obj: 'required - browser_obj returned from #open method)', keyword: 'required - keyword in title or url used to close tabs' ) #{self}.debugger( browser_obj: 'required - browser_obj returned from #open method)', action: 'optional - action to take :pause|:resume (Defaults to :pause)', url: 'optional - URL to navigate to after pausing debugger (Defaults to nil)' ) current_dom = #{self}.dom( browser_obj: 'required - browser_obj returned from #open method)' ) #{self}.step_into( browser_obj: 'required - browser_obj returned from #open method)', steps: 'optional - number of steps taken (Defaults to 1)' ) #{self}.step_out( browser_obj: 'required - browser_obj returned from #open method)', steps: 'optional - number of steps taken (Defaults to 1)' ) #{self}.step_over( browser_obj: 'required - browser_obj returned from #open method)', steps: 'optional - number of steps taken (Defaults to 1)' ) #{self}.toggle_devtools( browser_obj: 'required - browser_obj returned from #open method)' ) #{self}.jmp_devtools_panel( browser_obj: 'required - browser_obj returned from #open method)', panel: 'optional - panel to switch to :elements|:inspector|:console|:debugger|:sources|:network' ) browser_obj1 = #{self}.close( browser_obj: 'required - browser_obj returned from #open method)' ) #{self}.authors " end |
.jmp_devtools_panel(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.jmp_devtools_panel(
browser_obj: 'required - browser_obj returned from #open method)', panel: 'optional - panel to switch to :elements|:inspector|:console|:debugger|:sources|:network
)
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 886 public_class_method def self.jmp_devtools_panel(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) panel = opts[:panel] ||= :elements browser = browser_obj[:browser] browser_type = browser_obj[:type] firefox_types = %i[firefox headless_firefox] chrome_types = %i[chrome headless_chrome] # TODO: Find replacement for hotkey - there must be a better way. hotkey = [] case PWN::Plugins::DetectOS.type when :linux, :openbsd, :windows hotkey = %i[control shift] when :macos hotkey = %i[command option] end case panel when :elements, :inspector hotkey.push('i') if chrome_types.include?(browser_type) hotkey.push('c') if firefox_types.include?(browser_type) when :console hotkey.push('j') if chrome_types.include?(browser_type) hotkey.push('k') if firefox_types.include?(browser_type) when :debugger, :sources hotkey.push('s') if chrome_types.include?(browser_type) if firefox_types.include?(browser_type) # If we're in the console, we need to switch to the inspector first jmp_devtools_panel(browser_obj: browser_obj, panel: :inspector) sleep 1 hotkey.push('z') if firefox_types.include?(browser_type) end when :network hotkey.push('e') if firefox_types.include?(browser_type) else raise 'ERROR: panel parameter must be :elements|:inspector|:console|:debugger|:sources|:network' end # Have to call twice for Chrome, otherwise devtools stays closed browser_obj[:browser].send_keys(:escape) # browser.body.click! browser.send_keys(hotkey) browser.send_keys(hotkey) if chrome_types.include?(browser_type) browser.send_keys(:escape) rescue StandardError => e raise e end |
.jmp_tab(opts = {}) ⇒ Object
- Supported Method Parameters
-
tab = PWN::Plugins::TransparentBrowser.jmp_tab(
browser_obj: 'required - browser_obj returned from #open method)', keyword: 'required - keyword in title or url used to switch tabs', explicit: 'optional - boolean to indicate if the keyword is an exact match (Defaults to false)'
)
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 552 public_class_method def self.jmp_tab(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) keyword = opts[:keyword] raise 'ERROR: keyword parameter is required' if keyword.nil? explicit = opts[:explicit] ||= false browser = browser_obj[:browser] all_tabs = browser.windows if explicit tab_sel = all_tabs.select { |tab| tab.use if tab.title == keyword || tab.url == keyword } else tab_sel = all_tabs.select { |tab| tab.use if tab.title.include?(keyword) || tab.url.include?(keyword) } end { title: tab_sel.last.title, url: tab_sel.last.url, state: :active } if tab_sel.any? rescue StandardError => e raise e end |
.list_tabs(opts = {}) ⇒ Object
- Supported Method Parameters
-
tabs = PWN::Plugins::TransparentBrowser.list_tabs(
browser_obj: 'required - browser_obj returned from #open method)'
)
531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 531 public_class_method def self.list_tabs(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) browser = browser_obj[:browser] browser.windows.map do |tab| state = :inactive state = :active if browser.title == tab.title && browser.url == tab.url { title: tab.title, url: tab.url, state: state } end rescue StandardError => e raise e end |
.new_tab(opts = {}) ⇒ Object
- Supported Method Parameters
-
tab = PWN::Plugins::TransparentBrowser.new_tab(
browser_obj: 'required - browser_obj returned from #open method)', first_tab: 'optional - boolean to indicate if this is the first tab (Defaults to false)'
)
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 580 public_class_method def self.new_tab(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) chrome_types = %i[chrome headless_chrome] first_tab = opts[:first_tab] ||= false browser = browser_obj[:browser] browser_type = browser_obj[:type] devtools = browser_obj[:devtools] browser.driver.switch_to.new_window(:tab) unless first_tab rand_tab = SecureRandom.hex(8) url = 'about:about' url = 'chrome://chrome-urls/' if chrome_types.include?(browser_type) browser.goto(url) # TODO: replace sleep with something more reliable like an event listener sleep 1 browser.execute_script("document.title = 'about:about-#{rand_tab}'") toggle_devtools(browser_obj: browser_obj, first_tab: first_tab) if devtools { title: browser.title, url: browser.url, state: :active } rescue StandardError => e raise e end |
.open(opts = {}) ⇒ Object
- Supported Method Parameters
-
browser_obj1 = PWN::Plugins::TransparentBrowser.open(
browser_type: 'optional - :firefox|:chrome|:headless|:rest|:websocket (defaults to :chrome)', proxy: 'optional - scheme://proxy_host:port || tor (defaults to nil)', devtools: 'optional - boolean (defaults to true)',
)
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 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 47 public_class_method def self.open(opts = {}) browser_type = opts[:browser_type] ||= :chrome proxy = opts[:proxy].to_s unless opts[:proxy].nil? browser_obj = {} browser_obj[:type] = browser_type 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 devtools_supported = %i[chrome headless_chrome firefox headless_firefox headless] devtools = opts[:devtools] ||= false devtools = true if devtools_supported.include?(browser_type) && devtools # Let's crank up the default timeout from 30 seconds to 15 min for slow sites Watir.default_timeout = 900 args = [] # args.push('--start-maximized') args.push('--disable-notifications') unless browser_type == :rest logger = Selenium::WebDriver.logger logger.level = :error end 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 if devtools # args.push('--start-debugger-server') # this_profile['devtools.debugger.remote-enabled'] = true # this_profile['devtools.debugger.remote-host'] = 'localhost' # this_profile['devtools.debugger.remote-port'] = 6000 # DevTools ToolBox Settings in Firefox about:config this_profile['devtools.f12.enabled'] = true this_profile['devtools.toolbox.host'] = 'right' this_profile['devtools.toolbox.selectedTool'] = 'jsdebugger' this_profile['devtools.toolbox.sidebar.width'] = 1700 this_profile['devtools.toolbox.splitconsoleHeight'] = 200 # DevTools Debugger Settings in Firefox about:config this_profile['devtools.chrome.enabled'] = true this_profile['devtools.debugger.start-panel-size'] = 200 this_profile['devtools.debugger.end-panel-size'] = 200 this_profile['devtools.debugger.auto-pretty-print'] = true this_profile['devtools.debugger.ui.editor-wrapping'] = true this_profile['devtools.debugger.features.javascript-tracing'] = true this_profile['devtools.debugger.xhr-breakpoints-visible'] = true this_profile['devtools.debugger.expressions-visible'] = true this_profile['devtools.debugger.dom-mutation-breakpoints-visible'] = true this_profile['devtools.debugger.features.async-live-stacks'] = true this_profile['devtools.debugger.features.autocomplete-expressions'] = true this_profile['devtools.debugger.features.code-folding'] = true this_profile['devtools.debugger.features.command-click'] = true this_profile['devtools.debugger.features.component-pane'] = true this_profile['devtools.debugger.map-scopes-enabled'] = true # Never optimize out variables in the debugger this_profile['javascript.options.baselinejit'] = false this_profile['javascript.options.ion'] = false end # 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 # Private browsing mode args.push('--private') = Selenium::WebDriver::Firefox::Options.new( args: args, accept_insecure_certs: true ) .web_socket_url = true .profile = this_profile 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' if proxy args.push("--host-resolver-rules='MAP * 0.0.0.0 , EXCLUDE #{tor_obj[:ip]}'") if tor_obj args.push("--proxy-server=#{proxy}") end if devtools args.push('--auto-open-devtools-for-tabs') args.push('--disable-hang-monitor') end # Incognito browsing mode args.push('--incognito') = Selenium::WebDriver::Chrome::Options.new( args: args, accept_insecure_certs: true ) # This is for bidi, once it's ready # options.web_socket_url = true .profile = this_profile 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 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.push('--headless') # Private browsing mode args.push('--private') = Selenium::WebDriver::Firefox::Options.new( args: args, accept_insecure_certs: true ) # This is for bidi, once it's ready # options.web_socket_url = 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' if proxy args.push("--host-resolver-rules='MAP * 0.0.0.0 , EXCLUDE #{tor_obj[:ip]}'") if tor_obj args.push("--proxy-server=#{proxy}") end args.push('--headless') # Incognito browsing mode args.push('--incognito') = Selenium::WebDriver::Chrome::Options.new( args: args, accept_insecure_certs: true ) # This is for bidi, once it's ready # options.web_socket_url = 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, :headless_chrome, :headless_firefox, :rest, :websocket' return nil end if devtools_supported.include?(browser_type) if devtools driver = browser_obj[:browser].driver browser_obj[:devtools] = driver.devtools browser_obj[:devtools].send_cmd('DOM.enable') browser_obj[:devtools].send_cmd('Log.enable') browser_obj[:devtools].send_cmd('Network.enable') browser_obj[:devtools].send_cmd('Page.enable') browser_obj[:devtools].send_cmd('Runtime.enable') browser_obj[:devtools].send_cmd('Security.enable') chrome_browser_types = %i[chrome headless_chrome] if chrome_browser_types.include?(browser_type) browser_obj[:devtools].send_cmd('Debugger.enable') browser_obj[:devtools].send_cmd('DOMStorage.enable') browser_obj[:devtools].send_cmd('DOMSnapshot.enable') end firefox_browser_types = %i[firefox headless_firefox] if firefox_browser_types.include?(browser_type) # browser_obj[:devtools].send_cmd( # 'EventBreakpoints.setInstrumentationBreakpoint', # eventName: 'script' # ) end # Future BiDi API that's more universally supported across browsers # browser_obj[:bidi] = driver.bidi jmp_devtools_panel(browser_obj: browser_obj, panel: :elements) end browser_obj[:browser].driver.manage.window.maximize new_tab(browser_obj: browser_obj, first_tab: true) end browser_obj rescue StandardError => e raise e end |
.step_into(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.step_into(
browser_obj: 'required - browser_obj returned from #open method)', steps: 'optional - number of steps taken (Defaults to 1)'
)
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 731 public_class_method def self.step_into(opts = {}) browser_obj = opts[:browser_obj] supported = %i[chrome headless_chrome] verify_devtools_browser(browser_obj: browser_obj, supported: supported) steps = opts[:steps].to_i steps = 1 if steps.zero? || steps.negative? diff_arr = [] devtools = browser_obj[:devtools] steps.times do |s| diff_hash = {} step = s + 1 diff_hash[:step] = step dom_before = dom(browser_obj: browser_obj) diff_hash[:dom_before_step] = dom_before devtools.send_cmd('Debugger.stepInto') dom_after = dom(browser_obj: browser_obj) diff_hash[:dom_after_step] = dom_after da = dom_before.to_a - dom_after.to_a diff_hash[:diff_dom] = da.to_h.transform_keys(&:to_sym) diff_arr.push(diff_hash) end diff_arr rescue StandardError => e raise e end |
.step_out(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.step_out(
browser_obj: 'required - browser_obj returned from #open method)', steps: 'optional - number of steps taken (Defaults to 1)'
)
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 771 public_class_method def self.step_out(opts = {}) browser_obj = opts[:browser_obj] supported = %i[chrome headless_chrome] verify_devtools_browser(browser_obj: browser_obj, supported: supported) steps = opts[:steps].to_i steps = 1 if steps.zero? || steps.negative? diff_arr = [] devtools = browser_obj[:devtools] steps.times do |s| diff_hash = {} step = s + 1 diff_hash[:step] = step dom_before = dom(browser_obj: browser_obj) diff_hash[:pre_step] = dom_before devtools.send_cmd('Debugger.stepOut') dom_after = dom(browser_obj: browser_obj, step_sum: step_sum) diff_hash[:post_step] = dom_after da = dom_before.to_a - dom_after.to_a diff_hash[:diff] = da.to_h.transform_keys(&:to_sym) diff_arr.push(diff_hash) end diff_arr rescue StandardError => e raise e end |
.step_over(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.step_over(
browser_obj: 'required - browser_obj returned from #open method)', steps: 'optional - number of steps taken (Defaults to 1)'
)
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 811 public_class_method def self.step_over(opts = {}) browser_obj = opts[:browser_obj] supported = %i[chrome headless_chrome] verify_devtools_browser(browser_obj: browser_obj, supported: supported) steps = opts[:steps].to_i steps = 1 if steps.zero? || steps.negative? diff_arr = [] devtools = browser_obj[:devtools] steps.times do |s| diff_hash = {} step = s + 1 diff_hash[:step] = step dom_before = dom(browser_obj: browser_obj) diff_hash[:dom_before_step] = dom_before devtools.send_cmd('Debugger.stepOver') dom_after = dom(browser_obj: browser_obj, step_sum: step_sum) diff_hash[:dom_after_step] = dom_after da = dom_before.to_a - dom_after.to_a diff_hash[:diff_dom] = da.to_h.transform_keys(&:to_sym) diff_arr.push(diff_hash) end diff_arr rescue StandardError => e raise e end |
.toggle_devtools(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.toggle_devtools(
browser_obj: 'required - browser_obj returned from #open method)', first_tab: 'optional - boolean to indicate if this is the first tab (Defaults to false)',
)
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 851 public_class_method def self.toggle_devtools(opts = {}) browser_obj = opts[:browser_obj] verify_devtools_browser(browser_obj: browser_obj) first_tab = opts[:first_tab] ||= false browser = browser_obj[:browser] browser_type = browser_obj[:type] chrome_types = %i[chrome headless_chrome] tab_id = browser.title.split('-').last.strip if chrome_types.include?(browser_type) devtools_tab_title = "DevTools-#{tab_id}" jmp_tab(browser_obj: browser_obj, keyword: 'DevTools', explicit: true) browser.execute_script("document.title = '#{devtools_tab_title}'") end # TODO: Find replacement for hotkey - there must be a better way. browser.send_keys(:f12) if first_tab # TODO: replace sleep with something more reliable like an event listener sleep 1 browser.send_keys(:escape) end tab_tied_to_devtools = "about:about-#{tab_id}" jmp_tab(browser_obj: browser_obj, keyword: tab_tied_to_devtools, explicit: true) 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)'
)
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 439 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 |
.update_about_config(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::TransparentBrowser.update_about_config(
browser_obj: browser_obj1, key: 'required - key to update in about:config', value: 'required - value to set for key in about:config'
)
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/pwn/plugins/transparent_browser.rb', line 499 public_class_method def self.update_about_config(opts = {}) browser_obj = opts[:browser_obj] supported = %i[firefox headless_firefox] verify_devtools_browser(browser_obj: browser_obj, supported: supported) key = opts[:key] raise 'ERROR: key parameter is required' if key.nil? value = opts[:value] raise 'ERROR: value parameter is required' if value.nil? browser = browser_obj[:browser] browser_type = browser_obj[:type] # chrome_types = %i[chrome headless_chrome] firefox_types = %i[firefox headless_firefox] browser.goto('about:config') # Confirmed working in Firefox js = %{Services.prefs.setStringPref("#{key}", "#{value}")} if firefox_types.include?(browser_type) console(browser_obj: browser_obj, js: js) browser.back rescue Timeout::Error, Timeout::ExitException console_resp rescue StandardError => e raise e end |