nuclei icon indicating copy to clipboard operation
nuclei copied to clipboard

Support to use "ip" DSL in the requests

Open brenocss opened this issue 3 years ago • 6 comments

This works:

id: basic-raw-example
info:
  name: Test RAW Template
  author: pdteam
  severity: info

requests:
  - raw:
      - |
        GET / HTTP/1.1
        Host: {{Hostname}}

    extractors:
      - type: dsl
        dsl:
          - ip

But not this:

id: basic-raw-example
info:
  name: Test RAW Template
  author: pdteam
  severity: info

requests:
  - raw:
      - |
        GET / HTTP/1.1
        Host: {{Hostname}}
        Origin: {{ip}}

should be exposed to use in all supported protocols.

brenocss avatar May 18 '22 18:05 brenocss

@brenocss Unfortunately, the IP information is available only after performing at least one connection to the target. A temporary workaround could be a template like the following one:

id: basic-raw-example
info:
  name: Test RAW Template
  author: pdteam
  severity: info

requests:
  - raw:
      - |
        GET / HTTP/1.1
        Host: {{Hostname}}
        
      - |
        GET / HTTP/1.1
        Host: {{Hostname}}
        Origin: {{extractedip}}

    extractors:
      - type: dsl
        internal: true
        name: extractedip
        dsl:
          - ip

Is there any specific use case you encountered that requires the IP information to be available before the connection?

Mzack9999 avatar Jun 22 '22 12:06 Mzack9999

Use case

nuclei -t internetdb.yaml  -u google.com
nuclei -t internetdb.yaml  -u https://google.com

It is important that this template can be executed even for entries that are not URLs

requests:
  - raw:
      - |
        @Host: https://internetdb.shodan.io/
        GET /{{ip}} HTTP/1.1
        Host: internetdb.shodan.io

An example of a workaround that would be possible when the cross-protocol data sharing function is working

id: teste

info:
  name: debug
  author: brenocss
  severity: info
  description: Ip 
  reference:
    - https://google.com
  classification:
    cwe-id: CWE-200
  tags: dns,A

dns:
  - name: "{{FQDN}}"
    type: A

    matchers:
      - type: word
        words:
          - "IN\tA"

    extractors:
      - type: regex
        name: extractedip
        group: 1
        # internal: true
        regex:
          - "IN\tA\t(\\S+)"
requests:
  - raw:
      - |
        @Host: https://internetdb.shodan.io/
        GET /{{extractedip}} HTTP/1.1
        Host: internetdb.shodan.io

But that won't work for this, that's why dsl would be a better way to do it

echo hackerone.com | nuclei -t internetdb -u 8.8.8.8

Another problem is to keep redoing unnecessary dns/http requests

brenocss avatar Jun 22 '22 15:06 brenocss

Unfortunately, knowing the actual server's IP is impossible before performing at least one connection to the DNS hostname. @ehsandeep What do you think about adding a DNS function to resolve hostname=>ip and assuming that the first available IP is optimistically the one used to perform a successful connection?

Mzack9999 avatar Jul 25 '22 05:07 Mzack9999

@Mzack9999 indeed, it will not only solve this, but also helpful for new helpers at https://github.com/projectdiscovery/nuclei/issues/2341

ehsandeep avatar Jul 25 '22 10:07 ehsandeep

Unfortunately, knowing the actual server's IP is impossible before performing at least one connection to the DNS hostname. @ehsandeep What do you think about adding a DNS function to resolve hostname=>ip and assuming that the first available IP is optimistically the one used to perform a successful connection?

Don't we need to preprocess all domains before using for all templates?

it is worth mentioning that when the input is an ip the variable {{ip}} is also not valid

echo https://127.0.0.1 | nuclei -t teste.yaml -duc -debug

brenocss avatar Aug 17 '22 17:08 brenocss

@brenocss, the pre-processing phase only lexicographically (fqdn)/range (ip + cidr) deduplicates input items. The DNS resolution, if a domain name is provided, happens within fastdialer at connection time.

On Hold - We need to clarify if the helper function with heuristic assumptions can cover the particular use case

Mzack9999 avatar Aug 31 '22 05:08 Mzack9999

  • Blocked by https://github.com/projectdiscovery/nuclei/issues/2341
  • Most likely not feasible on first request as the ip info is not available at pre-processing time

Mzack9999 avatar Nov 23 '22 15:11 Mzack9999

@Mzack9999 don't scan based in ip type ( such as ipv6 or ipv4 ) pre process domains and resolve before running?

brenocss avatar Dec 04 '22 04:12 brenocss

@brenocss, that is an excellent point. Still, this happens only in the case of scan-all-ips, as we use a custom ip to connect to.

Mzack9999 avatar Dec 09 '22 13:12 Mzack9999