9
Shannon’s entropy is given by the formula:
Where Ti will be the data extracted from my network dump (dump.pcap).
The end of an HTTP header on a normal connection is marked by \r\n\r\n:

Example of an incomplete HTTP header (could be a denial of service attack):
My goal is to calculate the entropy of the number of packets with \r\n\r\n and without \r\n\r\n in order to compare them.
I can read the PCAP file like this:
import pyshark
pkts = pyshark.FileCapture('dump.pcap')
The entropy based on the IP numbers I made:
import numpy as np
import collections
sample_ips = [
"131.084.001.031",
"131.084.001.031",
"131.284.001.031",
"131.284.001.031",
"131.284.001.000",
]
C = collections.Counter(sample_ips)
counts = np.array(list(C.values()),dtype=float)
#counts = np.array(C.values(),dtype=float)
prob = counts/counts.sum()
shannon_entropy = (-prob*np.log2(prob)).sum()
print (shannon_entropy)
Any idea? It is possible/makes sense to calculate entropy based on the number of packages with \r\n\r\n and without \r\n\r\n? Or is it something that doesn’t make sense?
Any idea how to calculate?
The network dump is here: https://ufile.io/y5c7k
Some lines from it:
30 2017/246 11:20:00.304515 192.168.1.18 192.168.1.216 HTTP 339 GET / HTTP/1.1
GET / HTTP/1.1
Host: 192.168.1.216
accept-language: en-US,en;q=0.5
accept-encoding: gzip, deflate
accept: */*
user-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Firefox/45.0
Connection: keep-alive
content-type: application/x-www-form-urlencoded; charset=UTF-8



I made the network dump file available here: https://ufile.io/y5c7k
– Ed S
I didn’t understand how to get this information from the package from the dump...
– Ed S
@Eds your link has 53MB, glue some lines in your question...
– MagicHat
@Magichat : what do you want me to extract? I stick to the question!
– Ed S
So put an excerpt from your file...
– MagicHat
@Magichat: edited. Is this good? Thanks! I used wireshark http filter!
– Ed S
To be honest it’s not good, you’re putting the image puts a few lines of the file code that you’re capturing some data...
– MagicHat
@Magichat: Improved? I pasted a line of the image. Need more?
– Ed S
@Magichat: You could help?
– Ed S
@Eds to be honest I didn’t understand your doubt... https://chat.stackexchange.com/rooms/11910/pilooverflow. sometimes there is easier chat to understand
– MagicHat
@Magichat: I don’t know how to check the string " r n r n" to create the counter: com_string and sem_string
– Ed S
@Eds but that’s not exactly what this answer answers?
– MagicHat
@Magichat: I read the PCAP but didn’t understand how to check the string "in practice"!
– Ed S
@Eds I believe you have to make one
parsein your pcap through a regex... I won’t be able to help you, now pq num is so simple, but I think if you search on regex if you can....– MagicHat