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

1-实践目标

1.1-web安全基础

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

返回目录

1.2-实践内容

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

返回目录

1.3-实践要求

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

返回目录

2-实践过程

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

安装之前check一下有没有安装Java和Tomcat。
新版本需要注册一个账号,自己注册吧:

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

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报头:

  • 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-参考资料&实践体会

实践体会

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

参考资料

posted @ 2018-05-30 07:40  blackay03  阅读(519)  评论(0编辑  收藏  举报
Live2D
*/