MCPcopy
hub / github.com/projectdiscovery/uncover / queryIPCIDR

Method queryIPCIDR

sources/agent/driftnet/driftnet.go:153–215  ·  view source on GitHub ↗
(ctx context.Context, session *sources.Session, driftnetRequest *DriftnetRequest, results chan sources.Result)

Source from the content-addressed store, hash-verified

151}
152
153func (agent *Agent) queryIPCIDR(ctx context.Context, session *sources.Session, driftnetRequest *DriftnetRequest, results chan sources.Result) {
154 var targetCIDR = driftnetRequest.Query
155
156 if iputil.IsIP(targetCIDR) {
157 if iputil.IsIPv4(targetCIDR) {
158 targetCIDR = iputil.AsIPV4CIDR(targetCIDR)
159 } else if iputil.IsIPv6(targetCIDR) {
160 targetCIDR = iputil.AsIPV6CIDR(targetCIDR)
161 }
162 }
163
164 requestCIDRs, splitError := mapcidr.SplitByNumber(targetCIDR, 1024)
165 if splitError != nil {
166 sources.SendResult(ctx, results, sources.Result{Source: agent.Name(), Error: splitError})
167 return
168 }
169
170 totalReportedResults := 0
171 for _, requestCIDR := range requestCIDRs {
172 if ctx.Err() != nil {
173 return
174 }
175 driftnetRequest.Query = requestCIDR.String()
176
177 resp, queryError := agent.queryURL(ctx, session, OpenPortIPPortsURL, driftnetRequest)
178
179 if queryError != nil {
180 if resp != nil && resp.StatusCode == http.StatusNoContent {
181 continue
182 }
183
184 sources.SendResult(ctx, results, sources.Result{Source: agent.Name(), Error: queryError})
185 return
186 }
187 defer func() {
188 _ = resp.Body.Close()
189 }()
190
191 driftnetResponse := &DriftnetAPIOpenIPPortResponse{}
192 if err := json.NewDecoder(resp.Body).Decode(driftnetResponse); err != nil {
193 sources.SendResult(ctx, results, sources.Result{Source: agent.Name(), Error: err})
194 return
195 }
196
197 for ip, portsResponse := range driftnetResponse.Values {
198 result := sources.Result{Source: agent.Name(), IP: ip}
199 result.Raw, _ = json.Marshal(driftnetResponse)
200
201 for port := range portsResponse.Values {
202 result.Port = port
203 if !sources.SendResult(ctx, results, result) {
204 return
205 }
206
207 totalReportedResults += 1
208
209 if driftnetRequest.ResultLimit > 0 && totalReportedResults >= driftnetRequest.ResultLimit {
210 return

Callers 1

queryMethod · 0.95

Implementers 15

Agentsources/agent/odin/odin.go
Agentsources/agent/shodanidb/shodan.go
Agentsources/agent/nerdydata/nerdydata.go
Agentsources/agent/quake/quake.go
Agentsources/agent/onyphe/onyphe.go
Agentsources/agent/netlas/netlas.go
Agentsources/agent/greynoise/greynoise.go
Agentsources/agent/driftnet/driftnet.go
Agentsources/agent/zoomeye/zoomeye.go
Agentsources/agent/publicwww/publicwww.go
Agentsources/agent/google/google.go
Agentsources/agent/shodan/shodan.go

Calls 4

NameMethod · 0.95
queryURLMethod · 0.95
SendResultFunction · 0.92
CloseMethod · 0.45

Tested by

no test coverage detected