aptdetector.network.parser package¶
aptdetector.network.parser.httpparser module¶
http_parser implementation
couple of functions that was required to parse and reassemble http requests and responses
-
class
aptdetector.network.parser.httpparser.
HttpParser
[source]¶ Bases:
object
parse http req & resp
-
read_chunked_body
(reader, skip=False)[source]¶ read chunked body
- Args:
- reader (DataReader): type of reader that is required skip (bool): either return if error happened or continue to work
- Returns:
- if skip=False return None else return broken packet
-
read_headers
(reader, lines)[source]¶ read headers
- Args:
- reader (DataReader): type of reader that is required lines (list): list of lines that we think is part of the header section
- Returns:
- dict of parsed_header
-
read_http_req_header
(reader)[source]¶ read & parse request http headers
- Args:
- reader (DataReader): type of reader that is required
- Returns:
- None if not a response or any error happend , dict of parsed_header otherwise
-
read_http_resp_header
(reader)[source]¶ read & parse response http headers
- Args:
- reader (DataReader): type of reader that is required
- Returns:
- None if not a response or any error happend , dict of parsed_header otherwise
-
read_request
(reader, message)[source]¶ read and output one http request.
- Args:
- reader (DataReader): type of reader that is required message (RequestMessage): response packet
- Returns:
- None if error happened , content otherwise
-
-
class
aptdetector.network.parser.httpparser.
HttpRequestHeader
[source]¶ Bases:
object
mimic the header of a request packet
aptdetector.network.parser.parse_pcap module¶
parse_pcap
parsing a pcap file so that later we would be able to use the urls that was found to check for any harmfull activity
>>> from aptdetector.network.parser.parse_pcap import parse_pcap_file
>>> parse_pcap_file()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: parse_pcap_file() missing 1 required positional argument: 'file_path'
-
class
aptdetector.network.parser.parse_pcap.
Stream
[source]¶ Bases:
object
stream handler
handle the problem of tcp window and reassembling a packet by using tcp sequence number and keeping track of last ack sequence number
-
class
aptdetector.network.parser.parse_pcap.
TcpConnection
(packet)[source]¶ Bases:
object
pcap tcp parser
parse a pcap file and creates
TcpPacket
objects from that by the help of packetparse project
-
aptdetector.network.parser.parse_pcap.
get_file_format
(infile)[source]¶ get cap file format by magic num.
- Args:
- infile (file): saved Pcap file that is ready to be parsed
- Returns:
- file format and the first byte of string
- Raises:
- :class:FileParsingException when file is empty or too small
-
aptdetector.network.parser.parse_pcap.
parse_pcap_file
(file_path)[source]¶ pcap parser.
parse a pcap file to get a list
TcpPacket
objects- Args:
- file_path (str): address of the Pcap file that is ready to be parsed
- Returns:
- list of :class:TcpPacket of found conversations in the Pcap file
- Raises:
- :class:FileParsingException if either file format were not recognized or file was not found