Exemple #1
0
    def start(self, config):
        if not self.prepare(config):
            return

        #multiprocessing
        nprocess = int(config['processes'])
        idx = self.fork(nprocess)
        xutils.closeLogger()
        if idx == -1:  #parent
            return

        self.pid = os.getpid()

        self.logger = xutils.initLogger(config['logfile'])
        num = len(self.targets) / nprocess
        if num * nprocess < len(self.targets):
            num += 1
        self.targets = self.targets[num * idx:num * idx + num]

        #TODO:
        #Please implement your DataBaseStorage object
        dbs = DataBaseStorage(config)
        store = BruteStorage(dbs)
        bruter = BruteRunner(store)

        nworker = int(config['threads'])
        kargs = {
            'constructor': self.constructor,
            'userdict': self.userdict,
            'passwords': self.passwords
        }
        bruter.start(nworker, kargs)

        maxruntime = float(config['maxruntime'])
        starttime = time.time()
        endtime = starttime + maxruntime

        for task in self.targets:
            bruter.putTask(task)

        taskleft = bruter.getTaskCount()
        while time.time() < endtime and taskleft > 0:
            time.sleep(5)
            taskleft = bruter.getTaskCount()
        bruter.signal()
        time.sleep(5)
        bruter.stop(60)
        store.close()
        dbs.close()
        logging.getLogger().info('Bruter.start: pid:%d, runtime:%.2fS. done.' %
                                 (self.pid, time.time() - starttime))
Exemple #2
0
def main():
    options = OptionParser(usage='%prog [options]',
                           description='BruteScanRun.py')
    options.add_option('-l',
                       '--logfile',
                       type='string',
                       default='BruteScanRun.log',
                       help='log file path')
    options.add_option('-c',
                       '--config',
                       type='string',
                       default='',
                       help='config file path')

    opts, args = options.parse_args()
    try:
        logger = xutils.initLogger(opts.logfile)
        if not os.path.isfile(opts.config):
            logger.error('config file {%s} is missing. bye!' % (opts.config))
            return 1
        #TODO:
        #Please implement your loadConfig
        wcfg = loadConfig(opts.config)
        config = {
            'threads': wcfg['THREADS'],
            'userdict': wcfg['DICTFILE'],
            'proto': wcfg['PROTO'].lower(),
            'ports': ports,
            'maxruntime': int(wcfg['MAXTIME']),
            'processes': wcfg['PROCESSES'],
            'logfile': opts.logfile,
        }
        bruter = Bruter(MssqlBruteTester)
        bruter.start(config)
    except Exception as e:
        sys.stderr.write('EXCEPTION: %s, pid: %d, exit.\n' %
                         (str(e), os.getpid()))
Exemple #3
0
        if not rs:
           logging.getLogger().info('SAFE %s:%d'%(host, port)) 
        return rs


if __name__=='__main__':
    import sys
    import xutils
    if len(sys.argv)!=5:
	print("usage:x.py host port passdictPath pathoflogfile")
	exit(0)
    host,port = sys.argv[1],int(sys.argv[2])
    
    passdict = []
    for ln in open(sys.argv[3]):
        #fs = ln.strip().split(':',1)
        #if len(fs)!=2:
        #    continue
        username = "******"
        password = ln.strip()
        #if username not in userdict:
        #    userdict[username] = set()
        #userdict[username].add(password)
	#print(password)
	passdict.append(password)
    logger = xutils.initLogger(sys.argv[4])
    tester = MssqlBruteTester(passdict)
    rs = tester.test( (host,port) )
    print rs