DVWA环境搭建
DVWA-1.0.7.ziphttp://IP:Port/dvwa/login.php。默认用户名 admin, 默认密码 password
什么是SQL注入
SQL注入是发生在应用程序数据库层的安全漏洞。简而言之,是输入的文本中注入SQL指令,在设计不良的程序当中忽略了检查,那么这些注入进去的指令就会被数据库服务器误认为是正常的SQL指令而执行,因此遭到破坏。
SQL注入类型
1.数字型注入
http://www.test.com/msg/test.php?myno=1'http://www.test.com/msg/test.php?myno=1 or 1=1http://www.test.com /msg/test.php?myno=1 and 1=2http://www.test.com/msg/test/php?myno=1 or'abc'='ab'||'c'
![fef492fe27e9cc321180285d884fa0a5.png](https://i-blog.csdnimg.cn/blog_migrate/cab92a1692f68e9a99455d87419b6898.jpeg)
2. 字符串注入
http://www.test.com/msg/test.php?mychar=aaaa'http://www.test.com/msg/test.php?mychar=aaaa' or'1'='1http://www.test.com /msg/test.php?mychar=aaaa' and'1'='2http://www.test.com/msg/test/php?mychar=aaaa' or'abc'='ab'||'c
![8f7a6cae1651370d090d5581d7ea1602.png](https://i-blog.csdnimg.cn/blog_migrate/1b585de372cf64949b065c3a76c9ffa3.jpeg)
3. 终止式SQL注入
![24dcf984198b0517094d0569a9249895.png](https://i-blog.csdnimg.cn/blog_migrate/8b2ce7c5db679770f224035b718e405a.jpeg)
SQL注入防范
- 使用绑定变量
- 使用存储过程
- 检查数据类型
- 使用安全函数
- ESAPI.encoder().encodeForSQL
OWASP防御方案,服务端输入校验和输出编码规则一:进入HTML标签HTML编码,& -> &ESAPI.encoder().encodeForHTML规则二:进入HTML属性值value,width,height等,编码单引号和双引号为HHESAPI.encoder().encodeForAttribute规则三:进入JavaScript中ESAPI.encoder().encodeForJavaScript规则四:进入CSS中ESAPI.encoder().encodeForCSS规则五:进入URL对特殊字符采用%HH编码ESAPI.encoder.encodeForURL