Skip to content

Adds TLS SNI to ghidra client connections #8

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: master
Choose a base branch
from
Open

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 21, 2025

This PR adds the SNI extension to the TLS requests, which enables proxying by domain. It should be ignored/unused for direct connections, since the Ghidra server-side doesn't look at SNI.

  • Adds SNI to RMI sockets (13100 and 13101)
  • Adds SNI to Block Stream socket

Summary by CodeRabbit

  • New Features
    • Introduced enhanced SSL client socket support with explicit Server Name Indication (SNI) for improved server communication.
  • Improvements
    • Updated remote and RMI connection logic to use the new SSL client socket, providing better compatibility with servers requiring SNI.
  • Chores
    • Adjusted internal imports and replaced standard SSL socket factories with the new implementation for consistency.

@arvi18
Copy link
Author

arvi18 commented Apr 21, 2025

Had you encountered issues with the canonical hostname resolution issue NationalSecurityAgency#4924 in conjunction with the use of a proxy server? It seems like it would cause an issue, even with your change, if connectioning to multiple separate Ghidra Servers handled by the proxy agent due to the manner that server connections are cached.

@arvi18
Copy link
Author

arvi18 commented Apr 21, 2025

No, but it could be used to work around the issue in a cloud environment. AWS allows you to configure reverse DNS for Network Load Balancers with EIPs assigned.

This PR was originally created to allow for a single AWS SNI-based proxy to be in front of multiple Ghidra Server instances using the same RMI ports. SNI aware proxies can route IP traffic to different backends solely based on FQDN and subdomain used to connect to the server.

@arvi18
Copy link
Author

arvi18 commented Apr 21, 2025

@dtshepherd I think this PR suffers from the same problem that the canonical hostname issue raises. The key point is that unless a different IP is used for each connection, you cannot distinguish between connections. You cannot use a proxy because regardless of the servername the user entered when creating the project, Ghidra will always connect with (and send as the SNI) the canonical hostname for the IP.

So this PR in itself doesn't really help at all, and cannot be used to work around the canonical hostname issue.

@arvi18
Copy link
Author

arvi18 commented Apr 21, 2025

This PR is really dependent on correcting the canonical hostname transformation issue raised by NationalSecurityAgency#4924.

@arvi18
Copy link
Author

arvi18 commented Apr 21, 2025

Is this change still neccessary given that the canonical hostname transformation issue raised by NationalSecurityAgency#4924 has been resolved?

Copy link

coderabbitai bot commented Apr 21, 2025

Walkthrough

The changes introduce explicit Server Name Indication (SNI) support for SSL/TLS client connections within Ghidra's server and RMI infrastructure. A new class, GhidraSSLClientSocket, is added to create SSL sockets with SNI set to the target host. Existing code in ServerConnectTask is updated to use this new socket factory instead of the default Java implementation. Additionally, the SSL connection setup in RemoteBlockStreamHandle is modified to set SNI parameters directly on the socket. Import statements are adjusted to accommodate these changes.

Changes

File(s) Change Summary
Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/GhidraSSLClientSocket.java Introduced new public class GhidraSSLClientSocket for creating SSL sockets with SNI support.
Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ServerConnectTask.java Replaced usage of SslRMIClientSocketFactory with GhidraSSLClientSocket for RMI SSL connections.
Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteBlockStreamHandle.java Modified SSL socket creation in connect() to set SNI parameters; updated import statements.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GhidraSSLClientSocket
    participant Server

    Client->>GhidraSSLClientSocket: createSocket(host, port)
    GhidraSSLClientSocket->>Server: Establish SSL connection with SNI(host)
    Server-->>GhidraSSLClientSocket: SSL handshake (with SNI)
    GhidraSSLClientSocket-->>Client: Return configured SSLSocket
Loading

Poem

In tunnels of code where secrets flow,
A bunny hops where SNI must go.
With sockets snug and handshakes neat,
Connections now are quite complete!
Ghidra’s SSL now knows each name,
Secure and clever—never the same!
🐇🔒✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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 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.

Copy link

@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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2abfd4e and bda2052.

📒 Files selected for processing (3)
  • Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteBlockStreamHandle.java (2 hunks)
  • Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/GhidraSSLClientSocket.java (1 hunks)
  • Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ServerConnectTask.java (2 hunks)
🔇 Additional comments (6)
Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ServerConnectTask.java (2)

164-165: SNI support added for RMI registry connections.

The switch from the standard SslRMIClientSocketFactory to the custom GhidraSSLClientSocket enables Server Name Indication (SNI) when connecting to the RMI registry. This is necessary to support domain-based proxy routing as mentioned in the PR objectives.


322-323: SNI support added for SSL connection testing.

Consistent with the change in the RMI registry connection, the SSL handshake test now uses the custom GhidraSSLClientSocket implementation to enable SNI support when testing connectivity.

Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/GhidraSSLClientSocket.java (2)

18-23: Clean and appropriate imports for SNI functionality.

The imports include necessary classes for SNI implementation including java.net.*, java.util.*, and SSL-related classes.


29-43: Well-implemented SNI extension for SSL sockets.

The class correctly extends SslRMIClientSocketFactory and overrides the createSocket method to add SNI support. The implementation:

  1. Creates the base SSL socket using the parent implementation
  2. Creates an SNI host name entry using the connection's host parameter
  3. Sets this SNI information on the socket's SSL parameters
  4. Returns the properly configured socket

This implementation allows the socket to indicate the intended hostname to upstream proxies, which is essential for the PR's goal of enabling proxy routing by domain name.

Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteBlockStreamHandle.java (2)

21-24: Updated imports to support SNI functionality.

The imports have been expanded to include java.util.* and updated to import all classes from javax.net.* and javax.net.ssl.*, which are needed for the SNI implementation added to the connect method.


282-287: Added SNI support to block stream socket connections.

Similarly to the changes in GhidraSSLClientSocket, this code now explicitly sets up SNI for the SSL socket used in block streaming. The implementation:

  1. Creates an SSL socket from the default factory
  2. Sets SNI server names to the stream server IP address
  3. Applies the updated parameters to the socket

This ensures consistent SNI behavior across all types of connections (RMI and block streaming).

Socket socket = socketFactory.createSocket(streamServerIPAddress, streamServerPort);
SSLSocket socket = (SSLSocket)socketFactory.createSocket(streamServerIPAddress, streamServerPort);

List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(streamServerIPAddress));
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider using the hostname rather than IP address for SNI.

SNI is designed to indicate the hostname being accessed, not the IP address. While using the IP address will work technically, it may not provide the expected behavior with certain proxy configurations that rely on hostname-based routing.

-		List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(streamServerIPAddress));
+		// Use the original hostname if available, falling back to IP address if necessary
+		String sniHostname = streamServerIPAddress;
+		List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(sniHostname));

Note: This implementation would require tracking and passing the original hostname through the API. The current implementation using IP address will work for basic SNI functionality, but might not provide the optimal behavior with hostname-based proxy routing.


🌐 Web query:

Is using an IP address with SNI (Server Name Indication) valid?

💡 Result:

Using an IP address with SNI (Server Name Indication) is not valid according to the SNI specification and its intended purpose.

SNI is an extension to the TLS protocol that allows a client to specify the hostname (domain name) it wants to connect to during the TLS handshake, enabling servers to present the correct certificate for that hostname even when multiple domains are hosted on the same IP address[2][3][7]. The key point is that SNI is designed for hostnames, not IP addresses.

If a client attempts to use an IP address in the SNI field:

  • Most servers will ignore the SNI field or be unable to present the correct certificate, because the certificate is typically issued for a domain name, not an IP address[3][9].
  • The SNI specification requires a "hostname" (per RFC 3546 and RFC 6066) in the SNI extension, not an IP address. Using an IP address does not comply with the standard and may result in errors or a fallback to a default certificate, leading to browser security warnings about certificate mismatches[2][3][9].

In summary:
SNI is designed to be used with domain names, not IP addresses. Using an IP address in the SNI field is not valid, and is not supported by the protocol or by major web servers. If you use an IP address in SNI, you will likely encounter connection errors or certificate warnings.[2][3][9]

Citations:


Use DNS hostname for SNI instead of IP address

SNI (per RFC 6066) must carry the server’s DNS name. Supplying an IP address will be ignored by many servers or cause a default‐certificate fallback, leading to TLS failures or certificate mismatches.

Please update the code at:

  • Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteBlockStreamHandle.java: line 284

Suggested changes:

  • Propagate the original hostname (e.g. streamServerHostname) through your API.
  • Construct the SNI value from the hostname, falling back to the IP only if the hostname is unavailable.

Example diff:

-   List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(streamServerIPAddress));
+   // Use DNS hostname for SNI, fallback to IP if necessary
+   String sniHostname = (streamServerHostname != null && !streamServerHostname.isEmpty())
+           ? streamServerHostname
+           : streamServerIPAddress;
+   List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(sniHostname));

You’ll need to update the surrounding API to accept and pass along streamServerHostname accordingly.

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

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.

2 participants