Class: Ronin::Web::CLI::BrowserShell Private

Inherits:
Core::CLI::CommandShell
  • Object
show all
Defined in:
lib/ronin/web/cli/browser_shell.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.

The interactive browser shell used by the ronin-web browser --shell command.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser, **kwargs) ⇒ BrowserShell

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 browser shell.

Parameters:

  • browser (Ronin::Web::Browser::Agent)

    The browser instance.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for the shell.

Since:

  • 1.0.0



51
52
53
54
55
# File 'lib/ronin/web/cli/browser_shell.rb', line 51

def initialize(browser,**kwargs)
  super(**kwargs)

  @browser = browser
end

Instance Attribute Details

#browserRonin::Web::Browser::Agent (readonly)

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.

The browser instance.

Returns:

  • (Ronin::Web::Browser::Agent)

Since:

  • 1.0.0



40
41
42
# File 'lib/ronin/web/cli/browser_shell.rb', line 40

def browser
  @browser
end

Instance Method Details

#at_css(css_path) ⇒ 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.

The at_css command.

Parameters:

  • css_path (String)

    The CSS path expression.

Since:

  • 1.0.0



161
162
163
# File 'lib/ronin/web/cli/browser_shell.rb', line 161

def at_css(css_path)
  puts @browser.at_css(css_path)
end

#at_xpath(xpath) ⇒ 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.

The at_xpath command.

Parameters:

  • xpath (String)

    The XPath expression.

Since:

  • 1.0.0



135
136
137
# File 'lib/ronin/web/cli/browser_shell.rb', line 135

def at_xpath(xpath)
  puts @browser.at_xpath(xpath)
end

#backObject

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.

The back command.

Since:

  • 1.0.0



75
76
77
# File 'lib/ronin/web/cli/browser_shell.rb', line 75

def back
  @browser.back
end

#basic_auth(user, password) ⇒ 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.

The basic_auth command.

Parameters:

  • user (String)

    The user name.

  • password (String)

    The password.

Since:

  • 1.0.0



347
348
349
# File 'lib/ronin/web/cli/browser_shell.rb', line 347

def basic_auth(user,password)
  @browser.network.authorize(user: user, password: password, &:continue)
end

#bodyObject

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.

The body command.

Since:

  • 1.0.0



259
260
261
# File 'lib/ronin/web/cli/browser_shell.rb', line 259

def body
  puts @browser.body
end

#bypass_cspObject

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.

The bypass_csp command.

Since:

  • 1.0.0



241
242
243
# File 'lib/ronin/web/cli/browser_shell.rb', line 241

def bypass_csp
  @browser.bypass_csp = true
end

#clear_cacheObject

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.

The clear_cache command.

Since:

  • 1.0.0



331
332
333
# File 'lib/ronin/web/cli/browser_shell.rb', line 331

def clear_cache
  @browser.clear(:cache)
end

#cookiesObject

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.

The cookies command.

Since:

  • 1.0.0



356
357
358
# File 'lib/ronin/web/cli/browser_shell.rb', line 356

def cookies
  print_cookies(@browser.cookies)
end

#css(css_path) ⇒ 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.

The css path command.

Parameters:

  • css_path (String)

    The CSS path expression.

Since:

  • 1.0.0



148
149
150
# File 'lib/ronin/web/cli/browser_shell.rb', line 148

def css(css_path)
  puts @browser.css(css_path)
end

#eval_js(javascript) ⇒ 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.

The eval_js command.

Parameters:

  • javascript (String)

    The JavaScript source code to inject.

Since:

  • 1.0.0



174
175
176
# File 'lib/ronin/web/cli/browser_shell.rb', line 174

def eval_js(javascript)
  p @browser.eval_js(javascript)
end

#forewardObject

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.

The foreward command.

Since:

  • 1.0.0



84
85
86
# File 'lib/ronin/web/cli/browser_shell.rb', line 84

def foreward
  @browser.foreward
end

#goto(url) ⇒ 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.

The goto command.

Parameters:

  • url (String)

    The URL to visit.

Since:

  • 1.0.0



66
67
68
# File 'lib/ronin/web/cli/browser_shell.rb', line 66

def goto(url)
  @browser.goto(url)
end

#inject_js(javascript) ⇒ 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.

The inject_js command.

Parameters:

  • javascript (String)

    The JavaScript source code to inject.

Since:

  • 1.0.0



187
188
189
# File 'lib/ronin/web/cli/browser_shell.rb', line 187

def inject_js(javascript)
  @browser.evaluate_on_new_document(javascript)
end

#jsObject

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.

The js command.

Since:

  • 1.0.0



214
215
216
# File 'lib/ronin/web/cli/browser_shell.rb', line 214

def js
  JSShell.start(@browser)
end

#load_cookies(path) ⇒ 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.

The load_cookies command.

Parameters:

  • path (String)

    The path to the cookies file.

Since:

  • 1.0.0



397
398
399
400
401
402
403
404
# File 'lib/ronin/web/cli/browser_shell.rb', line 397

def load_cookies(path)
  unless File.file?(path)
    print_error "no such file or directory: #{path}"
    return false
  end

  @browser.load_cookies(path)
end

#load_css(url_or_css) ⇒ 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.

The load_css command.

Parameters:

  • url_or_css (String)

    The URL or CSS code to load.

Since:

  • 1.0.0



227
228
229
230
231
232
233
234
# File 'lib/ronin/web/cli/browser_shell.rb', line 227

def load_css(url_or_css)
  if url_or_css.start_with('http://') ||
     url_or_css.start_with('https://')
    @browser.load_css(url: url_or_css)
  else
    @browser.load_css(content: url_or_css)
  end
end

#load_js(url_or_js) ⇒ 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.

The load_js command.

Parameters:

  • url_or_js (String)

    The URL or JavaScript code to load.

Since:

  • 1.0.0



200
201
202
203
204
205
206
207
# File 'lib/ronin/web/cli/browser_shell.rb', line 200

def load_js(url_or_js)
  if url_or_js.start_with('http://') ||
     url_or_js.start_with('https://')
    @browser.load_js(url: url_or_js)
  else
    @browser.load_js(content: url_or_js)
  end
end

#mhtml(path) ⇒ 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.

The mhtml command.

Since:

  • 1.0.0



295
296
297
# File 'lib/ronin/web/cli/browser_shell.rb', line 295

def mhtml(path)
  @browser.mhtml(path: path)
end

#pdf(path) ⇒ 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.

The pdf command.

Parameters:

  • path (String)

    The output path.

Since:

  • 1.0.0



285
286
287
# File 'lib/ronin/web/cli/browser_shell.rb', line 285

def pdf(path)
  @browser.pdf(path: path)
end

#pos(x, y) ⇒ 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.

The pos command.

Parameters:

  • x (String)

    The X coordinate.

  • y (String)

    The Y coordinate.

Since:

  • 1.0.0



109
110
111
# File 'lib/ronin/web/cli/browser_shell.rb', line 109

def pos(x,y)
  @browser.position = {left: x.to_i, top: y.to_i}
end

#refreshObject

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.

The refresh command.

Since:

  • 1.0.0



93
94
95
# File 'lib/ronin/web/cli/browser_shell.rb', line 93

def refresh
  @browser.refresh
end

#requestsObject

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.

The requests command.

Since:

  • 1.0.0



313
314
315
# File 'lib/ronin/web/cli/browser_shell.rb', line 313

def requests
  puts @browser.network.traffic
end

#resetObject

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.

The reset command.

Since:

  • 1.0.0



304
305
306
# File 'lib/ronin/web/cli/browser_shell.rb', line 304

def reset
  @browser.reset
end

#save_cookies(path) ⇒ 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.

The save_cookies command.

Parameters:

  • path (String)

    The path to the cookies file.

Since:

  • 1.0.0



415
416
417
# File 'lib/ronin/web/cli/browser_shell.rb', line 415

def save_cookies(path)
  @browser.save_cookies(path)
end

#screenshot(path) ⇒ 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.

The screenshot command.

Parameters:

  • path (String)

    The output path.

Since:

  • 1.0.0



272
273
274
# File 'lib/ronin/web/cli/browser_shell.rb', line 272

def screenshot(path)
  @browser.screenshot(path: path)
end

#session_cookiesObject

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.

The session_cookies command.

Since:

  • 1.0.0



365
366
367
# File 'lib/ronin/web/cli/browser_shell.rb', line 365

def session_cookies
  print_cookies(@browser.each_session_cookie)
end

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.

The set_cookie command.

Parameters:

  • args (Array<String>)

Since:

  • 1.0.0



377
378
379
380
381
382
383
384
385
386
# File 'lib/ronin/web/cli/browser_shell.rb', line 377

def set_cookie(*args)
  if args.empty?
    print_error "must specify at least a NAME=VALUE"
    return false
  end

  cookie = Web::Browser::Cookie.parse(args.join(' '))

  @browser.cookies.set(cookie)
end

#urlObject

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.

The url command.

Since:

  • 1.0.0



250
251
252
# File 'lib/ronin/web/cli/browser_shell.rb', line 250

def url
  puts @browser.current_url
end

#waitObject

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.

The wait command.

Since:

  • 1.0.0



322
323
324
# File 'lib/ronin/web/cli/browser_shell.rb', line 322

def wait
  @browser.wait_for_idle
end

#xpath(xpath) ⇒ 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.

The xpath command.

Parameters:

  • xpath (String)

    The XPath expression.

Since:

  • 1.0.0



122
123
124
# File 'lib/ronin/web/cli/browser_shell.rb', line 122

def xpath(xpath)
  puts @browser.xpath(xpath)
end