예제 #1
0
def parse_IPv4(eth_data):

    iph = unpack('!BBHHHBBH4s4s', eth_data[0:20])

    version_ihl = iph[0]
    version = version_ihl >> 4
    ihl = version_ihl & 0xF

    iph_length = ihl * 4

    type_of_service = iph[1]
    total_len = iph[2]
    datagram_id = iph[3]

    flags_fr_offset = iph[4]
    flags = flags_fr_offset >> 13
    fr_offset = flags_fr_offset & 0xFF

    ttl = iph[5]
    protocol = iph[6]
    h_checksum = iph[7]
    s_addr = iph[8]
    d_addr = iph[9]

    if iph_length == 20:
        opt = None
    elif iph_length > 20:
        opt = eth_data[20:iph_length]
    else:
        raise ValueError("Parse IP Header Error")

    header = Headers.IPv4Header(version, iph_length, type_of_service,
                                total_len, datagram_id, flags, fr_offset, ttl,
                                protocol, h_checksum, s_addr, d_addr, opt)
    return Packet(header, eth_data[header.header_length:])
예제 #2
0
 def getrequest(self):
     headers = Headers(self.headers)
     return self.Request(self.path,
                         method=self.method,
                         headers=headers,
                         body=self.body,
                         connect_timeout=self.timeout,
                         request_timeout=self.timeout,
                         validate_cert=False)
예제 #3
0
 def getrequest(self, scheme=None):
     scheme = scheme if scheme else self.scheme
     host = self.host
     if self.port and self.port != self.default_ports[scheme]:
         host = '{0}:{1}'.format(host, self.port)
     url = urlunsplit((scheme, host, self.path, '', ''))
     headers = Headers(self.headers)
     return self.Request(url, method=self.method, headers=headers,
                         body=self.body, connect_timeout=self.timeout,
                         request_timeout=self.timeout, validate_cert=False)
예제 #4
0
def parse_ARP(eth_data):
    hw_type, proto_type, hw_adr_size, proto_addr_size, opt = divide_packet(
        [2, 2, 1, 1, 2], eth_data)

    hw_adr_size = unpack("!B", hw_adr_size)[0]
    proto_addr_size = unpack("!B", proto_addr_size)[0]

    addrs_size = hw_adr_size + proto_addr_size

    hw_sender, proto_sender = divide_packet([hw_adr_size, proto_addr_size],
                                            eth_data, 8)
    hw_target, proto_target = divide_packet([hw_adr_size, proto_addr_size],
                                            eth_data, 8 + addrs_size)

    header = Headers.ARPHeader(hw_type, proto_type, hw_adr_size,
                               proto_addr_size, opt, hw_sender, proto_sender,
                               hw_target, proto_target)
    return Packet(header, b"")
예제 #5
0
def main():
    file_headers = ["DOS", "file", "PE", "sections", "all"]

    parser = argparse.ArgumentParser(description="PE file parser",
                                     usage="%(prog)s [options]")
    parser.add_argument("file", nargs=1, help="PE file to parse")
    parser.add_argument("-o",
                        "--options",
                        dest="opt",
                        type=str,
                        choices=file_headers,
                        help="Headers to dump")
    parser.add_argument("-d",
                        "--disassemble",
                        dest="dis",
                        type=str,
                        help="Section to disassemble")

    args = parser.parse_args()
    file = args.file[0]

    if not os.path.exists(file):
        print("File {} doesn't exists.".format(file), file=sys.stderr)
        parser.exit(FileNotFoundError.errno)

    ################## Choices ##################
    if args.opt is not None:
        if args.opt == "DOS":
            Headers.DecodeFile(file).dump_dos()

        elif args.opt == "file":
            Headers.DecodeFile(file).dump_file_hdr()

        elif args.opt == "PE":
            Headers.DecodeFile(file).dump_pe_opt_header()

        elif args.opt == "sections":
            Headers.DecodeFile(file).dump_sections_header()

        elif args.opt == "all":
            Headers.DecodeFile(file).dump_file_info()

    if args.dis is not None:
        Headers.DecodeFile(file).disassemble_section(args.dis)
예제 #6
0
def parse_TCP(raw_data):
    """
    https://www.techrepublic.com/article/exploring-the-anatomy-of-a-data-packet/
    https://en.wikipedia.org/wiki/Transmission_Control_Protocol
    """

    s_port, d_port, seq_num, ack_num = divide_packet([2, 2, 4, 4], raw_data)
    data_offset = raw_data[12] >> 4

    tcph_len = data_offset // 4
    # reserved
    NS = raw_data[12] & 1
    other_flags = raw_data[13]
    flags = bytes([NS]) + bytes([other_flags])

    opt = raw_data[20:tcph_len]

    window_size, check_sum, urgent_pointer = divide_packet([2, 2, 2], raw_data,
                                                           14)

    return Packet(
        Headers.TCPHeader(s_port, d_port, seq_num, ack_num, data_offset, flags,
                          window_size, check_sum, urgent_pointer, opt),
        raw_data[tcph_len:])
예제 #7
0
(新增折扣力度)
固有折扣 bundle_base_discount
新增折扣 discount_pct
原价 discount_original_price
折扣后价格 discount_final_price
(固有折扣力度)
固有折扣 bundle_base_discount
折扣后价格 discount_final_price 或者 game_purchase_price price
"""

from bs4 import BeautifulSoup
import re
import requests
import Headers

headers = Headers.steam_headers()
'''名称获取'''


def get_name(soup):
    name_list = soup.find('h1')
    name = re.search('购买(.*?)<|预购(.*?)<|玩(.*?)<|下载(.*?)<', str(name_list))
    if name:
        name = name.group()
        name = re.sub('购买', '', name)
        name = re.sub('预购', '', name)
        name = re.sub('玩', '', name)
        name = re.sub('下载', '', name)
        name = re.sub('<', '', name)
        name = re.sub('&amp;', '&', name)
        name = name.strip()
예제 #8
0
def parse_Ethernet(raw_data):
    eth_length = 14
    destination_mac, source_mac, proto = divide_packet([6, 6, 2], raw_data)

    headers = Headers.EthernetHeader(destination_mac, source_mac, proto)
    return Packet(headers, raw_data[eth_length:])
예제 #9
0
def parse_ICMP(raw_data):
    icmp_type, code, checksum = divide_packet([1, 1, 2], raw_data)
    return Packet(Headers.ICMPHeader(icmp_type, code, checksum), raw_data[4:])
예제 #10
0
def parse_UDP(raw_data):
    s_port, d_port, length, checksum = divide_packet([2, 2, 2, 2], raw_data)
    return Packet(Headers.UDPHeader(s_port, d_port, length, checksum),
                  raw_data[8:])