簡介
redis是一種key-value鍵值對的非關系型數據庫,默認運行在6379端口
它啟動時不會像Apache一樣,以一種www-data低權限身份運行。而是以運行者的身份,例如用root權限直接運行redis時,redis的權限就是root權限
其次它的默認配置是無需密碼的,也就造成了默認的未授權訪問
redis還支持本地存儲,也就導致了任意文件寫入。從而可以寫入私鑰,利用私鑰直接ssh登錄服務器。
漏洞環(huán)境搭建
攻擊機
操作系統:ubuntu 16.04
ip :192.168.85.128
安裝redis
靶機
操作系統: centos 6.5
ip :192.168.85.132
下載編譯redis
修改下配置文件,不然默認雖然是無密碼,但是會有protected模式,導致無法從外部主機連接
bind 127.0.0.1前面加上#號 protected-mode設為no
啟動redis
寫入ssh-keygen公鑰
現在下先在本地生成一對密鑰
這樣就可以在~/.ssh目錄下生成一對id_rsa、id_rsa.pub

然后連接靶機redis
這樣,我們就把公鑰寫入對方的服務器了,直接用生成的私鑰連接即可

假如報了如下錯誤
運行下如下兩句即可
利用計劃任務反彈shell
先開一個終端監(jiān)聽本地的23333端口
利用之前類似的文件寫入,寫入定時命令
需要等待一會,一般一分鐘之內吧,nc就能收到反彈回來的shell了

寫入webshell
當redis權限較低,上面兩種方法都行不通的時候,可以嘗試往web服務中寫入一句話,獲取webshell
這樣,就能在根目錄下生成shell.php。訪問一下
結合SSRF
之前能看到,默認情況下雖然是沒有密碼,但是會開啟protected保護模式
在這情況下,我們嘗試連接一下對方redis
kingkk@ubuntu:~/test/redis$ redis-cli -h 192.168.85.132192.168.85.132:6379> infoDENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
可以看到保護模式拒絕了redis的遠程連接,所以經常redis都是配合著ssrf這個可以偽造身份的攻擊方式一起進行攻擊