首页 > 编程语言 > 详细

python3 Redis未授权检测脚本

时间:2020-11-26 23:29:23      阅读:48      评论:0      收藏:0      [点我收藏+]
import sys
import getopt
import socket


def get_target():

    opts, args = getopt.getopt(sys.argv[1:], ‘-i:-p:-h‘)
    # print(opts)
    for opt_name, opt_value in opts:
        if opt_name == ‘-h‘:
            print(‘[*]This is help information                     [*]\n‘
                  ‘[*]-i + vulnerable-ip                           [*]\n‘
                  ‘[*]-p + vulnerable-port                         [*]\n‘
                  ‘[*]Example:python3 redis.py -i 127.0.0.1 -p 6379[*]\n‘)

        if opt_name in (‘-i‘, ):
            ip = opt_value

        if opt_name in (‘-p‘, ):
            port = opt_value

    return ip, port

def passwd_dict():
    passwd = [‘redis@123‘, ‘Redis@123‘, ‘Passw0rd‘, ‘123456‘]
    return passwd
    # 简单的弱口令检测功能,后续可改为读取字典进行爆破

def main(ip, port, passwd):
    print("[*]Redis Unauthorized and Weak Password Detection  [*]\n"
          "[*]By: Zh1z3ven                                    [*]\n"
          "[*]Blog: https://www.cnblogs.com/Zh1z3ven/         [*]\n")
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((ip, int(port)))
    send_data = ‘INFO\r\n‘
    s.send(send_data.encode())
    res = s.recv(1024)
    response = bytes.decode(res)
    # print(response)
    if ‘redis_version‘ in response:
        result = ‘[!]Vulnerable {0}:{1} 存在未授权访问  [!]‘.format(ip, port)
        print(result)
        return result

    elif ‘NOAUTH‘ in response:
        for item in passwd:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((ip, int(port)))
            send_data = ‘AUTH {0}\r\n‘.format(item)
            s.send(send_data.encode())
            res = s.recv(1024)
            response = bytes.decode(res)
            # print(response)

            if ‘+OK‘ in response:
                result = ‘[!]Vulnerable: {0}:{1} 存在弱口令{2} [!]‘.format(ip, port, item)
                print(result)
                return result
    else:
        result = [‘[*] 不存在未授权及弱口令 [*]‘]
        print(result)
        return result


if __name__ == ‘__main__‘:

    ip, port = get_target()
    passwd = passwd_dict()
    main(ip, port, passwd)

ps:简单记录下,欢迎各位大佬师傅表哥们评论指正缺点~

python3 Redis未授权检测脚本

原文:https://www.cnblogs.com/Zh1z3ven/p/14045340.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!