命令行版 HTTP 工具集,自動化檢查網站狀態
如果我們有幾十萬個網站需要檢測,該如何實現?手工檢測嗎?當然不行,這是非常不現實的,只有自動化才是正確的選擇,那么如何自動化實現?
對于幾十個網站的目標,如果要對所有網站進行掃描,每一個網站的掃描都需要比較長的時間,而且,其中難免有很多無效網站,如果我們可以將無效網站排除,那么我們就可以節省掃描的時間,從而提升檢測效率。
自動化檢測,離不開自動化的工具,今天來為大家分享一款命令行版的 HTTP 工具集 httpx,項目地址:
https://github.com/projectdiscovery/httpx
該工具使用 go 語言編寫,安裝方式也比較簡單,需要提前安裝 go 環境,安裝完成之后需要換成國內的代理,否則安裝的時候,會出現連接超時的問題,安裝命令如下:
go get -v github.com/projectdiscovery/httpx/cmd/httpx
Windows 下安裝時報錯,然后執行下面的命令之后,再進行安裝就可以了:
go env -w GOSUMDB=off

安裝完成之后,查看幫助信息:
[root@vultrguest ~]# httpx -hUsage of httpx: -H value # 自定義 header,比如 UA、cookie 等 Custom Header -allow value Allowlist ip/cidr -body string Content to send in body with HTTP request -cdn # 根據頁面返回 header,判斷是否存在 cdn Check if domain's ip belongs to known CDN (akamai, cloudflare, ..) -cname Output first cname -content-length # 輸出返回包的長度 Extracts content length -content-type # 輸出網站的內容類型 Extracts content-type -csp-probe Send HTTP probes on the extracted CSP domains -debug Debug mode -deny value Denylist ip/cidr -exclude-cdn Skip full port scans for CDNs (only checks for 80,443) -extract-regex string Extract Regex -fc string # 過濾掉某些狀態碼的網站,比如 404、500 等 Filter status code -filter-regex string Filter Regex -filter-string string Filter String -fl string Filter content length -follow-host-redirects Only follow redirects on the same host -follow-redirects Follow Redirects -http-proxy string # 設置請求代理 HTTP Proxy, eg http://127.0.0.1:8080 -http2 HTTP2 probe -include-chain Show Raw HTTP Chain In Output (-json only) -include-response Show Raw HTTP Response In Output (-json only) -ip # 輸出域名對應的 IP Output target ip -json JSON Output -l string File containing domains -location Extracts location header -match-regex string Match Regex -match-string string Match string -mc string Match status code -method Display request method -ml string Match content length -no-color No Color -no-fallback If HTTPS on port 443 is successful on default configuration, probes also port 80 for HTTP -no-fallback-scheme The tool will respect and attempt the scheme specified in the url (if HTTPS is specified no HTTP is attempted) -o string File to write output to (optional) -path string Request path/file (example '/api') -paths string Command separated paths or file containing one path per line (example '/api/v1,/apiv2') -pipeline HTTP1.1 Pipeline -ports value ports range (nmap syntax: eg 1,2-10,11) -probe Display probe status -random-agent Use randomly selected HTTP User-Agent header value (default true) -rate-limit int Maximum requests to send per second (default 150) -request string File containing raw request -response-in-json Show Raw HTTP Response In Output (-json only) (deprecated) -response-size-to-read int Max response size to read in bytes (default - unlimited) (default 2147483647) -response-size-to-save int Max response size to save in bytes (default - unlimited) (default 2147483647) -response-time Output the response time -resume Resume scan using resume.cfg -retries int Number of retries -silent Silent mode -sr Save response to file (default 'output') -srd string Save response directory (default "output") -stats Enable statistic on keypress (terminal may become unresponsive till the end) -status-code Extracts status code -store-chain Save chain to file (default 'output') -tech-detect Perform wappalyzer based technology detection -threads int Number of threads (default 50) -timeout int Timeout in seconds (default 5) -title Extracts title -tls-grab Perform TLS data grabbing -tls-probe Send HTTP probes on the extracted TLS domains -unsafe Send raw requests skipping golang normalization -verbose Verbose Mode -version Show version of httpx -vhost Check for VHOSTs -vhost-input Get a list of vhosts as input -web-server Extracts server header -websocket Prints out if the server exposes a websocket -x string Request Methods, use ALL to check all verbs ()
使用場景一:檢查網站是否存活
將網站列表保存為一個文本,比如:

最簡單的命令,無需加任何參數:
type domain.txt | httpx (windows)/ cat domain.txt | httpx (Linux)
或者
httpx -l domain.txt
無法訪問的網站,在結果中未進行顯示:

這個工具在 linux 下使用顯示會比較好看,如果我們想要顯示連接失敗的網站,可以使用命令:
httpx -l domain.txt -silent -probe

使用場景二:獲取網站 Title 、狀態碼等
通過獲取網站的 Title 和狀態碼,可以排除大量非正常網站,比如 404、500 等狀態碼,還有很多域名指向同一個網站,然后通過網站標題可以去掉大量重復的網站域名,從而提升檢測的效率。
httpx -l domain.txt -title -tech-detect -status-code

對于有大量無法訪問網站的情況,默認的超時時間是 5 秒,想要提升速度,可以將超時時間,比如:
httpx -l domain.txt -title -tech-detect -status-code -timeout 2
目標多的情況下,可以結合多線程技術,使用參數 -threads:
httpx -l domain.txt -title -tech-detect -status-code -timeout 2 -threads 30
如果還想獲取目標網的服務器信息,可以使用 -web-server 參數:
httpx -l domain2.txt -title -tech-detect -status-code -threads 30 -web-server

使用場景三:使用域名作為目標,獲取網站信息
當我們收集了很多域名,并沒有生成網站的鏈接,httpx 通用可以檢測域名上搭建的網站信息,比如下面的域名:

通用使用獲取 title 的命令:
httpx -l domain2.txt -title -tech-detect -status-code -timeout 2 -threads 30

總結
本文對 httpx 做了一個簡單的使用,工具好壞主要與使用者面臨的問題和需求決定,當你需要時,它是一個提效的好幫手,當你不需要時,他不過就是個工具而已,對于大量目標的狀態檢測和信息收集,httpx 是個不錯的幫手,在這幾天的實戰訓練營中,這個工具也是可以使用的,當然,如果自己有編碼基礎,寫腳本來實現自己的目標,更高效且高度自定義化,滿足自己的各種需求,公開的工具多少是有缺陷的,作者不可能把所有狀況都考慮到,而且在使用的時候,目標過多的情況下,會出現各種各樣的 bug,參與訓練營的小伙伴,多少都體驗多了。