lib/ronin/ui/shell.rb in ronin-support-0.4.0.rc1 vs lib/ronin/ui/shell.rb in ronin-support-0.4.0.rc2
- old
+ new
@@ -1,7 +1,7 @@
#
-# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
+# Copyright (c) 2006-2012 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This file is part of Ronin Support.
#
# Ronin Support is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
@@ -24,10 +24,72 @@
module Ronin
module UI
#
# Spawns a ReadLine powered interactive Shell.
#
+ # ## Simple Shell
+ #
+ # require 'ronin/ui/shell'
+ # require 'ronin/network/tcp'
+ #
+ # include Ronin::Network::TCP
+ #
+ # tcp_session('victim.com',1337) do |socket|
+ # UI::Shell.new(:name => 'bind_shell') do |shell,line|
+ # socket.puts "#{line}; echo 'EOC'"
+ #
+ # socket.each_line do |output|
+ # puts output
+ #
+ # break if output.chomp == 'EOC'
+ # end
+ # end
+ # end
+ #
+ # ## Shell with Commands
+ #
+ # require 'ronin/ui/shell'
+ # require 'ronin/network/http'
+ #
+ # class HTTPShell < Ronin::UI::Shell
+ #
+ # include Ronin::Network::HTTP
+ #
+ # def initialize(host)
+ # super(:name => host)
+ #
+ # @host = host
+ # end
+ #
+ # protected
+ #
+ # def get(path)
+ # print_response http_get(:host => @host, :path => path)
+ # end
+ #
+ # def post(path,*params)
+ # print_response http_post(
+ # :host => @host,
+ # :path => path,
+ # :post_data => Hash[params.map { |param| param.split('=') }]
+ # )
+ # end
+ #
+ # private
+ #
+ # def print_response(response)
+ # response.canonical_each do |name,value|
+ # puts "#{name}: #{value}"
+ # end
+ #
+ # puts
+ #
+ # puts response.body
+ # end
+ #
+ # end
+ #
# @api semipublic
#
class Shell
include Output::Helpers
@@ -68,19 +130,19 @@
# @api semipublic
#
# @since 0.3.0
#
def initialize(options={},&block)
- @name = options.fetch(:name,'')
+ @name = options[:name]
@prompt = options.fetch(:prompt,DEFAULT_PROMPT)
- @commands = Set[:help, :exit]
+ @commands = Set['help', 'exit']
self.class.ancestors.each do |subclass|
if subclass < Shell
subclass.protected_instance_methods(false).each do |name|
- @commands << name.to_sym
+ @commands << name.to_s
end
end
end
@@ -161,13 +223,11 @@
command = arguments.shift
# ignore empty lines
return false unless command
- command = command.to_sym
-
# no explicitly calling handler
- return false if command == :handler
+ return false if command == 'handler'
unless @commands.include?(command)
print_error "Invalid command: #{command}"
return false
end