Update search.py to use config
This commit is contained in:
@@ -3,19 +3,36 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import binascii
|
import binascii
|
||||||
|
import ConfigParser
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pybloom import BloomFilter
|
from pybloom import BloomFilter
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
default_config_file='/nsrl/nsrl.conf'
|
||||||
|
config = ConfigParser.ConfigParser()
|
||||||
|
config.read(default_config_file)
|
||||||
|
#add commandline options
|
||||||
|
hash_type=config.get('config','hashfile_type')
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog='nsrl')
|
parser = argparse.ArgumentParser(prog='nsrl')
|
||||||
parser.add_argument("-v", "--verbose", help="Display verbose output message", action="store_true", required=False)
|
parser.add_argument("-v", "--verbose", help="Display verbose output message", action="store_true", required=False)
|
||||||
parser.add_argument("-m", "--mismatched", help="Echo only mismatched Hashvalues", action="store_true", required=False)
|
parser.add_argument("-0", "--no-hits", help="Suppress Output of matching hashes", action="store_true", required=False)
|
||||||
|
parser.add_argument("-1", "--no-misses", help="Suppress Output of mismatching hashes", action="store_true", required=False)
|
||||||
inputs = parser.add_mutually_exclusive_group(required=True)
|
inputs = parser.add_mutually_exclusive_group(required=True)
|
||||||
inputs.add_argument('hash', metavar='<MD5>', type=str, nargs='*', default=[], help='md5 hash to search for.')
|
inputs.add_argument('hash', metavar='<{}>'.format(hash_type), type=str, nargs='*', default=[], help='{} hash to search for.'.format(hash_type))
|
||||||
inputs.add_argument('-s','--stdin',help="Read hashes from stdin", action="store_true")
|
inputs.add_argument('-s','--stdin',help="Read hashes from stdin", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.verbose:
|
||||||
|
print("Version INFO: {}".format(config.get('config',"rds_version")))
|
||||||
|
print("Error Rate: {}".format(config.get('config',"error_rate")))
|
||||||
|
print("Build Date: {}".format(config.get('config',"build_date")))
|
||||||
|
print("Filename: {}".format(config.get('config',"hashfile_name")))
|
||||||
|
print("Hashcount: {}".format(config.get('config',"hash_count")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
with open('nsrl.bloom', 'rb') as nb:
|
with open('nsrl.bloom', 'rb') as nb:
|
||||||
bf = BloomFilter.fromfile(nb)
|
bf = BloomFilter.fromfile(nb)
|
||||||
|
|
||||||
@@ -28,15 +45,15 @@ def main():
|
|||||||
output=""
|
output=""
|
||||||
|
|
||||||
# only print output if for mismatches if selected
|
# only print output if for mismatches if selected
|
||||||
if ((not hash in bf) or (not args.mismatched)):
|
hash_is_a_match=(hash in bf)
|
||||||
|
if (hash_is_a_match and not args.no_hits) or (not hash_is_a_match and not args.no_misses):
|
||||||
|
#output
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
output = "{}:{}".format(hash_hex,hash in bf)
|
output = "{}:{}".format(hash_hex,hash_is_a_match)
|
||||||
else:
|
elif args.no_hits != args.no_misses :
|
||||||
if args.mismatched:
|
|
||||||
output = "{}".format(hash_hex)
|
output = "{}".format(hash_hex)
|
||||||
else:
|
else:
|
||||||
output = "{}".format(hash in bf)
|
output = "{}:{}".format("+"if hash_is_a_match else "-",hash_hex)
|
||||||
|
|
||||||
print output
|
print output
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user