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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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