(options, args) = p.parse_args() # Accept only when either offline or online mode respectively if len(args) != 2: logging.error("Double-check your arguments...!") sys.exit(1) logging.basicConfig(filename="detection.log", level=logging.DEBUG) logging.info("[Start] %s" % datetime.today().strftime("%B %d %Y %I:%M%p (%A)")) filter = args[1] # Proceed detection at online or offline if options.pcap and options.bpf: pcap_file = args[0] if not os.path.isfile(pcap_file): logging.warning("Inappropriate file provided!") sys.exit(1) dt = Detector("offline", iface=None, pcap=pcap_file, bpf=filter) dt.sniff_n_detect(PKT_INSPECTED_CNT) elif options.iface and options.bpf: dt = Detector("online", iface=util.ifce_sanity_check(args[0]), pcap=None, bpf=filter) dt.sniff_n_detect(PKT_INSPECTED_CNT) else: logging.error("Unsupported mode - How did you do that?") sys.exit(1) print "\t%d packets are detected as injection! (%d inspected)" % (dt.get_detected_pkt_cnt(), PKT_INSPECTED_CNT) logging.info("[End] %s" % datetime.today().strftime("%B %d %Y %I:%M%p (%A)"))
(options, args) = p.parse_args() # Accept only when either offline or online mode respectively if len(args) != 2: logging.error('Double-check your arguments...!') sys.exit(1) logging.basicConfig(filename='detection.log', level=logging.DEBUG) logging.info('[Start] %s' % datetime.today().strftime("%B %d %Y %I:%M%p (%A)")) filter = args[1] # Proceed detection at online or offline if options.pcap and options.bpf: pcap_file = args[0] if not os.path.isfile(pcap_file): logging.warning('Inappropriate file provided!') sys.exit(1) dt = Detector('offline', iface=None, pcap=pcap_file, bpf=filter) dt.sniff_n_detect(PKT_INSPECTED_CNT) elif options.iface and options.bpf: dt = Detector('online', iface=util.ifce_sanity_check(args[0]), pcap=None, bpf=filter) dt.sniff_n_detect(PKT_INSPECTED_CNT) else: logging.error('Unsupported mode - How did you do that?') sys.exit(1) print '\t%d packets are detected as injection! (%d inspected)' % (dt.get_detected_pkt_cnt(), PKT_INSPECTED_CNT) logging.info('[End] %s' % datetime.today().strftime("%B %d %Y %I:%M%p (%A)"))
# Check provided arguments from command line try: (options, args) = p.parse_args() if len(args) != 4: logging.error('Double-check your arguments!') sys.exit(1) except: logging.error("Something went wrong!!") sys.exit(1) logging.basicConfig(filename='injection.log', level=logging.DEBUG) logging.info('[Start] %s' % datetime.today().strftime("%B %d %Y %I:%M%p (%A)")) # Setup arguments o/w default values iface = util.ifce_sanity_check( args[0]) if options.iface else util.get_default_iface() pattern = args[1] if options.regex else 'works' data = util.data_sanity_check(args[2]) if options.data else 'xxx' filter = args[3] if options.bpf else 'tcp' util.print_injection_info(iface, pattern, args[2], len(data), filter) ij = Injector(iface, pattern, data, filter) ij.sniff_n_inject(PKT_MONITOR_CNT) print '\t%d packets are injected! (%d monitored)' % ( ij.get_injected_pkt_cnt(), PKT_MONITOR_CNT) logging.info('[End] %s' % datetime.today().strftime("%B %d %Y %I:%M%p (%A)"))
p.add_option("-b", "--filter", dest="bpf", action="store_true", help="BPF filter that specifies a subset of the traffic to be monitored") print "quantuminject %s" % VER # Check provided arguments from command line try: (options, args) = p.parse_args() if len(args) != 4: logging.error('Double-check your arguments!') sys.exit(1) except: logging.error("Something went wrong!!") sys.exit(1) logging.basicConfig(filename='injection.log', level=logging.DEBUG) logging.info('[Start] %s' % datetime.today().strftime("%B %d %Y %I:%M%p (%A)")) # Setup arguments o/w default values iface = util.ifce_sanity_check(args[0]) if options.iface else util.get_default_iface() pattern = args[1] if options.regex else 'works' data = util.data_sanity_check(args[2]) if options.data else 'xxx' filter = args[3] if options.bpf else 'tcp' util.print_injection_info(iface, pattern, args[2], len(data), filter) ij = Injector(iface, pattern, data, filter) ij.sniff_n_inject(PKT_MONITOR_CNT) print '\t%d packets are injected! (%d monitored)' % (ij.get_injected_pkt_cnt(), PKT_MONITOR_CNT) logging.info('[End] %s' % datetime.today().strftime("%B %d %Y %I:%M%p (%A)"))