Skip to content

CheckRDPEncryption function #6204

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

CheckRDPEncryption function #6204

wants to merge 1 commit into from

Conversation

pussycat0x
Copy link
Contributor

@pussycat0x pussycat0x commented May 1, 2025

Proposed changes

Detect RDP encryption using CheckRDPEncryption()

javascript:
  - code: |
      let m = require('nuclei/rdp');
      let response = m.CheckRDPEncryption(Host,Port);
      Export(response);

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)

Summary by CodeRabbit

  • New Features
    • Added the ability to check supported security layers and encryption levels of an RDP server, including detailed reporting of protocol and cipher support.
    • Introduced caching for RDP encryption checks to improve performance on repeated queries.

@auto-assign auto-assign bot requested a review from dogancanbakir May 1, 2025 12:56
Copy link
Contributor

coderabbitai bot commented May 1, 2025

Walkthrough

A new feature was introduced to the RDP package to actively probe and report the supported security layers and encryption levels of a given RDP server. This includes the addition of a new response struct, probing logic for various protocols and ciphers, and memoization to cache results for repeated checks. The probing is performed by establishing TCP connections, sending crafted RDP requests, and interpreting the server's responses. The results are aggregated and returned in a structured format, with memoization ensuring efficiency for repeated queries.

Changes

File(s) Change Summary
pkg/js/libs/rdp/rdp.go Added RDPEncryptionResponse struct, CheckRDPEncryption function, and internal logic for probing RDP encryption.
pkg/js/libs/rdp/memo.rdp.go Introduced memoizedcheckRDPEncryption function to cache results of RDP encryption checks.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant rdp
    participant Memoizer
    participant RDPServer

    Caller->>rdp: CheckRDPEncryption(host, port)
    rdp->>Memoizer: Check cache for (host, port)
    alt Cache hit
        Memoizer-->>rdp: Cached RDPEncryptionResponse
    else Cache miss
        rdp->>RDPServer: Probe security protocols/ciphers
        RDPServer-->>rdp: Responses to probes
        rdp->>Memoizer: Store RDPEncryptionResponse
        Memoizer-->>rdp: Confirmation
    end
    rdp-->>Caller: RDPEncryptionResponse
Loading

Poem

In the warren, secrets deep,
RDP's layers no longer sleep.
With every probe, a cipher found,
Memoized so hops abound!
Now bunnies check with nimble flair,
Encryption truths are everywhere.
🐇🔒✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pussycat0x pussycat0x linked an issue May 1, 2025 that may be closed by this pull request
@pussycat0x
Copy link
Contributor Author

Debug Data

./nuclei -u 127.0.0.1  -t rdp.yaml

                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.4.2

                projectdiscovery.io

[INF] Current nuclei version: v3.4.2 (latest)
[INF] Current nuclei-templates version: v10.2.0 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 268
[INF] Templates loaded for current scan: 1
[WRN] Loading 1 unsigned templates for scan. Use with caution.
[INF] Targets loaded for current scan: 1
[rdp-enc-check] [javascript] [info] 127.0.0.1:3389 ["{\n  "SecurityLayer": {\n    "NativeRDP": false,\n    "SSL": true,\n    "CredSSP": false,\n    "RDSTLS": true,\n    "CredSSPWithEarlyUserAuth": false\n  },\n  "EncryptionLevel": {\n    "RC4_40bit": false,\n    "RC4_56bit": false,\n    "RC4_128bit": false,\n    "FIPS140_1": false\n  }\n}"]

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
pkg/js/libs/rdp/memo.rdp.go (1)

43-57: Memoization logic looks solid – tiny opportunity for naming consistency

Behaviour mirrors the existing memoizedcheckRDPAuth implementation and should work as-is.
If you ever touch this file again, consider renaming all three helpers to memoizedCheckXYZ (capital C) for camel-case consistency, but this is definitely non-blocking.

pkg/js/libs/rdp/rdp.go (3)

127-140: Add JSON tags to keep the public JS API stable

toJSON() in the usage examples will currently serialise fields as NativeRDP, RC4_40bit, … which is fine, but any future refactor (e.g. renaming fields) could silently break templates.
Explicit JSON tags make the contract crystal-clear and avoid surprises.

-       SecurityLayer struct {
-           NativeRDP                bool
-           SSL                      bool
-           CredSSP                  bool
-           RDSTLS                   bool
-           CredSSPWithEarlyUserAuth bool
-       }
-       EncryptionLevel struct {
-           RC4_40bit  bool
-           RC4_56bit  bool
-           RC4_128bit bool
-           FIPS140_1  bool
-       }
+       SecurityLayer struct {
+           NativeRDP                bool `json:"native_rdp"`
+           SSL                      bool `json:"ssl"`
+           CredSSP                  bool `json:"credssp"`
+           RDSTLS                   bool `json:"rdstls"`
+           CredSSPWithEarlyUserAuth bool `json:"credssp_early_user_auth"`
+       } `json:"security_layer"`
+       EncryptionLevel struct {
+           RC4_40bit  bool `json:"rc4_40bit"`
+           RC4_56bit  bool `json:"rc4_56bit"`
+           RC4_128bit bool `json:"rc4_128bit"`
+           FIPS140_1  bool `json:"fips140_1"`
+       } `json:"encryption_level"`

194-201: Hard-coded magic numbers deserve named constants

Using integers 0,1,3,4,8 for protocols and 1,8,2,16 for ciphers makes the code error-prone.
Defining constants (or even slices of structs) improves readability and prevents accidental duplication.


229-243: Missing ingress‐egress validation & packet crafting disclaimer

The simplified TPDU you craft ([]byte{0x03,0x00,…}) may not trigger deterministic behaviour across all RDP implementations and could create false negatives.
Consider adding comments that this is heuristic-only and, if possible, move the magic slice into a const baseConnectionRequest = [...]byte{…} for maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbf57ef and 32845bc.

⛔ Files ignored due to path filters (3)
  • cmd/nuclei/rdp.yaml is excluded by !**/*.yaml
  • pkg/js/generated/go/librdp/rdp.go is excluded by !**/generated/**
  • pkg/js/generated/ts/rdp.ts is excluded by !**/generated/**
📒 Files selected for processing (2)
  • pkg/js/libs/rdp/memo.rdp.go (1 hunks)
  • pkg/js/libs/rdp/rdp.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)

Comment on lines +160 to +176
// Test different security protocols
protocols := map[string]int{
"NativeRDP": 0,
"SSL": 1,
"CredSSP": 3,
"RDSTLS": 4,
"CredSSPWithEarlyUserAuth": 8,
}

for name, value := range protocols {
conn, err := protocolstate.Dialer.Dial(context.TODO(), "tcp", fmt.Sprintf("%s:%d", host, port))
if err != nil {
continue
}
defer conn.Close()

// Test protocol
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

defer conn.Close() inside a tight loop leaks sockets until function exit

Every iteration defers a close that is only executed when checkRDPEncryption returns.
For a single call that’s ~9 open TCP fds; across many goroutines this quickly exhausts file descriptors and slows scanning.

-   conn, err := protocolstate.Dialer.Dial(...)
-   ...
-   defer conn.Close()
+   conn, err := protocolstate.Dialer.Dial(...)
+   ...
+   // close immediately after the test to free the fd
+   isRDP, err := testRDPProtocol(conn, timeout, value)
+   _ = conn.Close()

Do the same in the cipher loop below (lines 202-208).

Committable suggestion skipped: line range outside the PR's diff.

@pussycat0x pussycat0x self-assigned this May 1, 2025
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.

[FEATURE] ... RDP Encryption Enumeration
1 participant