Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated zoption to handle multiple data types #24

Merged
merged 1 commit into from Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,6 @@ def eval_type(value, type):
elif type == "str":
# anything can be a string
rval = (True, str(value))
elif type == "ip or ipmask":
t1 = eval_type(value, "ip")
if t1[0] == False:
t1 = eval_type(value, "ipmask")
return t1
return t1
elif type == "ipmask":
ip = value.split('.')
if len(ip) != 4:
Expand Down
27 changes: 17 additions & 10 deletions src/core/zoption.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from util import eval_type


class Zoption:
""" generic option class for managing and validating
zarp options.
"""
def __init__(self, value = None, type = None, required = False,
display = None, opts = None):

def __init__(self, value=None, type=None, required=False, display=None, opts=None):
self.value = value
self.type = type
if isinstance(type, basestring):
self.types = [type]
self.type = type
else:
self.types = type
self.type = None
self.required = required
self.display = display
self.opts = opts
self.opts = opts

def getStr(self):
""" Some objects don't have a __str__ method (regex),
Expand All @@ -30,9 +36,10 @@ def validate(self):
""" Validates the object's value to ensure it conforms
to whatever type the object dictates.
"""
rvals = eval_type(self.value, self.type)
if rvals[0]:
self.value = rvals[1]
return True
else:
return False
for t in self.types:
rvals = eval_type(self.value, t)
if rvals[0]:
self.value = rvals[1]
self.type = t
return True
return False
4 changes: 2 additions & 2 deletions src/modules/poison/arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self):
required=True,
display="Target to poison"),
"from_ip": Zoption(value=None,
type="ip or ipmask",
type=["ip", "ipmask"],
required=False,
display="Address or addresses to spoof from target"),
"respoof": Zoption(value=2,
Expand Down Expand Up @@ -254,4 +254,4 @@ def view(self):
""" ARP poisoner doesnt have a view, yet.
"""
Msg('No view for ARP poison. Enable a sniffer for detailed analysis.')
return
return