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

Identification of flows based on network ports #53

Closed
MrSuicideParrot opened this issue Jan 28, 2020 · 2 comments · Fixed by #55
Closed

Identification of flows based on network ports #53

MrSuicideParrot opened this issue Jan 28, 2020 · 2 comments · Fixed by #55

Comments

@MrSuicideParrot
Copy link

I was analyzing the implementation of the GetFlowForPacket function and noticed that it only uses the source and destination port to identify flows.

Is there any reason to base the identification exclusively on these ports? Why can't the destination and source IP be used as a way to complement this process?

If we have two different pairs of machines using the same pair of ports to communicate, the current implementation will see these communications as a single flow and not two independent flows.

@MrSuicideParrot MrSuicideParrot changed the title Identification of flows based on ports Identification of flows based on network ports Jan 28, 2020
@glaslos
Copy link
Member

glaslos commented Jan 29, 2020

We use flow.String() which should be a string like ip:port->ip:port if I'm not mistaken https://github.com/google/gopacket/blob/master/flows.go#L178

@MrSuicideParrot
Copy link
Author

The Flow type can be applied to the NetworkLayer and TransportLayer. When it is retrieved from the network layer it will be two IPs and in the case of the transport layer it will be network ports.

A Flow is a simple object made up of a set of two Endpoints, one source and one destination. It details the sender and receiver of the Layer of the Packet. An Endpoint is a hashable representation of a source or destination. For example, for LayerTypeIPv4, an Endpoint contains the IP address bytes for a v4 IP packet.
Gopacket - Flow documentation

As GetFlowForPacket retrieves the Flow from the transport layer, the string representation will be a string like port->port.

To test my hypothesis, I changed the GetFlowForPacket function to print the flow string.

func GetFlowForPacket(packet gopacket.Packet) (flow *Flow, isNew bool) {
	isNew = true
	if transport := packet.TransportLayer(); transport != nil {
		gpktFlow := transport.TransportFlow()
		fmt.Println("Flow: " + gpktFlow.String()) //Change
		srcEp, dstEp := gpktFlow.Endpoints()

The result can be seen in the following picture. The program prints port->port.
2020-01-29_21-25

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 a pull request may close this issue.

2 participants