httpx

package
v0.0.0-...-26462ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// 请求配置
	Method          string
	Path            string
	Body            string
	Headers         []string
	CustomHost      string
	Timeout         int
	FollowRedirects bool

	// 探测配置
	Threads    int
	RateLimit  int
	Retries    int
	Ports      []string
	TechDetect bool
	Favicon    bool

	// 网络配置
	Proxy string

	// 响应体配置
	ResponseBodySize int

	// 输出配置
	ShowStatistics bool
}

Config 封装 httpx 探测的所有可配置项,与上游 runner.Options 解耦

type HttpxClient

type HttpxClient struct {
	// contains filtered or unexported fields
}

HttpxClient 封装 projectdiscovery/httpx 的探测客户端

func NewHttpxClient

func NewHttpxClient(opts ...Option) *HttpxClient

NewHttpxClient 创建一个新的 HttpxClient,支持通过 Option 函数自定义配置

Example

示例:创建 HTTP 探测客户端,配置线程数、技术检测、跟随重定向

package main

import (
	"fmt"

	"github.com/polite-007/toolbox/httpx"
)

func main() {
	_ = httpx.NewHttpxClient(
		httpx.WithThreads(50),
		httpx.WithTechDetect(),
		httpx.WithFollowRedirects(),
	)
	fmt.Println("httpx client created")
}
Output:
httpx client created
Example (HeaderMerge)

示例:组合使用 Headers 和 CustomHost(验证追加不覆盖)

package main

import (
	"fmt"

	"github.com/polite-007/toolbox/httpx"
)

func main() {
	_ = httpx.NewHttpxClient(
		httpx.WithHeaders([]string{"X-Token: abc123"}),
		httpx.WithCustomHost("internal.example.com"),
	)
	fmt.Println("httpx client created")
}
Output:
httpx client created
Example (WithProxy)

示例:使用代理和自定义端口创建客户端

package main

import (
	"fmt"

	"github.com/polite-007/toolbox/httpx"
)

func main() {
	_ = httpx.NewHttpxClient(
		httpx.WithProxy("http://127.0.0.1:7890"),
		httpx.WithPorts([]string{"80", "443", "8080"}),
		httpx.WithFaviconMMH3(),
	)
	fmt.Println("httpx client created")
}
Output:
httpx client created

func (*HttpxClient) Run

func (c *HttpxClient) Run(ctx context.Context, targets []string, onResult func(r Result)) error

Run 执行 HTTP 探测,并按结果回调。

  • ctx: 用于拦截初始化阶段;上游 RunEnumeration 不支持 context,扫描本身无法取消
  • targets: 目标列表(host:port 或 URL)
  • onResult: 每条探测结果的回调,使用本包 Result 类型

注意:不修改全局 gologger,库默认静默输出,结果通过回调返回。

type Option

type Option func(*Config)

Option 配置函数类型

func WithBody

func WithBody(body string) Option

WithBody 设置请求 Body

func WithCustomHost

func WithCustomHost(host string) Option

WithCustomHost 设置自定义 Host 头(追加模式,可与 WithHeaders 共存)

func WithFaviconMMH3

func WithFaviconMMH3() Option

WithFaviconMMH3 启用 favicon hash 计算

func WithFollowRedirects

func WithFollowRedirects() Option

WithFollowRedirects 启用跟随重定向

func WithHeaders

func WithHeaders(headers []string) Option

WithHeaders 设置自定义请求头(追加模式,可与 WithCustomHost 共存)

func WithMethod

func WithMethod(method string) Option

WithMethod 设置请求方法(GET/POST/HEAD 等)

func WithPath

func WithPath(path string) Option

WithPath 设置请求路径

func WithPorts

func WithPorts(ports []string) Option

WithPorts 设置探测端口列表

func WithProxy

func WithProxy(proxy string) Option

WithProxy 设置 HTTP/SOCKS5 代理

func WithRateLimit

func WithRateLimit(rateLimit int) Option

WithRateLimit 设置每秒最大请求数

func WithResponseBodySize

func WithResponseBodySize(size int) Option

WithResponseBodySize 设置响应体最大读取和保存大小(字节)

func WithRetries

func WithRetries(retries int) Option

WithRetries 设置重试次数

func WithShowStatistics

func WithShowStatistics() Option

WithShowStatistics 启用扫描统计信息输出

func WithTechDetect

func WithTechDetect() Option

WithTechDetect 启用 Web 指纹识别

func WithThreads

func WithThreads(threads int) Option

WithThreads 设置并发线程数

func WithTimeout

func WithTimeout(timeout int) Option

WithTimeout 设置超时时间(秒)

type Result

type Result struct {
	Timestamp     time.Time // 探测时间
	Input         string    // 原始输入(host:port 或 URL)
	URL           string    // 探测的 URL
	FinalURL      string    // 重定向后的最终 URL
	Scheme        string    // http/https
	Host          string    // Host 头
	HostIP        string    // 目标 IP
	Port          string    // 端口
	Path          string    // 请求路径
	Method        string    // 请求方法
	StatusCode    int       // HTTP 状态码
	Title         string    // 页面标题
	WebServer     string    // Server 头
	ContentType   string    // Content-Type
	ContentLength int       // 响应体长度
	Location      string    // 重定向 Location
	ResponseTime  string    // 响应耗时
	Technologies  []string  // 识别到的技术栈
	CDN           bool      // 是否 CDN
	CDNName       string    // CDN 名称
	CDNType       string    // CDN 类型
	HTTP2         bool      // 是否 HTTP/2
	WebSocket     bool      // 是否 WebSocket
	Pipeline      bool      // 是否 HTTP pipeline
	VHost         bool      // 是否虚拟主机
	FavIconMMH3   string    // favicon mmh3 hash
	FavIconMD5    string    // favicon md5 hash
	JarmHash      string    // JARM 指纹
	A             []string  // A 记录
	AAAA          []string  // AAAA 记录
	CNAMEs        []string  // CNAME 记录
	Error         string    // 错误信息字符串
	Failed        bool      // 是否探测失败
	Err           error     // 探测错误
	ResponseBody  string    // 响应体(截取前 4KB)
	SubjectCN     string    // TLS 证书 Subject Common Name
	SubjectOrg    []string  // TLS 证书 Subject Organization
}

Result 表示一条 HTTP 探测结果,封装了上游 runner.Result 的常用字段, 避免业务代码直接依赖原生 httpx 库类型。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL