def main(): NIC = config.load()["scapy_network_card"] # network adapter name try: if NIC == 'all': sniff(filter="tcp", prn=lambda x: capture(x)) else: sniff(iface=NIC, filter="tcp", prn=lambda x: capture(x)) except Exception as e: error("scapy out!") conf = config.load() conf['scapy_stat'].lower = "false" config.update(conf)
def check_update(): out.good("Checking update...") try: res = requests.get(config.load()['check_url'], timeout=10) version = res.content if version != config.load()['version']: update() return True else: return False except: out.error("Can not connect to update server!") return False
def scan_start(): while config.load()['scan_stat'].lower() == "true": try: while thread_filled(): time.sleep(5) reqhash = conn.rpoplpush("waiting", "running") if not reqhash: time.sleep(10) continue reqed = conn.hget("request", reqhash) request = json.loads(ds(reqed)) rules = config.load_rule()['scan_type'] url = urlparse.urlparse(request['url']).query if (request['method'] == "GET" and url != "") or (request['method'] == "POST" and (request["postdata"] != "" or url != "")): t = threading.Thread(target=new_scan, args=(reqhash, requests_convert(request), rules)) t.start() else: conn.lrem("running", 1, reqhash) conn.lpush("finished", reqhash) except Exception,e: out.error(str(e))
def get(self): try: request_hash = self.get_argument("hash") request = json.loads( base64.b64decode(conn.hget("request", request_hash))) if conn.hget("results", request_hash): results = {} stat = "success" else: results = json.loads( base64.b64decode(conn.hget("results", request_hash))) stat = results['stat'] stats = ['success', 'info', 'warning', "danger"] stat = stats[stat] if results['stat'] == 0: results = {} else: del results['stat'] for rule in results.keys(): if results[rule]['stat'] == 0: del results[rule] else: results[rule]['stat'] = stats[results[rule] ['stat']] messages = [] for message in results[rule]['message']: if message != "": messages.append(message) results[rule]['message'] = messages return self.render("req.html", request=request, results=results, stat=stat) except Exception, e: out.error(str(e)) return self.write(str(e))