數字驗證正則繞過


0x01

<?php
error_reporting(0);
$flag = 'flag{test}';
if ("POST" == $_SERVER['REQUEST_METHOD']){
	$password = $_POST['password'];
//1、正則匹配,[:graph:]為任意字符,要求password長度超過12
	if (0 >= preg_match('/^[[:graph:]]{12,}$/', $password)){
		echo 'flag';
		exit;
}
while (TRUE){
//2、password中必須包含標點符號,數字,大寫字母,小寫字母,並且檢測次數要超過6次
	$reg = '/([[:punct:]]+|[[:digit:]]+|[[:upper:]]+|[[:lower:]]+)/';
	if (6 > preg_match_all($reg, $password, $arr))
		break;
//c為字符種類,
	$c = 0;
	$ps = array('punct', 'digit', 'upper', 'lower'); 
	//[[:punct:]] 任何標點符號 [[:digit:]] 任何數字 [[:upper:]]任何大寫字母 [[:lower:]] 任何小寫字母
//標點符號,數字,大寫字母,小寫字母,包含3種以上繞過
	foreach ($ps as $pt){
		if (preg_match("/[[:$pt:]]+/", $password))
			$c += 1;
	}
	if ($c < 3) break;
//>=3,必須包含四種類型三種與三種以上
//4、弱類型比較,42abc,強制轉換為數字
	if ("42" == $password) echo $flag;
	else 
		echo 'Wrong password';
	exit;
}
}
?>

preg_match()

定義:

  • 執行一個正則表達式匹配

語法:preg_math(pattern,string,matches,flags)

  • pattern,必需,要搜索的模式
  • string,必需,輸入的字符串
  • 返回pattern的匹配次數,0次(不匹配)或1次,匹配成功第一次就會停止搜索。

preg_match_all()

與preg_match的區別:

  • 返回匹配完整次數(可能是0),或者發生錯誤后返回FALSE,匹配完整個字符串。
名字 ASCII
[:alnum:] [a-zA-Z0-9]
[:alpha:] [a-zA-Z]
[:ascii:] [\x00-\x7F]
[:blank:] [ \t]
[:digit:] [0-9]
[:graph:] [\x21-\x7E]
[:punct:] [!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]
[:lower:] [a-z]
[:upper:] [A-Z]
[:word:] [A-Za-z0-9_]
[:xdigit:] [A-Fa-f0-9]

0x02 繞過

//post傳值:
//滿足條件的都可以

flag=42aaaaaaa.aaA2aaa
flag=42aaaaabb.cccC

//post傳入一個空值也輸出flag

password=
flag=

參考鏈接:
https://www.cnblogs.com/Jordandan/p/11211729.html
https://blog.csdn.net/destiny1507/article/details/100926454
https://www.cnblogs.com/chrysanthemum/p/11704812.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM