def FeatureCompute(currentdirname): for (thisDir, subsHere, filesHere) in os.walk(currentdirname): for filename in filesHere: (shortname, extension) = os.path.splitext(filename) pcapfullname = os.path.join(thisDir,filename) #featurefilename = if( os.path.isfile(pcapfullname) and (extension==".pcap" or extension == ".PCAP" ) ): #fullfeaturefilename=pcapfullname+".arff" #cmd1_s= "rm %s" % (APPCONFIG.GlobalConfig['tmp_arff_filename']) if os.path.isfile(APPCONFIG.GlobalConfig['tmp_arff_filename']): os.remove(APPCONFIG.GlobalConfig['tmp_arff_filename']) cmd1_s='OpenDPI_demo -f %s' % pcapfullname p = Popen(cmd1_s, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT,close_fds=True) output = p.stdout.read() prog=re.compile("###.*###") m = prog.search(output) p = re.compile('[a-zA-Z0-9,.@#_]') app_str_limited='' for i in m.group(0): if p.match(i): app_str_limited+=i else: app_str_limited+='=' appfilename=pcapfullname+"."+app_str_limited+".arff" logging.info ("computing feature to: %s" % appfilename) cmd2_s= "netmate -f %s" % (pcapfullname ) cmd3_s= "mv %s %s"%(APPCONFIG.GlobalConfig['tmp_arff_filename'],appfilename) #os.system(cmd1_s) #os.system(cmd2_s) #os.system(cmd3_s) allcmd_s=("%s && %s"%(cmd2_s,cmd3_s)) os.system(allcmd_s) else: logging.info ("%s is not a directory" % pcapfullname ) pass
def SFR_token(username, passwd): TOKEN = SFR_fetch_token() if not TOKEN or TOKEN is None: print("[err] failed to receive a token: " + str(TOKEN)) print( "[info] try: curl -s -G http://192.168.1.1/api/1.0/?method=auth.getToken" ) sys.exit(1) if not username or username is None: print("[err] unable to locate username") sys.exit(1) if not passwd or passwd is None: print("[err] unable to locate passwd") sys.exit(1) SFR_HASH = SFR_hash(TOKEN, username) + SFR_hash(TOKEN, passwd) checkToken_cmd = "curl -s http://192.168.1.1/api/1.0/?method=auth.checkToken\&token=" + TOKEN + "\&hash=" + SFR_HASH checkToken = Popen(checkToken_cmd, shell=True, stdout=PIPE).stdout.read() if not checkToken.match("auth"): print("[WARN] failed to check token " + TOKEN + " with hash: " + SFR_HASH) print( "[info] its possible that the CPE has locked us out with a cooldown" ) sys.exit(1) return TOKEN
def get_address_of_buf(remaining_stack_frame_size, trailer_length): cmd = ['gdb', '-n', '--batch', '--command=' + './dump32.gdb', '--args', './overflow', 'A' * (remaining_stack_frame_size + trailer_length)] print('Command: {}'.format(' '.join(cmd))) p = Popen(cmd, stdin=None, stdout=PIPE, stderr=PIPE) output, err = p.communicate(None) rc = p.returncode addr = None if len(err) != 0 or len(output) == 0: return (rc, addr) output_str = output.decode() p = re.compile('.*(0x[0-9a-f]+)$') for line in output_str.split('\n'): #print('--- ' + str(line)) m = p.match(line) if m is not None and len(m.groups()) == 1: addr = int(m.groups()[0], 16) break return (rc, addr)
#!/bin/python import re import subprocess from subprocess import Popen p = Popen(["xsel", "-o"], stdout=subprocess.PIPE) output, err = p.communicate() out = str(output).replace("b'", "").replace("\\n'", "") words = out.split(" ") p = re.compile(r"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?") for word in words: #print(word) #print(p.findall(word)) if p.match(word) != None: # print(word) subprocess.call(["xdg-open", word])