php num rows `$_GET`、`$_POST` 到 `$_SERVER`,安全测试里这些东西天天见
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>1e5ccf4624dc5805715ca1567307f~tplv-tt-origin-web:gif.jpeg?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1778322446&x-signature=ONd7VQCQ3jNC8nddWKHzDmMzwJw%3D” alt=”php num rows”/ style=”max-width: 100%; height: auto; display: block; margin: 1.8em auto; border-radius: 10px; box-shadow: 0 4px 20px rgba(236,72,153,0.18);”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>做 PHP 开发,绕不开超级全局变量。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>做 Web 安全测试,更绕不开。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为你盯的大多数输入点、请求头、登录表单、文件上传、、,本质上都和这些变量有关系。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>很多人刚学 PHP 时,对这块最大的误区有两个:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>实际上,超级全局变量这一章,恰恰是 PHP 和 Web 安全开始真正接轨的地方。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>今天这篇文章,就把 PHP 里最常用的几个超级全局变量讲透,重点放在:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>文章会尽量讲人话,不玩虚的,直接上代码和运行结果。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>一、什么叫“超级全局变量”?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>先说定义。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>在 PHP 里,超级全局变量就是:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>系统预定义好的变量,并且在整个脚本作用域内都能直接使用。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>你不用自己声明它,也不用刻意 一下,它本身就是全局可访问的。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>常见的超级全局变量有这些:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这几个名字,以后你做代码审计、漏洞分析、日志排查时,会反复看到。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二、先别急着看超级全局,先搞懂“作用域”
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果不理解“作用域”,你很容易看不懂 $ 为什么存在。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>先看一段普通代码:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”><?php
$x = 100;
function test() {
echo $x;
}
test();
?>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>Warning: Undefined variable $x
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>为什么?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为 $x 定义在函数外部,而 test() 函数内部默认拿不到外部普通变量。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这就叫作用域隔离。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>也就是说:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>三、函数内部定义的变量,外面也拿不到
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>再看一个反过来的例子:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>Warning: Undefined variable $y
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>原因还是一样:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这就是 PHP 里最基本的函数作用域规则。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>四、那为什么 $ 很重要?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为它可以让你在函数内部,访问函数外部的全局变量。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>先看代码:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>100
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这里发生了什么?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>五、怎么理解 $?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>你可以把 $ 理解成:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>一个装着当前全局变量的“总表”数组
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>也就是说,函数外定义的全局变量,其实都能在 $ 这个数组里找到。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”><?php
$a = 1;
$b = 2;
var_dump($GLOBALS['a']);
var_dump($GLOBALS['b']);
?>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>int(1)
int(2)
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>所以php num rows,$ 本质上就是一个全局变量映射表。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>六、用 $ 修改变量,外部值会跟着变
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这一点在审计代码时特别重要。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”><?php
$num = 10;
function changeNum() {
$GLOBALS['num'] = 999;
}
changeNum();
echo $num;
?>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>999
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这说明:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>也就是说,$ 不只是“读”,还能“改”。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>七、为什么安全审计里要注意 $?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为它会影响变量追踪。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>很多时候你在看代码,以为某个变量值是固定的,结果半路某个函数里通过 $ 给改了。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果你不注意这一点,做逻辑分析时就很容易看错。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>在一些老项目、历史代码、低质量代码里,这种写法并不少见。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>八、$ 是什么?为什么安全人员特别爱看它?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果说 $ 更偏 PHP 语言机制,那 $ 就是 Web 环境里特别实用的一组数据。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>它里面通常存着:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>你可以直接把它打印出来看看。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示意
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>array(若干项) {
["HTTP_HOST"]=>
string(9) "127.0.0.1"
["REQUEST_METHOD"]=>
string(3) "GET"
["PHP_SELF"]=>
string(8) "/test.php"
["HTTP_USER_AGENT"]=>
string(120) "Mozilla/5.0 ..."
...
}
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>不同环境下数量不一样,但本质都是一个数组。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>九、$ 本质上也是数组
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这点一定要记住。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为你以后看到这样的代码:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>$_SERVER['PHP_SELF']
$_SERVER['HTTP_USER_AGENT']
$_SERVER['SERVER_NAME']
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>本质上和你之前学的数组取值完全一样。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>就跟:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>$cars[0]
$user['name']
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>一个道理。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十、怎么把 $ 一项一项列出来?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>最适合的就是 。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”> $value) {
echo $key . " => " . $value . PHP_EOL;
}
?>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示意
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>HTTP_HOST => 127.0.0.1
REQUEST_METHOD => GET
PHP_SELF => /test.php
SERVER_NAME => 127.0.0.1
HTTP_USER_AGENT => Mozilla/5.0 ...
...
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这个方法在调试和审计时非常有用。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十一、几个最常见的 $ 字段php num rows,必须认识1)$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>''
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>表示当前执行脚本的路径或文件名。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示例
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>/test.php
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>2)$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>''
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>表示当前服务器主机名。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示例
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>127.0.0.1
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>或者:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>localhost
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>3)$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>''
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>表示请求来源页。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示例
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>http://127.0.0.1/index.php
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>不过这里要提醒一句:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”> 可以伪造,不能当绝对安全依据。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>4)$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>''
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>表示客户端浏览器标识,也就是常说的 UA。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示例
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ...
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这串内容就是浏览器类型、系统、内核等信息。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十二、别把 User-Agent 当 IP,这种低级错误真有人犯
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这个事必须专门说一句。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>有些人第一次看日志或者 $ 输出时,会看到一大串数字和浏览器版本,误以为那是攻击者 IP。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这是错的。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>比如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>Mozilla/5.0 (...) Chrome/104.0.5112.102 Safari/537.36
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这里的 104.0.5112.102 是浏览器版本号,不是 IP 地址。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>IP 地址正常长这样:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>192.168.1.1
127.0.0.1
10.0.0.5
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>不会冒出 5112 这种段值。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>做应急、看日志、做流量分析时php num rows `$_GET`、`$_POST` 到 `$_SERVER`,安全测试里这些东西天天见,这种基础错误一定别犯。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十三、$ 在安全场景里能干什么?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>很多。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>比如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如根据请求方法做判断:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”><?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "这是一个 POST 请求";
} else {
echo "这不是 POST 请求";
}
?>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果示例
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>这是一个 POST 请求
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这类判断在表单提交、接口鉴权、CSRF 防护逻辑里很常见。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十四、再看最常见的输入点:$_GET
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>进入 Web 安全后,$_GET 你会天天见。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>它的作用很简单:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>接收 URL 参数,或者接收 为 GET 的表单数据。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>先看最简单的方式。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><span style="color: black; background-color: #FF1493; font-weight: bold;”>如果你访问这样一个地址:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>http://127.0.0.1/test.php?name=admin&id=1
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>然后 PHP 里这样写:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>admin
1
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这说明:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这两个参数都被 $_GET 接收到了。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十五、GET 参数最明显的特点:会直接显示在 URL 上
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这也是它最经典的特征。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>http://127.0.0.1/test.php?user=admin&pass=123456
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>参数和值全部挂在问号后面,肉眼可见。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这意味着什么?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>意味着:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>比如账号密码、验证码、Token 这类东西,不应该裸奔在 URL 上。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十六、用表单演示 GET 传值,最直观
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>下面是一个简单的 HTML 表单页面:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果用户输入:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>123
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>点击提交后,浏览器地址栏通常会变成:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>receive.php?bcd=123
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>后端 .php 这样接收:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>123
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十七、GET 可以传多个参数
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>http://127.0.0.1/receive.php?a=123&b=456
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>接收代码:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>123
456
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>所以 GET 传参格式就是:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>?参数1=值1&参数2=值2&参数3=值3
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这是 Web 最基础的常识之一。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十八、为什么说 GET 不适合传密码?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>举个最直白的例子。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果登录表单用的是 GET:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>你输入账号密码后,地址栏可能会变成:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>login.php?username=admin&password=123456
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>虽然前端密码框显示的是黑点,但一提交,真实密码还是直接出现在 URL 里。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这就意味着:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>所以登录、支付、敏感操作,别用 GET 传关键字段。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>十九、POST 又是什么?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>POST 的作用和 GET 类似,也是接收提交的数据。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>区别在于:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>POST 的数据通常放在请求体里,不直接显示在 URL 上。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>先看表单:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>接收页面:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果输入:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>123
456
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这和 GET 一样能传值,但地址栏通常不会显示参数。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十、POST 为什么更适合敏感数据传输?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为它不会把数据直接挂在 URL 上。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如你提交后,地址栏可能还是:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>http://127.0.0.1/receive.php
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>而不是:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>receive.php?a=123&b=456
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>注意php num rows `$_GET`、`$_POST` 到 `$_SERVER`,安全测试里这些东西天天见,这里说的是不直接显示在 URL 上,不等于“绝对安全”。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果没有 HTTPS,数据仍然可能被中间人窃听。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>所以别把“POST”直接等同于“加密”。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十一、GET 和 POST 的区别,面试几乎必问
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这块你最好记熟。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>1)传输位置不同2)可见性不同3)适用场景不同4)长度限制不同5)接收方式不同
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这个千万别接错。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十二、自己给自己提交:$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>''
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>的常见写法
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>很多表单页面会这样写:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”><form action="" method="post">
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>意思就是:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>表单提交给当前页面自己处理
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如页面名叫 test.php,那它最终就相当于:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这种“自提交”写法很常见。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>完整示例:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<form action="" method="post">
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果输入:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>hello
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>运行结果
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>你提交的内容是:hello
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十三、前后端分离前,传统 PHP 项目就是这么交互的
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>很多老项目、CMS、后台系统,前端表单 + PHP 接收页,就是这么构成的。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>常见有两种模式:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>1. 同页面自提交
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>页面自己展示自己处理
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>2. 分页面处理
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>一个 HTML/PHP 页面负责发,一个 PHP 页面负责收
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这是很多漏洞练习环境、旧系统后台、历史业务系统的常见结构。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十四、静态 HTML 页面为什么相对难“打”?
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这个问题很多做安全的都会碰到。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>原因并不玄乎:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>也就是说,纯静态页面本身的可攻击面很小。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>真正有价值的目标,往往在后台处理逻辑那一层,也就是:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>换句话说:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>有交互,才更可能有漏洞。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十五、$_GET、$_POST 是输入点,输入点就必须做过滤
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这是 Web 安全最基本的原则之一。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>例如:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”><pre class="syl-page-code" style="background: #f0e0fa; color: #7c3aed; padding: 1.2em; border-radius: 8px; overflow-x: auto; margin: 1.6em 0; font-family: ‘JetBrains Mono’, Consolas, monospace; font-size: 14px; line-height: 1.6;”>
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果只是输出php num rows,看起来问题不大。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>但如果后面把它拼进 SQL、拼进文件路径、拼进命令执行,那风险就来了。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这就是为什么代码审计里,一看到:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>就要立刻提起精神。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>因为这些地方,都是外部可控输入。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十六、再提一下 $、$、$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>虽然今天重点不展开,但你至少要知道它们是干嘛的。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>处理文件上传
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>常见场景:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>接收客户端
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>常见场景:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>服务端会话数据
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>常见场景:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>二十七、做安全测试时,最值得盯住的超级全局变量
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>如果从攻击面角度看,优先盯这些:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>第一梯队:高危输入点第二梯队:环境信息、绕过辅助第三梯队:全局变量追踪二十八、常见踩坑点,提前给你避开1. 把函数内外变量当成默认互通
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>不是互通的,除非显式传参、、$
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>2. 用 GET 传密码
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>功能能跑,不代表设计合理
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>3. 把 POST 当加密
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>POST 只是“不显示在 URL”,不是天然加密
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>4. 迷信 和 User-Agent
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这些头很多都能伪造,不能当核心安全依据
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>5. 把 $
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>''
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>看成 IP
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这是非常低级但又真的有人会犯的错误
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>6. 直接信任 $_GET
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>'id'
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>输入点不校验,后面就是 SQL 注入、文件包含、命令执行、XSS 的温床
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>总结
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>PHP 的超级全局变量,不只是“会用几个名字”这么简单。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>它真正重要的地方在于:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>你如果想从“会写 PHP”往“看得懂 Web 逻辑、能做安全分析”迈一步,那这一块必须扎实。
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>最少要真正掌握这几件事:
<p style="margin: 1.25em 0; line-height: 1.9; font-size: 16px; color: #222222; text-align: justify; letter-spacing: 0.02em;”>这不是语法题,这是 Web 安全入门题。
1. 本站所有资源来源于用户上传和网络,如有侵权请联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系站长处理!
6. 本站不售卖代码,资源标价只是站长收集整理的辛苦费!如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
7. 站长QQ号码 2205675299
资源库 - 资源分享下载网 » php num rows `$_GET`、`$_POST` 到 `$_SERVER`,安全测试里这些东西天天见
常见问题FAQ
- 关于资源售价和售后服务的说明?
- 代码有没有售后服务和技术支持?
- 有没有搭建服务?
- 链接地址失效了怎么办?
- 关于解压密码

