Class: Ronin::Web::CLI::Commands::Browser Private
- Inherits:
-
Ronin::Web::CLI::Command
- Object
- Core::CLI::Command
- Ronin::Web::CLI::Command
- Ronin::Web::CLI::Commands::Browser
- Includes:
- CommandKit::Colors, BrowserOptions
- Defined in:
- lib/ronin/web/cli/commands/browser.rb
Overview
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.
Screenshots one or more URLs.
Usage
ronin-web browser [options] [URL]
Options
-B, --browser NAME|PATH The browser name or path to execute
-W, --width WIDTH Sets the width of the browser viewport (Default: 1024)
-H, --height HEIGHT Sets the height of the browser viewport (Default: 768)
--headless Run the browser in headless mode
--visible Open a visible browser
-x, --x INT Sets the position of the browser X coordinate
-y, --y INT Sets the position of the browser Y coordinate
--inject-js JS Injects JavaScript into every page
--inject-js-file FILE Injects a JavaScript file into every page
--bypass-csp Enables bypassing CSP
--print-urls Print all requested URLs
--print-status Print the status of all requested URLs
--print-requests Print all requests sent by the browser
--print-responses Print responses to all requests
--print-traffic Print requests and responses
--print-headers Print headers of requests/responses
--print-body Print request/response bodies
--shell Starts an interactive shell
--js-shell Starts an interactive JavaScript shell
-h, --help Print help information
Arguments
[URL] The initial URL to visit
Instance Method Summary collapse
-
#browser_kwargs ⇒ Hash{Symbol => Object}
private
Additional keyword arguments for
Ronin::Web::Browser.new
. -
#close_browser ⇒ Object
private
Close the browser.
-
#configure_browser ⇒ Object
private
Configures the browser and registers callbacks.
-
#initialize(**kwargs) ⇒ Browser
constructor
private
Initializes the
ronin-web browser
command. -
#open_browser(url = nil) ⇒ Object
private
Open the browser window.
-
#print_body(sigil, body) ⇒ Object
private
Prints the request or response body.
-
#print_cookies(response) ⇒ Object
private
Prints the
Set-Cookie
header for each HTTP response. -
#print_headers(sigil, headers) ⇒ Object
private
Prints headers.
-
#print_request(request) ⇒ Object
private
Prints a request from the browser.
-
#print_response(response) ⇒ Object
private
Prints a response.
-
#print_url_status(response) ⇒ Object
private
Prints the status and URL of a response.
-
#run(url = nil) ⇒ Object
private
Runs the
ronin-web browser
command. -
#start_shell ⇒ Object
private
Starts an interactive browser shell.
-
#wait_until_closed ⇒ Object
private
Waits until the browser is done or if the user exits the command.
Methods included from BrowserOptions
Constructor Details
#initialize(**kwargs) ⇒ Browser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the ronin-web browser
command.
142 143 144 145 146 147 148 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 142 def initialize(**kwargs) super(**kwargs) @mode = if stdout.tty? then :visible else :headless end end |
Instance Method Details
#browser_kwargs ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Additional keyword arguments for Ronin::Web::Browser.new
.
255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 255 def browser_kwargs kwargs = super() case @mode when :headless then kwargs[:headless] = true when :visible then kwargs[:visible] = true end return kwargs end |
#close_browser ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Close the browser.
246 247 248 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 246 def close_browser browser.quit end |
#configure_browser ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Configures the browser and registers callbacks.
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 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 177 def configure_browser if [:x] || [:y] browser.position = { left: .fetch(:x,0), top: .fetch(:y,0) } end browser.bypass_csp = true if [:bypass_csp] if [:inject_js_file] browser.inject_js(File.read([:inject_js_file])) elsif [:inject_js] browser.inject_js([:inject_js]) end if [:print_status] browser.every_response(&method(:print_url_status)) elsif [:print_cookies] browser.every_response(&method(:print_cookies)) elsif [:print_urls] browser.every_url(&method(:puts)) elsif [:print_traffic] browser.every_request(&method(:print_request)) browser.every_response(&method(:print_response)) else browser.every_request(&method(:print_request)) if [:print_requests] browser.every_response(&method(:print_response)) if [:print_responses] end end |
#open_browser(url = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Open the browser window.
214 215 216 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 214 def open_browser(url=nil) browser.goto(url) if url end |
#print_body(sigil, body) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints the request or response body.
350 351 352 353 354 355 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 350 def print_body(sigil,body) puts sigil response.body.each_line do |line| puts "#{sigil} #{line}" end end |
#print_cookies(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints the Set-Cookie
header for each HTTP response.
363 364 365 366 367 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 363 def (response) if ( = respones.headers['set-cookie']) puts end end |
#print_headers(sigil, headers) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints headers.
334 335 336 337 338 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 334 def print_headers(sigil,headers) headers.each do |name,value| puts "#{sigil} #{colors.bright_white(name)}: #{value}" end end |
#print_request(request) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints a request from the browser.
289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 289 def print_request(request) sigil = colors.bold(colors.bright_white('>')) puts "#{sigil} #{colors.bold(colors.bright_cyan(request.method))} #{colors.cyan(request.url)}" if [:print_headers] print_headers(sigil,request.headers) end if [:print_body] && (body = request.body) print_body(sigil,body) end end |
#print_response(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints a response.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 309 def print_response(response) sigil = colors.bold(colors.bright_white('<')) print "#{sigil} " print_url_status(response) if [:print_headers] print_headers(sigil,response.headers) end if [:print_body] print_body(sigil,response.body) end end |
#print_url_status(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prints the status and URL of a response.
272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 272 def print_url_status(response) if response.status < 300 puts "#{colors.bright_green(response.status)} #{colors.green(response.url)}" elsif response.status < 400 puts "#{colors.bright_yellow(response.status)} #{colors.yellow(response.url)}" elsif response.status < 500 puts "#{colors.bright_red(response.status)} #{colors.red(response.url)}" else puts "#{colors.bold(colors.bright_red(response.status))} #{colors.bold(colors.red(response.url))}" end end |
#run(url = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin-web browser
command.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 156 def run(url=nil) unless (url || [:shell] || [:js_shell]) print_error "must specify a URL or --shell / --js-shell" exit(-1) end configure_browser open_browser(url) if [:shell] || [:js_shell] start_shell else wait_until_closed end close_browser end |
#start_shell ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Starts an interactive browser shell.
221 222 223 224 225 226 227 228 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 221 def start_shell # start the shell then immediately quit the browser once exited if [:js_shell] JSShell.start(browser) elsif [:shell] BrowserShell.start(browser) end end |
#wait_until_closed ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Waits until the browser is done or if the user exits the command.
233 234 235 236 237 238 239 240 241 |
# File 'lib/ronin/web/cli/commands/browser.rb', line 233 def wait_until_closed if @mode == :visible # wait for the browser window to be closed browser.wait_until_closed else # wait until there's no network traffic browser.network.wait_for_idle { browser.quit } end end |