+1

Katana — Web Crawler thế hệ mới của ProjectDiscovery: Kiến trúc, điểm mạnh, và thực chiến

Katana — Web Crawler "thế hệ mới" của ProjectDiscovery: Kiến trúc, điểm mạnh, và tiềm năng thực tế

TL;DR: Katana không phải crawler bình thường. Nó là một crawling engine được thiết kế cho automation pipeline, security research, và recon chuyên nghiệp — với JavaScript execution, headless mode, và output có cấu trúc. Bài này mình clone về, chạy thật trên viblo.asia, rồi phân tích source Go để hiểu tại sao nó "nhanh và thông minh" hơn các tool cũ.


Mở đầu: Tại sao cần crawler mới?

Năm 2022, khi ProjectDiscovery (team tạo ra nuclei, httpx, subfinder...) release Katana, câu hỏi đầu tiên của cộng đồng là: "Đã có Scrapy, Playwright, Puppeteer rồi — sao lại cần thêm?"

Câu trả lời nằm ở use case: Katana được thiết kế không phải để scrape data (như Scrapy), cũng không phải để test UI (như Playwright) — mà để map toàn bộ attack surface của một web application theo cách tự động, có thể chain vào CI/CD pipeline.


Clone và cài đặt

# Katana yêu cầu Go 1.25+, hệ thống đang có Go 1.18 nên dùng pre-built binary
wget https://github.com/projectdiscovery/katana/releases/download/v1.5.0/katana_1.5.0_linux_amd64.zip
unzip katana_1.5.0_linux_amd64.zip
chmod +x katana
./katana -version
   __        __
  / /_____ _/ /____ ____  ___ _
 /  '_/ _  / __/ _  / _ \/ _  /
/_/\_\\_,_/\__/\_,_/_//_/\_,_/

        projectdiscovery.io

[INF] Current version: v1.5.0

Chạy thử trên viblo.asia — Real output

Test 1: Standard crawl với JavaScript parsing

./katana -u "https://viblo.asia/followings" -d 2 -jc -kf all -timeout 15 -c 5 -silent

Output thực tế (truncated):

https://viblo.asia/followings
https://accounts.viblo.asia/sso/auth?continue=http://viblo.asia/followings&service=viblo
https://accounts.viblo.asia/assets/webpack/app.e5a07e6.css
https://accounts.viblo.asia/login?service=viblo&continue=https%3A%2F%2Fviblo.asia%2Ffollowings
https://accounts.viblo.asia/assets/webpack/app.e5a07e6.js
https://accounts.viblo.asia/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js
https://accounts.viblo.asia/api/admin/roles
https://accounts.viblo.asia/api/admin/user-roles/search-user
https://accounts.viblo.asia/oauth/tokens
https://accounts.viblo.asia/admin/roles/manage
https://accounts.viblo.asia/oauth/authorize
https://accounts.viblo.asia/oauth/clients
https://accounts.viblo.asia/me/accounts
https://accounts.viblo.asia/security/tokens/new
https://accounts.viblo.asia/oauth/personal-access-tokens
https://accounts.viblo.asia/api/universities
https://accounts.viblo.asia/password/forgot

Điều thú vị: /followings yêu cầu login nên bị redirect về accounts.viblo.asia. Katana vẫn tiếp tục crawl trang login và extract được toàn bộ API endpoints từ JavaScript bundle — bao gồm cả /api/admin/roles, /oauth/clients, /oauth/tokens... những thứ không visible trên UI.

Test 2: JSONL output với full request/response

./katana -u "https://viblo.asia" -d 2 -jc -kf all -timeout 15 -c 10 -rl 20 -silent -jsonl -o /tmp/viblo.jsonl

Sample JSON record:

{
  "timestamp": "2026-03-16T16:00:53.079+07:00",
  "request": {
    "method": "GET",
    "endpoint": "https://viblo.asia/u/LeAnh",
    "tag": "a",
    "attribute": "href",
    "source": "https://viblo.asia/newest"
  },
  "response": {
    "status_code": 200,
    "headers": {
      "Cf-Ray": "9dd291e13d670984-HKG",
      "Server": "cloudflare",
      "X-Cache-Status": "MISS"
    },
    "content_length": 37398
  }
}

19 URLs được crawl trong 25 giây, với full request/response metadata — đủ để chain vào vulnerability scanner.


Kiến trúc: Tại sao Katana nhanh?

Sau khi đọc source code, kiến trúc có thể tóm tắt thành 3 tầng:

CLI Options
     │
     ▼
Runner (internal/runner/)
     │
     ├─── Standard Engine (pkg/engine/standard/)
     │         ├─ retryablehttp client
     │         ├─ goquery HTML parser
     │         └─ jsluice JS parser
     │
     ├─── Headless Engine (pkg/engine/headless/)
     │         └─ go-rod (Chromium DevTools Protocol)
     │
     └─── Hybrid Engine (pkg/engine/hybrid/)
               └─ Standard + Headless kết hợp

1. Dual-mode crawling engine

Standard mode dùng retryablehttp + goquery — pure HTTP, không cần browser. Nhanh, nhẹ, phù hợp với server-rendered HTML:

// pkg/engine/standard/crawl.go
func (c *Crawler) makeRequest(s *common.CrawlSession, request *navigation.Request) (*navigation.Response, error) {
    httpReq, _ := http.NewRequestWithContext(ctx, request.Method, request.URL, nil)
    req, _ := retryablehttp.FromRequest(httpReq)
    req.Header.Set("User-Agent", utils.WebUserAgent())

    // Cookie jar support — giữ session qua nhiều requests
    if c.Jar != nil {
        cookies := c.Jar.Cookies(req.Request.URL)
        for _, cookie := range cookies {
            req.AddCookie(cookie)
        }
    }
    // ...
}

Headless mode dùng go-rod (Go binding cho Chrome DevTools Protocol) — chạy Chromium thật, render JavaScript, handle SPA (React/Vue/Angular). Chi phí cao hơn nhưng hiểu được dynamic content.

2. JavaScript Intelligence với jsluice

Đây là điểm khác biệt lớn nhất. Katana không chỉ parse <a href=""> mà còn phân tích JavaScript để extract endpoints:

./katana -u "https://viblo.asia" -jc -jsl -silent

Flag -jsl kích hoạt jsluice — một AST-based JS analyzer. Nó đọc .js bundle và extract:

  • Hardcoded API paths: /api/users, /v2/search...
  • Template literals: `/users/${id}/profile`
  • Fetch/XHR calls trong code

Ví dụ từ crawl viblo: endpoint /api/admin/roles, /api/admin/user-roles/search-user được tìm thấy trong app.e5a07e6.js — không bao giờ xuất hiện trong HTML.

3. Scope-aware crawling

Katana có hệ thống scope control tinh tế. Thay vì crawl tất cả hoặc chỉ same-domain, bạn có thể define:

# Chỉ crawl trong viblo.asia
./katana -u https://viblo.asia -d 3 -cs "viblo.asia"

# Crawl theo regex pattern
./katana -u https://viblo.asia -d 3 -cr ".*\.viblo\.asia"

# Out-of-scope: skip CDN và static assets
./katana -u https://viblo.asia -e cdn,images.viblo.asia

Đây là thứ tool cũ như wget --mirror không có — crawl thông minh thay vì crawl mù.

4. Automatic Form Filling

./katana -u https://viblo.asia -d 2 -aff

Katana có thể tự động điền form (login, search, contact) để trigger thêm endpoints. Logic nằm ở pkg/utils/formfill.go:

// Tự detect input type và fill heuristically
// email fields → test@example.com
// password fields → Password1!
// number fields → 1

Với -form-extraction, nó export toàn bộ form structure ra JSONL — perfect để feed vào fuzzer.

5. Pipeline-first design

Output mặc định là stdout lines → dễ pipe:

# Tìm tất cả API endpoints rồi check với httpx
./katana -u https://viblo.asia -d 2 -silent | grep "/api/" | httpx -sc

# Feed vào nuclei để scan vuln
./katana -u https://target.com -d 3 -silent | nuclei -t exposures/

# Lưu jsonl rồi process với jq
./katana -u https://viblo.asia -jsonl | jq 'select(.response.status_code == 200) | .request.endpoint'

Đây là lý do tại sao Katana nằm trong hầu hết automated bug bounty/recon pipeline hiện đại.


Điểm mạnh thực sự

1. Go concurrency model Worker pool với channel-based queue. Mình chạy -c 10 -rl 20 (10 concurrent workers, 20 req/s rate limit) mà CPU load vẫn thấp. So với Python crawler tương đương thì tiết kiệm memory đáng kể.

2. Không bị fingerprint dễ

// utils.WebUserAgent() random rotation
// TLS impersonation với -tls-impersonate
// JA3 fingerprint randomization

3. Known files auto-discovery Flag -kf all tự động crawl robots.txt, sitemap.xml, .well-known/security.txt... rồi parse và add URLs vào queue.

4. Tech detection

./katana -u https://viblo.asia -td -silent

Kết hợp crawling với technology fingerprinting — biết target dùng Vue.js, Nuxt.js, Cloudflare, Pusher... từ response headers và JS patterns.


Điểm yếu / hạn chế

Authentication: Katana chưa có built-in OAuth flow. Để crawl behind login cần workaround:

# Dùng cookie từ browser session
./katana -u https://viblo.asia/followings \
  -H "Cookie: viblo_session=xxx; viblo_auth=yyy"

SPA handling: Standard mode không execute JS. Với React/Vue apps nặng, cần -headless hoặc -hybrid, nhưng headless mode chậm hơn ~10x và cần Chromium installed.

Rate limiting detection: Không có adaptive rate limiting — nếu target trả 429, Katana không tự giảm speed.


Ứng dụng thực tế

Bug bounty automation:

# Full recon pipeline
subfinder -d target.com -silent | \
  httpx -silent | \
  katana -d 3 -jc -silent | \
  grep "\.js$" | \
  nuclei -t exposures/tokens/

API discovery:

./katana -u https://api.target.com -d 2 -jc -jsl -silent | \
  grep -E "^https?://.*/api/" | sort -u

Security audit nội bộ: Map toàn bộ endpoints của internal app trước khi pentest — thay vì manual explore, để Katana tự tìm route ẩn, admin panel, debug endpoints.

Content discovery:

./katana -u https://viblo.asia -d 4 -kf all -c 20 -silent | \
  httpx -sc -content-length | \
  grep "200"

Kết luận

Katana không cố gắng thay thế Scrapy hay Playwright. Nó giải quyết một bài toán cụ thể: automated web surface mapping cho security/recon workflows. Và ở bài toán đó, nó làm tốt hơn bất kỳ tool hiện có nào.

Những điểm đáng học từ kiến trúc Katana:

  • Dual-mode engine: standard vs headless, chọn đúng tool cho đúng target
  • Pipeline-first: mọi thứ output ra stdout JSONL, dễ chain
  • JS intelligence: không dừng ở HTML parser, extend sang AST analysis
  • Scope control: crawl thông minh thay vì crawl mù

Nếu bạn làm bug bounty, pentesting, hoặc security engineering — thêm Katana vào toolbox ngay.

# One-liner cài và chạy
wget -qO- "https://github.com/projectdiscovery/katana/releases/download/v1.5.0/katana_1.5.0_linux_amd64.zip" | \
  funzip > katana && chmod +x katana && \
  ./katana -u https://viblo.asia -d 2 -jc -silent

Repo: github.com/projectdiscovery/katana | Stars: 13k+ | License: MIT


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí