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

Hulto eldritch feature pivot ncat #44

Merged
merged 29 commits into from
Sep 16, 2022
Merged

Conversation

hulto
Copy link
Collaborator

@hulto hulto commented Jun 17, 2022

What type of PR is this?

What this PR does / why we need it:

This PR adds support for eldritch to send UDP / TCP data to an arbitrary host / port. If the host/port responds with any data that data will be returned to the user.

@hulto
Copy link
Collaborator Author

hulto commented Jun 17, 2022

This PR also includes stubs for the pivot library.

use tokio::net::{TcpStream, UdpSocket};

// Since we cannot go from async (test) -> sync (ncat) `block_on` -> async (handle_ncat) without getting an error "cannot create runtime in current runtime since current thread is calling async code."
async fn handle_ncat(address: String, port: i32, data: String, protocol: String) -> Result<String> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The working portion and the primary function have been separated to make testing async code easier.

// Since we cannot go from async (test) -> sync (ncat) `block_on` -> async (handle_ncat) without getting an error "cannot create runtime in current runtime since current thread is calling async code."
async fn handle_ncat(address: String, port: i32, data: String, protocol: String) -> Result<String> {
// If the response is longer than 4096 bytes it will be truncated.
let mut response_buffer = [0; 4096];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if there's a better way to receive more bytes.
If not should we add a truncated indicator? Eg. "I got. lots of bytes of data ...trunc...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use read_exact either to read enough header to determine the packet size, or alternatively read_exact in a loop?

https://docs.rs/tokio/0.1.22/tokio/io/fn.read_exact.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion.
Do you know of a good way to read an undefined number of bytes? I think this still uses a fixed length buffer.

@hulto hulto added the feature New feature or request label Sep 11, 2022
@hulto hulto linked an issue Sep 15, 2022 that may be closed by this pull request
Copy link
Collaborator

@Milkshak3s Milkshak3s left a comment

Choose a reason for hiding this comment

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

LGTM!

// Connect to remote host

// Setting the bind address to unspecified should leave it up to the OS to decide.
// https://stackoverflow.com/a/67084977
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥

}
}

// We do not want to make this async since it would require we make all of the starlark bindings async.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to know :blob_salute:

@hulto hulto merged commit 85cd355 into main Sep 16, 2022
@hulto hulto deleted the hulto-eldritch-feature-pivod-ncat branch September 16, 2022 00:02
KCarretto pushed a commit that referenced this pull request Feb 1, 2024
 
Hulto eldritch feature pivot ncat (#44)

* ncat tcp  test seems to be setup.
* test echo server works for tcp.
* TCP and UDP tests work.
* Test cover ncat not just async handle.
* Added windows error catch
* Added unused port allocation to avoid overlap.
* TCP buffered reader instead of set buffer size.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] eldritch pivot.ncat implementation
2 participants