class Ronin::CLI::HTTPShell

The interactive HTTP shell for the ‘ronin http –shell` command.

Attributes

base_url[R]

The base URI.

@return [URI::HTTP]

http[R]

The HTTP session.

@return [Ronin::Support::Network::HTTP]

Public Class Methods

new(base_url, **kwargs) click to toggle source

Initializes the HTTP Shell.

@param [Addressable::URI] base_url

The base URL to connect to.

@param [Hash{Symbol => Object}] kwargs

Additional arguments for `Ronin::Support::Network::HTTP#connect_uri`.
Calls superclass method
# 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

Public Instance Methods

cd(path) click to toggle source

The ‘cd` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 76
def cd(path)
  @base_url.path = join(path)
end
copy(path,dest) click to toggle source

The ‘copy` shell command.

@param [String] path

@param [String] dest

# File lib/ronin/cli/http_shell.rb, line 158
def copy(path,dest)
  request(:copy,path, destination: dest)
end
delete(path) click to toggle source

The ‘delete` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 170
def delete(path)
  request(:delete,path)
end
get(path,body=nil) click to toggle source

The ‘get` shell command.

@param [String] path

@param [String, nil] body

# File lib/ronin/cli/http_shell.rb, line 90
def get(path,body=nil)
  request(:get,path, body: body)
end
head(path) click to toggle source

The ‘head` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 102
def head(path)
  request(:head,path)
end
headers(subcommand=nil,name=nil,value=nil) click to toggle source

The ‘set_header` shell command.

@param [String, nil] subcommand

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

@param [String, nil] name

The optional header name to set/unset.

@param [String, nil] value

The optional value of the header to set.
# 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) click to toggle source

Joins the given path with the {#base_url}.

@param [String] path

The path to join.

@return [String]

The resulting joined path.
# 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) click to toggle source

The ‘lock` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 182
def lock(path)
  request(:lock,path)
end
mkcol(path) click to toggle source

The ‘mkcol` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 206
def mkcol(path)
  request(:mkcol,path)
end
move(path,dest) click to toggle source

The ‘move` shell command.

@param [String] path

@param [String] dest

# File lib/ronin/cli/http_shell.rb, line 220
def move(path,dest)
  request(:move,path, destination: dest)
end
options(path) click to toggle source

The ‘options` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 194
def options(path)
  request(:options,path)
end
patch(path,body=nil) click to toggle source

The ‘patch` shell command.

@param [String] path

@param [String] body

# File lib/ronin/cli/http_shell.rb, line 116
def patch(path,body=nil)
  request(:patch,path, body: body)
end
post(path,body) click to toggle source

The ‘post` shell command.

@param [String] path

@param [String, nil] body

# File lib/ronin/cli/http_shell.rb, line 130
def post(path,body)
  request(:post,path, body: body)
end
print_response(response) click to toggle source

Prints an HTTP response.

@param [Net::HTTPResponse] response

The HTTP response object.

@see HTTPMethods#print_response

propfind(path) click to toggle source

The ‘propfind` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 232
def propfind(path)
  request(:propfind,path)
end
proppatch(path) click to toggle source

The ‘proppatch` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 243
def proppatch(path)
  request(:proppatch,path)
end
put(path,body=nil) click to toggle source

The ‘patch` shell command.

@param [String] path

@param [String, nil] body

# File lib/ronin/cli/http_shell.rb, line 144
def put(path,body=nil)
  request(:put,path, body: body)
end
request(method,path,**kwargs) click to toggle source

Sends an HTTP request.

@param [Symbol] method

The HTTP request method name.

@param [String] path

The path for the request.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for
`Ronin::Support::Network::HTTP#request`.
# 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
shell_name() click to toggle source

The shell prompt name.

@return [String]

Returns the {#base_url} as a String.
# File lib/ronin/cli/http_shell.rb, line 64
def shell_name
  "#{@base_url}"
end
trace(path) click to toggle source

The ‘trace` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 255
def trace(path)
  request(:trace,path)
end
unlock(path) click to toggle source

The ‘unlock` shell command.

@param [String] path

# File lib/ronin/cli/http_shell.rb, line 267
def unlock(path)
  request(:unlock,path)
end