Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for multiple ports in network template #4401

Merged
merged 3 commits into from
Nov 23, 2023
Merged

Conversation

tarunKoyalwar
Copy link
Member

@tarunKoyalwar tarunKoyalwar commented Nov 21, 2023

Proposed Changes

  • While writing network templates common use case is to check for multiple open ports
Example:
while default port of ssh service is 22 . it is also commonly configured to use port 2222
  • this pr adds support for multiple comma seperated values in port field and does the following
    • if more than one port is specified it probes to check if those ports are open on that targets
    • template is then executed on those open ports (can be one or more )
  • this does not remove / change any existing functionality introduced in port field PR and only extends its support for multiple ports
  • closes allow multiple ports(csv) in network templates #4400

@tarunKoyalwar tarunKoyalwar self-assigned this Nov 21, 2023
@tarunKoyalwar tarunKoyalwar linked an issue Nov 21, 2023 that may be closed by this pull request
@tarunKoyalwar
Copy link
Member Author

tarunKoyalwar commented Nov 21, 2023

Example Template

id: openssh-detect

info:
  name: OpenSSH Service - Detect
  author: r3dg33k,daffainfo,iamthefrogy
  severity: info
  description: |
    OpenSSH service was detected.
  reference:
    - http://www.openwall.com/lists/oss-security/2016/08/01/2
    - http://www.openwall.com/lists/oss-security/2018/08/15/5
    - http://seclists.org/fulldisclosure/2016/Jul/51
    - https://nvd.nist.gov/vuln/detail/CVE-2016-6210
    - https://nvd.nist.gov/vuln/detail/CVE-2018-15473
  classification:
    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N
    cwe-id: CWE-200
  metadata:
    max-request: 1
  tags: seclists,network,ssh,openssh,detect

tcp:
  - host:
      - "{{Hostname}}"
    port: 22,2222

    matchers:
      - type: regex
        regex:
          - '(?i)OpenSSH'

    extractors:
      - type: regex
        regex:
          - '(?i)SSH-(.*)-OpenSSH_[^\r]+'
$  ./nuclei -l targets.txt -t ./openssh-detect.yaml       

                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.1.0-dev

		projectdiscovery.io

[INF] Current nuclei version: v3.1.0-dev (development)
[INF] Current nuclei-templates version: v9.6.9 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 73
[INF] Templates loaded for current scan: 1
[WRN] Executing 1 unsigned templates. Use with caution.
[INF] Targets loaded for current scan: 4
[openssh-detect] [tcp] [info] xx.xx.xx.xx:2222 [SSH-2.0-OpenSSH_9.3 FreeBSD-openssh-portable-9.3.p2_1,1]
[openssh-detect] [tcp] [info] scanme.sh:22 [SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.9]
[openssh-detect] [tcp] [info] xx.xx.xx.xx:2222 [SSH-2.0-OpenSSH_7.9 FreeBSD-openssh-portable-7.9.p1_1,1]
[openssh-detect] [tcp] [info] xx.xx.xx.xx:2222 [SSH-2.0-OpenSSH_8.9 FreeBSD-openssh-portable-8.9.p1_3,1]

@tarunKoyalwar tarunKoyalwar marked this pull request as ready for review November 21, 2023 18:56
@dogancanbakir
Copy link
Member

I got the following err with the ports port: 22,99999—besides, LGTM.

$ go run . -u scanme.sh -t ./test.yaml

                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.1.0-dev

                projectdiscovery.io

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x1a62db0]

goroutine 1 [running]:
github.com/projectdiscovery/nuclei/v3/pkg/protocols/network.(*Request).Compile(0x4000c8eb40, 0x4000cace00)
        /workspaces/nuclei/pkg/protocols/network/network.go:189 +0x470
github.com/projectdiscovery/nuclei/v3/pkg/tmplexec.(*TemplateExecuter).Compile(0x40009c0200)
        /workspaces/nuclei/pkg/tmplexec/exec.go:69 +0x88
github.com/projectdiscovery/nuclei/v3/pkg/templates.parseTemplate({_, _, _}, {{0x0, 0x0}, {0x40004da600, 0x27}, {{0x0, 0x0}, {{0x0, ...}}, ...}, ...})
        /workspaces/nuclei/pkg/templates/compile.go:371 +0x598
github.com/projectdiscovery/nuclei/v3/pkg/templates.ParseTemplateFromReader({_, _}, {_, _}, {{0x0, 0x0}, {0x40004da600, 0x27}, {{0x0, 0x0}, ...}, ...})
        /workspaces/nuclei/pkg/templates/compile.go:260 +0x408
github.com/projectdiscovery/nuclei/v3/pkg/templates.Parse({_, _}, {_, _}, {{0x0, 0x0}, {0x0, 0x0}, {{0x0, 0x0}, ...}, ...})
        /workspaces/nuclei/pkg/templates/compile.go:78 +0x2f4
github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader.(*Store).LoadTemplatesWithTags(0x40009c4090, {0x4000178670?, 0x0?, 0x0?}, {0x0, 0x0, 0x0})
        /workspaces/nuclei/pkg/catalog/loader/loader.go:392 +0x2dc
github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader.(*Store).LoadTemplates(...)
        /workspaces/nuclei/pkg/catalog/loader/loader.go:354
github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader.(*Store).Load(0x40009c4090)
        /workspaces/nuclei/pkg/catalog/loader/loader.go:250 +0x38
github.com/projectdiscovery/nuclei/v3/internal/runner.(*Runner).RunEnumeration(0x40012dcdc0)
        /workspaces/nuclei/internal/runner/runner.go:440 +0xa70
main.main()
        /workspaces/nuclei/cmd/nuclei/main.go:149 +0x4d8
exit status 2

Copy link
Member

@dogancanbakir dogancanbakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ehsandeep ehsandeep merged commit a09b8af into dev Nov 23, 2023
12 checks passed
@ehsandeep ehsandeep deleted the issue-4400-csv-ports branch November 23, 2023 11:04
@ehsandeep ehsandeep added Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Enhancement Most issues will probably ask for additions or changes. labels Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Enhancement Most issues will probably ask for additions or changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow multiple ports(csv) in network templates
3 participants