title: W3AF身份認證
date: 2016-09-05 11:16
tags: Kali滲透測試 Web滲透測試
0x00 W3AF簡介
無論是Httrack,Nikto,Vega還是skipfish都是比較輕量級的tools。Web Application Attack and Audit Framework,基于Python編寫的Web滲透測試框架,此框架的目標是用來發現
和利用
所有WEB應用程序bug。
不同于,nikto,vega,這些都是個別的大牛一時興起而寫出來的,畢竟個人的能力是有限的,所以很有可能這些工具也只是停留在一個版本就絕跡了,而w3af是基于開源的,所以它的生命周期會更長。
現在w3af一共覆蓋了9個大類近150個plugin:
audit:審計,在該組件下,集成了大量的web掃描工具。
infrastructure:基礎架構,主要用來掃描服務器的banner等基本信息。
grep:被動掃描類型。
evasion:逃避,主要是用來逃避目標的IDS,IBS的檢測。
mangle:主要是基于正則表達式的信息替換,比如注入,代碼修改。
auth:基于表單的身份認證。
brutefoece:暴力破解。
output:對掃描出來的結果輸出為特定的文件。
crawl:爬網,比如web spider,爬網爬得越全,那么發現漏洞的可能行越大。
attack
其實attack算是w3af中的第十類,但是不同與前九個,attck模塊不能人為的進行配置的,所有的攻擊的方法都是固定的,使用者無法修改。
0x01 原生安裝 w3af
測試Kali自帶w3af
在Kali Rolling上測試自帶w3af失敗。
殺死所有有關w3af的進程:
root@kali:~# ps -aux | grep -n w3af
root@kali:~# kill -9 8362 8437 9943 9945 9946 9949 10086
安裝步驟
在主目錄里實現源碼下載和安裝等相關步驟:
$ cd ~
更新update源:
apt-get update
安裝pip以及w3af
apt-get install -y python-pip w3af
升級pip:
pip install --upgrade pip
通過 github clone w3af 源代碼 :
git clone https://github.com/andresriancho/w3af.git
等待w3af源代碼下載完成,然后進入w3af目錄:
$ cd w3af
./w3af_console (./w3af.gui)
提示,需要安裝相關依賴:
$ apt-get install python-dev libxml2-dev libxslt1-dev zlib1g-dev
$ apt-get build-dep python-lxml
然后,可以使用pip或者運行替換腳本安裝w3af的相關依賴:
$ ./tmp/w3af_dependency_install.sh
#$ pip install pyClamd==0.3.15 PyGithub==1.21.0 GitPython==0.3.2.RC1 nltk==3.0.1 chardet==2.1.1 tblib==0.2.0 futures==2.1.5 ndg-httpsclient==0.3.3 pyasn1==0.1.8 lxml==3.4.4 scapy-real==2.2.0-dev guess-language==0.2 msgpack-python==0.4.4 python-ntlm==1.0.1 Jinja2==2.7.3 markdown==2.6.1 psutil==2.2.1 mitmproxy==0.13 ruamel.ordereddict==0.4.8
升級w3af
root ~ cd w3af
root ~ w3af git pull
創建w3af快捷方式
Linux下的快捷方式文件都是已 .desktop
結尾的。
首先將 Kali 自帶的 w3af 的快捷方式 copy 到桌面
$: cp /usr/share/applications/w3af.desktop /root/Desktop
然后打開 w3af.desktop 文件
root ~ cd Desktop
root ~ Desktop vim w3af.desktop
[Desktop Entry]
Name=w3af
Encoding=UTF-8
Exec=sh -c "/root/w3af/w3af_gui" <---修改為最新安裝的 w3af_gui 啟動路徑
Icon=kali-w3af.png
StartupNotify=false
Terminal=false
Type=Application
Categories=03-webapp-analysis;
X-Kali-Package=w3af
保存退出 vim,回到 desktop 為w3af.desktop 添加運行權限
root ~ Desktop chmod u+x w3af.desktop
w3af有兩種啟動方式,console和GUI啟動.
0x02 w3af_console 使用簡介
help命令
help
可以查看w3af當前模塊下可用的命令
root ~ w3af ./w3af_console
w3af>>> help
|----------------------------------------------------------------------------|
| start | Start the scan. |
| plugins | Enable and configure plugins. |
| exploit | Exploit the vulnerability. |
| profiles | List and use scan profiles. |
| cleanup | Cleanup before starting a new scan. |
|----------------------------------------------------------------------------|
| help | Display help. Issuing: help [command] , prints more |
| | specific help about "command" |
| version | Show w3af version information. |
| keys | Display key shortcuts. |
|----------------------------------------------------------------------------|
| http-settings | Configure the HTTP settings of the framework. |
| misc-settings | Configure w3af misc settings. |
| target | Configure the target URL. |
|----------------------------------------------------------------------------|
| back | Go to the previous menu. |
| exit | Exit w3af. |
|----------------------------------------------------------------------------|
| kb | Browse the vulnerabilities stored in the Knowledge Base |
|----------------------------------------------------------------------------|
plugins模塊
plugins
功能下共有九個可供選擇的掃描模塊。
比如:
w3af/plugins>>> audit xss sqli lfi
代表選擇同時 audit
下的 xss
,sqli
和 lfi
掃描功能。
當然也可以指定 audit
下的所有功能
w3af/plugins>>> audit all
確定選擇以后,各個 功能 對應的 status 將會啟動。
w3af/plugins>>> crawl spider_man
w3af/plugins>>> back
選擇完成以后使用 back
返回上一級目錄。
profile
我們可以就將所選的 plugins
下的配置通過 profile
保存,方便下次直接調用。
w3af>>> profiles save_as myScanProfile
Profile saved.
使用 profile
w3af/profiles>>> use fast_scan
w3af 的全局設置
http-settings
w3af>>> http-settings
w3af/config:http-settings>>> view
|----------------------------------------------------------------------------|
| Setting | Value | Modified | Description |
|----------------------------------------------------------------------------|
| url_parameter | | | URL parameter |
| | | | (http://host.tld/path;<parameter>) |
| timeout | 0 | | HTTP connection timeout |
| headers_file | | | HTTP headers filename which |
| | | | contains additional headers to be |
| | | | added in each request |
|----------------------------------------------------------------------------|
| cookie_jar_file | | | Cookie Jar file holding HTTP |
| | | | cookies-指定一個包含cookies信息的文件 |
| ignore_session_cookies | False | | Ignore session cookies |
|----------------------------------------------------------------------------|
| ntlm_auth_url | | | NTLM authentication domain (target |
| | | | domain name) |
| ntlm_auth_user | | | NTLM authentication username |
| ntlm_auth_passwd | | | NTLM authentication password |
| ntlm_auth_domain | | | NTLM authentication domain |
| | | | (windows domain name) |
|----------------------------------------------------------------------------|
| rand_user_agent | False | | Use random User-Agent header 使用能夠隨機的user-agent |
| max_file_size | 400000 | | Maximum file size |
| max_http_retries | 2 | | Maximum number of HTTP request |
| | | | retries |
| user_agent (默認agent為w3f,不建議使用默認值) | w3af.org | | User Agent header |
| max_requests_per_second | 0 | | Maximum HTTP requests per second |
|----------------------------------------------------------------------------|
| string_match_404 | | | Tag HTTP response as 404 if the |
| | | | string is found in it's body |
| always_404 | | | Comma separated list of URLs which |
| | | | will always be detected as 404 |
| | | | pages |
| never_404 | | | Comma separated list of URLs which |
| | | | will never be detected as 404 |
| | | | pages |
|----------------------------------------------------------------------------|
| proxy_port (支持外部代理) | 8080 | | Proxy TCP port |
| proxy_address | | | Proxy IP address |
|----------------------------------------------------------------------------|
| basic_auth_user (w3af的基本認證信息) | | | Basic authentication username |
| basic_auth_passwd | | | Basic authentication password |
| basic_auth_domain | | | Basic authentication domain |
|----------------------------------------------------------------------------|
不使用默認的 user-agent 使用隨機user-agent
w3af/config:http-settings>>> set rand_user_agent True
設置完畢后 save
,并 back
上一級目錄
w3af/config:http-settings>>> save
The configuration has been saved.
w3af/config:http-settings>>> back
The configuration has been saved.
w3af>>>
misc-settings
w3af>>> misc-settings
w3af/config:misc-settings>>> help
w3af/config:misc-settings>>> view
|----------------------------------------------------------------------------|
| Setting | Value | Modified | Description |
|----------------------------------------------------------------------------|
| msf_location | /opt/metasploit3/bin/ | | Full path of |
| | | | Metasploit |
| | | | framework |
| | | | binary |
| | | | directory |
| | | | (/opt/metasploit3/bin/ |
| | | | in most linux |
| | | | installs) |
|----------------------------------------------------------------------------|
| interface | wlan0 | | Local |
| | | | interface |
| | | | name to use |
| | | | when |
| | | | sniffing, |
| | | | doing reverse |
| | | | connections, |
| | | | etc. |
| local_ip_address | 192.168.1.6 | | Local IP |
| | | | address to |
| | | | use when |
| | | | doing reverse |
| | | | connections |
|----------------------------------------------------------------------------|
| max_discovery_time | 120 | | Maximum crawl |
| | | | time |
| | | | (minutes) |
| stop_on_first_exception | False | | Stop scan |
| | | | after first |
| | | | unhandled |
| | | | exception |
|----------------------------------------------------------------------------|
| non_targets | | | A comma |
| | | | separated |
| | | | list of URLs |
| | | | that w3af |
| | | | should |
| | | | completely |
| | | | ignore |
|----------------------------------------------------------------------------|
| fuzz_url_filenames | False | | Indicates if |
| | | | w3af plugins |
| | | | will send |
| | | | fuzzed file |
| | | | names in |
| | | | order to find |
| | | | vulnerabilities |
| fuzz_url_parts | False | | Indicates if |
| | | | w3af plugins |
| | | | will send |
| | | | fuzzed URL |
| | | | parts in |
| | | | order to find |
| | | | vulnerabilities |
| fuzzable_headers | | | A list with |
| | | | all fuzzable |
| | | | header names |
| fuzzed_files_extension | gif | | Indicates the |
| | | | extension to |
| | | | use when |
| | | | fuzzing file |
| | | | content |
| form_fuzzing_mode | tmb | | Indicates |
| | | | what HTML |
| | | | form combo |
| | | | values w3af |
| | | | plugins will |
| | | | use: all, tb, |
| | | | tmb, t, b |
| fuzz_form_files | True | | Indicates if |
| | | | w3af plugins |
| | | | will send |
| | | | payloads in |
| | | | the content |
| | | | of |
| | | | multipart/post |
| | | | form files. |
| fuzz_cookies | False | | Indicates if |
| | | | w3af plugins |
| | | | will use |
| | | | cookies as a |
| | | | fuzzable |
| | | | parameter |
|----------------------------------------------------------------------------|
target 模塊
target
用于設置需要被掃描的目標地址。
w3af>>> target
w3af/config:target>>> view
|---------------------------------------------------------------------------|
| Setting | Value | Modified | Description |
|---------------------------------------------------------------------------|
| target_framework | unknown | | Target programming framework |
| | | | (unknown/php/asp/asp.net/java/jsp/cfm/ruby/perl) |
| target (設置要掃描的網站url) | | | A comma separated list of URLs |
| target_os (設置要掃描的操作體統的主機ip)| unknown | | Target operating system (unknown/unix/windows) |
|---------------------------------------------------------------------------|
使用 target
指定目標地址
w3af/config:target>>> set target http://www.sina.com
w3af/config:target>>> view
|---------------------------------------------------------------------------|
| Setting | Value | Modified | Description |
|---------------------------------------------------------------------------|
| target_framework | unknown | | Target programming framework |
| | | | (unknown/php/asp/asp.net/java/jsp/cfm/ruby/perl) |
| target | http://www.sina.com | Yes | A comma separated list of URLs |
| target_os | unknown | | Target operating system |
| | | | (unknown/unix/windows) |
|---------------------------------------------------------------------------|
使用self-contained
將上述設置另存為
w3af>>> profiles
w3af/profiles>>> save_as test2 self-contained
Profile saved.
由此,我們可以將 test1
設置與他人共享。
start
啟動掃描
w3af>>> start
w3af下 script
w3af 也自帶了許多的掃描腳本
root ~ w3af 1 cd scripts
root ~ w3af scripts 1 ls
allowed_methods.w3af login_brute_password_only.w3af
以sqli.w3af 腳本為例
我們只需要修改腳本中的 target 地址便可以很方便的調用這些腳本了
root ~ w3af scripts 1 cat sqli.w3af master
# This is a demo of the attack plugin sql_shell
plugins
output console,text_file
output config text_file
set output_file output-w3af.txt
set verbose True
back
output config console
set verbose False
back
audit sqli
crawl web_spider
crawl config web_spider
set only_forward True
back
grep path_disclosure
back
target
set target http://www.sina.com <---更改為目標ip
back
start
bug-report
details 0
back
exit
./w3af_console -s scripts/scriptname.weaf
root ~ w3af 1 ./w3af_console -s scripts/sqli.w3af
腳本執行完成,并會在w3af根目錄下生成 掃描報告 :
root ~ w3af 1 ls master
circle.yml extras profiles tools w3af_api w3af_gui
doc output-w3af.txt scripts w3af w3af_console
0x03 w3af 身份認證
w3af
支持四種身份認證: HTTP Basic
, NTLM
, Form
, Cookie
。不同的認證方式對應不同的目標掃描類型。
HTTP Basic
HTTP Basic
并沒有嚴格意義上的加密,只不過是經過了簡單的編碼而已,基于這種認證,使用很簡單的破解工具便可以破解了。
我們以 win7 為例,首先安裝win7 IIS 服務器,選擇默認網站屬性,關閉默認網站的匿名身份認證,從而選擇基本身份認證,并設置登錄的用戶名和密碼。
然后通過Kali去訪問該網站,使用 wireshark 進行抓包,通過 Floow TCP Stream
分析,我們可以得到一個 經過 base64 進行編碼的 Authorization
信息,其中包含了登錄使用的用戶名和密碼,使用 W3af --> tools --> Encode/Uncode
功能對所得到編碼字符進行反向解碼便可以得到用戶名和密碼。
對使用 HTTP basic 認證的網站進行掃描
在 Configuration
--> HTTP Config
--> Basic HTTP Authentication
添加基本認證信息:
等待一切配置完畢可以勾選需要掃描的模塊進行掃描,在 Target 中指定要掃描的目標 url。
NTML
NTML 身份認證是微軟一家才有的身份認證方式。
開啟 NTML 的認證功能需要使用到 IIS 的集成身份認證摸塊。NTML 也是windows 下的默認身份認證方式。
然后,回到 Kali 下的 W3af中配置 NTML 認證信息。
同樣的,等待一切配置完畢可以勾選需要掃描的模塊進行掃描,在 Target 中指定要掃描的目標 url。
基于From的身份認證
基于From的身份認證便不能使用 W3af的HTTP Configuration了,而是使用 W3af中的 auth 插件,目前 w3af 提供兩種方式的 From 表單提交認證,即是 detailed 和 generic方法,detailed 相比于 generic的信息更加詳細。
detailed
選擇 W3f 下的 auth 插件在的 detailed 選擇,配置要提交的From信息,
username_field 和 password_field分別表示在表單中要提交的用戶名和密碼控件的 username,如下所示:
auth_url 表示表單所在的url地址。
check_url 表示一旦表單驗證成功以后進入的頁面,主要是為了驗證表單提交是否成功。同樣,check_string
具有同樣的作用,它表示的是表單登錄成功以后可以看到的特征字符串。
ok,配置完成以后,選擇保存,繼續進行 crawl 爬網插件的配置。
在 crawl
下首先需要要選擇 web_Spider
一項勾選 only_forward
指定在該 target url 下要掃描的特定的子目錄。同時還可以配置follow_regex
(需要掃描的特定類型的頁面)和 ignore_regex
(需要忽略的頁面) 以此進行交叉組合篩選。
Cookie 雙因素身份認證
W3af Cookie認證方法比較嚴格的,直接copy cookies 信息是沒法認證的。所以首先需要導出 cookies 的信息。
比如,使用 firebug 導出 dvwa 站點的 cookies 信息,格式如下
192.168.56.101 FALSE / FALSE PHPSESSID c04db28f36bf5cd9a7e4ebfed22045bd
192.168.56.101 FALSE /dvwa/ FALSE security high
將其改成 w3af 的專用格式:
# Netscape HTTP Cookie File
192.168.56.101 FALSE / FALSE 173151000100 PHPSESSID c04db28f36bf5cd9a7e4ebfed22045bd
192.168.56.101 FALSE /dvwa/ FALSE 173151000100 security high
//domain flag path secure_flag 時間信息,表示cookie有沒有過期 name name value
根據 W3af 官方的解釋,使用cookie 信息時,每一行之上必需使用特定的數據格式,其各個數據字段之間必需使用 TAB 制表符來進行分隔,而不是空格。
更改完 cookies 格式以后,將其保存為本地文件,回到 w3af
--> HTTP Configuration
下選擇 Cookies
,導入保存的本地 cookie 文件。
ok,cookies 信息配置完成,接下來可以在 audit
選擇相應的掃描插件然后填寫 target 開始掃描了。