80,443 - Pentesting Web 方法论

Reading time: 25 minutes

tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

基本信息

Web 服务是最 常见且范围广泛的服务,存在许多 不同类型的漏洞

默认端口: 80 (HTTP), 443(HTTPS)

bash
PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  ssl/https
bash
nc -v domain.com 80 # GET / HTTP/1.0
openssl s_client -connect domain.com:443 # GET / HTTP/1.0

Web API 指南

Web API Pentesting

方法论摘要

在本方法论中,我们假定你将针对一个 domain(或 subdomain)进行攻击,仅针对该目标。因此,应当对范围内每个发现的 domain、subdomain 或运行不明 web server 的 IP 应用此方法论。

  • 首先识别 web server 使用的 technologies。如果能成功识别该 tech,请在后续测试中留意相关 tricks
  • 该 technology 的版本是否存在已知的 known vulnerability
  • 是否使用了任何 well known tech?是否有任何 useful trick 可用于提取更多信息?
  • 是否有需要运行的 specialised scanner(例如 wpscan)?
  • 运行 general purposes scanners。你永远不知道它们是否会发现什么或提供有价值的信息。
  • initial checks 开始:检查 robotssitemap404 错误以及 SSL/TLS scan(如果为 HTTPS)。
  • 开始对网页进行 spidering:现在是时候 find 出所有可能的 files, folders 及正在使用的 parameters。同时,检查是否有 special findings
  • 注意:在 brute-forcing 或 spidering 过程中发现任何新目录时,应该对其进行 spidering。
  • Directory Brute-Forcing:尝试对所有已发现的文件夹进行 brute force,以寻找新的 filesdirectories
  • 注意:在 brute-forcing 或 spidering 过程中发现任何新目录时,应该对其进行 Brute-Forced。
  • Backups checking:通过附加常见的备份扩展名,测试是否能找到 discovered filesbackups
  • Brute-Force parameters:尝试 find hidden parameters
  • 一旦你 identified 了所有可能接受 user inputendpoints,就要检查与之相关的各种 vulnerabilities
  • Follow this checklist

服务器版本(是否易受攻击?)

识别

检查正在运行的服务器 version 是否存在 known vulnerabilities
HTTP headers and cookies of the responseidentify 所使用的 technologies 和/或 version 非常有帮助。Nmap scan 可以识别服务器版本,但工具 whatweb, webtech or https://builtwith.com/:

bash
whatweb -a 1 <URL> #Stealthy
whatweb -a 3 <URL> #Aggresive
webtech -u <URL>
webanalyze -host https://google.com -crawl 2

搜索 是否有 web 应用的漏洞 版本信息

检查是否有 WAF

Web 技术 技巧

一些 技巧 用于在不同知名 技术发现漏洞

请注意,同一域名 可能在不同的 端口目录子域 上使用 不同的技术.
如果该 web 应用 使用 之前列出的任何知名 技术/平台任何其他,别忘了 在互联网上搜索 新的技巧(并告诉我!)。

源代码审查

如果应用的 源代码 可在 github 获取,除了你亲自对应用进行 White box test 外,还有一些 信息 可能对当前的 Black-Box testing 有用:

  • 是否有 Change-log 或 Readme 或 Version 文件或任何通过 web 可访问的 版本信息
  • 凭据 是如何以及在哪里保存的?是否有任何(可访问的?)文件 包含凭据(用户名或密码)?
  • 密码明文加密 还是使用了哪种 哈希算法
  • 是否使用任何 master key 来加密某些东西?使用了哪种 算法
  • 你能否通过利用某些漏洞 访问这些文件中的任意一个
  • github 中是否有任何有趣的信息(已解决和未解决的)issues?或者在 commit history 中(可能某个旧提交中引入了某个 密码)?

Source code Review / SAST Tools

自动扫描器

通用自动扫描器

bash
nikto -h <URL>
whatweb -a 4 <URL>
wapiti -u <URL>
W3af
zaproxy #You can use an API
nuclei -ut && nuclei -target <URL>

# https://github.com/ignis-sec/puff (client side vulns fuzzer)
node puff.js -w ./wordlist-examples/xss.txt -u "http://www.xssgame.com/f/m4KKGHi2rVUN/?query=FUZZ"

CMS 扫描器

如果使用了 CMS,别忘了运行扫描器,可能会发现有价值的内容:

Clusterd: JBoss, ColdFusion, WebLogic, Tomcat, Railo, Axis2, Glassfish
CMSScan: WordPress, Drupal, Joomla, vBulletin 用于检测网站的安全问题。 (GUI)\
VulnX: Joomla, Wordpress, Drupal, PrestaShop, Opencart
CMSMap: (W)ordpress, (J)oomla, (D)rupal (M)oodle
droopscan: Drupal, Joomla, Moodle, Silverstripe, Wordpress

bash
cmsmap [-f W] -F -d <URL>
wpscan --force update -e --url <URL>
joomscan --ec -u <URL>
joomlavs.rb #https://github.com/rastating/joomlavs

到此为止,你应该已经对客户端使用的 web server(如果有提供数据)有了一些了解,并掌握在测试中需注意的一些技巧。如果幸运的话,你甚至可能已经发现了 CMS 并运行了一些 scanner。

逐步 Web Application 发现

从这一点开始,我们将开始与 web application 交互。

初步检查

带有有用信息的默认页面:

  • /robots.txt
  • /sitemap.xml
  • /crossdomain.xml
  • /clientaccesspolicy.xml
  • /.well-known/
  • 也检查主页面和次要页面中的注释。

触发错误

当向 Web 服务器发送异常数据时,服务器可能会异常行为。这可能会打开 vulnerabilities泄露敏感信息

  • 访问 伪造页面,例如 /whatever_fake.php (.aspx,.html,.etc)
  • cookie 值参数值添加 "[]", "]]", 和 "[[" 以制造错误
  • 通过在 URL末尾 提供输入 /~randomthing/%s 来生成错误
  • 尝试不同的 HTTP Verbs,例如 PATCH、DEBUG,或故意使用错误的 FAKE

检查是否可以上传文件 (PUT verb, WebDav)

如果你发现 WebDav 已启用,但你在根目录没有足够的权限来 上传文件,尝试:

  • Brute Force 凭证
  • 通过 WebDav Upload files 到网页中已发现的其他文件夹。你可能对其他文件夹具有上传权限。

SSL/TLS 漏洞

  • 如果应用在任何部分没有强制使用 HTTPS,则容易受到 MitM 攻击。
  • 如果应用通过 HTTP 发送敏感数据(如密码),则这是一个高危漏洞。

使用 testssl.sh 检查 vulnerabilities(在 Bug Bounty 计划中这类漏洞可能不会被接受),并使用 a2sv 重新核实这些 vulnerabilities:

bash
./testssl.sh [--htmlfile] 10.10.10.10:443
#Use the --htmlfile to save the output inside an htmlfile also

# You can also use other tools, by testssl.sh at this momment is the best one (I think)
sslscan <host:port>
sslyze --regular <ip:port>

Information about SSL/TLS vulnerabilities:

Spidering

在 web 应用内启动某种 spider。spider 的目标是从被测试的应用中找到尽可能多的路径。因此,应使用 web 爬行和外部来源来发现尽可能多的有效路径。

  • gospider (go): HTML 爬虫,可在 JS 文件中使用 LinkFinder,并使用外部来源 (Archive.org, CommonCrawl.org, VirusTotal.com)。
  • hakrawler (go): HTML 爬虫,具有针对 JS 文件的 LinkFinder 并使用 Archive.org 作为外部来源。
  • dirhunt (python): HTML 爬虫,同时标记“juicy files”。
  • evine (go): 交互式 CLI HTML 爬虫。也会在 Archive.org 中搜索。
  • meg (go): 该工具不是蜘蛛但很有用。你可以提供一个 hosts 文件和一个 paths 文件,meg 会对每个主机的每个路径进行抓取并保存响应。
  • urlgrab (go): 具有 JS 渲染能力的 HTML 爬虫。然而,看起来它没有维护,预编译版本较旧且当前代码无法编译。
  • gau (go): 使用外部提供者(wayback, otx, commoncrawl)的 HTML 爬虫。
  • ParamSpider: 该脚本会找到带参数的 URL 并列出它们。
  • galer (go): 具有 JS 渲染能力的 HTML 爬虫。
  • LinkFinder (python): HTML 爬虫,具备 JS 美化能力,可在 JS 文件中搜索新路径。也可以看看 JSScanner,它是 LinkFinder 的一个封装。
  • goLinkFinder (go): 从 HTML 源和嵌入的 javascript 文件中提取 endpoints。对 bug 猎人、red teamers、infosec ninjas 很有用。
  • JSParser (python2.7): 一个使用 Tornado 和 JSBeautifier 的 python 2.7 脚本,用于从 JavaScript 文件中解析相对 URL。对轻松发现 AJAX 请求很有用。似乎未维护。
  • relative-url-extractor (ruby): 给定一个文件 (HTML),它将使用巧妙的正则表达式从混淆(minify)文件中查找并提取相对 URL。
  • JSFScan (bash, several tools): 使用多个工具从 JS 文件中收集有趣信息。
  • subjs (go): 查找 JS 文件。
  • page-fetch (go): 在 headless browser 中加载页面并打印出所有为加载页面所请求的 urls。
  • Feroxbuster (rust): 内容发现工具,融合了前述工具的多种选项。
  • Javascript Parsing: 一个 Burp 扩展,用于在 JS 文件中查找路径和参数。
  • Sourcemapper: 给定 .js.map URL 时,获取美化后的 JS 代码的工具。
  • xnLinkFinder: 用于为给定目标发现 endpoints 的工具。
  • waymore: 从 wayback machine 发现链接(也会下载 wayback 中的响应并寻找更多链接)。
  • HTTPLoot (go): 爬取(甚至通过填写表单)并使用特定 regex 查找敏感信息。
  • SpiderSuite: Spider Suite 是为网络安全专家设计的高级多功能 GUI web 安全 Crawler/Spider。
  • jsluice (go): 一个 Go 包和 command-line tool,用于从 JavaScript 源代码中提取 URLs、paths、secrets 和其他有趣数据。
  • ParaForge: ParaForge 是一个简单的 Burp Suite extension,用于从请求中提取参数和 endpoints,以为 fuzzing 和枚举创建自定义 wordlist。
  • katana (go): 对此非常棒的工具。
  • Crawley (go): 打印它能够找到的每个 link。

Brute Force directories and files

从根目录开始进行 brute-forcing,并确保使用此方法发现的所有目录进行 brute-force,也对通过 Spidering 发现的所有目录进行 brute-force(你可以递归地进行 brute-forcing,并在所用 wordlist 开头添加已发现目录的名称)。
工具:

  • Dirb / Dirbuster - 包含在 Kali 中,老旧(且)但可用。允许 auto-signed certificates 和递归搜索。与其它选项相比太慢。
  • Dirsearch (python): 它不允许 auto-signed certificates 但允许递归搜索**。
  • Gobuster (go): 它允许 auto-signed certificates,但支持递归搜索。
  • Feroxbuster - 快速,支持递归搜索。
  • wfuzz wfuzz -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt https://domain.com/api/FUZZ
  • ffuf - 快速: ffuf -c -w /usr/share/wordlists/dirb/big.txt -u http://10.10.10.10/FUZZ
  • uro (python): 这不是蜘蛛,但给定已发现的 URL 列表后,它会删除“重复”的 URLs。
  • Scavenger: Burp 扩展,从不同页面的 burp 历史中创建目录列表。
  • TrashCompactor: 基于 js imports 移除具有重复功能的 URLs。
  • Chamaleon: 使用 wapalyzer 检测使用的技术并选择要使用的 wordlists。

Recommended dictionaries:

注意:每当在 brute-forcing 或 spidering 过程中发现新目录时,应该对其进行 Brute-Force。

What to check on each file found

Special findings

在执行 spideringbrute-forcing 时,你可能会发现需要特别注意有趣东西

Interesting files

403 Forbidden/Basic Authentication/401 Unauthorized (bypass)

403 & 401 Bypasses

502 Proxy Error

如果任何页面以该 code 响应,很可能是一个 配置错误的 proxy如果你发送一个像这样的 HTTP 请求: GET https://google.com HTTP/1.1(包含 host header 和其他常见头),proxy 会尝试访问 google.com,那么你就发现了一个 SSRF

NTLM Authentication - Info disclosure

如果要求认证的运行服务器是 Windows,或者你发现一个要求你输入 credentials(并要求 domain name)的登录,你可以触发一个信息泄露
发送 头:“Authorization: NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=”,由于 NTLM authentication 的工作机制,服务器会在头 "WWW-Authenticate" 中返回内部信息(IIS 版本、Windows 版本...)。
你可以使用 nmap 插件 "http-ntlm-info.nse" 来自动化此操作。

HTTP Redirect (CTF)

可以把内容放在 Redirection 中。这些内容不会显示给用户(因为浏览器会执行重定向),但有东西可能被隐藏在里面。

Web Vulnerabilities Checking

在对 web 应用进行了全面枚举之后,就该检查大量可能的漏洞了。你可以在这里找到检查清单:

Web Vulnerabilities Methodology

Find more info about web vulns in:

Monitor Pages for changes

你可以使用像 https://github.com/dgtlmoon/changedetection.io 这样的工具来监控页面修改,这些修改可能引入漏洞。

HackTricks Automatic Commands

Protocol_Name: Web    #Protocol Abbreviation if there is one.
Port_Number:  80,443     #Comma separated if there is more than one.
Protocol_Description: Web         #Protocol Abbreviation Spelled out

Entry_1:
Name: Notes
Description: Notes for Web
Note: |
https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/index.html

Entry_2:
Name: Quick Web Scan
Description: Nikto and GoBuster
Command: nikto -host {Web_Proto}://{IP}:{Web_Port} &&&& gobuster dir -w {Small_Dirlist} -u {Web_Proto}://{IP}:{Web_Port} && gobuster dir -w {Big_Dirlist} -u {Web_Proto}://{IP}:{Web_Port}

Entry_3:
Name: Nikto
Description: Basic Site Info via Nikto
Command: nikto -host {Web_Proto}://{IP}:{Web_Port}

Entry_4:
Name: WhatWeb
Description: General purpose auto scanner
Command: whatweb -a 4 {IP}

Entry_5:
Name: Directory Brute Force Non-Recursive
Description:  Non-Recursive Directory Brute Force
Command: gobuster dir -w {Big_Dirlist} -u {Web_Proto}://{IP}:{Web_Port}

Entry_6:
Name: Directory Brute Force Recursive
Description: Recursive Directory Brute Force
Command: python3 {Tool_Dir}dirsearch/dirsearch.py -w {Small_Dirlist} -e php,exe,sh,py,html,pl -f -t 20 -u {Web_Proto}://{IP}:{Web_Port} -r 10

Entry_7:
Name: Directory Brute Force CGI
Description: Common Gateway Interface Brute Force
Command: gobuster dir -u {Web_Proto}://{IP}:{Web_Port}/ -w /usr/share/seclists/Discovery/Web-Content/CGIs.txt -s 200

Entry_8:
Name: Nmap Web Vuln Scan
Description: Tailored Nmap Scan for web Vulnerabilities
Command: nmap -vv --reason -Pn -sV -p {Web_Port} --script=`banner,(http* or ssl*) and not (brute or broadcast or dos or external or http-slowloris* or fuzzer)` {IP}

Entry_9:
Name: Drupal
Description: Drupal Enumeration Notes
Note: |
git clone https://github.com/immunIT/drupwn.git for low hanging fruit and git clone https://github.com/droope/droopescan.git for deeper enumeration

Entry_10:
Name: WordPress
Description: WordPress Enumeration with WPScan
Command: |
?What is the location of the wp-login.php? Example: /Yeet/cannon/wp-login.php
wpscan --url {Web_Proto}://{IP}{1} --enumerate ap,at,cb,dbe && wpscan --url {Web_Proto}://{IP}{1} --enumerate u,tt,t,vp --passwords {Big_Passwordlist} -e

Entry_11:
Name: WordPress Hydra Brute Force
Description: Need User (admin is default)
Command: hydra -l admin -P {Big_Passwordlist} {IP} -V http-form-post '/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log In&testcookie=1:S=Location'

Entry_12:
Name: Ffuf Vhost
Description: Simple Scan with Ffuf for discovering additional vhosts
Command: ffuf -w {Subdomain_List}:FUZZ -u {Web_Proto}://{Domain_Name} -H "Host:FUZZ.{Domain_Name}" -c -mc all {Ffuf_Filters}

tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks