URL攻击:顾名思义,就是利用URL来进行攻击,攻击方式就是更改地址栏中的$_GET的参数,另外进行一些必要的猜测,比如以下面的URL为例:

http://www.myfreax.com/category.php?category=mysql3

攻击者可以了更改后面的参数mysql3的数值,进行猜测,或者结合一些其它的手段,我所知道有两个个Linux发行版专做攻击工具的,和测试的,非常强大,都是基于ubuntu制作的,

BackTrack  #这个曾经在我学习Linux是安装过,专门用来攻击和渗透
blackbox Linux  #这个就没有使用过了

下面就是实例了,:

<?php
    /**
     * 
     *  @author Freax
     *  @2014-3-24
     *  @contact  huangyanxiong2013@gmail.com
     * 
     */
    define('FREAX', true);
    require_once 'include/init.php';
    'http://www.myfreax.com/category.php?category=PHP5';//正常url是这样的 
    class category{
        /**
         * 数据库      对象
         * @var Object
         */
        public $db;
        /**
         * smarty 对象
         * @var Object
         */
        public $smarty;
        /**
         * 地址  指向需要显示的页面
         * @var String
         */
        public $action;
        /**
         * 分页类
         * @var Object
         */
        public $Page;
        /**
         * 缓存id
         * @var string
         */
        public $cacheid;
        /**
         * 初始化
         * @var String
         */
        public function __construct($db,$smarty,$page){  //做完这个函数就是将页面显示出来
            $this->db=$db;
            $this->smarty=$smarty;
            $this->Page=$page;
            $this->getAtion();
            $this->getData();
            $this->display();
        }
        /**
         * 获取地址    这个是非常关键的这里做的不得好也是攻击的机会
         * 在在这个函数中,由于我只想获取到的是一个数字其它都是不要的,所以要将其它过滤
         */
        public function getAtion(){
            $bool=preg_match_all('/\d+/', $_SERVER['QUERY_STRING'],$match);
            /* 如果按照我正常些的url来执行的话,根本就不要这个判断,也可以正常执行,
             * 但是有意的人就会尝试更改这些参数 ,这里我需要获取到数据库分类的id,
             * 并且使用这个id查询数据,难免不会受到sql攻击的,所以有这个判断*/
            if (!$bool) {
                header("HTTP/1.1 301 Moved Permanently");   //攻击者更改参数后你将重定向404,或者其它相对安全的页面,不过建议还是重定向404静态页面,
                                                            //我这里是首页,因为我首页是不接受任何参数的
                header("location:http://".WEB);
                exit();   //记得要退出不然重定向后还是会执行的,因为php解释器没有看到结束标签\?\>
            }else {
                $this->action=$match[0][0];
            }
        }
        /**
         * 获取缓存id
         * @return string
         */
        public function getcacheid(){
            $this->cacheid=(isset($_GET['category'])?$_GET['category']:'').@(isset($_GET['page'])?$_GET['page']:'');
            return $this->cacheid;
        }
        /**
         * 根据地址 获取对应的数据
         * 根据地址判断smarty是否有缓存
         * 没有缓存区数据库获取
         * 赋值给模板
         */
        public function getData(){
            /* 这里根据cacheid判断是否存在缓存,如果没有缓存则从数据库中获取数据 ,由于cacheid在客户端也是可以更改的,
             * http://www.myfreax.com/category.php?category=PHP2&page=23 这个url就是很形的了,一个是分类,一个是页数,
             * 客户端可以随意更改页数,cacheid永远不同,生成的缓存,也会增多,只要来个循环,就生成N的文件缓存
             * 为什么我这里可以随意更改$_GET参数都不会参数,都可以执行,因为$article=$this->db->selectArrs。。。。。。。。。。。。这个语句来说,即使没有从数据库中获取到数据也会返回空数组*/
            if (!$this->smarty->isCached('index.html',$this->getcacheid())){
                $nav=$this->db->selectArrs('select * from '.PREFIX.'class');
                $this->Page->getTotalPageClass($this->db,PREFIX.'article','typeid',$this->action);
                $this->Page->getcurrPage();
                $this->Page->getStartPage();
                $article=$this->db->selectArrs('select  '.PREFIX.'article.*,'.PREFIX.'class.name from '.PREFIX.'article left join blog_class  on ('.PREFIX.'article.typeid='.PREFIX.'class.id)   where typeid= '.$this->action.' order by  id desc  limit '.$this->Page->startPage .','. $this->Page->paging);
                /* 所以这里就加上一个断
                 *  */
                if (!$article) {
                    header("HTTP/1.1 301 Moved Permanently");
                    header("location:http://".WEB);
                    exit();
                }
                $this->Page->getLinkPage('category.php');
                $this->Page->getClassPage($article[0]['name'].$article[0]['typeid']);
                $pagelink=$this->Page->createPageLinks();
                $navAtcion=@$article[0]['name'];
                $this->smarty->assign('articles',$article);
                $this->smarty->assign('navs',$nav);
                $this->smarty->assign('navAction',$navAtcion);
                $this->smarty->assign('pagelink',$pagelink);
                }
            }
        /**
         *  返回给前可以对模板进行一些操作
         *  将数据返回给用户
         */
        public function display(){
            $this->smarty->display('index.html',$this->getcacheid());
        }
    }
    /**
     * 实例化category类
     */
    new category($db,$smarty,$page);
?>