【实验目的】
1)理解SQL注入的原理
2)学习手工注入的过程
【实验原理】
所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。
首先,在以【.asp?id=32(数字任意)】结尾的链接依次添加语句【'】、【and 1=1】和【and1=2】,来判断网站是否存在注入点。
然后,添加语句【and exists(select * from admin)】,根据页面返回结果来猜解表名。
再次,添加语句【and exists(select admin from admin)】,来猜解admin表中的列名admin。
最后,添加语句【and (select top 1 len (admin) from admin)>1】,来猜解字段长度;添加【and (select top 1asc(mid(admin,1,1)) from admin)>97】,来猜解字段中字符的ASCII码。
通过以上四个步骤,反复猜解,即可得到数据库存储的用户名和密码。
【实验步骤】
一、找到有注入漏洞的目标网站
1.1目标站点:
1.2测试链接,在链接末尾添加【'】
1.3在链接末尾添加【 and 1=1】
1.4在链接末尾添加【and 1=2】 由以上测试结果可知:该网站存在注入漏洞。
二、猜解表名 2.1在链接末尾添加语句【and exists(select * from admin)】,页面正常显示,说明存在表名【admin】如图5所示。
三、猜解列名 3.1在连接末尾添加语句【and exists(select admin from admin)】,页面显示正常,即在表中存在admin列
3.2同样的方法,在链接末尾添加【and exists(select password from admin)】,页面显示正常,说明存在列password
四、猜测字段内容 4.1猜测字段的长度,在连接末尾输入语句【and (select top 1 len (admin) from admin)>1】,页面显示正常,数字依次加1,进行测试,如【and (select top 1 len(admin) from admin)>5】,说明字段长度为5
4.2同样的方法,在链接末尾添加连接【and (select top 1asc(mid(admin,1,1)) from admin)>97 】,可猜解出第一条记录的第一位字符的ASCII码为97,对应a
4.3同样的方法可以得到admin内容为【admin】,password内容为【bfpms】。
|