32 KiB
80,443 - Pentesting Web Methodology
{{#include ../../banners/hacktricks-training.md}}
基本情報
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 ガイダンス
{{#ref}} web-api-pentesting.md {{#endref}}
Methodology summary
この手法では、ドメイン(またはサブドメイン)1つだけを攻撃対象とすることを想定します。したがって、スコープ内で発見した各ドメイン、サブドメイン、または未確定の web server を持つ IP ごとにこの手法を適用してください。
- まずは 識別 して、web server が使用している technologies を把握します。技術が特定できれば、テスト中に役立つ tricks を探してください。
- その技術のバージョンに対する 既知の脆弱性 はありますか?
- 既知の well known tech を使っていますか?追加情報を引き出すための useful trick はありますか?
- 実行すべき specialised scanner(例: wpscan)はありますか?
- general purposes scanners を起動します。何か見つかるか、興味深い情報が出るかもしれません。
- initial checks から始めます: robots, sitemap, 404 エラー、そして SSL/TLS scan(HTTPS の場合)。
- Webページの spidering を開始します: すべての可能な files, folders と使用されている parameters を発見する時です。special findings も確認してください。
- 注: brute-forcing または spidering 中に新しいディレクトリが発見された場合は、そのディレクトリも必ず spider してください。
- Directory Brute-Forcing: 発見したフォルダ全てを brute force して、新しい files や directories を探します。
- 注: brute-forcing または spidering 中に新しいディレクトリが発見された場合は、そのディレクトリを必ず Brute-Force してください。
- Backups checking: 一般的なバックアップ拡張子を付けて、発見した files の backups を見つけられるか試します。
- Brute-Force parameters: 隠されたパラメータを find してください。
- すべてのユーザ入力を受け付ける可能性のある endpoints を識別したら、それらに関連するあらゆる種類の vulnerabilities をチェックします。
- Follow this checklist
Server Version (Vulnerable?)
Identify
Check if there are known vulnerabilities for the server version that is running.
The HTTP headers and cookies of the response could be very useful to identify the technologies and/or version being used. Nmap scan can identify the server version, but it could also be useful the tools 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
Search: 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 技術のトリック
使用されているさまざまな有名な技術でvulnerabilitiesを見つけるためのいくつかの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)
Take into account that the same domain can be using different technologies in different ports, folders and subdomains.
同じドメインでも、異なるポート、フォルダ、サブドメインで異なる技術が使用されている可能性があることに注意してください。
もしwebアプリケーションが前述のようなよく知られたtech/platformまたはその他のものを使用している場合、新しいtricksをインターネットで検索することを忘れないでください(そして教えてください!)。
ソースコードレビュー
アプリケーションのsource codeがgithubで入手可能な場合、自身でWhite box testを行うことに加えて、現在のBlack-Box testingに有用な情報がいくつかあります:
- Is there a Change-log or Readme or Version file or anything with version info accessible via web?
- ウェブ経由でアクセス可能なChange-log、Readme、Version ファイルやversion infoはありますか?
- How and where are saved the credentials? Is there any (accessible?) file with credentials (usernames or passwords)?
- credentialsはどのように、どこに保存されていますか?credentials(usernamesやpasswords)が書かれた(アクセス可能な)fileはありますか?
- Are passwords in plain text, encrypted or which hashing algorithm is used?
- passwordsはplain textですか、それともencryptedされていますか?あるいはどのhashing algorithmが使われていますか?
- Is it using any master key for encrypting something? Which algorithm is used?
- 何かを暗号化するためのmaster keyを使用していますか?どのalgorithmが使われていますか?
- Can you access any of these files exploiting some vulnerability?
- 何らかのvulnerabilityを悪用して、これらのファイルのいずれかにaccessできますか?
- Is there any interesting information in the github (solved and not solved) issues? Or in commit history (maybe some password introduced inside an old commit)?
- githubのissues(解決済み・未解決)に興味深い情報はありますか?またはcommit history(古いcommitにpasswordが含まれている可能性)に何かありますか?
{{#ref}} code-review-tools.md {{#endref}}
自動スキャナ
汎用の自動スキャナ
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
この時点で、クライアントが使用しているウェブサーバーに関するいくつかの情報(もし提供されていれば)や、テスト中に覚えておくべきいくつかのコツを既に持っているはずです。運が良ければ、CMS を見つけて scanner を実行しているかもしれません。
Step-by-step Web Application Discovery
この時点から Web アプリケーションと対話を開始します。
Initial checks
Default pages with interesting info:
- /robots.txt
- /sitemap.xml
- /crossdomain.xml
- /clientaccesspolicy.xml
- /.well-known/
- Check also comments in the main and secondary pages.
Forcing errors
ウェブサーバーは、奇妙なデータが送られると予期せぬ挙動をすることがあります。これにより脆弱性が発生したり、機密情報の漏えいにつながることがあります。
- Access fake pages like /whatever_fake.php (.aspx,.html,.etc)
- Add "[]", "]]", and "[[" in cookie values and parameter values to create errors
- Generate error by giving input as
/~randomthing/%s
at the end of URL - Try different HTTP Verbs like PATCH, DEBUG or wrong like FAKE
Check if you can upload files (PUT verb, WebDav)
If you find that WebDav is enabled but you don't have enough permissions for uploading files in the root folder try to:
- Brute Force credentials
- Upload files via WebDav to the rest of found folders inside the web page. You may have permissions to upload files in other folders.
SSL/TLS 脆弱性
- If the application isn't forcing the user of HTTPS in any part, then it's vulnerable to MitM
- If the application is sending sensitive data (passwords) using HTTP. Then it's a high vulnerability.
Use testssl.sh to checks for vulnerabilities (In Bug Bounty programs probably these kind of vulnerabilities won't be accepted) and use a2sv to recheck the 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>
SSL/TLS の脆弱性に関する情報:
- https://www.gracefulsecurity.com/tls-ssl-vulnerabilities/
- https://www.acunetix.com/blog/articles/tls-vulnerabilities-attacks-final-part/
Spidering
ウェブ内で何らかの spider を起動します。spider の目的は、テスト対象アプリケーションから可能な限り多くのパスを見つけることです。したがって、Web クローリングや外部ソースを利用して、できるだけ多くの有効なパスを見つけるべきです。
- gospider (go): HTML スパイダー。JS ファイル内の LinkFinder 機能と外部ソース (Archive.org, CommonCrawl.org, VirusTotal.com, AlienVault.com) を利用します。
- hakrawler (go): HTML スパイダー。JS ファイル用の LinkFinder と Archive.org を外部ソースとして利用します。
- dirhunt (python): HTML スパイダーで、"juicy files" を示してくれます。
- evine (go): 対話式 CLI の HTML スパイダー。Archive.org も検索します。
- meg (go): このツールはスパイダーではありませんが便利です。hosts のファイルと paths のファイルを指定すると、各ホストの各パスを取得してレスポンスを保存します。
- urlgrab (go): JS レンダリング機能を備えた HTML スパイダー。ただしメンテナンスされていないようで、事前コンパイル版は古く、現在のコードはコンパイルできません。
- gau (go): 外部プロバイダ (wayback, otx, commoncrawl) を利用する HTML スパイダーです。
- ParamSpider: パラメータ付き URL を見つけて一覧化します。
- galer (go): JS レンダリング機能を持つ HTML スパイダーです。
- LinkFinder (python): JS の beautify 機能を持つ HTML スパイダーで、JS ファイル内の新しいパスを検索できます。LinkFinder のラッパーである JSScanner も確認すると良いでしょう。
- goLinkFinder (go): HTML ソースと埋め込み javascript ファイルの両方からエンドポイントを抽出します。bug hunters や red team、infosec の方に有用です。
- JSParser (python2.7): Tornado と JSBeautifier を使って JavaScript ファイルから相対 URL を解析する python 2.7 スクリプト。AJAX リクエストの発見に便利。メンテナンスされていない模様。
- relative-url-extractor (ruby): HTML ファイルを受け取り、正規表現で相対 URL を抽出します(minify されたファイルから相対 URL を取り出すのに便利)。
- JSFScan (bash, several tools): 複数のツールを使って JS ファイルから興味深い情報を収集します。
- subjs (go): JS ファイルを探索します。
- page-fetch (go): ヘッドレスブラウザでページを読み込み、そのページをロードするために読み込まれたすべての URL を出力します。
- Feroxbuster (rust): 先述のツール群の複数のオプションを組み合わせたコンテンツ発見ツールです。
- Javascript Parsing: JS ファイル内のパスやパラメータを見つける Burp extension。
- Sourcemapper: .js.map の URL が分かれば、beautified な JS コードを取得するツール。
- xnLinkFinder: あるターゲットのエンドポイント発見に使うツールです。
- waymore: wayback machine からリンクを発見します(wayback のレスポンスをダウンロードしてさらにリンクを探します)。
- HTTPLoot (go): フォームの入力まで行ってクローリングし、特定の正規表現で機密情報を見つけます。
- SpiderSuite: GUI ベースの多機能 web セキュリティクローラー/スパイダー。
- jsluice (go): JavaScript ソースコードから URL、パス、シークレット、その他興味深いデータを抽出する Go パッケージ兼 command-line tool。
- ParaForge: Burp Suite extension。リクエストからパラメータとエンドポイントを抽出し、fuzzing や列挙用のカスタムワードリストを作成します。
- katana (go): この用途に優れたツールです。
- Crawley (go): 発見可能なすべてのリンクを出力します。
Brute Force directories and files
ルートフォルダから brute-forcing を開始し、この方法で見つかったすべてのディレクトリと、Spidering によって発見されたすべてのディレクトリを必ず brute-force してください(これを 再帰的に 行い、見つかったディレクトリ名をワードリストの先頭に追加して試すことができます)。
ツール:
- Dirb / Dirbuster - Kali に含まれる、古い(そして 遅い)が機能するツール。自己署名証明書を許可し、再帰検索が可能。他のオプションと比べると遅すぎます。
- Dirsearch (python): 自己署名証明書は許可しませんが、再帰検索をサポートします。
- Gobuster (go): 自己署名証明書を許可し、ただし 再帰検索はサポートしていません。
- 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 の一覧から「重複」URL を削除します。
- Scavenger: Burp の履歴からディレクトリ一覧を作成する Burp Extension。
- TrashCompactor: js の import に基づいて機能が重複する URL を削除します。
- Chamaleon: wapalyzer を使って使用されている技術を検出し、適切なワードリストを選択します。
推奨ワードリスト:
- 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 の対象になり得ます。
- File Backups: すべてのファイルを見つけたら、実行可能ファイルのバックアップ(".php", ".aspx"…)を探します。バックアップ名の一般的なバリエーションは: file.ext~, #file.ext#, ~file.ext, file.ext.bak, file.ext.tmp, file.ext.old, file.bak, file.tmp and 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 キーを見つけた場合、さまざまなプラットフォームの API キーの使い方を示すプロジェクトがあります: keyhacks、zile、truffleHog、SecretFinder、RegHex、DumpsterDive、EarlyBird
- Google API keys: AIzaSyA-qLheq6xjDiEIRisP_ujUseYLQCHUjik のような形式の API キーを見つけた場合、どの API にアクセスできるかを確認するために gmapapiscanner を使えます。
- S3 Buckets: spidering 中にサブドメインやリンクが 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 を見つけた場合は should also test them。これらはファイルではありませんが、見た目はファイルと似ていることが多いです。
- JS files: spidering セクションで JS ファイルからパスを抽出できるツールをいくつか挙げました。見つかった各 JS ファイルを監視するのも有用です。場合によってはコードの変更が潜在的な脆弱性の導入を示すことがあります。例えば JSMon を使うと良いでしょう。
- 発見した JS ファイルは RetireJS や JSHole で脆弱性がないか確認するべきです。
- 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)
{{#ref}} 403-and-401-bypasses.md {{#endref}}
502 Proxy Error
もしページがこのステータスコードで応答する場合、設定ミスのあるプロキシである可能性が高いです。もし次のような HTTP リクエストを送ると: GET https://google.com HTTP/1.1
(Host ヘッダや他の一般的なヘッダ付きで)、プロキシは google.com にアクセスしようとし、SSRF を発見できることがあります。
NTLM Authentication - Info disclosure
要求しているサーバが Windows であったり、ログインがドメイン名を要求する場合、情報漏洩を引き起こすことができます。
ヘッダを送信してください: “Authorization: NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=”
。NTLM 認証の仕組みにより、サーバは "WWW-Authenticate" ヘッダ内に内部情報(IIS バージョン、Windows バージョンなど)を返すことがあります。
これを自動化するには nmap のプラグイン "http-ntlm-info.nse" を使えます。
HTTP Redirect (CTF)
リダイレクション内にコンテンツを入れることが可能です。このコンテンツはブラウザがリダイレクトを実行するためユーザーには表示されませんが、そこに何かが隠されている場合があります。
Web Vulnerabilities Checking
包括的な web アプリケーションの列挙を終えたら、多くの可能性のある脆弱性をチェックする時です。チェックリストは以下にあります:
{{#ref}} ../../pentesting-web/web-vulnerabilities-methodology.md {{#endref}}
Web 脆弱性に関する詳細情報:
- 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}
{{#include ../../banners/hacktricks-training.md}}