本實踐的目標理解經常使用網絡攻擊技術的基本原理。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
試了一下,能夠用來註冊,可是沒研究出來怎麼登陸,這個之後解決?如今太菜了……
此次實驗綜合性比較強啊,寫的較慢……