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

register goja func to check udp port #5397

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

RamanaReddy0M
Copy link
Contributor

@RamanaReddy0M RamanaReddy0M commented Jul 11, 2024

Proposed changes

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@RamanaReddy0M RamanaReddy0M linked an issue Jul 11, 2024 that may be closed by this pull request
@RamanaReddy0M RamanaReddy0M self-assigned this Jul 11, 2024
@RamanaReddy0M
Copy link
Contributor Author

RamanaReddy0M commented Jul 11, 2024

Before:

Tempalte:

id: tftp-detect

info:
  name: TFTP Service - Detection
  author: pussycat0x
  severity: info
  description: |
    Detect TFTP Service.
  metadata:
    verified: true
    max-request: 1
    shodan-query: "port:69"
  tags: js,tftp,udp,network
javascript:
  - pre-condition: |
      isPortOpen(Host,Port);
    code: |
      let packet = bytes.NewBuffer();
      let message = "1.txt"
      let data = message;
      packet.WriteString(data)
      let c = require("nuclei/net");
      let conn = c.Open('udp', `${Host}:${Port}`);
      conn.SendHex(packet.Hex());
      let resp = conn.RecvString(256);
      resp;

    args:
      Host: "{{Host}}"
      Port: 69

    matchers:
      - type: word
        words:
          - "Unknown transfer ID"
# digest: 4a0a00473045022100c512c1a23c479681469c4b6a1e1e7a5740dfee043f58cb2a1d79767822cbb32802203dfa42884afa515fb2ac6dd0e0075422bc1f3ece618c6538164c8b9b09062e46:922c64590222798bb761d5b6d8e72950
✗ go run . -t port-detect.yaml -u 201.194.192.183 -v -debug

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

                projectdiscovery.io

[VER] Started metrics server at localhost:9092
[INF] Current nuclei version: v3.3.0-dev (development)
[INF] Current nuclei-templates version: v9.9.1 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 75
[INF] Templates loaded for current scan: 1
[INF] Executing 1 signed templates from projectdiscovery/nuclei-templates
[INF] Targets loaded for current scan: 1
[DBG] [tftp-detect] Executing Precondition for request
[DBG]  [tftp-detect] Javascript Code:

        isPortOpen(Host, Port);

[WRN] [tftp-detect] Could not execute request for 201.194.192.183: [tftp-detect:RUNTIME] could not execute pre-condition: dial tcp 201.194.192.183:69: connect: connection refused
[INF] No results found. Better luck next time!

After

Tempalte:

id: tftp-detect

info:
  name: TFTP Service - Detection
  author: pussycat0x
  severity: info
  description: |
    Detect TFTP Service.
  metadata:
    verified: true
    max-request: 1
    shodan-query: "port:69"
  tags: js,tftp,udp,network
javascript:
  - pre-condition: |
      isUDPPortOpen(Host,Port);
    code: |
      let packet = bytes.NewBuffer();
      let message = "1.txt"
      let data = message;
      packet.WriteString(data)
      let c = require("nuclei/net");
      let conn = c.Open('udp', `${Host}:${Port}`);
      conn.SendHex(packet.Hex());
      let resp = conn.RecvString(256);
      resp;

    args:
      Host: "{{Host}}"
      Port: 69

    matchers:
      - type: word
        words:
          - "Unknown transfer ID"
# digest: 4a0a00473045022100c512c1a23c479681469c4b6a1e1e7a5740dfee043f58cb2a1d79767822cbb32802203dfa42884afa515fb2ac6dd0e0075422bc1f3ece618c6538164c8b9b09062e46:922c64590222798bb761d5b6d8e72950
✗ ./nuclei -t test.yaml -u 201.194.192.183 -v -debug

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

                projectdiscovery.io

[VER] Started metrics server at localhost:9092
[INF] Current nuclei version: v3.3.0-dev (development)
[INF] Current nuclei-templates version: v9.9.1 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 75
[INF] Templates loaded for current scan: 1
[WRN] Loading 1 unsigned templates for scan. Use with caution.
[INF] Targets loaded for current scan: 1
[DBG] [tftp-detect] Executing Precondition for request
[DBG]  [tftp-detect] Javascript Code:

        isUDPPortOpen(Host, Port);

[DBG] [tftp-detect] Precondition for request was satisfied
[VER] [tftp-detect] Sent Javascript request to 201.194.192.183:69
[DBG] [tftp-detect] Dumped Javascript request for 201.194.192.183:69:
Variables:
        1. Host => 201.194.192.183
        2. Port => 69 address=201.194.192.183:69
[DBG]  [tftp-detect] Javascript Code:

        let packet = bytes.NewBuffer();
        let message = "1.txt"
        let data = message;
        packet.WriteString(data)
        let c = require("nuclei/net");
        let conn = c.Open('udp', `${Host}:${Port}`);
        conn.SendHex(packet.Hex());
        let resp = conn.RecvString(256);
        resp;

[DBG] [tftp-detect] Dumped Javascript response for 201.194.192.183:69:
        1. error => [:RUNTIME] failed to read .... 4.192.183:69: i/o timeout
        2. success => false address=201.194.192.183:69
[WRN] [tftp-detect] Could not execute request for 201.194.192.183: [:RUNTIME] failed to read 256 bytes <- read udp 192.168.1.3:56995->201.194.192.183:69: i/o timeout
[INF] No results found. Better luck next time!

Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

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

implementation lgtm !

./nuclei  -u 201.194.192.183 -t a.yaml -debug 

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

		projectdiscovery.io

[INF] Current nuclei version: v3.3.0-dev (development)
[INF] Current nuclei-templates version: v9.9.1 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 75
[INF] Templates loaded for current scan: 1
[WRN] Loading 1 unsigned templates for scan. Use with caution.
[INF] Targets loaded for current scan: 1
[DBG] [tftp-detect] Executing Precondition for request
[DBG]  [tftp-detect] Javascript Code:

	isPortOpenWithNetwork(Host, Port, Network);

[DBG] [tftp-detect] Precondition for request was satisfied
[DBG] [tftp-detect] Dumped Javascript request for 201.194.192.183:69:
Variables:
 	1. Host => 201.194.192.183
	2. Network => udp
	3. Port => 69 address=201.194.192.183:69
[DBG]  [tftp-detect] Javascript Code:

	let packet = bytes.NewBuffer();
	let message = "1.txt"
	let data = message;
	packet.WriteString(data)
	let c = require("nuclei/net");
	let conn = c.Open('udp', `${Host}:${Port}`);
	conn.SendHex(packet.Hex());
	let resp = conn.RecvString(256);
	resp;

[DBG] [tftp-detect] Dumped Javascript response for 201.194.192.183:69:
	1. response => Illegal TFTP operation.
	2. success => true address=201.194.192.183:69
[INF] No results found. Better luck next time!

Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

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

tagging @ehsandeep @princechaddha since this involves change/design with templates

instead of

isPortOpenWithNetwork(Host,Port,Network);

i propose

isUDPPortOpen(Host,Port)

we already have isPortOpen() which default to tcp and since there is only one alternative value isUDPPortOpen seems simple compared to adding new argument for network selection

@princechaddha
Copy link
Member

isUDPPortOpen(Host,Port) looks good.

@RamanaReddy0M RamanaReddy0M changed the title register goja func to check port with network param register goja func to check udp port Jul 15, 2024
@tarunKoyalwar tarunKoyalwar removed the request for review from princechaddha July 15, 2024 06:42
@ehsandeep ehsandeep merged commit d4e81fd into dev Jul 15, 2024
12 checks passed
@ehsandeep ehsandeep deleted the issue-5396-register-to-check-port-with-network branch July 15, 2024 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isPortOpen() function doesnt work if scanning udp port
4 participants