[[文件下载常用路径]]
文件包含漏洞 LFI labs LFI-1 根据提示我们直接访问之前在文件夹里写的shell脚本。
http://127.0.0.1/lfi-labs-master/LFI-1/?page=../info.php#
../指的是上级文件夹。
LFI-2 根据提示我们采用%00进行截断。
http://127.0.0.1/lfi-labs-master/LFI-2/?library=../../info.php%00
使用%00截断注意的问题:
(1)php版本小于5.3.4。 (2)php的magic_quotes_gpc为OFF状态。
LFI-3 查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <?php include ("../common/header.php" ); ?> <!-- from http: <?php hint("will include the arg specified in the GET parameter \"file\", looks for .php at end - bypass by apending /. (slash plus dot)" ); ?> <form action="/LFI-3/index.php" method="GET" > <input type="text" name="file" > </form> <?php if (substr($_GET ['file' ], -4 , 4 ) != '.php' ) echo file_get_contents($_GET ['file' ]); else echo 'You are not allowed to see source files!' ."\n" ; ?>
两个函数
substr():字符串裁剪,返回字符串的一部分,其用法substr(string,start,length),如果start为负数就是从末尾开始返回长度为length的字符串。
file_get_contents():把整个文件读入一个字符串中。
所以这段源代码是对get请求到的file查看其文件后缀,如果文件后缀与php相同就会禁止查看源码,如果后缀不是php才能查看其源码,也就是文件上传漏洞里的黑名单嘛。
解决方法:
黑名单绕过,包括但不局限于
LFI-4 查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 <?php include ("../common/header.php" ); ?> <!-- from http: <?php hint("will include the arg specified in the GET parameter \"class\", appends .php to end, defeat with NULL byte %00" ); ?> <form action="/LFI-4/index.php" method="GET" > <input type="text" name="class" > </form> <?php include ('includes/class_' .addslashes($_GET ['class' ]).'.php' );?>
其中的includes/class_
相当于一个文件路径,没啥限制直接使用%00进行截断就行
LFI-5 查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <!-- from http: <?php include ("../common/header.php" ); ?> <?php hint("will include the arg specified in the GET parameter \"file\", strips prepended \"../\" strings, must encode / with %2f" ); ?> <form action="/LFI-5/index.php" method="GET" > <input type="text" name="file" > </form> <?php $file = str_replace('../' , '' , $_GET ['file' ]); if (isset ($file )) { include ("pages/$file " ); } else { include ("index.php" ); } ?>
两个函数:
str_replace():将接收到的字符串中的../替换为NULL
isset():函数用于检测变量是否已设置并且非 NULL。如果指定变量存在且不为 NULL,则返回 TRUE,否则返回 FALSE。
绕过方法:
直接进行双写绕过 http://127.0.0.1/lfi-labs-master/LFI-5/?file=....//....//info.php
LFI-6 查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php include ("../common/header.php" ); ?> <!-- from https: <?php hint("will include the arg specified in the POST parameter \"page\"" ); ?> <form action="/LFI-6/index.php" method="POST" > <input type="text" name="page" > </form> <?php include ($_POST ["page" ]);?>
使用Post传参即可
LFI-7 查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php include ("../common/header.php" ); ?> <!-- from http: <?php hint("will include the arg specified in the POST parameter \"library\", appends .php to end, use null byte %00 to bypass" ); ?> <form action="/LFI-7/index.php" method="POST" > <input type="text" name="library" > </form> <?php include ("includes/" .$_POST ['library' ].".php" ); ?>
使用POST传参然后使用%00进行截断就可以
LFI-8—LFI-10 原理很简单,只是使用POST传参即可
LFI-11 查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 <!-- from http: <?php include ("../common/header.php" ); ?> <?php hint("not everything you need to play with is in a text field" ); ?> <form action="/LFI-11/index.php" method="POST" > <input type="text" name="file" > <input type="hidden" name="style" name="stylepath" > </form> <?php include ($_POST ['stylepath' ]); ?>
使用POST传参,向参数stylepath进行传参即可
LFI-13和LFI-14跟LFI-5和LFI-10一样