源码:
<?php
if($_GET[id]){
mysql_connect('localhost:3306','root','');
mysql_select_db(ctf);
$id=intval($_GET[id]);
$query=@mysql_fetch_array(mysql_query("selectcontent from ctf2 where id='$id'"));
if($_GET[id]==1024){
echo"<p>no!tryagain</p>";
}
else{
echo($query[content]);
}
}
?>
函数释义:
intval()函数用于获取变量的整数值
intval()函数通过使用指定的进制 base 转换(默认是十进制),返回变量 var 的 integer 数值。intval() 不能用于 object,否则会产生E_NOTICE 错误并返回 1。
代码修改:
需要注意对源代码的修改如下,数据库相关信息需要进行替换:
mysql_connect('localhost:3306','root','');
mysql_select_db(ctf);
$id=intval($_GET[id]);
$query=@mysql_fetch_array(mysql_query("selectcontent from ctf2 where id='$id'"));
使用mysql_connect()方法建立与数据库的连接,并使用mysql_select_db()方法选择要操作的数据库
使用mysql_query()方法执行查询数据库的语句
mysql_fetch_array()函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有
返回根据从结果集取得的行生成的数组,如果没有更多行则返回false。
select contentfrom ctf2 where id='$id' 的意思是从ctf2的表中查询id号为1024的content字段值。
在数据库中添加对应的数据库ctf及数据表ctf2,添加进相关数据id=1024,content=123456,如下图所示:
解题过程:
当id=1024时访问链接:
http://localhost:63342/php_bugs-master/14%20intval%E5%87%BD%E6%95%B0%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5.php?id=1024
获取flag的条件:
$id=intval($_GET[id]);
if($_GET[id]==1024) 不满足
根据id在数据库中查询flag,具体链接如下:
http://localhost:63342/php_bugs-master/14%20intval%E5%87%BD%E6%95%B0%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5.php?id=1024.1
参考链接:
https://github.com/bowu678/php_bugs
https://blog.csdn.net/wangjian1012/article/details/51581564
https://www.runoob.com/php/func-mysqli-fetch-array.html
https://jingyan.baidu.com/article/e2284b2b2687b0a3e6118dd5.html