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

Add PE32/PE32+ risk detection (detect transmitted windows executables). #2312

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

utoni
Copy link
Collaborator

@utoni utoni commented Feb 9, 2024

Please sign (check) the below before submitting the Pull Request:

Link to the related issue:

Describe changes:

The risk detection is far from perfect e.g. the amount of packets it does look for is hard coded. I think it might be better to let the user decide how many packets should checked for a possible PE transmission. It also assumes that the first 0x3C + 4 bytes are transmitted as one packet e.g. w/o fragmentation/retransmission.

@utoni utoni force-pushed the add/pe-dissector branch 3 times, most recently from 37925d6 to 9c818c2 Compare February 9, 2024 07:32
@0xA50C1A1
Copy link
Contributor

0xA50C1A1 commented Feb 9, 2024

I think it makes sense to also add HTTP content-type check for application/vnd.microsoft.portable-executable.

@utoni
Copy link
Collaborator Author

utoni commented Feb 9, 2024

I think there is already such check in src/lib/protocols/http.c. But it may be useful to check the HTTP body for PE32/PE32+. What do you think?

@0xA50C1A1
Copy link
Contributor

I think there is already such check in src/lib/protocols/http.c. But it may be useful to check the HTTP body for PE32/PE32+. What do you think?

Yeah, that's a great idea.

@0xA50C1A1
Copy link
Contributor

I think there is already such check in src/lib/protocols/http.c.

Yes, it's there, but I meant something else: to classify flows with that content-type as Portable_Executable.

@utoni
Copy link
Collaborator Author

utoni commented Feb 9, 2024

I think there is already such check in src/lib/protocols/http.c.

Yes, it's there, but I meant something else: to classify flows with that content-type as Portable_Executable.

Yea, makes also sense. I'll do both.

Copy link

sonarcloud bot commented Feb 10, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@utoni utoni requested a review from IvanNardi February 10, 2024 07:03
@IvanNardi
Copy link
Collaborator

I'll do a proper review later, but I have an initial question: is there any specific reasons why this PE stuff is treated as a new protocol instead of a new flow risk?
[It seems that the former allows a simpler code for the generic UDP/TCP case]
I might have a preference for the flow risk solution (PE seems a specific case of "binary transfer risk"] but I don't have strong opinions and I am fine with both solutions. I would like to know your reasoning about that...

@utoni
Copy link
Collaborator Author

utoni commented Feb 13, 2024

I'll do a proper review later, but I have an initial question: is there any specific reasons why this PE stuff is treated as a new protocol instead of a new flow risk? [It seems that the former allows a simpler code for the generic UDP/TCP case] I might have a preference for the flow risk solution (PE seems a specific case of "binary transfer risk"] but I don't have strong opinions and I am fine with both solutions. I would like to know your reasoning about that...

Initially, I did not want to create a new protocol id for that.
But: The PCAP file shows a plaintext executable xfer, which was not classified before.
At first I've just wanted to write a protocol dissector that does not classify a protocol, but set's a risk.
It seems that there is a limitation in the core which prevents to do such things. So I've decided to create a new protocol id for it.
But I am open to revert that new protocol id creation if we can at least set the risk if a PE32/PE32+ executable is transmitted.

@IvanNardi
Copy link
Collaborator

I'll do a proper review later, but I have an initial question: is there any specific reasons why this PE stuff is treated as a new protocol instead of a new flow risk? [It seems that the former allows a simpler code for the generic UDP/TCP case] I might have a preference for the flow risk solution (PE seems a specific case of "binary transfer risk"] but I don't have strong opinions and I am fine with both solutions. I would like to know your reasoning about that...

Initially, I did not want to create a new protocol id for that. But: The PCAP file shows a plaintext executable xfer, which was not classified before. At first I've just wanted to write a protocol dissector that does not classify a protocol, but set's a risk. It seems that there is a limitation in the core which prevents to do such things. So I've decided to create a new protocol id for it. But I am open to revert that new protocol id creation if we can at least set the risk if a PE32/PE32+ executable is transmitted.

Just an idea. Your current code basically checks for PE transfer only for unknown traffic (because when/if the flow is classified, PE dissector is not called anymore). [let's ignore the HTTP case which seems easy to handle]
If we want that, we could remove the new dissector/protocol and add something like that

static ndpi_protocol ndpi_internal_detection_process_packet(...) {
[...]
  /* At the end of this function */
  if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN) {
    /* just the code that is right now in ndpi_search_portable_executable and if we found it we set a risk */
  }
}

This way, we don't need a new protocol and we can set a risk.
Just an idea

@utoni utoni changed the title Add PE32/PE32+ dissector to detect transmitted executables. Add PE32/PE32+ risk detection (detect transmitted windows executables). Apr 4, 2024
@utoni
Copy link
Collaborator Author

utoni commented Apr 4, 2024

@IvanNardi
Again, I forgot a PR.
Need some kind of stale PR alert or so..

@utoni utoni force-pushed the add/pe-dissector branch 2 times, most recently from 6cae419 to f1d23e3 Compare April 4, 2024 22:00
src/lib/ndpi_main.c Show resolved Hide resolved
src/lib/protocols/http.c Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Apr 5, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Collaborator

@IvanNardi IvanNardi left a comment

Choose a reason for hiding this comment

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

Thank you

@IvanNardi IvanNardi merged commit 0f77f49 into ntop:dev Apr 5, 2024
33 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.

3 participants