首页 > 数据库 > Redis > 正文

python3 Redis未授权检测脚本怎么写

WBOY
发布: 2023-05-29 23:55:04
转载
1540 人浏览过

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 -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 = 'INFOrn'
    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}rn'.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)
登录后复制

以上是python3 Redis未授权检测脚本怎么写的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:yisu.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!