def validate(self, username, password): # ensure the user exists. index = self.view.find(username=username, password=password) if (index == -1): raise serverx("invalid username or password") # see if the passwords match. user = self.view[index] if (user.password != password): raise serverx("invalid username or password")
def run(self): # enter an infinite read loop to process all inbound requests. while 1: try: buf = self.sock.recv(1024) buf = buf.rstrip("\n") if (not buf): raise Exception except: msg = "[!] connection from %s for ida_sync::%s closed." % ( self.sock.getpeername()[0], self.project) self.sock.close() raise serverx(msg) # parse out the fields, ignore and continue on error. try: (type, address, data) = buf.split(":::") type = int(type) address = long(address, 16) except: continue # print to console. if type == server_constants.NAME or type == server_constants.STACK_NAME: print_data = data.split("*")[1] else: print_data = data print "[*] data from %s. type %d. @%08x. %s" % ( self.username, type, address, print_data) # erase any previous overlapping data at this address. self.delete_row(address, type) # append the received data to the database. self.proj_view.append(type=type, address=address, data=data, timestamp=long(time.time()), user=self.username) # commit changes to database. self.db.commit() # walk through all active connections and relay the received data # to all equivalent module/project combinations. for conn in self.connections: # ignore the current connection. if (conn == self.connection): continue if (conn[server_constants.MODULE] == "ida_sync" and conn[server_constants.PROJECT] == self.project): conn[server_constants.SOCK].sendall(buf) self.update_last(conn[server_constants.USERNAME], conn[server_constants.PROJECT])
def run(self): # enter an infinite read loop to process all inbound requests. while 1: try: buf = self.sock.recv(1024) buf = buf.rstrip("\n") if (not buf): raise Exception except: msg = "[!] connection from %s for ida_sync::%s closed." % (self.sock.getpeername()[0], self.project) self.sock.close() raise serverx(msg) # parse out the fields, ignore and continue on error. try: (type, address, data) = buf.split(":::") type = int(type) address = long(address, 16) except: continue # print to console. if type == server_constants.NAME or type == server_constants.STACK_NAME: print_data = data.split("*")[1] else: print_data = data print "[*] data from %s. type %d. @%08x. %s" % (self.username, type, address, print_data) # erase any previous overlapping data at this address. self.delete_row(address, type) # append the received data to the database. self.proj_view.append(type = type, address = address, data = data, timestamp = long(time.time()), user = self.username) # commit changes to database. self.db.commit() # walk through all active connections and relay the received data # to all equivalent module/project combinations. for conn in self.connections: # ignore the current connection. if (conn == self.connection): continue if (conn[server_constants.MODULE] == "ida_sync" and conn[server_constants.PROJECT] == self.project): conn[server_constants.SOCK].sendall(buf) self.update_last(conn[server_constants.USERNAME], conn[server_constants.PROJECT])
def delete(self, username): # ensure the user exists. index = self.view.find(username=username) if (index == -1): raise serverx("username not found") # remove the user and commit the changes. self.view.delete(index) self.db.commit()
def add(self, username, password, realname): # ensure the user doesn't already exist. if (self.view.find(username=username) != -1): raise serverx("username already exists") # add the user and commit the changes. self.view.append(username=username, password=password, realname=realname) self.db.commit()
def _init(self, s, connections, connection, project, username, password): self.sock = s self.connections = connections self.connection = connection self.project = project self.username = username self.password = password # retrieve the project view. self.proj_view = self.db.view(project) # create an exception if the view doesn't exist. if (str(self.proj_view.structure()) == "[]"): raise serverx("requested project not found.") self.db.commit() # determine the user's last update. index = self.last_view.find(username=username, project=project) if (index != -1): last = self.last_view[index].timestamp # refresh the last update record. self.update_last(username, project) else: last = 0 print ">>DEBUG %08x" % last # locate all changes made since the user's last update. index = self.proj_view.filter(lambda row: row.timestamp >= last) subview = self.proj_view.remapwith(index) # XXX - this is a cheap hack because the IDA plugin doesn't seem to # process the first message. self.sock.sendall("31337:::deadbeef:::sync") for record in subview: msg = "%d:::%08x:::%s" % (record.type, record.address, record.data) try: self.sock.sendall(msg) self.sock.recv(1) except: break print "[*] data to %s. type %d. @%08x. %s" % (self.username, record.type, record.address, record.data) time.sleep(0.1) # reset the last update time. self.update_last(username, project)
def _init(self, s, connections, connection, project, username, password): self.sock = s self.connections = connections self.connection = connection self.project = project self.username = username self.password = password # retrieve the project view. self.proj_view = self.db.view(project) # create an exception if the view doesn't exist. if (str(self.proj_view.structure()) == "[]"): raise serverx("requested project not found.") self.db.commit() # determine the user's last update. index = self.last_view.find(username=username, project=project) if (index != -1): last = self.last_view[index].timestamp # refresh the last update record. self.update_last(username, project) else: last = 0 print ">>DEBUG %08x" % last # locate all changes made since the user's last update. index = self.proj_view.filter(lambda row: row.timestamp >= last) subview = self.proj_view.remapwith(index) # XXX - this is a cheap hack because the IDA plugin doesn't seem to # process the first message. self.sock.sendall("31337:::deadbeef:::sync") for record in subview: msg = "%d:::%08x:::%s" % (record.type, record.address, record.data) try: self.sock.sendall(msg) self.sock.recv(1) except: break # reset the last update time. self.update_last(username, project)
def update(self, username, password, realname): # ensure the user exists. index = self.view.find(username=username) if (index == -1): raise serverx("username not found") # remove the user. self.view.delete(index) # insert the updated user in it's place. self.view.insert(index, username=username, password=password, realname=realname) # commit the changes. self.db.commit()