mirror of
https://github.com/lanjelot/patator
synced 2024-11-10 01:13:31 +00:00
added checks on FILE and RANGE keywords
This commit is contained in:
parent
3b069a347b
commit
96eb9f9604
51
patator.py
51
patator.py
@ -865,6 +865,7 @@ from select import select
|
|||||||
from itertools import islice
|
from itertools import islice
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
from decimal import Decimal
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
@ -1042,12 +1043,14 @@ def padhex(d):
|
|||||||
class RangeIter:
|
class RangeIter:
|
||||||
|
|
||||||
def __init__(self, typ, rng, random=None):
|
def __init__(self, typ, rng, random=None):
|
||||||
|
if typ not in ['hex', 'int', 'float', 'letters', 'lower', 'lowercase', 'upper', 'uppercase']:
|
||||||
|
raise ValueError("Incorrect range type '%s'" % typ)
|
||||||
|
|
||||||
if typ in ('hex', 'int', 'float'):
|
if typ in ('hex', 'int', 'float'):
|
||||||
|
|
||||||
m = re.match(r'(-?.+?)-(-?.+)$', rng) # 5-50 or -5-50 or 5--50 or -5--50
|
m = re.match('(-?[^-]+)-(-?[^-]+)$', rng) # 5-50 or -5-50 or 5--50 or -5--50
|
||||||
if not m:
|
if not m:
|
||||||
raise NotImplementedError("Unsupported range '%s'" % rng)
|
raise ValueError("Unsupported range '%s'" % rng)
|
||||||
|
|
||||||
mn = m.group(1)
|
mn = m.group(1)
|
||||||
mx = m.group(2)
|
mx = m.group(2)
|
||||||
@ -1063,7 +1066,6 @@ class RangeIter:
|
|||||||
fmt = '%d'
|
fmt = '%d'
|
||||||
|
|
||||||
elif typ == 'float':
|
elif typ == 'float':
|
||||||
from decimal import Decimal
|
|
||||||
mn = Decimal(mn)
|
mn = Decimal(mn)
|
||||||
mx = Decimal(mx)
|
mx = Decimal(mx)
|
||||||
|
|
||||||
@ -1081,9 +1083,6 @@ class RangeIter:
|
|||||||
elif typ in ('upper', 'uppercase'):
|
elif typ in ('upper', 'uppercase'):
|
||||||
charset = [c for c in string.uppercase]
|
charset = [c for c in string.uppercase]
|
||||||
|
|
||||||
else:
|
|
||||||
raise NotImplementedError("Incorrect type '%s'" % typ)
|
|
||||||
|
|
||||||
def zrange(start, stop, step, fmt):
|
def zrange(start, stop, step, fmt):
|
||||||
x = start
|
x = start
|
||||||
while x != stop+step:
|
while x != stop+step:
|
||||||
@ -1500,7 +1499,7 @@ Please read the README inside for more examples and usage information.
|
|||||||
name, opts = action, None
|
name, opts = action, None
|
||||||
|
|
||||||
if name not in self.available_actions:
|
if name not in self.available_actions:
|
||||||
raise NotImplementedError('Unsupported action: %s' % name)
|
raise ValueError('Unsupported action: %s' % name)
|
||||||
|
|
||||||
if name not in ns_actions:
|
if name not in ns_actions:
|
||||||
ns_actions[name] = []
|
ns_actions[name] = []
|
||||||
@ -1632,6 +1631,10 @@ Please read the README inside for more examples and usage information.
|
|||||||
iterables = []
|
iterables = []
|
||||||
total_size = 1
|
total_size = 1
|
||||||
|
|
||||||
|
def abort(msg):
|
||||||
|
logger.warn(msg)
|
||||||
|
self.ns.quit_now = True
|
||||||
|
|
||||||
for _, (t, v, _) in self.iter_keys.items():
|
for _, (t, v, _) in self.iter_keys.items():
|
||||||
|
|
||||||
if t in ('FILE', 'COMBO'):
|
if t in ('FILE', 'COMBO'):
|
||||||
@ -1640,7 +1643,14 @@ Please read the README inside for more examples and usage information.
|
|||||||
|
|
||||||
for fname in v.split(','):
|
for fname in v.split(','):
|
||||||
fpath = os.path.expanduser(fname)
|
fpath = os.path.expanduser(fname)
|
||||||
size += sum(1 for _ in open(fpath))
|
|
||||||
|
if not os.path.isfile(fpath):
|
||||||
|
return abort("No such file '%s'" % fpath)
|
||||||
|
|
||||||
|
with open(fpath) as f:
|
||||||
|
for _ in f:
|
||||||
|
size += 1
|
||||||
|
|
||||||
files.append(FileIter(fpath))
|
files.append(FileIter(fpath))
|
||||||
|
|
||||||
iterable = chain(*files)
|
iterable = chain(*files)
|
||||||
@ -1661,11 +1671,12 @@ Please read the README inside for more examples and usage information.
|
|||||||
for r in v.split(','):
|
for r in v.split(','):
|
||||||
typ, opt = r.split(':', 1)
|
typ, opt = r.split(':', 1)
|
||||||
|
|
||||||
if typ not in ['hex', 'int', 'float', 'letters', 'lower', 'lowercase', 'upper', 'uppercase']:
|
try:
|
||||||
raise NotImplementedError("Incorrect range type '%s'" % typ)
|
it = RangeIter(typ, opt)
|
||||||
|
size += len(it)
|
||||||
|
except ValueError as e:
|
||||||
|
return abort("Invalid range '%s' of type '%s', %s" % (opt, typ, e))
|
||||||
|
|
||||||
it = RangeIter(typ, opt)
|
|
||||||
size += len(it)
|
|
||||||
ranges.append(it)
|
ranges.append(it)
|
||||||
|
|
||||||
iterable = chain(*ranges)
|
iterable = chain(*ranges)
|
||||||
@ -1683,7 +1694,7 @@ Please read the README inside for more examples and usage information.
|
|||||||
iterable, size = chain(it), int(size)
|
iterable, size = chain(it), int(size)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Incorrect keyword '%s'" % t)
|
return abort("Incorrect keyword '%s'" % t)
|
||||||
|
|
||||||
total_size *= size
|
total_size *= size
|
||||||
iterables.append(iterable)
|
iterables.append(iterable)
|
||||||
@ -1892,9 +1903,6 @@ Please read the README inside for more examples and usage information.
|
|||||||
except Empty:
|
except Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
if 'quit' in actions:
|
|
||||||
self.ns.quit_now = True
|
|
||||||
|
|
||||||
if actions == 'skip':
|
if actions == 'skip':
|
||||||
p.skip_count += 1
|
p.skip_count += 1
|
||||||
continue
|
continue
|
||||||
@ -1931,6 +1939,9 @@ Please read the README inside for more examples and usage information.
|
|||||||
|
|
||||||
p.done_count += 1
|
p.done_count += 1
|
||||||
|
|
||||||
|
if 'quit' in actions:
|
||||||
|
self.ns.quit_now = True
|
||||||
|
|
||||||
|
|
||||||
def monitor_interaction(self):
|
def monitor_interaction(self):
|
||||||
|
|
||||||
@ -2320,7 +2331,7 @@ class SSH_login(TCP_Cache):
|
|||||||
fp.auth_password(user, password, fallback=True)
|
fp.auth_password(user, password, fallback=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Incorrect auth_type '%s'" % auth_type)
|
raise ValueError("Incorrect auth_type '%s'" % auth_type)
|
||||||
|
|
||||||
logger.debug('No error')
|
logger.debug('No error')
|
||||||
code, mesg = '0', banner
|
code, mesg = '0', banner
|
||||||
@ -3294,7 +3305,7 @@ class Oracle_login:
|
|||||||
elif service_name:
|
elif service_name:
|
||||||
dsn = cx_Oracle.makedsn(host=host, port=port, service_name=service_name)
|
dsn = cx_Oracle.makedsn(host=host, port=port, service_name=service_name)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Options sid and service_name cannot be both empty")
|
raise ValueError("Options sid and service_name cannot be both empty")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with Timing() as timing:
|
with Timing() as timing:
|
||||||
@ -3494,7 +3505,7 @@ class HTTP_fuzz(TCP_Cache):
|
|||||||
elif auth_type == 'ntlm':
|
elif auth_type == 'ntlm':
|
||||||
fp.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM)
|
fp.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Incorrect auth_type '%s'" % auth_type)
|
raise ValueError("Incorrect auth_type '%s'" % auth_type)
|
||||||
|
|
||||||
if ssl_cert:
|
if ssl_cert:
|
||||||
fp.setopt(pycurl.SSLCERT, ssl_cert)
|
fp.setopt(pycurl.SSLCERT, ssl_cert)
|
||||||
@ -4159,7 +4170,7 @@ class SNMP_login:
|
|||||||
return self.Response('1', 'SNMPv3 requires passphrases to be at least 8 characters long')
|
return self.Response('1', 'SNMPv3 requires passphrases to be at least 8 characters long')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Incorrect SNMP version '%s'" % version)
|
raise ValueError("Incorrect SNMP version '%s'" % version)
|
||||||
|
|
||||||
with Timing() as timing:
|
with Timing() as timing:
|
||||||
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
|
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
|
||||||
|
Loading…
Reference in New Issue
Block a user