zoukankan      html  css  js  c++  java
  • 数字验证正则绕过

    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:] [ ]
    [: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

  • 相关阅读:
    redis改配置
    redis主从复制
    nginx做维护页面
    go_http
    DRF源码-views.py
    DRF教程10-关系字段
    语言特性
    DRF源码-fields.py
    python_@classmethod
    HTML5:定位
  • 原文地址:https://www.cnblogs.com/observering/p/12833596.html
Copyright © 2011-2022 走看看