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

Fix sniffer #7973

Merged
merged 1 commit into from
Oct 29, 2024
Merged

Fix sniffer #7973

merged 1 commit into from
Oct 29, 2024

Conversation

bandi13
Copy link
Contributor

@bandi13 bandi13 commented Sep 13, 2024

Description

Using Linux, there is a 'linux cooked capture' layer that is added on, and the packets seem to contain two extra bytes.

Also reworked the argument handling to be able to individually add in arguments without needing to pass in a PCAP file. Now we can sniff live packets and set filters. Additionally, we can now define the output of the trace file.

Testing

Able to read packet capture when using 'any' interface

@JacobBarthelmeh
Copy link
Contributor

Assigning back to @bandi13. Failing one of the sniffer tests snifftest static RSA failed

}
else {
/* packet doesn't contain minimum ip/tcp header */
continue;
}
int ptype = pcap_datalink(pcap);
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid mixed-declaration. Move int ptype up. Also please add comment documenting what Linux SLL is and what the 2 bytes are.

@bandi13 bandi13 force-pushed the fixSniffer branch 2 times, most recently from cd14a7b to 71d37bf Compare September 26, 2024 15:55
@bandi13 bandi13 assigned wolfSSL-Bot and unassigned bandi13 Sep 26, 2024
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Ask discussed yesterday. Works now with "any" interface, but not with "lo".

@bandi13 bandi13 force-pushed the fixSniffer branch 2 times, most recently from e5ba8b3 to aab5752 Compare October 2, 2024 16:32
@bandi13
Copy link
Contributor Author

bandi13 commented Oct 2, 2024

retest this please

@dgarske dgarske self-requested a review October 2, 2024 19:01
@dgarske dgarske assigned dgarske and unassigned dgarske Oct 2, 2024
@dgarske dgarske removed their request for review October 3, 2024 18:02
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Otherwise PR looks awesome!

src/sniffer.c Outdated
for (i = 0; i < chainSz; i++)
for (i = 0; i < chainSz; i++) length += chain[i].iov_len;

tmpPacket = (byte*)XMALLOC(length, NULL, DYNAMIC_TYPE_TMP_BUFFER);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there is a better dynamic type like DYNAMIC_TYPE_SNIFFER_PB_BUFFER that could be used or maybe even a new DYNAMIC_TYPE_SNIFFER_CHAIN_BUFFER?

Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Please squash this PR. Thanks @bandi13

Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Can you update the comment: "Please run directly from wolfSSL root dir".... It is no longer true.

Enter the port to scan [default: 11111, '0' for all]:
Enter the server key [default: ../../certs/statickeys/ecc-secp256r1.pem,../../certs/statickeys/dh-ffdhe2048.pem,../../certs/statickeys/x25519.pem]:
Enter alternate SNI [default: none]:
Failed loading private key ../../certs/statickeys/ecc-secp256r1.pem: ret -1
Please run directly from wolfSSL root dir
Failed loading private key ../../certs/statickeys/dh-ffdhe2048.pem: ret -1
Please run directly from wolfSSL root dir
Failed loading private key ../../certs/statickeys/x25519.pem: ret -1
Please run directly from wolfSSL root dir
davidgarske@Davids-MacBook-Pro-2 wolfssl % pwd
/Users/davidgarske/GitHub/wolfssl

Detect reading of packet errors

--enable-all and --enable-sniffer exposed this issue

Don't need variable

Rework argument parsing

Need a way to allow arguments to be supplied more granularly. Partucilarly, I needed a "-tracefile" argument without requiring the use of a PCAP file

Fix error prints to STDERR

Fix setting of port filtering

Fix 80 char limit

Not actually a bad packet when there are no more packets

Fix strcat size

Allow the sniffer to print the trace to STDOUT

Fix indexing

Take out superfluous error which is handled later

Set default port to 11111

Single return point

Combine chain to one contiguous memory block

Fix return

Add in error handling for XMALLOC

Add in debugging output when --enable-debug

It makes no sense to allocate a ton of small buffers to process chains

Ultimately, the code is slower because of the several small memcpy instead of a single large contiguous memcpy

Pass in a device name

Fix unused variable

Fix cast

Addressing PR comments

Add new flags to --help
@bandi13
Copy link
Contributor Author

bandi13 commented Oct 29, 2024

Can you update the comment: "Please run directly from wolfSSL root dir".... It is no longer true.

Enter the port to scan [default: 11111, '0' for all]:
Enter the server key [default: ../../certs/statickeys/ecc-secp256r1.pem,../../certs/statickeys/dh-ffdhe2048.pem,../../certs/statickeys/x25519.pem]:
Enter alternate SNI [default: none]:
Failed loading private key ../../certs/statickeys/ecc-secp256r1.pem: ret -1
Please run directly from wolfSSL root dir
Failed loading private key ../../certs/statickeys/dh-ffdhe2048.pem: ret -1
Please run directly from wolfSSL root dir
Failed loading private key ../../certs/statickeys/x25519.pem: ret -1
Please run directly from wolfSSL root dir
davidgarske@Davids-MacBook-Pro-2 wolfssl % pwd
/Users/davidgarske/GitHub/wolfssl

Done, and squashed.

@dgarske dgarske merged commit 72306b9 into wolfSSL:master Oct 29, 2024
142 checks passed
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.

4 participants