Post

Information Gathering - Web Edition

HTB CPTS note về quy trình information gathering cho mục tiêu web.

Information Gathering - Web Edition

🌐 Information Gathering – Web Edition

Web reconnaissance là bước đầu tiên trong mọi pentest engagement — giống như thám tử thu thập manh mối trước khi lập kế hoạch hành động.


🎯 Mục tiêu chính

Mục tiêuMô tả
Xác định assetsTìm tất cả domain, subdomain, IP liên quan
Khám phá thông tin ẩnDirectory, file, công nghệ không công khai
Phân tích attack surfaceOpen ports, services, phiên bản phần mềm
Thu thập intelligenceEmail, nhân viên, công nghệ đang dùng

🔍 Passive vs Active Recon

LoạiMô tảNguy cơ bị phát hiệnVí dụ
ActiveTương tác trực tiếp với targetCaoPort scan, vuln scan
PassiveDùng dữ liệu công khai, không chạm targetThấpWHOIS, DNS enum, Google Dork, Wayback Machine

Chiến lược Luôn bắt đầu bằng passive recon để giảm noise trước khi chuyển sang active.


📋 WHOIS

Mục đích: Tra cứu thông tin đăng ký domain — chủ sở hữu, ngày đăng ký, nameserver, thông tin liên hệ.

1
whois example.com

Lưu ý WHOIS data có thể không chính xác hoặc bị che giấu bởi privacy service. Luôn cross-verify từ nhiều nguồn.


🌍 DNS Enumeration

Mục đích: Truy vấn DNS records để ánh xạ hạ tầng của target.

🛠️ Công cụ DNS Recon

ToolTính năng nổi bậtDùng khi nào
digQuery mọi loại record, output chi tiết, tùy chỉnh caoManual query, zone transfer, phân tích sâu
nslookupĐơn giản, chủ yếu A/AAAA/MXQuick check cơ bản
hostOutput ngắn gọnKiểm tra nhanh A/AAAA/MX
dnsenumTự động hóa, brute-force, zone transferEnum subdomain hàng loạt
fierceRecursive search, wildcard detectionThân thiện, tìm subdomain
dnsreconKết hợp nhiều kỹ thuật, nhiều output formatEnum toàn diện
theHarvesterOSINT — gom email, info từ nhiều nguồnThu thập email/nhân viên liên quan domain

Ưu tiên dig là tool quan trọng nhất — linh hoạt và output đầy đủ nhất. Học thành thục trước.


Các loại DNS record quan trọng

RecordMô tả
AHostname → IPv4
AAAAHostname → IPv6
CNAMEAlias trỏ sang hostname khác
MXMail server của domain
NSAuthoritative nameserver
TXTDữ liệu text tùy ý (SPF, DKIM, v.v.)
SOAThông tin quản trị DNS zone
SRVHostname + port của một service cụ thể
PTRReverse DNS: IP → Hostname

Bảng lệnh dig đầy đủ

LệnhMô tả
dig domain.comQuery A record mặc định
dig domain.com ALấy IPv4
dig domain.com AAAALấy IPv6
dig domain.com MXTìm mail server
dig domain.com NSTìm authoritative nameserver
dig domain.com TXTLấy TXT record (SPF, DKIM…)
dig domain.com CNAMELấy CNAME record
dig domain.com SOALấy thông tin quản trị zone
dig domain.com ANYLấy tất cả record (nhiều server ignore theo RFC 8482)
dig @1.1.1.1 domain.comDùng DNS server cụ thể (Cloudflare)
dig +trace domain.comXem toàn bộ chuỗi resolution: root → TLD → authoritative
dig -x 192.168.1.1Reverse lookup: IP → hostname
dig +short domain.comOutput ngắn gọn, chỉ lấy kết quả
dig +noall +answer domain.comChỉ hiển thị phần Answer

Dùng trong script +short+noall +answer hữu ích khi pipe output sang tool khác hoặc viết script tự động hóa recon.


Đọc hiểu output của dig

1
dig google.com
1
2
3
4
5
6
7
8
9
10
11
12
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16449
;; flags: qr rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             0       IN      A       142.251.47.142

;; Query time: 0 msec
;; SERVER: 172.23.176.1#53(172.23.176.1) (UDP)
;; MSG SIZE  rcvd: 54

Header:

FieldÝ nghĩa
status: NOERRORQuery thành công
qrĐây là gói trả lời (Query Response)
rdClient yêu cầu recursive lookup
adResolver xác nhận data xác thực
ANSWER: 1Có 1 kết quả trả về

Question Section: Câu hỏi đã gửi đi — “A record của google.com là gì?”

Answer Section:

FieldÝ nghĩa
google.com.Domain được query
0TTL = 0s → không cache kết quả này
INInternet class (chuẩn)
ALoại record
142.251.47.142IP address — đây là thứ cần tìm

Footer: DNS server đã trả lời (SERVER), thời gian xử lý (Query time), kích thước gói tin (MSG SIZE).

Rate limit Một số server phát hiện và block nếu query quá nhiều. Chỉ thực hành trên target được phép (HTB lab).


🏷️ Subdomain Enumeration

Subdomain có thể chứa: dev server, staging, app cũ chưa được bảo mật, admin panel, v.v.

Cách tiếp cậnMô tảCông cụ
ActiveBrute-force, zone transferdnsenum, dig axfr, gobuster
PassiveCT logs, search enginecrt.sh, Google Dork

🛠️ Công cụ Brute-Force Subdomain

ToolMô tả
dnsenumToàn diện: DNS enum, brute-force, zone transfer, Google scraping, WHOIS
fierceRecursive, wildcard detection, giao diện thân thiện
dnsreconKết hợp nhiều kỹ thuật, nhiều output format
amassTích hợp nhiều nguồn dữ liệu, actively maintained
assetfinderNhẹ, nhanh, ideal cho quick scan
purednsMạnh, lọc kết quả hiệu quả, xử lý được wordlist lớn

Brute-force subdomain với dnsenum

Khả năng đầy đủ của dnsenum:

Tính năngMô tả
DNS Record EnumerationLấy A, AAAA, NS, MX, TXT records
Zone TransferTự động thử AXFR từ các nameserver tìm được
Subdomain Brute-ForceDò subdomain theo wordlist
Google ScrapingTìm subdomain thêm từ kết quả Google
Reverse LookupIP → domain, phát hiện website cùng server
WHOIS LookupTra cứu thông tin đăng ký domain

Lệnh chuẩn với SecLists:

1
dnsenum --enum inlanefreight.com -f /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -r
FlagÝ nghĩa
--enumShortcut bật nhiều option hữu ích cùng lúc
-f <wordlist>Đường dẫn wordlist
-rRecursive — nếu tìm được subdomain, tiếp tục enum subdomain của subdomain đó

Wordlist nên dùng (SecLists):

1
2
/usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt  # nhanh, phổ thông
/usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt # toàn diện hơn

Wordlist strategy

  • Không biết gì về target → dùng general-purpose wordlist (top 20k)
  • Biết ngành/công nghệ → dùng targeted wordlist
  • Có intel từ recon trước → tự tạo custom wordlist từ keywords tìm được

Zone Transfer (AXFR) với dig

1
dig @ns1.example.com example.com axfr

Zone Transfer Hầu hết server đã khóa AXFR. Nhưng nếu misconfigured → lộ toàn bộ DNS zone (tất cả subdomain + IP). Đây là goldmine nếu thành công!

CT Logs với crt.sh

1
2
3
4
curl -s "https://crt.sh/?q=%25.example.com&output=json" \
  | jq -r '.[].name_value' \
  | sed 's/\*\.//g' \
  | sort -u

Giải thích lệnh

  • %25. = wildcard %. được URL-encode
  • jq -r '.[].name_value' → trích xuất tên domain từ JSON
  • sed 's/\*\.//g' → bỏ prefix *.
  • sort -u → sắp xếp và loại trùng lặp

🏠 Virtual Host Discovery

Vấn đề: Một server có một IP nhưng host nhiều website. Scan IP đơn thuần không thấy hết.

Cơ chế: Web server (Apache/Nginx/IIS) đọc HTTP Host header trong mỗi request để quyết định trả về content của website nào.

1
2
GET / HTTP/1.1
Host: www.example1.com     ← server đọc cái này để phân biệt

VHost vs Subdomain

Tiêu chíSubdomainVirtual Host
DNS recordBắt buộc cóKhông bắt buộc
Phát hiện qua DNS enum?Không nhất thiết
Ví dụblog.example.comdev.example.com, example2.org

Điểm mấu chốt VHost không cần DNS record — server vẫn serve được nếu map thủ công trong /etc/hosts. Đây là lý do DNS enum không tìm được hết VHost.

Ví dụ cấu hình Apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 3 website khác nhau, cùng 1 IP
<VirtualHost *:80>
    ServerName www.example1.com
    DocumentRoot /var/www/example1
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example2.org
    DocumentRoot /var/www/example2
</VirtualHost>

<VirtualHost *:80>
    ServerName www.another-example.net
    DocumentRoot /var/www/another-example
</VirtualHost>

Tại sao quan trọng trong Pentest?

VHost ẩn thường không public, không có DNS record — nhưng vẫn chạy trên server:

1
2
3
dev.example.com      → staging server, ít được bảo mật
admin.example.com    → admin panel ẩn
internal.example.com → app nội bộ

VHost Fuzzing – Cách tìm VHost ẩn

1
2
3
4
5
6
7
# Gobuster vhost mode
gobuster vhost -u http://10.10.10.5 -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt --append-domain

# ffuf (alternative)
ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt \
     -u http://10.10.10.5 \
     -H "Host: FUZZ.example.com"
Flag (gobuster)Ý nghĩa
-uTarget IP/URL
-wWordlist hostname
--append-domainTự ghép domain vào sau mỗi từ trong wordlist

Khi tìm được VHost → thêm vào /etc/hosts:

1
echo "10.10.10.5  dev.example.com" | sudo tee -a /etc/hosts

Active Recon VHost fuzzing gửi hàng nghìn request → dễ bị phát hiện và log lại. Chỉ thực hành trên target được phép.


🕷️ Web Crawling

Mục đích: Tự động duyệt toàn bộ cấu trúc website, thu thập link, file, endpoint ẩn.

Công cụ Web Crawler phổ biến

ToolMô tảDùng khi nào
Burp Suite SpiderCrawler tích hợp Burp, map web app, tìm hidden contentPentest web app toàn diện
OWASP ZAPFree, open-source, có spider tự độngQuét lỗ hổng kết hợp crawl
ScrapyPython framework, tùy biến caoViết spider tùy chỉnh cho recon
Apache NutchJava, scale lớn, crawl hàng triệu trangLarge-scale recon project

LinkFinder – Tìm endpoint trong JS files

Mục đích: Phân tích file JavaScript để tìm API endpoint, hidden path, REST API — những thứ ReconSpider hay bỏ sót.

Cách dùng:

1
2
3
4
5
6
7
8
# Scan 1 file JS cụ thể
linkfinder -i https://example.com/main.js -o cli

# Scan toàn bộ website (crawl + phân tích JS)
linkfinder -i https://example.com -d -o cli

# Output ra file HTML
linkfinder -i https://example.com/main.js -o results.html
FlagÝ nghĩa
-iInput — URL của JS file hoặc website
-dDomain mode — crawl toàn bộ site tìm JS
-oOutput format: cli hoặc results.html

Output mẫu:

1
2
3
4
5
/api/v1/users
/api/v1/admin/settings
/internal/dashboard
/.env
/api/auth/token

Workflow chuẩn

  1. Dùng ReconSpider → lấy danh sách js_files
  2. Feed từng JS file vào LinkFinder → tìm API endpoint ẩn
  3. Test từng endpoint tìm được

Kết hợp với curl

1
2
3
4
# Lấy list JS từ results.json rồi feed vào LinkFinder
cat results.json | jq -r '.js_files[]' | while read url; do
  linkfinder -i "$url" -o cli
done
1
http://example.com/robots.txt

robots.txt File này liệt kê những path mà webmaster **không muốn index → thường chứa path nhạy cảm!**


ReconSpider – Spider

Cài đặt Scrapy trên Kali:

1
python3 ReconSpider.py http://inlanefreight.com

Output — results.json:

KeyDữ liệuGiá trị với Pentest
emailsEmail tìm thấy trên domainSocial engineering, phishing
linksURL nội bộMapping cấu trúc website
external_filesPDF, DOC, file ngoàiMetadata leak, thông tin nhạy cảm
js_filesFile JavaScriptAPI endpoint ẩn, hardcoded secret
form_fieldsForm inputAttack surface cho injection
imagesURL ảnhEXIF metadata, path disclosure
commentsHTML comment trong sourceCredential bị bỏ quên, path nội bộ

JS files & Comments — hay bị bỏ qua

  • JS files thường chứa hardcoded API key, endpoint ẩn, logic xác thực
  • HTML comments đôi khi chứa credential hoặc path nội bộ mà dev quên xóa

🔎 Google Dorks (Search Engine Discovery)

Dùng search operator để tìm thông tin nhạy cảm mà không cần chạm vào target — hoàn toàn passive recon.

Bảng operator đầy đủ

OperatorMô tảVí dụ
site:Giới hạn theo domainsite:example.com
inurl:Tìm keyword trong URLinurl:login
filetype:Lọc theo loại filefiletype:pdf
intitle:Tìm trong title trangintitle:"confidential report"
intext: / inbody:Tìm trong body textintext:"password reset"
cache:Xem cached versioncache:example.com
link:Tìm trang link tới URLlink:example.com
related:Tìm website tương tựrelated:example.com
numrange:Tìm số trong khoảngsite:example.com numrange:1000-2000
allintext:Body chứa tất cả từ chỉ địnhallintext:admin password reset
allinurl:URL chứa tất cả từ chỉ địnhallinurl:admin panel
allintitle:Title chứa tất cả từ chỉ địnhallintitle:confidential report 2023
ANDBắt buộc cả hai điều kiệnsite:example.com AND inurl:admin
ORMột trong hai"linux" OR "ubuntu"
NOTLoại trừ điều kiệnsite:bank.com NOT inurl:login
*Wildcard — bất kỳ từ nàosite:x.com filetype:pdf user* manual
..Range sốsite:shop.com "price" 100..500
" "Exact phrase"information security policy"
-Loại trừ keywordsite:news.com -inurl:sports

Google Dorking – Ứng dụng thực tế

Tìm login page:

1
2
site:example.com inurl:login
site:example.com (inurl:login OR inurl:admin)

Tìm file nhạy cảm bị lộ:

1
2
site:example.com filetype:pdf
site:example.com (filetype:xls OR filetype:docx)

Tìm file cấu hình:

1
2
site:example.com inurl:config.php
site:example.com (ext:conf OR ext:cnf)

Tìm database backup:

1
2
site:example.com inurl:backup
site:example.com filetype:sql

Google Hacking Database (GHDB) Kho lưu trữ hàng nghìn Google Dork mẫu theo category: https://www.exploit-db.com/google-hacking-database


⏳ Web Archives – Wayback Machine

URL: https://web.archive.org — lưu trữ snapshot website từ năm 1996 đến nay.

Cách hoạt động

1
Crawling → Archiving → Accessing

Bot tự động download toàn bộ trang (HTML, CSS, JS, ảnh) → lưu kèm timestamp → user truy cập bằng cách chọn URL + ngày.

Tại sao quan trọng trong Pentest?

Tình huốngÝ nghĩa
Tìm asset ẩnDirectory, file, subdomain cũ không còn trên site hiện tại
Theo dõi thay đổiSo sánh snapshot → thấy cấu trúc cũ, tech stack đã thay
Thu thập OSINTNhân viên cũ, chiến lược, công nghệ từng dùng
Tìm lỗ hổng cũConfig file, credential bị expose trong phiên bản cũ
StealthPassive hoàn toàn — không chạm vào infrastructure của target

Query qua API

1
curl -s "https://web.archive.org/cdx/search/cdx?url=example.com&output=json&fl=timestamp,original&collapse=digest" | jq

Mẹo Website cũ có thể chứa file cấu hình, credentials, hoặc endpoint không còn tồn tại trong phiên bản hiện tại nhưng vẫn accessible.


📜 Certificate Transparency (CT) Logs

Mục đích: Mọi SSL/TLS certificate được cấp đều phải đăng ký vào public ledger — ai cũng có thể xem. Dùng để tìm subdomain mà không cần brute-force.

CT Logs vs Brute-force

Brute-force subdomainCT Logs
Đoán tên theo wordlistLấy từ record certificate thực tế
Bị giới hạn bởi wordlistKhông bị giới hạn
Miss subdomain tên khó đoánTìm được cả subdomain không còn active

Điểm đặc biệt CT logs lưu cả **certificate cũ/hết hạn → subdomain đó có thể chạy software lỗi thời → dễ khai thác hơn.**

2 Tool tìm kiếm CT Logs

ToolĐiểm mạnhĐiểm yếu
crt.shFree, không cần đăng ký, giao diện web đơn giảnFilter hạn chế
CensysFilter mạnh, tìm được IP/cert liên quan, có APICần đăng ký

Lệnh crt.sh từ terminal

1
2
3
4
5
6
7
8
9
10
# Lấy tất cả subdomain
curl -s "https://crt.sh/?q=%25.example.com&output=json" \
  | jq -r '.[].name_value' \
  | sed 's/\*\.//g' \
  | sort -u

# Lọc chỉ lấy subdomain chứa "dev"
curl -s "https://crt.sh/?q=example.com&output=json" \
  | jq -r '.[] | select(.name_value | contains("dev")) | .name_value' \
  | sort -u

📁 Well-Known URIs

Đường dẫn chuẩn: https://example.com/.well-known/

Lưu trữ metadata, cấu hình, thông tin bảo mật tại vị trí cố định, có thể đoán trước — browser, app, security tool đều biết tìm ở đây.

Các URI quan trọng

URIMô tảGiá trị với Pentest
security.txtThông tin liên hệ report lỗ hổngTìm contact security team
openid-configurationCấu hình OpenID Connect / OAuth 2.0Chi tiết auth infrastructure
change-passwordURL trang đổi mật khẩuXác nhận có auth system
assetlinks.jsonXác minh ownership digital assetTìm app liên kết domain
mta-sts.txtPolicy bảo mật email SMTPHiểu cấu hình mail server

openid-configuration — Quan trọng nhất

1
https://example.com/.well-known/openid-configuration

Trả về JSON chứa toàn bộ cấu hình auth:

1
2
3
4
5
6
7
8
{
  "issuer": "https://example.com",
  "authorization_endpoint": "https://example.com/oauth2/authorize",
  "token_endpoint": "https://example.com/oauth2/token",
  "userinfo_endpoint": "https://example.com/oauth2/userinfo",
  "jwks_uri": "https://example.com/oauth2/jwks",
  "scopes_supported": ["openid", "profile", "email"]
}
FieldGiá trị với Pentest
authorization_endpointTarget để test auth bypass
token_endpointTarget để test token forgery
userinfo_endpointTest broken access control
jwks_uriPhân tích thuật toán mã hóa JWT
scopes_supportedHiểu attack surface của auth

Đây là passive recon — chỉ đọc file public, không tương tác với hệ thống. Nhưng thông tin thu được rất chi tiết về auth infrastructure.


🤖 Automating Recon – FinalRecon

Các Framework Recon tự động

ToolMô tả
FinalReconPython, modular, all-in-one: header, WHOIS, SSL, crawl, DNS, subdomain, dir, wayback
Recon-ngFramework mạnh, modular, có thể exploit known vulns
theHarvesterChuyên gom email, subdomain, host từ search engine, Shodan
SpiderFootOSINT tự động, tích hợp nhiều nguồn dữ liệu
OSINT FrameworkBộ sưu tập tool và resource OSINT toàn diện

FinalRecon – Cài đặt

1
2
3
4
5
git clone https://github.com/thewhiteh4t/FinalRecon.git
cd FinalRecon
pip3 install -r requirements.txt
chmod +x ./finalrecon.py
./finalrecon.py --help

Bảng flag đầy đủ

FlagMô tả
--url URLTarget URL
--headersLấy header information
--sslinfoThông tin SSL certificate
--whoisWHOIS lookup
--crawlCrawl target website
--dnsDNS enumeration (40+ record types)
--subSubdomain enumeration
--dirDirectory search
--waybackLấy URL từ Wayback Machine
--psFast port scan
--fullFull recon — chạy tất cả module
-w WCustom wordlist
-e EFile extensions (vd: txt,xml,php)
-d DCustom DNS server (mặc định: 1.1.1.1)
-k KThêm API key (vd: shodan@key)
-o OExport format (mặc định: txt)

Ví dụ lệnh thực tế

1
2
3
4
5
6
7
8
9
10
11
# Header + WHOIS
./finalrecon.py --headers --whois --url http://inlanefreight.com

# Full recon
./finalrecon.py --full --url http://inlanefreight.com

# Subdomain + DNS
./finalrecon.py --sub --dns --url http://inlanefreight.com

# Directory search với custom wordlist
./finalrecon.py --dir -w /usr/share/seclists/Discovery/Web-Content/common.txt --url http://inlanefreight.com

Output từ --headers --whois:

1
2
3
4
5
6
7
8
9
10
11
12
[+] IP Address : 134.209.24.248

[!] Headers :
Server : Apache/2.4.41 (Ubuntu)
Content-Type : text/html; charset=UTF-8
...

[!] Whois Lookup :
Registrar: Amazon Registrar, Inc.
Creation Date: 2019-08-05
Name Server: NS-161.AWSDNS-20.COM
...

FinalRecon vs Manual FinalRecon đặc biệt mạnh ở **subdomain enum — tích hợp 8 nguồn dữ liệu: crt.sh, AnubisDB, ThreatMiner, CertSpotter, Facebook API, VirusTotal API, Shodan API, BeVigil API.**

Kali Linux Nếu pip3 install bị chặn do PEP 668:

1
pip3 install -r requirements.txt --break-system-packages

🛠️ Tool Summary

ToolMục đíchLệnh mẫu
whoisTra cứu đăng ký domainwhois example.com
digTruy vấn DNS / Zone transferdig @ns1.x.com x.com axfr
dnsenumBrute-force subdomaindnsenum x.com -f wordlist.txt
gobusterVhost / directory brute-forcegobuster vhost -u http://IP -w list.txt
ffufVhost fuzzing với filterffuf -w list.txt -u http://IP -H "Host: FUZZ.x.com" -fs 116
crt.shCT log – passive subdomain enumcurl -s "https://crt.sh/?q=%25.x.com&output=json"
LinkFinderTìm API endpoint trong JS filespython3 linkfinder.py -i https://target.com -d -o cli
ReconSpiderWeb crawling tự độngpython3 ReconSpider.py http://target.com
FinalReconAll-in-one recon framework./finalrecon.py --full --url http://target.com
Wayback MachineWeb archivehttps://web.archive.org

🔗 Liên kết

  • Footprinting
This post is licensed under CC BY 4.0 by the author.