Class: Ronin::CLI::HTTPShell Private

Inherits:
Core::CLI::CommandShell
  • Object
show all
Includes:
Printing::HTTP
Defined in:
lib/ronin/cli/http_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 HTTP shell for the ronin http --shell command.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Printing::HTTP

#print_body, #print_headers, #print_highlighted_body, #print_last_newline, #print_plain_body, #syntax_lexer_for_content_type

Methods included from Printing::SyntaxHighlighting

#syntax_formatter, #syntax_lexer, #syntax_lexer_for, #syntax_theme

Constructor Details

#initialize(base_url, **kwargs) ⇒ HTTPShell

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 HTTP Shell.

Parameters:

  • base_url (Addressable::URI)

    The base URL to connect to.

  • kwargs (Hash{Symbol => Object})

    Additional arguments for Ronin::Support::Network::HTTP#connect_uri.

Since:

  • 2.0.0



52
53
54
55
56
57
# File 'lib/ronin/cli/http_shell.rb', line 52

def initialize(base_url, **kwargs)
  @base_url = base_url
  @http     = Support::Network::HTTP.connect_uri(@base_url,**kwargs)

  super()
end

Instance Attribute Details

#base_urlURI::HTTP (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 base URI.

Returns:

  • (URI::HTTP)

Since:

  • 2.0.0



36
37
38
# File 'lib/ronin/cli/http_shell.rb', line 36

def base_url
  @base_url
end

#httpRonin::Support::Network::HTTP (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 HTTP session.

Returns:

  • (Ronin::Support::Network::HTTP)

Since:

  • 2.0.0



41
42
43
# File 'lib/ronin/cli/http_shell.rb', line 41

def http
  @http
end

Instance Method Details

#cd(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 cd shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



76
77
78
# File 'lib/ronin/cli/http_shell.rb', line 76

def cd(path)
  @base_url.path = join(path)
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 cookie shell command.

Since:

  • 2.0.0



318
319
320
321
322
# File 'lib/ronin/cli/http_shell.rb', line 318

def cookie
  if @http.cookie
    puts @http.cookie
  end
end

#copy(path, dest) ⇒ 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 copy shell command.

Parameters:

  • path (String)
  • dest (String)

Since:

  • 2.0.0



158
159
160
# File 'lib/ronin/cli/http_shell.rb', line 158

def copy(path,dest)
  request(:copy,path, destination: dest)
end

#delete(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 delete shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



170
171
172
# File 'lib/ronin/cli/http_shell.rb', line 170

def delete(path)
  request(:delete,path)
end

#get(path, body = 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.

The get shell command.

Parameters:

  • path (String)
  • body (String, nil) (defaults to: nil)

Since:

  • 2.0.0



90
91
92
# File 'lib/ronin/cli/http_shell.rb', line 90

def get(path,body=nil)
  request(:get,path, body: body)
end

#head(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 head shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



102
103
104
# File 'lib/ronin/cli/http_shell.rb', line 102

def head(path)
  request(:head,path)
end

#headers(subcommand = nil, name = nil, value = 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.

The set_header shell command.

Parameters:

  • subcommand (String, nil) (defaults to: nil)

    The optional sub-command (ex: "set" or "unset").

  • name (String, nil) (defaults to: nil)

    The optional header name to set/unset.

  • value (String, nil) (defaults to: nil)

    The optional value of the header to set.

Since:

  • 2.0.0



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
# File 'lib/ronin/cli/http_shell.rb', line 286

def headers(subcommand=nil,name=nil,value=nil)
  case subcommand
  when 'set'
    if (name && value)
      @http.headers[name] = value
    else
      puts "headers: must specify both NAME and VALUE arguments"
    end
  when 'unset'
    if name
      @http.headers.delete(name)
    else
      puts "headers: must specify NAME argument"
    end
  when nil
    unless @http.headers.empty?
      @http.headers.each do |name,value|
        puts "#{colors.bold(name)}: #{value}"
      end
    else
      puts "No request headers set"
    end
  else
    puts "headers: unknown sub-command: #{subcommand.inspect}"
  end
end

#join(path) ⇒ String

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.

Joins the given path with the #base_url.

Parameters:

  • path (String)

    The path to join.

Returns:

  • (String)

    The resulting joined path.

Since:

  • 2.0.0



347
348
349
350
351
352
353
# File 'lib/ronin/cli/http_shell.rb', line 347

def join(path)
  if path.start_with?('/')
    path
  else
    File.expand_path(File.join(@base_url.path,path))
  end
end

#lock(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 lock shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



182
183
184
# File 'lib/ronin/cli/http_shell.rb', line 182

def lock(path)
  request(:lock,path)
end

#mkcol(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 mkcol shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



206
207
208
# File 'lib/ronin/cli/http_shell.rb', line 206

def mkcol(path)
  request(:mkcol,path)
end

#move(path, dest) ⇒ 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 move shell command.

Parameters:

  • path (String)
  • dest (String)

Since:

  • 2.0.0



220
221
222
# File 'lib/ronin/cli/http_shell.rb', line 220

def move(path,dest)
  request(:move,path, destination: dest)
end

#options(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 options shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



194
195
196
# File 'lib/ronin/cli/http_shell.rb', line 194

def options(path)
  request(:options,path)
end

#patch(path, body = 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.

The patch shell command.

Parameters:

  • path (String)
  • body (String) (defaults to: nil)

Since:

  • 2.0.0



116
117
118
# File 'lib/ronin/cli/http_shell.rb', line 116

def patch(path,body=nil)
  request(:patch,path, body: body)
end

#post(path, 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.

The post shell command.

Parameters:

  • path (String)
  • body (String, nil)

Since:

  • 2.0.0



130
131
132
# File 'lib/ronin/cli/http_shell.rb', line 130

def post(path,body)
  request(:post,path, body: body)
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.

Prints an HTTP response.

Parameters:

  • response (Net::HTTPResponse)

    The HTTP response object.

See Also:

  • HTTPMethods#print_response

Since:

  • 2.0.0



384
385
386
# File 'lib/ronin/cli/http_shell.rb', line 384

def print_response(response)
  super(response, show_headers: true)
end

#propfind(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 propfind shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



232
233
234
# File 'lib/ronin/cli/http_shell.rb', line 232

def propfind(path)
  request(:propfind,path)
end

#proppatch(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 proppatch shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



243
244
245
# File 'lib/ronin/cli/http_shell.rb', line 243

def proppatch(path)
  request(:proppatch,path)
end

#put(path, body = 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.

The patch shell command.

Parameters:

  • path (String)
  • body (String, nil) (defaults to: nil)

Since:

  • 2.0.0



144
145
146
# File 'lib/ronin/cli/http_shell.rb', line 144

def put(path,body=nil)
  request(:put,path, body: body)
end

#request(method, path, **kwargs) ⇒ 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.

Sends an HTTP request.

Parameters:

  • method (Symbol)

    The HTTP request method name.

  • path (String)

    The path for the request.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Ronin::Support::Network::HTTP#request.

Since:

  • 2.0.0



368
369
370
371
372
373
374
# File 'lib/ronin/cli/http_shell.rb', line 368

def request(method,path,**kwargs)
  path = join(path)

  @http.request(method,path,**kwargs) do |response|
    print_response(response)
  end
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 shell command.

Parameters:

  • params (Array<String>)

    The NAME=VALUE param pairs.

Since:

  • 2.0.0



334
335
336
# File 'lib/ronin/cli/http_shell.rb', line 334

def set_cookie(*params)
  @http.cookie = params.join(' ')
end

#shell_nameString

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 shell prompt name.

Returns:

  • (String)

    Returns the #base_url as a String.

Since:

  • 2.0.0



64
65
66
# File 'lib/ronin/cli/http_shell.rb', line 64

def shell_name
  "#{@base_url}"
end

#trace(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 trace shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



255
256
257
# File 'lib/ronin/cli/http_shell.rb', line 255

def trace(path)
  request(:trace,path)
end

#unlock(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 unlock shell command.

Parameters:

  • path (String)

Since:

  • 2.0.0



267
268
269
# File 'lib/ronin/cli/http_shell.rb', line 267

def unlock(path)
  request(:unlock,path)
end