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
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
基本信息
Web 服务是最常见且最广泛的服务,存在许多不同类型的漏洞。
默认端口: 80 (HTTP), 443(HTTPS)
PORT STATE SERVICE
80/tcp open http
443/tcp open ssl/https
nc -v domain.com 80 # GET / HTTP/1.0
openssl s_client -connect domain.com:443 # GET / HTTP/1.0
Web API 指南
方法论摘要
在本方法论中,我们假定你将攻击一个域(或子域),并且仅此一个。因此,你应当将此方法应用于每个在范围内发现的域、子域或运行着未确定 web 服务器的 IP。
- 首先识别web 服务器使用的技术。如果能成功识别技术,请寻找在测试其余部分中应记住的tricks。
- 该技术版本是否存在任何已知的漏洞?
- 是否使用任何知名技术?是否有任何有用的技巧可以提取更多信息?
- 是否有任何需要运行的专用扫描器(例如 wpscan)?
- 启动通用扫描器。你永远不知道它们是否会发现一些东西或有趣的信息。
- 从初始检查开始:robots、sitemap、404 错误和 SSL/TLS scan(如果使用 HTTPS)。
- 开始spidering网页:现在是查找所有可能的文件、文件夹和正在使用的参数的时候。也要检查特殊发现。
- 注意:在 brute-forcing 或 spidering 期间发现任何新目录时,应对其进行 spidering。
- Directory Brute-Forcing:尝试对所有已发现的文件夹进行 brute force,以搜索新的文件和目录。
- 注意:在 brute-forcing 或 spidering 期间发现任何新目录时,均应对其进行 Brute-Forced。
- Backups checking:测试能否通过附加常见备份扩展名来找到已发现文件的backups。
- Brute-Force parameters:尝试查找隐藏参数。
- 一旦你识别了所有可能接受user input的endpoints,检查与之相关的所有类型的vulnerabilities。
- 遵循此检查清单
服务器版本(是否易受攻击?)
识别
检查运行的服务器版本是否存在任何已知的 known vulnerabilities。
响应的 HTTP headers and cookies of the response 可能非常有助于 identify 所使用的 technologies 和/或 version。Nmap scan 可以识别服务器版本,但工具 whatweb, webtech or https://builtwith.com/:
whatweb -a 1 <URL> #Stealthy
whatweb -a 3 <URL> #Aggresive
webtech -u <URL>
webanalyze -host https://google.com -crawl 2
搜索 针对 Web 应用程序的漏洞 版本
检查是否存在 WAF
- https://github.com/EnableSecurity/wafw00f
- https://github.com/Ekultek/WhatWaf.git
- https://nmap.org/nsedoc/scripts/http-waf-detect.html
Web tech tricks
一些用于在不同已知 技术 中 发现漏洞 的 技巧:
- AEM - Adobe Experience Cloud
- Apache
- Artifactory
- Buckets
- CGI
- Drupal
- Flask
- Git
- Golang
- GraphQL
- H2 - Java SQL database
- ISPConfig
- IIS tricks
- Microsoft SharePoint
- JBOSS
- Jenkins
- Jira
- Joomla
- JSP
- Laravel
- Moodle
- Nginx
- PHP (php has a lot of interesting tricks that could be exploited)
- Python
- Spring Actuators
- Symphony
- Tomcat
- VMWare
- Web API Pentesting
- WebDav
- Werkzeug
- Wordpress
- Electron Desktop (XSS to RCE)
- Sitecore
- Zabbix
请注意同一 domain 在不同的 ports、folders 和 subdomains 可能使用不同的 technologies。
如果 Web 应用使用之前列出的任何已知 tech/platform listed before 或 其他,不要忘记在 互联网上搜索 新技巧(并告诉我!)。
Source Code Review
如果应用的 source code 可在 github 获取,除了由你自行对应用执行 White box test,还有一些信息可能对当前的 Black-Box testing 有用:
- 是否存在 Change-log or Readme or Version 文件或任何通过 web 可访问的版本信息?
- credentials 是如何以及保存在哪里的?是否存在任何(可访问的?)文件包含 credentials(用户名或密码)?
- passwords 是以 plain text、encrypted 存在,还是使用了哪种 hashing algorithm?
- 是否使用任何 master key 来加密某些内容?使用了哪种 algorithm?
- 你能否通过利用某些漏洞访问这些文件?
- 在 github 中是否有任何有趣的信息(已解决或未解决的)issues?或者在 commit history 中(也许某个旧提交中引入了某个 password)?
Source code Review / SAST Tools
Automatic scanners
General purpose automatic scanners
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
cmsmap [-f W] -F -d <URL>
wpscan --force update -e --url <URL>
joomscan --ec -u <URL>
joomlavs.rb #https://github.com/rastating/joomlavs
到此为止,你应该已经掌握了一些关于客户端所使用的 web 服务器(如果有提供任何数据)的信息,并记住在测试期间需要注意的一些技巧。如果幸运的话,你甚至可能已经发现了一个 CMS 并运行了一些扫描器。
逐步 Web 应用发现
从这一点开始,我们将开始与 web 应用进行交互。
初始检查
包含有用信息的默认页面:
- /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 上传文件 到网页中 找到的文件夹 的 其余部分。你可能对其他文件夹有上传权限。
SSL/TLS 漏洞
- 如果应用程序在任何部分 没有强制使用 HTTPS,那么它就容易受到 MitM 攻击
- 如果应用程序 通过 HTTP 发送敏感数据(如密码),那么这是一个高风险漏洞。
使用 testssl.sh 来检查 vulnerabilities(在 Bug Bounty 计划中,这类问题可能不会被接受),并使用 a2sv 重新核实这些 vulnerabilities:
./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:
- https://www.gracefulsecurity.com/tls-ssl-vulnerabilities/
- https://www.acunetix.com/blog/articles/tls-vulnerabilities-attacks-final-part/
Spidering
在 Web 中启动某种 spider。spider 的目标是从被测试应用中找到尽可能多的路径。因此,应该使用 web crawling 和外部来源来发现尽可能多的有效路径。
- gospider (go): HTML spider,LinkFinder 用于 JS 文件以及外部来源(Archive.org, CommonCrawl.org, VirusTotal.com)。
- hakrawler (go): HML spider,带有 LinkFider 用于 JS 文件,并使用 Archive.org 作为外部来源。
- dirhunt (python): HTML spider,也会标示“juicy files”。
- evine (go): 交互式 CLI HTML spider。也会在 Archive.org 中搜索。
- meg (go): 该工具不是 spider,但很有用。你可以提供一个 hosts 文件和一个 paths 文件,meg 会对每个 host 的每个 path 发起请求并保存响应。
- urlgrab (go): 带有 JS 渲染能力的 HTML spider。但看起来没有维护,预编译版本较旧且当前代码无法编译。
- gau (go): 使用外部提供者(wayback, otx, commoncrawl)的 HTML spider。
- ParamSpider: 该脚本会找到带参数的 URL 并列出它们。
- galer (go): 带有 JS 渲染能力的 HTML spider。
- LinkFinder (python): HTML spider,具备 JS beautify 能力,能够在 JS 文件中搜索新路径。也值得看看 JSScanner,它是 LinkFinder 的封装。
- goLinkFinder (go): 从 HTML 源码和嵌入的 javascript 文件中提取 endpoints。对 bug hunters、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 extension 用于在 JS 文件中查找 path 和 params。
- Sourcemapper: 给定 .js.map URL 会获取 beautified 的 JS 代码。
- xnLinkFinder: 用于为给定目标发现 endpoints 的工具。
- waymore: 从 wayback machine 发现链接(也会下载 wayback 中的响应并寻找更多链接)。
- HTTPLoot (go): 爬取(甚至通过填表单)并使用特定 regex 查找敏感信息。
- SpiderSuite: Spider Suite 是为网络安全专业人员设计的高级多功能 GUI web security Crawler/Spider。
- jsluice (go): 一个 Go 包和 command-line tool 用于从 JavaScript 源代码中提取 URLs、paths、secrets 及其它有趣的数据。
- ParaForge: ParaForge 是一个简单的 Burp Suite extension,用于从请求中提取 parameters 和 endpoints以创建用于 fuzzing 和 enumeration 的自定义 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 和 recursive search。与其他选项相比太慢。
- Dirsearch (python): 它不允许 auto-signed certificates,但允许 recursive search。
- Gobuster (go): 允许 auto-signed certificates,但不支持 recursive search。
- Feroxbuster - Fast, supports recursive search.
- wfuzz
wfuzz -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt https://domain.com/api/FUZZ - ffuf - Fast:
ffuf -c -w /usr/share/wordlists/dirb/big.txt -u http://10.10.10.10/FUZZ - uro (python): 这不是 spider,但给定已发现 URL 列表后会删除“重复”的 URL。
- Scavenger: Burp Extension,用于从 burp history 的不同页面创建目录列表。
- TrashCompactor: 基于 js imports 移除功能重复的 URLs。
- Chamaleon: 使用 wapalyzer 检测使用的技术并选择要使用的 wordlists。
Recommended dictionaries:
- https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/bf_directories.txt
- Dirsearch included dictionary
- http://gist.github.com/jhaddix/b80ea67d85c13206125806f0828f4d10
- Assetnote wordlists
- https://github.com/danielmiessler/SecLists/tree/master/Discovery/Web-Content
- raft-large-directories-lowercase.txt
- directory-list-2.3-medium.txt
- RobotsDisallowed/top10000.txt
- https://github.com/random-robbie/bruteforce-lists
- https://github.com/google/fuzzing/tree/master/dictionaries
- https://github.com/six2dez/OneListForAll
- https://github.com/random-robbie/bruteforce-lists
- https://github.com/ayoubfathi/leaky-paths
- /usr/share/wordlists/dirb/common.txt
- /usr/share/wordlists/dirb/big.txt
- /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
注意:每当在 brute-forcing 或 spidering 过程中发现新的目录时,应该对其进行 Brute-Forced。
What to check on each file found
- Broken link checker: 在 HTML 中查找可能易受 takeover 的 broken links。
- File Backups: 找到所有文件后,查找所有可执行文件的备份(".php", ".aspx"...)。常见的备份命名变体包括: file.ext~, #file.ext#, ~file.ext, file.ext.bak, file.ext.tmp, file.ext.old, file.bak, file.tmp 和 file.old. 你也可以使用工具 bfac 或 backup-gen。
- Discover new parameters: 可以使用诸如 Arjun, parameth, x8 和 Param Miner 来发现隐藏参数。如果可能,应尝试在每个可执行的 web 文件上搜索 隐藏参数。
- Arjun all default wordlists: https://github.com/s0md3v/Arjun/tree/master/arjun/db
- Param-miner “params” : https://github.com/PortSwigger/param-miner/blob/master/resources/params
- Assetnote “parameters_top_1m”: https://wordlists.assetnote.io/
- nullenc0de “params.txt”: https://gist.github.com/nullenc0de/9cb36260207924f8e1787279a05eb773
- Comments: 检查所有文件的注释,可能会发现 credentials 或 hidden functionality。
- 如果你在玩 CTF,一个“常见”技巧是在页面的右侧注释中隐藏信息(使用数百个空格,以便在浏览器中查看源代码时看不到数据)。另一种可能性是使用多个换行并在页面底部的注释中隐藏信息。
- API keys: 如果你发现任何 API key,有些项目可以帮助你利用不同平台的 API keys: keyhacks, zile, truffleHog, SecretFinder, RegHex, DumpsterDive, EarlyBird
- Google API keys: 如果你发现任何看起来像 AIzaSyA-qLheq6xjDiEIRisP_ujUseYLQCHUjik 的 API key,可以使用项目 gmapapiscanner 检查该 key 可以访问哪些 apis。
- S3 Buckets: 在 spidering 时查看是否有任何 subdomain 或任何 link 与某个 S3 bucket 相关。如果是这样, check the permissions of the bucket。
Special findings
在执行 spidering 和 brute-forcing 时,可能会发现一些需要注意的有趣事项。
Interesting files
- 在 CSS 文件中查找指向其他文件的 links。
- If you find a .git file some information can be extracted
- 如果你找到 .env,可能会发现 api keys、db 密码和其他信息。
- 如果发现 API endpoints,你也应该测试它们。这些不是文件,但很可能“看起来像”文件。
- JS files: 在 spidering 部分提到过若干可以从 JS 文件中提取 path 的工具。此外,监控每个发现的 JS 文件也很有价值,因为在某些情况下,文件的变动可能表明代码中引入了潜在漏洞。你可以使用例如 JSMon。
- 你还应该使用 RetireJS 或 JSHole 检查发现的 JS 文件,以判断是否存在已知漏洞。
- Javascript Deobfuscator and Unpacker: https://lelinhtinh.github.io/de4js/, https://www.dcode.fr/javascript-unobfuscator
- Javascript Beautifier: http://jsbeautifier.org/, http://jsnice.org/
- JsFuck deobfuscation (javascript with chars:"[]!+" https://enkhee-osiris.github.io/Decoder-JSFuck/)
- TrainFuck](https://github.com/taco-c/trainfuck):
+72.+29.+7..+3.-67.-12.+55.+24.+3.-6.-8.-67.-23. - 在许多场合,你需要理解正则表达式的用法,这会很有帮助: https://regex101.com/ 或 https://pythonium.net/regex
- 你也可以监控检测到表单的文件,因为参数的变化或新表单的出现可能表明潜在的新易受攻击功能。
403 Forbidden/Basic Authentication/401 Unauthorized (bypass)
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
关于 web vulns 的更多信息:
- https://six2dez.gitbook.io/pentest-book/others/web-checklist
- https://kennel209.gitbooks.io/owasp-testing-guide-v4/content/en/web_application_security_testing/configuration_and_deployment_management_testing.html
- https://owasp-skf.gitbook.io/asvs-write-ups/kbid-111-client-side-template-injection
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
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
HackTricks