php黑魔法
@ Zhang zhiyang · Monday, Jan 1, 0001 · 2 minute read · Update at Monday, Jan 1, 0001

php的一些语法漏洞

0x00 比较符号

==

执行关系运算时要求运算符两边的数据类型必须一致,强制转换数据类型 数字转换规则:

  • 若字符串以数字开头,则取开头数字作为转换结果,若无则输出0
  • 若字符串形如(1e8),转换为科学计数法1*10^8
  • 若字符串是任意进制整数,转换为十进制整数
$num=$_GET['num'];//?num=1abc
if(!is_numeric($num)){
echo $num;
if($num==1)
echo 'flag{**********}';
}
<?php //输入什么都成立
$a=$_GET['a'];  
if ($a==0){echo "1";}

===

<?php
if (isset($_GET['name']) and isset($_GET['password'])){
    if ($_GET['name'] == $_GET['password']){
        print 'Your password can not be your name.';
    }//判断全等于操作符2边的数据类型是否相同 如果不相同,则返回false
     //判断全等于操作符2边的值是否相等,如果不相等,则返回false
    else if (sha1($_GET['name']) === sha1($_GET['password'])){
        die('Flag: '.$flag);//使用数组?name[]=1&password[]=2,俩边都是数组为Flase,相等
    }
    else{print 'Invalid password';}
}

0x01 函数

strcmp()

<?php
$password="***************";
if(isset($_POST['password'])){ //strcmp函数,比较俩个字符串
     if (strcmp($_POST['password'], $password) == 0){ //传值用数组password[]=1,绕过
          echo "Right!!!login success";
    }else{echo "Wrong password..";}
}

ereg()

<?php
if (isset ($_GET['password'])) {
	if (ereg("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE){	
		echo '<p>You password must be alphanumeric</p>';
	} //ereg()存在%00截断漏洞
	else if (strlen($_GET['password']) < 8 && $_GET['password'] > 9999999){
		if (strpos ($_GET['password'], '*-*') !== FALSE){
			die('Flag: ' .$flag);
		}//使用科学计数法绕过strpos(),?possword=1e9%00*-*
		else{echo('<p>*-* have not been found</p>');}
	}
	else{echo '<p>Invalid password</p>';}
}

is_numeric()

<?php
$a=$_GET['a'];
$b=$_GET['b']; //当有两个is_numeric判断并用and连接时,and后面的is_numeric可以绕过
$c=is_numeric($a) and is_numeric($b); //先执行$c=is_numeric($a)得真
if($c){ //然后执行is_numeric($a) and is_numeric($b),但是这时候$c已经被赋值为真了
	echo 'success';
}

算法

MD5

<?php
$a = $_GET['a']; 
$b = $_GET['b']; 
if ($a != $b){  //利用==符号的强制转换原理
    if (md5($a) == md5($b)){ //s878926199a   s155964671a   s214587387a
        echo '666';
    } 
}

Sha1

<?php
$a = $_GET['a']; 
$b = $_GET['b']; 
if ($a != $b){  //aaroZmOk  aaK1STfY  aaO8zKZF
    if (sha1($a) == sha1($b)){
        echo '666';
    } 
}
php
Save as image
Zhang zhiyang's blog
不过是些许风霜罢了
c cyber http linux math mysql php python 前端

© 2016 - 2022 Zhangzhiyang的博客

Powered by Hugo with theme Dream.

我听别人说这世界上有一种鸟是没有脚的,它只能够一直的飞呀飞呀,飞累了就在风里面睡觉,这种鸟一辈子只能下地一次,那一次就是它死亡的时候。

日程

Zhangzhiyang的 ❤️ 博客

其他

如果你喜欢我的开源项目或者它们可以给你带来帮助,可以赏一杯咖啡 ☕ 给我。~

If you like my open source projects or they can help you. You can buy me a coffee ☕.~

PayPal

https://paypal.me/g1eny0ung

Patreon

Become a Patron!

微信赞赏码

wechat

最好附加一下信息或者留言,方便我可以将捐助记录 📝 下来,十分感谢 🙏。

It is better to attach some information or leave a message so that I can record the donation 📝, thank you very much 🙏.