【安全牛学习笔记】基于PHP的SQL注入漏洞原理及解决办法

这篇博客探讨了基于PHP的SQL注入漏洞原理,详细分析了如何利用冯·诺依曼体系结构的特性进行攻击。文章展示了如何通过未经过滤的用户输入直接构造SQL语句,从而对数据库造成危害,包括数据篡改和系统文件读取等。作者还列举了漏洞的危害级别,并提供了避免和修复此类漏洞的方法,如数据转义、使用PDO进行预编译等。此外,文章提及了Security+认证在信息安全领域的价值,特别是对于IT运维人员的职业发展和提升。
摘要由CSDN通过智能技术生成

基于PHP的SQL注入漏洞原理及解决办法

----------------------------------------------------------------------

[mysqlDriver]

<?php

//this file is the entry

error_erporting(E_ALL);

//include files

include 'conf.php';

include 'functions.php';

include 'actions.php';

include 'models.php';

STRACE_LOG = array();

if($action = $_REQUEST['action'] and funciton_exists($action."Action")){

       call_user_func($action.'Action');

}else{

       error('action not exists');

}

-----------------------------------------------------------------------

root@w:~# service apache2 status

Apache2 is runing (pid 7970).

root@w:~# service mysql status

[info] /usr/bin/mysqladmin  ver 8.42 Distib 5.5.40, for debian-linux-gnu on i686

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All right reserved.

Oracle is a registere trademark of Oracle Corportion and/or its

affiliates.Other name may be trademarks of their respective owers.

Server version         5.5.40-0+wherezy-log

Protocol version       10

Connection             Localhost via UNIX socket

UNIX socket            /var/run/mysql/mysqld.sock

Uptime:                3 hours 47 min 40 sec

Threads: 1  Qestions: 1271  Slow queries: 0  Opens: 457  Flush tables: 1 Open

tables: 50  Qestions per second avg: 0.093

root@w:~# php -v

PHP 5.4.36-0+deb7ul (cli) (built: Dec 31 2014 08:33:05)

Copyright (c) 1997-2014 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

www-data@w:~$ vim conf.php

<?php

//here is configure file for framework

define('DSN','mysql:host=localhost;dbname=secruity' );

define('DBHOST','127.0.0.1');

define('DBUSER','root');

www-data@w:~$ vim mysqlDriver.php

<?php

//this file is for mysql connection;

class mysql{

    public $conn = null;

    public function musql($table){

        $this->conn = mysql_connect(DBHOST,DBUSER,DBPASS);

        mysql_select_db($table);

    }

}

class mysqlPDO{

    public $conn;

    public function mysqlPDO(){

        try{

            $pdo = new PDO(DSN,DBUSER,DBPASS);

            $this->conn = $pdo;

        }catch(PDOException $e){

            error('error:'.$e);

        }

    }

}

-----------------------------------------------------------------------


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值