80,443 - Pentesting Web 方法论
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 server 的 IP 分别应用此方法。
- 从 识别 web server 使用的 technologies 开始。如果能成功识别出 tech,请寻找在后续测试中需要记住的 tricks。
- 所使用的 technology 版本是否有已知漏洞?
- 是否使用任何 well known tech?有没有可用的 trick 用于提取更多信息?
- 是否有需要运行的 specialised scanner(例如 wpscan)?
- 运行 general purposes scanners。你永远不知道它们是否会发现某些东西或有趣的信息。
- 从 initial checks 开始:robots、sitemap、404 error 和 SSL/TLS scan(如果是 HTTPS)。
- 开始 spidering 网页:现在是发现所有可能的 files、folders 和 parameters 的时候。同时,检查任何 special findings。
- 注意:每当在 brute-forcing 或 spidering 过程中发现一个新目录时,应对其进行 spidering。
- Directory Brute-Forcing:尝试对发现的 folders 进行 brute force,以寻找新的 files 和 directories。
- 注意:每当在 brute-forcing 或 spidering 过程中发现一个新目录时,应对其进行 Brute-Forced。
- Backups checking:测试是否可以通过追加常见的 backup extensions 来找到 discovered files 的备份。
- Brute-Force parameters:尝试查找隐藏的 parameters。
- 一旦你识别出所有可能接受 user input 的 endpoints,检查与之相关的各种 vulnerabilities。
- Follow this checklist
服务器版本(是否易受攻击?)
识别
检查当前运行的服务器版本是否存在已知漏洞。
HTTP headers and cookies of the response 可能非常有助于识别所使用的 technologies 和/或 version。Nmap scan 可以识别 server version,但也可能有用的工具有 whatweb, webtech 或https://builtwith.com/:
whatweb -a 1 <URL> #Stealthy
whatweb -a 3 <URL> #Aggresive
webtech -u <URL>
webanalyze -host https://google.com -crawl 2
搜索 用于 vulnerabilities of the web application version
检查是否存在 WAF
- https://github.com/EnableSecurity/wafw00f
- https://github.com/Ekultek/WhatWaf.git
- https://nmap.org/nsedoc/scripts/http-waf-detect.html
Web 技术 小技巧
一些用于在不同知名技术中查找漏洞的技巧:
- AEM - Adobe Experience Cloud
- Apache
- Artifactory
- Buckets
- CGI
- Custom UDP RPC Protocols
- Dotnet SOAP WSDL client exploitation
- Drupal
- Flask
- Fortinet FortiWeb
- 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
- Roundcube
- Spring Actuators
- Symphony
- Tomcat
- VMWare
- Web API Pentesting
- WebDav
- Werkzeug
- Wordpress
- Electron Desktop (XSS to RCE)
- Sitecore
- Zabbix
_请注意,同一域名可能在不同的端口、文件夹和子域中使用不同的技术。_ 如果 web 应用使用了前面列出的任何已知的 tech/platform listed before 或 any other,别忘了在互联网上搜索新的技巧(并告诉我!)。
Source Code Review
如果应用程序的 source code 可在 github 上获取,除了由你自己对应用程序进行 White box test 外,还有一些 some information 可能对当前的 Black-Box testing 有用:
- 是否存在可通过 web 访问的 Change-log or Readme or Version 文件或任何包含 version info accessible 的东西?
- 凭据(credentials)如何以及在哪里保存?是否存在包含凭据(用户名或密码)的(可访问的?)file?
- passwords 是以 plain text、encrypted 保存,还是使用了哪种 hashing algorithm?
- 是否使用任何 master key 来加密某些内容?使用了哪种 algorithm?
- 你能否通过利用某些漏洞 access any of these files?
- 在 github 的 issues(已解决和未解决)中是否有任何有趣信息(interesting information in the github)?或者在 commit history 中(也许某个旧提交中引入了某个 password introduced inside an old commit)?
Source code Review / SAST Tools
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 server(如果有提供信息)有了一些了解,并且掌握了一些在测试中需要注意的小技巧。如果幸运的话,你甚至已经找到一个 CMS 并运行了一些扫描器。
Step-by-step Web Application Discovery
从此处我们将开始与 web application 进行交互。
Initial checks
Default pages with interesting info:
- /robots.txt
- /sitemap.xml
- /crossdomain.xml
- /clientaccesspolicy.xml
- /.well-known/
- 也检查主页面和次要页面中的注释。
Forcing errors
Web servers 可能在接收到异常数据时表现异常。这可能会暴露vulnerabilities或导致敏感信息泄露。
- 访问像 /whatever_fake.php (.aspx,.html,.etc) 这样的fake pages
- 在 cookie values 和 parameter values 中加入 “[]”, “]]”, 和 “[[” 以制造错误
- 在 URL 的 末尾 给出输入
/~randomthing/%s来触发错误 - 尝试不同的 HTTP Verbs,例如 PATCH、DEBUG,或错误的比如 FAKE
Check if you can upload files (PUT verb, WebDav)
如果你发现 WebDav 被启用但在根目录没有足够权限进行uploading files,尝试:
- Brute Force credentials
- 通过 WebDav 将文件 upload files 到网页中发现的其他文件夹。你可能有权限在其他文件夹中上传文件。
SSL/TLS vulnerabilites
- 如果应用在任何部分都没有强制使用 HTTPS,那么它容易受到 MitM 攻击
- 如果应用通过 HTTP 发送敏感数据(如 passwords),那么这是一个高危漏洞。
使用 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
Launch some kind of spider inside the web. The goal of the spider is to find as much paths as possible from the tested application. Therefore, web crawling and external sources should be used to find as much valid paths as possible.
- gospider (go): HTML spider,针对 JS 文件使用 LinkFinder,并利用外部来源 (Archive.org, CommonCrawl.org, VirusTotal.com)。
- hakrawler (go): HML spider,带有针对 JS 文件的 LinkFinder 并使用 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 美化功能,能够在 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),它会使用巧妙的正则表达式从混淆/压缩文件中查找并提取相对 URL。
- JSFScan (bash, several tools): 使用多个工具从 JS 文件收集有价值的信息。
- subjs (go): 用于查找 JS 文件。
- page-fetch (go): 在 headless 浏览器中加载页面并打印出为加载页面而加载的所有 urls。
- Feroxbuster (rust): 内容发现工具,结合了前面几个工具的多种选项。
- Javascript Parsing: 一个 Burp 扩展,用于在 JS 文件中查找 path 和 params。
- Sourcemapper: 给定 .js.map URL 时,该工具会为你获取 beautified 的 JS 代码。
- xnLinkFinder: 用于为给定目标发现 endpoints 的工具。
- waymore: 从 wayback machine 发现链接(也会下载 wayback 中的响应并寻找更多链接)。
- HTTPLoot (go): 爬行(甚至通过填写表单)并使用特定的正则表达式查找敏感信息。
- SpiderSuite: Spider Suite 是一款面向网络安全专业人员的多功能 GUI web 安全 Crawler/Spider。
- jsluice (go): 一个 Go 包和 command-line tool,用于从 JavaScript 源代码中提取 URLs、paths、secrets 及其它有趣的数据。
- ParaForge: ParaForge 是一个简单的 Burp Suite extension,用于 extract the paramters and endpoints 从请求中创建用于 fuzzing 和枚举的自定义 wordlist。
- katana (go): 处理这类任务的优秀工具。
- Crawley (go): 打印它能找到的每个 link。
Brute Force directories and files
Start brute-forcing from the root folder and be sure to brute-force all the directories found using this method and all the directories discovered by the Spidering (you can do this brute-forcing recursively and appending at the beginning of the used wordlist the names of the found directories).
Tools:
- Dirb / Dirbuster - Included in Kali, old (and slow) but functional. Allow auto-signed certificates and recursive search. Too slow compared with th other options.
- Dirsearch (python): It doesn’t allow auto-signed certificates but allows recursive search.
- Gobuster (go): It allows auto-signed certificates, it doesn’t have 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 扩展,从 burp 的不同页面历史中创建目录列表。
- TrashCompactor: 根据 js imports 删除功能重复的 URL。
- 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
Note that anytime a new directory is discovered during brute-forcing or spidering, it should be 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。
- If you are playing CTF, a “common” trick is to hide information inside comments at the right of the page (using hundreds of spaces so you don’t see the data if you open the source code with the browser). Other possibility is to use several new lines and hide information in a comment at the bottom of the web page.
- 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
While performing the spidering and brute-forcing you could find interesting things that you have to notice.
Interesting files
- 在 CSS 文件中查找指向其他文件的 links。
- If you find a .git file some information can be extracted
- 如果你发现一个 .env,可能会包含 api keys、数据库密码和其他信息。
- 如果你发现 API endpoints,你 should also test them。这些不一定是文件,但可能“看起来像”文件。
- JS files: 在 spidering 部分提到了若干可从 JS 文件中提取路径的工具。另外,监控每个发现的 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:
+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
If any page responds with that code, it’s probably a bad configured proxy. If you send a HTTP request like: GET https://google.com HTTP/1.1 (with the host header and other common headers), the proxy will try to access google.com and you will have found a SSRF.
NTLM Authentication - Info disclosure
If the running server asking for authentication is Windows or you find a login asking for your credentials (and asking for domain name), you can provoke an information disclosure.
Send the header: “Authorization: NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=” and due to how the NTLM authentication works, the server will respond with internal info (IIS version, Windows version…) inside the header “WWW-Authenticate”.
You can automate this using the nmap plugin “http-ntlm-info.nse”.
HTTP Redirect (CTF)
It is possible to put content inside a Redirection. This content won’t be shown to the user (as the browser will execute the redirection) but something could be hidden in there.
Web Vulnerabilities Checking
Now that a comprehensive enumeration of the web application has been performed it’s time to check for a lot of possible vulnerabilities. You can find the checklist here:
Web Vulnerabilities Methodology
Find more info about web vulns in:
- 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
You can use tools such as https://github.com/dgtlmoon/changedetection.io to monitor pages for modifications that might insert vulnerabilities.
HackTricks Automatic Commands
HackTricks 自动化命令
```yaml 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 outEntry_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}
</details>
> [!TIP]
> 学习和实践 AWS 黑客技术:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> 学习和实践 GCP 黑客技术:<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> 学习和实践 Azure 黑客技术:<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>支持 HackTricks</summary>
>
> - 查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
> - **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**Telegram 群组**](https://t.me/peass) 或 **在** **Twitter** 🐦 **上关注我们** [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub 仓库提交 PR 来分享黑客技巧。
>
> </details>
HackTricks

