MCPcopy Create free account
hub / github.com/secdev/scapy / from_packet

Method from_packet

scapy/modules/p0f.py:240–275  ·  view source on GitHub ↗

Receives an HTTP packet (assuming it's valid), and returns a HTTP_Signature object

(cls, pkt)

Source from the content-addressed store, hash-verified

238
239 @classmethod
240 def from_packet(cls, pkt):
241 """
242 Receives an HTTP packet (assuming it's valid), and returns
243 a HTTP_Signature object
244 """
245 http_payload = raw(pkt[TCP].payload)
246
247 crlfcrlf = b"\r\n\r\n"
248 crlfcrlfIndex = http_payload.find(crlfcrlf)
249 if crlfcrlfIndex != -1:
250 headers = http_payload[:crlfcrlfIndex + len(crlfcrlf)]
251 else:
252 headers = http_payload
253 headers = headers.decode() # XXX: Check if this could fail
254 first_line, headers = headers.split("\r\n", 1)
255
256 if "1.0" in first_line:
257 http_ver = 0
258 elif "1.1" in first_line:
259 http_ver = 1
260 else:
261 raise ValueError("HTTP version is not 1.0/1.1")
262
263 sw = ""
264 headers_found = []
265 hdr_set = set()
266 for header_line in headers.split("\r\n"):
267 name, _, value = header_line.partition(":")
268 if value:
269 value = value.strip()
270 headers_found.append((name, value))
271 hdr_set.add(name)
272 if name in ("User-Agent", "Server"):
273 sw = value
274 hdr = tuple(headers_found)
275 return cls(http_ver, hdr, hdr_set, None, sw)
276
277 @classmethod
278 def from_raw_sig(cls, sig_line):

Callers

nothing calls this directly

Calls 5

rawFunction · 0.90
findMethod · 0.80
decodeMethod · 0.80
appendMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected