//1. ‘ or ”=’ (不成功)
//2. ‘ or ”=” or ”='(成功)
//3. ‘ or ”=”#(能够)
//4. ‘ or 1=1#(能够)
//5. ‘ or 1=1;delete from bbs_user where qx=2;#(能够, 可是mysql_query()每次只能执行一个SQL语句)php
select * from users where id = 1 or ”=”
where 1=1;
$str = “”=””;
echo $str;mysql
//sql语句的拼装(将用户输入的内容当成了sql语句格式的一部分)
// $sql = “select username, password from bbs_user where username={$username} and password ={$password}”;sql
// pdo (预处理: 防sql注入, 将内容和sql语句分开)
// $sql = “select username, password from bbs_user where username=? and password =?”;数据库
举例说明:服务器
3.1 create database spdb;测试
--建立一张用户表spa
create table users (pdo
id int primary key auto_increment; --id号开发
username varchar(64) unique not null, --用户名rem
password varchar(64) not null,--密码
email varchar(64) not null)
--添加两个测试用户
insert into users (username,password,email) values('shunping','shunping','shunping@sohu.com');
insert into users (username,password,email) values('xiaoming','xiaoming','xiaoming@sohu.com');
php项目默认应当防在 htdos目前
Login.php
LoginCl.php
ManageUsers.php
对应咱们的php初学者,咱们写
① $sql="select * from users where username='$username' and password='$password'";
5.1
使用万能密码: bb' or 1='1
使用万能用户名 xx' union select * from users/*
② $sql="select * from users where username=$username and password=$password";
这种写法,没有’’ ,咱们的mysql数据库会把你的输入当作 数字对待
使用万能密码
33 union select * from users;
使用万能用户名:
33 union select * from users/*
select * from users where username=89 union select * from users/* and password=90;
① 在服务器中 magic_quotes_gpc 设置on,在php.ini文件中修改
$sql="select * from users where username='$username' and password='$password'"; 的万能密码和用户名就失效.
② 在服务器中 magic_quotes_gpc 设置on,在php.ini文件中修改
$sql="select * from users where username=$username and password=$password"; 的万能密码和用户名仍是能够攻击.
☞ 当咱们的magic_quotes_gpc设置成on后,服务器就会对全部的 ‘ 加入 \转义
name=’lll’ 当数据库执行 name=\’111\’ 高手 char()
7.1 密码比对
思想: 首先经过用户输入的用户名去查询数据库,若是查询到这个用户对应的密码,则和用户提交的密码比对,相同则说明该用户合法. 反之,则说明该用户非法
8.1 在php.ini文件中启用pdo
extension=php_pdo_mysql.dll 前面的;去掉便可.