Commit 4ef9e2f5 by fwkz

Introducing setg command

parent e3a9952d
......@@ -6,10 +6,14 @@ import time
from routersploit.utils import print_status, NonStringIterable
GLOBAL_OPTS = {}
class Option(object):
""" Exploit attribute that is set by the end user. """
def __init__(self, default, description="", validators=()):
self.label = None
if isinstance(validators, NonStringIterable):
self.validators = validators
else:
......@@ -20,7 +24,7 @@ class Option(object):
self.data = WeakKeyDictionary()
def __get__(self, instance, owner):
return self.data.get(instance, self.default)
return self.data.get(instance, GLOBAL_OPTS.get(self.label, self.default))
def __set__(self, instance, value):
self.data[instance] = self._apply_widgets(value)
......@@ -47,6 +51,7 @@ class ExploitOptionsAggregator(type):
for key, value in attrs.iteritems():
if isinstance(value, Option):
value.label = key
attrs['exploit_attributes'].update({key: value.description})
elif key == "__info__":
attrs["_{}{}".format(name, key)] = value
......
......@@ -5,6 +5,7 @@ import traceback
import atexit
from routersploit.exceptions import RoutersploitException
from routersploit.exploits import GLOBAL_OPTS
from routersploit import utils
if sys.platform == "darwin":
......@@ -301,6 +302,20 @@ class RoutersploitInterpreter(BaseInterpreter):
return self.current_module.options
@utils.module_required
def command_setg(self, *args, **kwargs):
key, _, value = args[0].partition(' ')
if key in self.current_module.options:
GLOBAL_OPTS[key] = value
utils.print_success({key: value})
else:
utils.print_error("You can't set option '{}'.\n"
"Available options: {}".format(key, self.current_module.options))
@utils.stop_after(2)
def complete_setg(self, text, *args, **kwargs):
return self.complete_set(text, *args, **kwargs)
@utils.module_required
def get_opts(self, *args):
""" Generator returning module's Option attributes (option_name, option_value, option_description)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment