Skip to content

Commit

Permalink
defanged mode
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/svn/framework3/trunk@4303 4d416f70-5f16-0410-b530-b9f4589650da
  • Loading branch information
Matt Miller committed Jan 30, 2007
1 parent 114050e commit 279c0e3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/msf/core/framework.rb
Expand Up @@ -132,7 +132,7 @@ def version
# maintains the database db and handles db events
#
attr_reader :db

protected

attr_writer :events # :nodoc:
Expand Down
7 changes: 7 additions & 0 deletions lib/msf/ui/console/command_dispatcher.rb
Expand Up @@ -43,6 +43,13 @@ def active_module=(mod)
driver.active_module = mod
end

#
# Checks to see if the driver is defanged.
#
def defanged?
driver.defanged?
end

#
# Logs an error message to the screen and the log file. The callstack is
# also printed.
Expand Down
1 change: 1 addition & 0 deletions lib/msf/ui/console/command_dispatcher/auxiliary.rb
Expand Up @@ -99,6 +99,7 @@ def cmd_exploit(*args)
# Executes an auxiliary module
#
def cmd_run(*args)
defanged?

opt_str = nil
action = mod.datastore['ACTION']
Expand Down
10 changes: 10 additions & 0 deletions lib/msf/ui/console/command_dispatcher/core.rb
Expand Up @@ -194,6 +194,8 @@ def cmd_info_tabs(str, words)
# Goes into IRB scripting mode
#
def cmd_irb(*args)
defanged?

print_status("Starting IRB shell...\n")

begin
Expand Down Expand Up @@ -254,6 +256,8 @@ def cmd_jobs_tabs(str, words)
# the framework root plugin directory is used.
#
def cmd_load(*args)
defanged?

if (args.length == 0)
print_line(
"Usage: load <path> [var=val var=val ...]\n\n" +
Expand Down Expand Up @@ -311,6 +315,8 @@ def cmd_load_tabs(str, words)
# storage medium, such as a flatfile.
#
def cmd_persist(*args)
defanged?

if (args.length == 0)
args.unshift("-h")
end
Expand Down Expand Up @@ -499,6 +505,8 @@ def cmd_route_tabs(str, words)
# restarts of the console.
#
def cmd_save(*args)
defanged?

# Save the console config
driver.save_config

Expand All @@ -521,6 +529,8 @@ def cmd_save(*args)
# Adds one or more search paths.
#
def cmd_loadpath(*args)
defanged?

if (args.length == 0)
print_error("No search paths were provided.")
return true
Expand Down
5 changes: 5 additions & 0 deletions lib/msf/ui/console/command_dispatcher/exploit.rb
Expand Up @@ -45,7 +45,10 @@ def name
# Checks to see if a target is vulnerable.
#
def cmd_check(*args)
defanged?

begin

mod.init_ui(
driver.input,
driver.output)
Expand Down Expand Up @@ -75,6 +78,8 @@ def cmd_check(*args)
# Launches an exploitation attempt.
#
def cmd_exploit(*args)
defanged?

opt_str = nil
payload = mod.datastore['PAYLOAD']
encoder = mod.datastore['ENCODER']
Expand Down
29 changes: 29 additions & 0 deletions lib/msf/ui/console/driver.rb
Expand Up @@ -95,6 +95,14 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {

# Whether or not command passthru should be allowed
self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true

# Disables "dangerous" functionality of the console
@defanged = opts['Defanged'] == true

# If we're defanged, then command passthru should be disabled
if @defanged
self.command_passthru = false
end
end

#
Expand Down Expand Up @@ -259,6 +267,17 @@ def on_variable_unset(glob, var)
#
attr_accessor :active_module

#
# If defanged is true, dangerous functionality, such as exploitation, irb,
# and command shell passthru is disabled. In this case, an exception is
# raised.
#
def defanged?
if @defanged
raise DefangedException
end
end

protected

attr_writer :framework # :nodoc:
Expand Down Expand Up @@ -330,6 +349,16 @@ def handle_loglevel(val)

end

#
# This exception is used to indicate that functionality is disabled due to
# defanged being true
#
class DefangedException < ::Exception
def to_s
"This functionality is currently disabled (defanged mode)"
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/rex/proto/http/client.rb
Expand Up @@ -121,7 +121,7 @@ def request_cgi(opts={})
pstr << '='
pstr << set_encode_uri(val)
end

req = ''
req += set_method(c_meth)
req += set_method_uri_spacer()
Expand Down
4 changes: 2 additions & 2 deletions lib/rex/services/local_relay.rb
Expand Up @@ -180,11 +180,11 @@ def start_tcp_relay(lport, opts = {})
if ((opts['PeerHost'] == nil or opts['PeerPort'] == nil) and (opts['Stream'] != true))
raise ArgumentError, "Missing peer host or peer port.", caller
end

listener = Rex::Socket.create_tcp_server(
'LocalHost' => opts['LocalHost'],
'LocalPort' => lport)

opts['LocalPort'] = lport
opts['__RelayType'] = 'tcp'

Expand Down
3 changes: 3 additions & 0 deletions msfconsole
Expand Up @@ -24,6 +24,9 @@ class OptsConsole
opts.separator ""
opts.separator "Specific options:"

opts.on("-d", "-d", "Execute the console as defanged") do
options['Defanged'] = true
end

opts.on("-r", "-r <filename>", "Execute the specified resource file") do |r|
options['Resource'] = r
Expand Down

0 comments on commit 279c0e3

Please sign in to comment.