本实践的目标理解经常使用网络攻击技术的基本原理。Webgoat实践下相关实验。html
返回目录前端
本实践的目标理解经常使用网络攻击技术的基本原理。Webgoat实践下相关实验。java
返回目录git
返回目录github
首先安装webgoat:
github地址
找最新的sever版本,我安装的是8.0.0.M15
在kali中安装,输入java -jar webgoat-server-8.0.0.M14.jar
安装以前check一下有没有安装Java和Tomcat。
新版本须要注册一个帐号,本身注册吧:
注册成功以后就可使用了:
web
下面咱们开始练习,查看到第一部分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
大概的意思就是,改成post方法,加一条x-request-intercepted:true,而后吧changeMe的值改为Requests are tampered easily,如图:
注意:数据库
成功的话如图:
这就是一个最简单的HTTP报头修改方法。
既然在这里用了代理,咱们在作一个使用代理的练习:Insecure Login
他的目的很简单,就是告诉咱们:浏览器
具体操做就是,点击小绿点,而后点网页的submit,而后ZAP就会把拦截的HTTP报头显示出来,成功的话以下:
安全
下面是SQL注入时间。SQL注入通常的目的是:
下面是提供的两个例子:
#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表里面的全部数据都查询并输出了。
好的,说明结束,咱们开始作题:
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表,须要注意的是构造注入的是字符串,个人构造以下:
成功!
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,因此个人构造以下:
成功!
这个题主要让咱们学会: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 //这个例子我不是很懂
下面看题:
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,由于是进阶,咱们分析的仔细一点:
首先,咱们根据建表信息,能够知道:
目标列为 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; --
成功!
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语句执行的选择后,选择的数据不能回显到前端页面。此时,咱们须要利用一些方法进行判断或者尝试,这个过程称之为盲注。
盲注分为三类
这里就不一一赘述,看这篇博客MYSQL注入天书之盲注讲解
在一片博客上看了一个布尔SQL盲注:
reborn' AND 1088=1088 AND 'DMXO'='DMXO
试了一下,能够用来注册,可是没研究出来怎么登陆,这个之后解决?如今太菜了……
此次实验综合性比较强啊,写的较慢……