preg_match函数是PHP中用于正则表达式匹配的函数。它的语法如下:
preg_match($pattern, $subject, $matches);其中,pattern表示需要匹配的正则表达式,subject表示需要被匹配的字符串,
matches是可选参数,如果存在,它将被填充为匹配到的结果数组。matches[0]包含整个正则表达式的匹配结果,
例如,如果要匹配一个字符串中是否包含数字,可以使用以下代码:
$string = 'abc123def';
if (preg_match('/\d+/', $string, $matches)) {
echo 'Match found: '.$matches[0];
} else {
echo 'No match found';
}输出结果为:
Match found: 123preg_match函数还有很多其他的用法,可以根据需要查看PHP官方文档。


flag In the variable ! <?php
error_reporting(0);
include "flag1.php";
highlight_file(__file__);
if(isset($_GET['args'])){
$args = $_GET['args'];
if(!preg_match("/^\w+$/",$args)){
die("args error!");
}
eval("var_dump($$args);");
}
?>审计源码
flag In the variable ! <?php
error_reporting(0);
include "flag1.php"; 引入flag1.php文件代码
highlight_file(__file__);
if(isset($_GET['args'])){ // 通过get方式传递 args变量才能执行if里面的代码
$args = $_GET['args'];
if(!preg_match("/^\w+$/",$args)){ // 这个正则表达式的意思是匹配任意 [A-Za-z0-9_] 的字符,就是任意大小写字母和0到9以及下划线组成
die("args error!");
}
eval("var_dump($$args);"); //此函数显示一个或多个表达式的信息,包括表达式的类型与值
}
?>根据!preg_match("/^\w+
使用GLOBALS得到全部变量
http://114.67.175.224:13724/?args=GLOBALS
得到flag:flag{a2b1e8779b922f41eca71bafb2029390}