Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testScn(host, port, scenario):
# run once in order to capture exchanged pdus
f = sk.socket(sk.AF_INET, sk.SOCK_STREAM)
f.connect((host, port))
(exc_info, msgs) = dwr_handler(scenario, f, local_hostname, local_realm)
if exc_info is not None:
print >> sys.stderr, '[ERROR] The scenario raised %r' % exc_info
sys.exit(1)
f.close()
return msgs
if exc_info is not None:
logging.warning('scenario %s raised: %s' % (fuzz.description, exc_info))
f.close()
elif args.mode == 'server':
srv = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, int(args.local_port)) for a in args.local_addresses]
ret = sctp.bindx(srv, addrs)
assert(ret == 0)
else:
srv.bind(('0.0.0.0', args.local_port))
srv.listen(64)
(f,_) = srv.accept()
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
if exc_info is not None:
logging.warning('vanilla scenario raised: %s' % (exc_info))
sys.exit(1)
f.close()
for (m, is_sent) in msgs:
Directory.tag(m)
fuzzs = analyze(msgs)
logging.info('generated %d scenarios of fuzzing' % len(fuzzs))
for fuzz in fuzzs:
(f,_) = srv.accept()
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm, fuzz)
if exc_info is not None:
logging.warning('scenario %s raised: %s' % (fuzz.description, exc_info))
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.WARNING)
if args.mode == 'client':
# run once in order to capture exchanged pdus
f = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, 0) for a in args.local_addresses]
ret = sctp.bindx(f, addrs)
assert(ret == 0)
else:
f.bind(('0.0.0.0', args.local_port))
f.connect((host, port))
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
if exc_info is not None:
logging.warning('vanilla scenario raised: %s' % (exc_info))
sys.exit(1)
f.close()
for (m, is_sent) in msgs:
Directory.tag(m)
fuzzs = analyze(msgs)
logging.info('generated %d scenarios of fuzzing' % len(fuzzs))
for fuzz in fuzzs:
f = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, 0) for a in args.local_addresses]
ret = sctp.bindx(f, addrs)
startT = time.time()
print("Scan started on %s..." % time.ctime())
for (i, fuzz) in analyze(msgs, vendor, args.min, args.max):
endT = time.time()
m, s = divmod(endT-startT, 60)
h, m = divmod(m, 60)
elapsedT = (h,m,s)
if i % 1000 == 0 and i> args.min:
percent = ((i-args.min)*100.0)/((args.max - args.min)*1.0)
print("%s - [INFO] %f%% : AVP %d to %d scanned (over %d) in %d:%d:%d..." % (time.ctime(), percent, i-1000, i, args.max, elapsedT[0], elapsedT[1], elapsedT[2]))
try:
f = sk.socket(sk.AF_INET, sk.SOCK_STREAM)
f.connect((host, port))
(exc_info, msgs) = dwr_handler(scenario, f, local_hostname, local_realm, mutator=fuzz)
f.close()
except sk.error as serr:
print >> sys.stderr, '%s - [ERROR] Connexion broken (%s) for AVP %d' % (time.ctime(), serr, i)
try:
testScn(host, port, scenario)
except sk.error as serr:
print >> sys.stderr, '%s - [ERROR] Connexion definitively broken (%s). I quit.' % (time.ctime(), serr)
sys.exit(-1)
continue
# Get the last message returned by fuzz_handler
# Which is the server's response to the fuzzed message
response = msgs[-1][0]
if response.code != msgs[0][0].code:
print('%s - [NOTI] Weird response (msg code %d) to AVP code %d.' % (time.ctime(), response.code, i))
(f,_) = srv.accept()
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
if exc_info is not None:
logging.warning('vanilla scenario raised: %s' % (exc_info))
sys.exit(1)
f.close()
for (m, is_sent) in msgs:
Directory.tag(m)
fuzzs = analyze(msgs)
logging.info('generated %d scenarios of fuzzing' % len(fuzzs))
for fuzz in fuzzs:
(f,_) = srv.accept()
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm, fuzz)
if exc_info is not None:
logging.warning('scenario %s raised: %s' % (fuzz.description, exc_info))
f.close()
Directory.tag(m)
fuzzs = analyze(msgs)
logging.info('generated %d scenarios of fuzzing' % len(fuzzs))
for fuzz in fuzzs:
f = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, 0) for a in args.local_addresses]
ret = sctp.bindx(f, addrs)
assert(ret == 0)
else:
f.bind(('0.0.0.0', args.local_port))
f.connect((host, port))
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm, fuzz)
if exc_info is not None:
logging.warning('scenario %s raised: %s' % (fuzz.description, exc_info))
f.close()
elif args.mode == 'server':
srv = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, int(args.local_port)) for a in args.local_addresses]
ret = sctp.bindx(srv, addrs)
assert(ret == 0)
else:
srv.bind(('0.0.0.0', args.local_port))
srv.listen(64)
(f,_) = srv.accept()
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
# load scenario
scenario = load_scenario(args.scenario, args.local_hostname, args.local_realm)
if args.mode in ('client', 'clientloop'):
while True:
f = sk.socket(family, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, int(args.local_port)) for a in args.local_addresses]
ret = sctp.bindx(f, addrs, family)
assert(ret == 0)
else:
f.bind((ADDR_ANY, args.local_port))
f.connect((target, port))
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
if exc_info is not None:
print('raised: %s' % (exc_info))
f.close()
if args.mode == 'client':
break
elif args.mode == 'server':
srv = sk.socket(family, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, int(args.local_port)) for a in args.local_addresses]
ret = sctp.bindx(srv, addrs, family)
assert(ret == 0)
else:
srv.bind((ADDR_ANY, args.local_port))
srv.listen(64)
if args.mode == 'client':
break
elif args.mode == 'server':
srv = sk.socket(family, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
if args.local_addresses:
addrs = [(a, int(args.local_port)) for a in args.local_addresses]
ret = sctp.bindx(srv, addrs, family)
assert(ret == 0)
else:
srv.bind((ADDR_ANY, args.local_port))
srv.listen(64)
while True:
(f,_) = srv.accept()
(exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
if exc_info is not None:
print('raised: %s' % (exc_info))
f.close()