From 3528287d618d2cba579b88622e0b2b874e2f7d3c Mon Sep 17 00:00:00 2001 From: BaaRai <130491490+BaaRai@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:53:33 +0100 Subject: [PATCH] enrich: route the HTTP probe through the pinned dialer (F13) doHTTP now connects through intercept.PinnedDialer under the target scope of the request's context, so the probe uses the same pinned-address dial as the target gate. ProbeSite takes the context of the call that asks for the probe. A probe without a scope is refused; with the gate on, the probe bypasses the recording proxy so the dialer decides on the target itself. The path stays dormant: nothing calls ProbeSite on main. --- agent/tools.go | 2 +- enrich/enrich.go | 33 ++++++++++++++------ intercept/enrich_probe_test.go | 56 ++++++++++++++++++++++++++++++++++ intercept/export_test.go | 33 ++++++++++++++++++++ 4 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 intercept/enrich_probe_test.go create mode 100644 intercept/export_test.go diff --git a/agent/tools.go b/agent/tools.go index 0fb479b..fe15db0 100644 --- a/agent/tools.go +++ b/agent/tools.go @@ -221,7 +221,7 @@ func (t *ToolSet) SetNotifyFinding(fn func(int64, string)) { t.notifyFinding = f // enrich). Kept as an interface here to avoid coupling agent → enrich. type EnrichTrigger interface { ResolveDomain(id int64, host string) - ProbeSite(id int64, url string) + ProbeSite(ctx context.Context, id int64, url string) } // WriteCounts breaks down what a worker persisted this run, by node kind, so the diff --git a/enrich/enrich.go b/enrich/enrich.go index d67120f..0d86f9b 100644 --- a/enrich/enrich.go +++ b/enrich/enrich.go @@ -7,6 +7,7 @@ package enrich import ( + "context" "crypto/tls" "html" "io" @@ -20,6 +21,7 @@ import ( "time" "github.com/Autumn-27/artex/db" + "github.com/Autumn-27/artex/intercept" "github.com/miekg/dns" "github.com/projectdiscovery/dnsx/libs/dnsx" @@ -34,8 +36,9 @@ const ( type job struct { kind jobKind - id int64 // asset id (domain for DNS, site for HTTP) - arg string // host (DNS) or url (HTTP) + id int64 // asset id (domain for DNS, site for HTTP) + arg string // host (DNS) or url (HTTP) + ctx context.Context // HTTP: carries the target scope the probe dials under } // Engine owns the resolver, the proxy-routed HTTP client, and the worker pool. @@ -90,15 +93,23 @@ func New(as *db.AssetStore, proxy func() string, workers int) *Engine { // buildClient returns an HTTP client that dials via the recording proxy (resolved // per-request via proxy(), so the traffic-capture toggle applies live) and skips // TLS verification (the proxy re-signs with its MITM CA; targets are often -// self-signed — this is a pentest probe). +// self-signed — this is a pentest probe). Every connection goes through +// intercept.PinnedDialer, under the target scope of the request's context: a +// probe without a scope is refused. When the scope's gate is on, the probe +// connects to the target itself, without the proxy, so that the dialer decides +// on the target and connects only to the addresses a pin covers. func buildClient(proxy func() string) *http.Client { tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, DisableKeepAlives: true, TLSHandshakeTimeout: httpTimeout, + DialContext: intercept.PinnedDialer("enrich", true), } if proxy != nil { - tr.Proxy = func(*http.Request) (*url.URL, error) { + tr.Proxy = func(req *http.Request) (*url.URL, error) { + if intercept.GateOn(req.Context()) { + return nil, nil // direct: the dialer decides on the target + } p := proxy() if p == "" { return nil, nil // direct @@ -116,10 +127,14 @@ func buildClient(proxy func() string) *http.Client { // ResolveDomain enqueues a DNS resolution for a domain asset (ungated). host is the // FQDN. No-op for an empty engine. -func (e *Engine) ResolveDomain(id int64, host string) { e.enqueue(job{jobDNS, id, host}) } +func (e *Engine) ResolveDomain(id int64, host string) { e.enqueue(job{jobDNS, id, host, nil}) } // ProbeSite enqueues an HTTP probe for a web-asset (site). rawURL is the site URL. -func (e *Engine) ProbeSite(id int64, rawURL string) { e.enqueue(job{jobHTTP, id, rawURL}) } +// ctx carries the target scope of the call that asks for the probe: the probe +// connects under that scope (see buildClient). +func (e *Engine) ProbeSite(ctx context.Context, id int64, rawURL string) { + e.enqueue(job{jobHTTP, id, rawURL, ctx}) +} func (e *Engine) enqueue(j job) { if e == nil || id0(j.id) || j.arg == "" { @@ -155,7 +170,7 @@ func (e *Engine) worker() { case jobDNS: e.doDNS(j.id, j.arg) case jobHTTP: - e.doHTTP(j.id, j.arg) + e.doHTTP(j.ctx, j.id, j.arg) } } } @@ -221,12 +236,12 @@ func (e *Engine) doDNS(id int64, host string) { var reTitle = regexp.MustCompile(`(?is)