2017-2018-2 《网络对抗技术》20155322 Exp9 web安全基础


[-= 博客目录 =-]


1-实践目标

1.1-web安全基础

本实践的目标理解经常使用网络攻击技术的基本原理。Webgoat实践下相关实验。html

返回目录前端

1.2-实践内容

本实践的目标理解经常使用网络攻击技术的基本原理。Webgoat实践下相关实验。java

返回目录git

1.3-实践要求

  • 基础问题回答
    • SQL注入攻击原理,如何防护
    • XSS攻击的原理,如何防护
    • CSRF攻击原理,如何防护
  • 实验总结与体会
  • 实践过程记录
  • 报告评分 1.5分
    • 报告总体观感 0.5分
    • 报告格式范围,版面整洁 加0.5。
    • 报告排版混乱,加0分。
  • 文字表述 1分
    • 报告文字内容很是全面,表述清晰准确 加1分。
    • 报告逻辑清楚,比较简要地介绍了本身的操做目标与过程 加0.5分。
    • 报告逻辑混乱表述不清或文字有明显抄袭可能 加0分

返回目录github

2-实践过程

首先安装webgoat:
github地址
找最新的sever版本,我安装的是8.0.0.M15
在kali中安装,输入java -jar webgoat-server-8.0.0.M14.jar

安装以前check一下有没有安装Java和Tomcat。
新版本须要注册一个帐号,本身注册吧:

注册成功以后就可使用了:
web

2.1 HTML

下面咱们开始练习,查看到第一部分HTML,须要安装一个ZAP扫描器,咱们安装一下,反正是免费的:

安装Linux installer:

下载后是个sh文件,直接sh xxx.sh,安装完毕。

安装完成以后须要进行设置:
首先是zap->tools->options->local proxies,将端口改为8090;
而后是浏览器Firefox,进入preferences->advanced->network->connection->settings->Manual proxy configuration:

输入127.0.0.1->8090->勾选Use this proxy server for all protocols

注意,继续往下拉会有一个no proxy for选项,里面有127.0.0.1和localhost这两个东西,表示这两个地址不用代理,这确定是不行的,由于咱们的webgoat就是在这里通讯的,因此必定要把这俩删掉。

下面进行测试,咱们打开zap,点击标签页的“+”,新增一个break,进入general->http proxy->(5)Intercept and modify a request
咱们点开小绿点(具体怎么用教程里面会有,我就不赘述了),再点击网页上的submit:

按照要求修改拦截的HTTP报头:sql

  • Change the Method to GET
  • Add a header 'x-request-intercepted:true'
  • Change the input value 'changeMe' to 'Requests are tampered easily' (without the single quotes)

大概的意思就是,改成post方法,加一条x-request-intercepted:true,而后吧changeMe的值改为Requests are tampered easily,如图:
注意:数据库

  • 改post方法以后,changeMe变量会跑到URL中,你就得在URL中修改,因此建议先改第二项x-request-intercepted:true,就找个地方插进去。

  • 而后'Requests are tampered easily'没有空格和单引号,用+号链接,如changeMe=Requests+are+tampered+easily,正确的格式会让字符变成橙色(若是仍是post方法的话)
  • 作完以上以后再将method改为GET,这样就OK了,点击右上角的播放键(绿色的按钮)

成功的话如图:

这就是一个最简单的HTTP报头修改方法。
既然在这里用了代理,咱们在作一个使用代理的练习:Insecure Login
他的目的很简单,就是告诉咱们:浏览器

  • The user should have a basic understanding of packet sniffer usage
  • The user will be able to intercept and read an unencrypted requests

具体操做就是,点击小绿点,而后点网页的submit,而后ZAP就会把拦截的HTTP报头显示出来,成功的话以下:
安全

返回目录

2.2 Injection Flaws

下面是SQL注入时间。SQL注入通常的目的是:

  • 读取和修改数据库中的敏感数据
  • 执行数据库管理员操做
    • 关闭审计或DBMS
    • 截获表格和日志
    • 添加用户
  • 恢复DBMS文件系统中给定文件的内容
  • 列出操做系统的指令

下面是提供的两个例子:

#Potential String Injection    字符串型注入
"select * from users where name = '" + userName + "'";

#Potential Numeric Injection 字符型注入
"select * from users where employee_id = "  + userID;

更详细的例子,如攻击者注入:userName = Smith' or '1' = '1
那么服务器可能会执行:select * from users where name='Smith' or '1'='1'
至关于执行了一个永真式:select * from users where name='Smith' or TRUE
这样至关于把users表里面的全部数据都查询并输出了。

好的,说明结束,咱们开始作题:

String SQL Injection

The query in the code builds a dynamic query as seen in the previous example. The query in the code builds a dynamic query by concatenating strings making it susceptible to String SQL injection:
"select * from users where name = ‘" + userName + "'";
Using the form below try to retrieve all the users from the users table. You shouldn’t need to know any specific user name to get the complete list, however you can use 'Smith' to see the data for one user.
由题可知,查询SQL语句为:"select * from users where name = ‘" + userName + "'";,那么咱们应该设计一种永真式,使得查询的对象变成整个users表,须要注意的是构造注入的是字符串,个人构造以下:

成功!

Numeric SQL Injection

The query in the code builds a dynamic query as seen in the previous example. The query in the code builds a dynamic query by concatenating a number making it susceptible to Numeric SQL injection:
"select * from users where employee_id = " + userID;
Using the form below try to retrieve all the users from the users table. You shouldn’t need to know any specific user name to get the complete list, however you can use '101' to see the data for one user.
这里须要使用数字来构成注入,题干中提示,咱们可使用'101' to see the data for one user,因此个人构造以下:

成功!

SQL Injection (advanced)

这个题主要让咱们学会:Combining SQL Injection Techniques(组合注入)Blind SQL injection(盲注)
提示了咱们一些小诀窍:

#1 关于注释
/* */    are inline comments
-- , #   are line comments
Example: Select * from users where name = 'admin' --and pass = 'pass'

#2 关于多句查询
;        allows query chaining
Example: Select * from users; drop table users;

#3 关于字符串串接&无引用字符串
',+,||   allows string concatenation
Char()   strings without quotes
Example: Select * from users where name = '+char(27) or 1=1
//这个例子我不是很懂

下面看题:

Pulling data from other tables!

Lets try to exploit a join to another table. One of the tables in the WebGoat database is:

CREATE TABLE user_system_data (userid varchar(5) not null primary key,
                               user_name varchar(12),
                               password varchar(10),
                               cookie varchar(30));

6.a) Execute a query to union or join these tables.
6.b) When you have figured it out…​. What is Dave’s password?
两个提示,一个是用union查询,一个是找Dave’s password,由于是进阶,咱们分析的仔细一点:
首先,咱们根据建表信息,能够知道:

  1. 目标表名 user_system_data
  2. 目标列为 password
    咱们先输入一我的名 Smith,结果以下:

    这样大概是了解了查询语句是能够查的不是user_system_data表,仍是不够,继续试探,这里用一个语句试探被查的表有几列属性:order by

    ORDER BY 关键字用于对结果集按照一个列或者多个列进行排序。
    ORDER BY 关键字默认按照升序对记录进行排序。若是须要按照降序对记录进行排序,您可使用 DESC 关键字。

能够用ORDER BY的功能悄咪咪一波,构造注入:Smith’ order by 10--,这里为没认真看我前面提到的注释语句的同窗说明一下,--能够注释掉后面的密码输入部分。
发现报错:

说明这表的列数没超过10行,通过屡次试探,我发现,这个表一共有七列,关键信息!
有了这个信息,咱们可使用union查询了:

先解释一下什么叫union查询:UNION 操做符用于合并两个或多个 SELECT 语句的结果集。UNION 内部的每一个 SELECT 语句必须拥有相同数量的列。列也必须拥有类似的数据类型。同时,每一个 SELECT 语句中的列的顺序必须相同。

有点难读懂,反正就是查找某个表的某个东东的同时再查找另外一张表的某个东东。
构造:
Smith’ union select null,user_name,password,null,null,null,null from user_system_data
woc!失败了,我但是照着别人的教程作的呀!(哭)

失败的尝试:

Smith’ union select null,user_name,password,null,null,null,null from user_system_data; --
Smith’ union null,user_name,password,null,null,null,null from user_system_data; --
’ union select null,user_name,password,null,null,null,null from user_system_data; --
’ union select null,user_name,password,null,null,null,null from user_system_data--
……

我拜读了一下王一帆大佬的博客发现都差很少啊?
为啥他注成功了?(他博客里的表名都打错了)
这就很难受,最后只能不用union,直接用;的多条查询语句来进行注入:'; select * from user_daa_system; --

成功!

Have fun!:

We now explained the basic steps involved in an SQL injection. In this assignment you will need to combine all the things we explained in the SQL lessons.

这道题是一个登录&注册界面,没有任何提示,这波思路,先试试一个不存在的用户看看他是怎么回复的:


嗯,好像没有任何信息,那咱们试试构造一个字符串注入:' or '1' = '1' --


依旧失败,这边找不到思路,咱们去注册那边试试:



而后咱们再使用同一条信息注册:

显示已经注册过,那么他是根据什么判断的呢?我试试同一个用户名不一样的其余信息:

能够看到我输入的信息,除了用户名同样其余都不同,结果为:

没错,他是根据username_reg这个东西查询的,那么咱们构造一个永真试试能不能获得什么信息:构造retest_01′and ’1′=’1
会提示建立成功(那张图找不到了)……
而后咱们再使用retest_01′and ’1′=’1会提示:

咱们使用retest_01′and ’1′=’2注意!有变化,而后提示:

啧啧啧,看来果真是个盲注。

何为盲注?盲注就是在sql注入过程当中,sql语句执行的选择后,选择的数据不能回显到前端页面。此时,咱们须要利用一些方法进行判断或者尝试,这个过程称之为盲注。

盲注分为三类

  • 基于布尔SQL盲注
  • 基于时间的SQL盲注
  • 基于报错的SQL盲注

这里就不一一赘述,看这篇博客MYSQL注入天书之盲注讲解
在一片博客上看了一个布尔SQL盲注:
reborn' AND 1088=1088 AND 'DMXO'='DMXO
试了一下,能够用来注册,可是没研究出来怎么登陆,这个之后解决?如今太菜了……

返回目录

2.3 XSS

返回目录

2.4 CSRF

返回目录

2.5 基础问题回答

  • SQL注入攻击原理,如何防护
    原理:向Web应用程序输入一段精心构造的SQL查询指令,攻击和利用不完善的输入验证机制,使得注入代码得以执行完成非预期的攻击操做。
    防范:输入过滤、参数化sql语句或直接使用存储过程、提供更少的错误信息
  • XXS攻击原理,如何防护
    原理:因为Web应用程序的输入验证机制不完善,攻击者在服务器端网页中插入一些恶意的客户端代码,在Web服务器上产生出一些恶意攻击页面。
    防范:输入验证、输出净化(对HTML标签进行转义)、消除危险输入点。提高客户端浏览器安全性。
  • CSRF攻击原理,如何防护
    原理:攻击者盗用用户身份,伪造恶意请求发送给服务器,完成预期操做。
    防护:经过referer、表单令牌token或验证码来检测用户提交、避免全站通用的cookie,严格设置cookie的域、不用在页面连接中暴露用户隐私信息。

返回目录

3-参考资料&实践体会

实践体会

此次实验综合性比较强啊,写的较慢……

参考资料

相关文章
相关标签/搜索