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

pivot.arp_scan() #258

Merged
merged 12 commits into from
Aug 14, 2023
Merged

pivot.arp_scan() #258

merged 12 commits into from
Aug 14, 2023

Conversation

jabbate19
Copy link
Collaborator

@jabbate19 jabbate19 commented Jul 30, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds ARP scan capability.

Will scan given subnets' IPs using ARP requests and checking for ARP replies. Does this multithreaded, one thread per subnet.

Which issue(s) this PR fixes:

Fixes #239

Note:

I will take any advice on how to test this!

@jabbate19 jabbate19 requested a review from hulto July 30, 2023 00:12
@codecov
Copy link

codecov bot commented Jul 30, 2023

Codecov Report

Merging #258 (d1354e9) into main (9d2a792) will increase coverage by 0.89%.
The diff coverage is 44.54%.

@@            Coverage Diff             @@
##             main     #258      +/-   ##
==========================================
+ Coverage   73.24%   74.13%   +0.89%     
==========================================
  Files          88       88              
  Lines        5490     5781     +291     
==========================================
+ Hits         4021     4286     +265     
- Misses       1383     1409      +26     
  Partials       86       86              
Files Changed Coverage Δ
implants/lib/eldritch/src/pivot/arp_scan_impl.rs 43.45% <43.45%> (+43.45%) ⬆️
implants/lib/eldritch/src/pivot.rs 58.77% <83.33%> (+0.51%) ⬆️

... and 13 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@hulto hulto left a comment

Choose a reason for hiding this comment

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

🌶️ feature very excited to have this.
Few change requests.

implants/lib/eldritch/src/pivot.rs Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/pivot/arp_scan_impl.rs Outdated Show resolved Hide resolved
@hulto
Copy link
Collaborator

hulto commented Jul 30, 2023

Also please add tests and docs.
Test could be as simple as run it through the interpreter passing a fresh heap make sure it runs successfully and sees a MAC address.

there may also be a few unwraps I didn’t tag.

@jabbate19 jabbate19 requested a review from hulto July 30, 2023 21:18
Copy link
Collaborator

@hulto hulto left a comment

Choose a reason for hiding this comment

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

First pass.
Few thoughts on error handling.
Please update the arp scan docs.

@@ -40,6 +40,8 @@ windows-sys = { workspace = true, features = [
"Win32_Security",
]}
whoami = { workspace = true }
pnet = "0.34.0"
ipnetwork = "0.20.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add these to the workspace root and use workspace true in the package. This way if another package wants to use a crate they'll be kept in step with the main version. If specific libs need to break with the current workspace version we can do that but should avoid it.

starlark_heap: &'v Heap,
target_cidrs: Vec<String>,
) -> anyhow::Result<Vec<Dict<'v>>> {
if false {
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 leave this as a single line for now. Would like to maintain consistency even while we look to auto formatting.

) {
if interface.ips.iter().filter(|ip| ip.is_ipv4()).count() == 0 {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to return an error? Might be nice in case something breaks to know why.

let (mut tx, mut rx) = match channel(&interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe if you return an error here instead of panicking the thread will close and pass back the error message to join similar to panic.
If we can do that instead that would be my preference even if it only achieves the same effect as panic it will be more reusable and also clearer that the function itself shouldn't panic.

Ok(elapsed) => elapsed,
Err(err) => {
println!("Failed to get elapsed time on {}: {}", interface.name, err);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We want to avoid println in production code eldritch should only print when a user calls print (print calls in eldritch have a special handler to ensure they get back to the c2 rust prints wont get recorded). If you want to preserve debug strings like this you can wrap them in an if debug and set debug to false.

@jabbate19 jabbate19 requested a review from hulto August 14, 2023 23:00
Copy link
Collaborator

@hulto hulto left a comment

Choose a reason for hiding this comment

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

There's one println left and please add docs to the docs/_docs/user-guide/eldritch.md#pivot.arp_scan currently just has boiler plate.
When adding docs make sure to include an example of the Dict output and document any edge cases or OS requirements.

Once those two are done go ahead and merge o7

@jabbate19 jabbate19 merged commit 8c11caa into main Aug 14, 2023
6 checks passed
@jabbate19 jabbate19 deleted the arp branch August 14, 2023 23:55
hulto added a commit that referenced this pull request Sep 30, 2023
* ARP Scan

* Fixup Error Messages

* Remove all unwraps

* Add Tests

* Fix Windows Compile Error

* Fix Windows Test

* Change listener thread to return result

* Update Dependency Location and Pivot.rs format

* Fixup Thread Failure

* Docs and Limiting Println to Debug

---------

Co-authored-by: Hulto <7121375+hulto@users.noreply.github.com>
hulto added a commit that referenced this pull request Sep 30, 2023
* ARP Scan

* Fixup Error Messages

* Remove all unwraps

* Add Tests

* Fix Windows Compile Error

* Fix Windows Test

* Change listener thread to return result

* Update Dependency Location and Pivot.rs format

* Fixup Thread Failure

* Docs and Limiting Println to Debug

---------

Co-authored-by: Hulto <7121375+hulto@users.noreply.github.com>
hulto added a commit that referenced this pull request Oct 5, 2023
* ARP Scan

* Fixup Error Messages

* Remove all unwraps

* Add Tests

* Fix Windows Compile Error

* Fix Windows Test

* Change listener thread to return result

* Update Dependency Location and Pivot.rs format

* Fixup Thread Failure

* Docs and Limiting Println to Debug

---------

Co-authored-by: Hulto <7121375+hulto@users.noreply.github.com>
KCarretto pushed a commit that referenced this pull request Feb 1, 2024
 
pivot.arp_scan() (#258)

* ARP Scan

* Fixup Error Messages

* Remove all unwraps

* Add Tests

* Fix Windows Compile Error

* Fix Windows Test

* Change listener thread to return result

* Update Dependency Location and Pivot.rs format

* Fixup Thread Failure

* Docs and Limiting Println to Debug

---------

Co-authored-by: Hulto <7121375+hulto@users.noreply.github.com>
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.

Implement pivot.arp_scan
2 participants