def manage_request(self, data): # quello che mi arriva è del tipo [OPCODE|S|C|sito|...|nonce|hash]kcs | IV unpacked_data = utility.unpack_message(data, 4) if(unpacked_data is None or len(unpacked_data) != 2): utility.print_user_log(self.client_address,"Bad packet format") return (False, 109) encrypted_data , IV = unpacked_data decrypted_data = utility.decrypt_AES(encrypted_data, self.session_key, IV) if decrypted_data is None: return (False, 102) #print decrypted_data decrypted_fields = utility.unpack_message(decrypted_data, 4) if decrypted_data is None: utility.print_user_log(self.client_address,"Bad packet format") return (False, 109) data_to_hash = ''.join(decrypted_fields[:-1]) hashed_data_c = decrypted_fields[-1] hashed_data = utility.get_hash(data_to_hash) ret = utility.secure_cmp(hashed_data_c, hashed_data) utility.print_user_log(self.client_address,"Request: %s" % decrypted_fields[0]) if ret is False: print hexlify(hashed_data_c) print hexlify(hashed_data) utility.print_user_log(self.client_address,"Different hashes") return (False, 103) #print fields nonce = decrypted_fields[-2] if nonce in self.nonces: utility.print_user_log(self.client_address, "No fresh nonce!!") return (False, 104) self.nonces.append(nonce) #print fields #execute query response_fields = self.execute_query(decrypted_fields[:-2]) # è una lista [:-2] tutto tranne nonce hash response_fields.append(nonce) # aggiungo nonce alla lista response = utility.concatenate(*response_fields) hashed_response = utility.get_hash(response) #print "hash,", hashed_response #data_to_pack = utility.concatenate((response, hashed_response)) # concateno hash alla risposta response_fields.append(hashed_response) #print "RF: ",response_fields packed_message = utility.pack_message(*response_fields) #print packed_message IV = os.urandom(16) data_to_send = utility.encrypt_AES(packed_message, self.session_key, IV) if data_to_send is None: return (False, 106) data_to_send = utility.pack_message(data_to_send, IV) #print "DATA TO SEND \n", data_to_send #un = utility.unpack_message(data_to_send, 4) #print "ENC",un[0] #print "IV", un[1] utility.print_user_log(self.client_address, 'Response: '+ response_fields[0]) return (True, data_to_send)
def message_M4(self, nonce_prot_c): utility.print_user_log(self.client_address,'Sending M4...') hash_nonce_c = utility.get_hash(nonce_prot_c) data_to_pack = utility.concatenate('100', self.server_ID, self.client_ID, hash_nonce_c) hash_data = utility.get_hash(data_to_pack) data = utility.pack_message('100', self.server_ID, self.client_ID, hash_nonce_c, hash_data) IV = os.urandom(16) enc_data = utility.encrypt_AES(data, self.session_key, IV) if enc_data is None: utility.print_user_log(self.client_address, '[ERROR] Error during encryption') return None data_to_send = utility.pack_message(enc_data, IV) return data_to_send
def download_sub(self, movie_path): self.movie_path = movie_path movie_hash = get_hash(self.movie_path) headers = {'User-Agent': self.user_agent} response = requests.get('http://api.thesubdb.com/?action=search&hash={}'.format(movie_hash), headers=headers) if 'en' in response.text: subtitle = requests.get('http://api.thesubdb.com/?action=download&hash={}&language=en'.format(movie_hash), headers=headers) _file = get_file(self.movie_path, subtitle.text) yield _file.name
def message_M3(self): priv_key = utility.load_priv_key('server_prvkey_1') if priv_key is None: utility.print_user_log(self.client_address,'[ERROR]Some errors occured reading the key') return None utility.print_user_log(self.client_address,'Private key loaded') # waiting for M3 utility.print_user_log(self.client_address,"Waiting for M3...") data_recv = utility.recv_data(self.request,0) if data_recv is None: utility.print_user_log(self.client_address, "[ERROR] Client disconnected during M3") return None utility.print_user_log(self.client_address, "Received M3..") encrypted_data = bytes(data_recv) decrypted_data = utility.decrypt_RSA(encrypted_data, priv_key) if decrypted_data is None: utility.print_user_log(self.client_address, '[ERROR] some errors occured decrypting the data') return None try: ''' print '_____________________________________' print decrypted_data print '_____________________________________' ''' fields = utility.unpack_message(decrypted_data, 4) #print fields if len(fields) != 8: return None # Manca TYPE | ... opcode, server_prot_ID,client_prot_ID, client_pass,session_key, nonce_prot_s, self.nonce_prot_c, hashed_data_c = fields except IndexError: utility.print_user_log(self.client_address, '[ERROR] incorrect message format') return None ''' for i in fields: print hexlify( i), "\n" ''' data_to_hash = ''.join(fields[0:7]) hashed_data = utility.get_hash(data_to_hash) ret = utility.secure_cmp(hashed_data, hashed_data_c) #print hexlify(hashed_data) #print hexlify(hashed_data_c) if (ret is False): utility.print_user_log(self.client_address, '[ERROR] Packet Hashes do not match') del session_key return None ret = utility.secure_cmp(self.nonce_s, nonce_prot_s) if(ret is False): utility.print_user_log(self.client_address, '[ERROR] Server Nonce is not fresh!') del session_key return None #print '1' ret = utility.secure_cmp(self.client_ID, client_prot_ID) if(ret is False): utility.print_user_log(self.client_address, '[ERROR] Client IDs do not match') del session_key return None #print '2' ret = utility.secure_cmp(self.server_ID, server_prot_ID) if(ret is False): utility.print_user_log(self.client_address, '[ERROR] Serve IDs do not match') del session_key return None #return (opcode, session_key, nonce_prot_c, client_pass) # ================================================================= if opcode == 'LOG': utility.print_user_log(self.client_address, "LOGIN REQUEST") # KDF(salted) e ricerca hash in database db = DB.Database() ret = db.connect() if ret[0] == False: utility.print_user_log(self.client_address, '[ERROR] Error during connecting to DB '+ str(ret[1])) del session_key return None user_config = db.find_user_config(self.client_ID, 'users') db.disconnect() if user_config == None: utility.print_user_log(self.client_address, '[ERROR] No user config found with ID: %s' % self.client_ID ) del session_key return None ID, hash_pwd, salt_hash = user_config hashed_pwd = bytes(hash_pwd) #print hash_pwd, hashed_pwd #print hexlify(hashed_pwd) #kdf = utility.get_kdf(client_pass, salt_kdf) #hashed_kdf = utility.get_hash(kdf, salt_hash) #if hashed_kdf == None: # utility.print_user_log(self.client_address, '[ERROR] Error during KDF creation') # del session_key # return None # Check importante, hashed_kdf é l'hash della kdf della password che mi invia l'utente # hashed_pwd é l'hash della kdf della password che ho nel DB hash_pwd_c = utility.get_hash(client_pass, salt_hash) ret = utility.secure_cmp(hashed_pwd, hash_pwd_c) if ret == False: utility.print_user_log(self.client_address, '[ERROR] Password hashes do not match') del session_key return None # ===================================================================== # REG =============================================================== elif opcode == 'REG': utility.print_user_log(self.client_address,'SIGNIN REQUEST') db = DB.Database() ret = db.connect() if ret[0] == False: utility.print_user_log(self.client_address,'[ERROR CONNECT] '+ str(ret[0])) del session_key return None user_config = db.find_user_config(self.client_ID, 'users') db.disconnect() if user_config != None: utility.print_user_log(self.client_address,'[ERROR CONFIG] User: '******' already present') del session_key return 203 # bytes salts salt_hash = os.urandom(16) #kdf = utility.get_kdf(client_pass, salt_kdf) #hashed_kdf = utility.get_hash(kdf, salt_hash) hashed_pwd = utility.get_hash(client_pass, salt_hash) #print hashed_kdf ''' if hashed_kdf == None: utility.print_user_log(self.client_address,'[ERROR] Error during KDF creation') del session_key return None ''' ret = db.connect() if ret[0] == False: utility.print_user_log(self.client_address,'[ERROR] Error during connecting to DB '+ str(ret[1])) del session_key return None ret = db.add_user('users',self.client_ID, hashed_pwd, salt_hash) db.disconnect() if ret[0] == False: utility.print_user_log(self.client_address,'[ERROR] Error during user add ' + ret[1]) del session_key return None else: del session_key return None self.session_key = session_key #self.client_key = kdf self.database = db self.nonces = [] return True
firefox_profile = webdriver.FirefoxProfile() firefox_profile.set_preference('permissions.default.image', 2) firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false') driver = Firefox(firefox_profile=firefox_profile) """ driver.get(settings.login_data['login_url']) driver.find_element_by_id( "loginRegisterTabs").find_element_by_css_selector( 'ul:nth-child(1)').find_element_by_css_selector( 'li:nth-child(1)').click() driver.find_element_by_xpath('//input[@name="email"]').send_keys( settings.login_data['user_email']) driver.find_element_by_xpath('//input[@name="password"]').send_keys( settings.login_data['user_password']) driver.find_element_by_xpath('//button[@type="submit"]').click() play_button = WebDriverWait(driver, 15).until( lambda x: x.find_element_by_xpath('//span[@class="serverDetails"]')) play_button.click() driver.switch_to.window(driver.window_handles[1]) time.sleep( 15 ) # TODO: fix into an elegant solution, gotta wait for 'secureHash' in JS to be defined and set secureHash = utility.get_hash(driver.page_source) print(f"Logged in, our secure hash is {secureHash}") plan_manager()
"delete self loops" g = get_graph(edgelist) length = len(g.es) while True : selfloop = False; for e in g.es: if g.is_loop(e): selfloop = True; g.delete_edges(e) if selfloop == False : break; g.write_edgelist(outputfilename) if __name__ == "__main__": edgelist = sys.argv[1] print('extracting the largest connected component') lcc_extraction(edgelist) print('trimming edges') trim_edges(edgelist + '_lcc') print('deleting self loops') delete_self_loop(edgelist + "_lcc", edgelist + "_final") print('getting the graph to make hash file of edgelist') g = get_graph(edgelist + "_final") print('hashing the edgelist') graph_hash = get_hash(g) print('dumping the edgelist') hashfile = edgelist + '_hash.p' pickle.dump(graph_hash, open(hashfile, 'wb'))