Skip to content

Detect SupportedLDAPVersion#6202

Merged
ehsandeep merged 1 commit intodevfrom
GetVersion--Ldap
Apr 30, 2025
Merged

Detect SupportedLDAPVersion#6202
ehsandeep merged 1 commit intodevfrom
GetVersion--Ldap

Conversation

@pussycat0x
Copy link
Contributor

@pussycat0x pussycat0x commented Apr 29, 2025

Proposed changes

GetVersion() helps detect the supported LDAP version.

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 retrieve the LDAP protocol versions supported by the connected server.

@auto-assign auto-assign bot requested a review from dogancanbakir April 29, 2025 11:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 29, 2025

Walkthrough

A new method named GetVersion has been introduced to the Client struct within the LDAP library. This method connects to the LDAP server, performs a base object search for the supportedLDAPVersion attribute, and returns the supported protocol versions as a slice of strings. The method handles cases where the connection is absent or the search fails by returning an appropriate fallback value or error.

Changes

File(s) Change Summary
pkg/js/libs/ldap/ldap.go Added the GetVersion method to the Client struct for querying supported LDAP protocol versions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant LDAPServer

    Client->>LDAPServer: Connect
    Client->>LDAPServer: Search (base, filter: (objectClass=*), attr: supportedLDAPVersion)
    LDAPServer-->>Client: Return supportedLDAPVersion values
    Client-->>Caller: Return versions as []string or ["unknown"] on failure
Loading

Poem

In the warren of code, a new path appears,
LDAP versions revealed, dispelling old fears.
With a hop and a query, the Client now knows,
What protocol magic the server bestows.
So raise your paws high, for discovery’s delight—
Versioning wisdom, brought into the light!
🐇✨

✨ 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.

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
Copy link
Contributor Author

pussycat0x commented Apr 29, 2025

Template:

id: ldap-version-detect

info:
  name: LDAP Version - Detect
  author: pussycat0x
  severity: info
  metadata:
    max-request: 1
    shodan-query: ldap
  tags: js,network,ldap,enum

javascript:
  - code: |
      let ldap = require('nuclei/ldap');
      let cfg = ldap.Config();
      cfg.Upgrade = true;
      let client = ldap.Client(Host, Port, cfg);
      let version = client.GetVersion();
      log(version);

    args:
      Host: "ldap://{{Host}}"
      Port: 389

    extractors:
      - type: dsl
        dsl:
          - response


Result:


                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   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
[JS] [3 2]
[ldap-version-detect] [javascript] [info] 27.0.0.0:389:389 ["[3 2]"]`

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 (2)
pkg/js/libs/ldap/ldap.go (2)

324-331: Enhance documentation to clarify return value format.

The JSDoc example is well-formatted, but it would be helpful to provide more information about the return value format and what it represents.

// GetVersion returns the LDAP versions being used by the server
+ // Returns a slice of strings representing the supported LDAP protocol versions (e.g., ["2", "3"])
+ // or ["unknown"] if the information cannot be retrieved
// @example
// ```javascript
// const ldap = require('nuclei/ldap');
// const client = new ldap.Client('ldap://ldap.example.com', 'acme.com');
// const versions = client.GetVersion();
// log(versions);
// ```

348-350: Consider handling empty attribute values.

The current implementation returns the raw attribute values, but it doesn't handle the case where the attribute exists but has no values. Consider providing a more consistent response in such cases.

if len(res.Entries) > 0 {
-	return res.Entries[0].GetAttributeValues("supportedLDAPVersion")
+	values := res.Entries[0].GetAttributeValues("supportedLDAPVersion")
+	if len(values) == 0 {
+		return []string{"unknown"}
+	}
+	return values
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4c1496 and 5af3a9d.

📒 Files selected for processing (1)
  • pkg/js/libs/ldap/ldap.go (1 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)
🔇 Additional comments (1)
pkg/js/libs/ldap/ldap.go (1)

332-353: Consider adding tests for the new functionality.

The PR introduces a new method but doesn't include tests. Consider adding tests to verify that the method correctly handles different scenarios, such as when:

  1. The server returns valid version information
  2. The server returns no entries
  3. The connection is nil

Can you confirm if you plan to add tests for this new functionality? This would help ensure that the feature works as expected and prevent regressions in the future.

@dogancanbakir dogancanbakir requested a review from ehsandeep April 30, 2025 08:26
@ehsandeep ehsandeep merged commit cbf57ef into dev Apr 30, 2025
21 of 22 checks passed
@ehsandeep ehsandeep deleted the GetVersion--Ldap branch April 30, 2025 08:40
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.

3 participants