Ejemplo n.º 1
0
def data_frame_parser(data, flags):
    R = []
    # PADDED
    if(flags & 0x8):
        # tmp_data=[PadLength, Data+Padding]
        tmp_data = (parser.bytes_parse(data, [1]))
        R = parser.bytes_parse(tmp_data[1], [len(tmp_data[1])-tmp_data[0]])
    else:
        R.append(data)
    return R
Ejemplo n.º 2
0
def settings_frame_parser(data, flagss):
    R = []
    tmp_data = parser.bytes_parse(data, [2, 4])
    length = int(len(data)/6)
    if(1 < length):
        for _ in range(length):
            R.append([tmp_data[0], tmp_data[1]])
            tmp_data = parser.bytes_parse(tmp_data[-1], [2, 4])
    else:
        R = tmp_data
    return R
Ejemplo n.º 3
0
def push_promise_frame_parser(data, flags):
    R = []
    tmp_data = []
    # R will... [R+PromisedStreamId, HeaderBlockFragment]
    if(flags & 0x8):
        # tmp_data=[PadLength, Data+Padding]
        tmp_data = (parser.bytes_parse(data, [1]))
        tmp_data = parser.bytes_parse(tmp_data[1], [len(tmp_data[1])-tmp_data[0]])[0]
        R = parser.bytes_parse(tmp_data, [4])
    else:
        R = parser.bytes_parse(data, [4])
    return R
Ejemplo n.º 4
0
def frame_parser(data):
    R = []
    tmp_data = []
    while True:
        tmp_data = parser.bytes_parse(data, [3, 1, 1, 4])
        payload_and_data = parser.bytes_parse(tmp_data[-1], [int.from_bytes(tmp_data[0], "big")])
        tmp_data = tmp_data[:-1]
        if(tmp_data[1] == b"\x09"):
            R[0] += tmp_data[-1]
        else:
            tmp_data.append(frame_payload_parsers[tmp_data[1]](payload_and_data[0], int.from_bytes(tmp_data[2], "big")))
            R.append(tmp_data)
        if(len(payload_and_data) == 1):
            break
        data = payload_and_data[1]
    return R
Ejemplo n.º 5
0
def headers_frame_parser(data, flags):
    #print(data.hex())
    R = []
    tmp_data = []
    # R will... [E+StreamDependency, Weight, HeaderBlockFragment]
    # PADDED
    tmp_data = data
    if(flags & 0x8):
        # tmp_data=[PadLength, Data+Padding]
        tmp_data = (parser.bytes_parse(data, [1]))
        tmp_data = parser.bytes_parse(tmp_data[1], [len(tmp_data[1])-tmp_data[0]])[0]
        #R = [b"\xff\xff\xff\xff", b"\xff",parser.bytes_parse(tmp_data[1], [len(tmp_data[1])-tmp_data[0]])[0]]
        R = [parser.bytes_parse(tmp_data[1], [len(tmp_data[1])-tmp_data[0]])[0]]
    if(flags & 0x20):
        R = parser.bytes_parse(tmp_data, [4, 1])
    return R
Ejemplo n.º 6
0
def priority_frame_parser(data, flags):
    R = []
    R = parser.bytes_parse(data, [4, 1])
    return R
Ejemplo n.º 7
0
def goaway_frame_parser(data, flags):
    R = []
    R = parser.bytes_parse(data, [4, 4])
    return R
Ejemplo n.º 8
0
def get_mail_servers(domain):
    HOST, PORT = "8.8.8.8", 53
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.connect((HOST, PORT))
    domain = domain.split(b".")
    domain_name = b""
    for a in domain:
        leng = len(a)
        domain_name += leng.to_bytes(1, "big") + a
    sock.send(b'\x00\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00' +
              domain_name + b'\x00\x00\x0f\x00\x01')
    R = sock.recv(1024 * 10)
    # ID, FLAGS, QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT
    H = parser.bytes_parse(R, (2, 2, 2, 2, 2, 2))
    #print("ID", H[0])
    #print("FLAGS", H[1])
    QDCOUNT = int.from_bytes(H[2], "big")
    ANCOUNT = int.from_bytes(H[3], "big")
    NSCOUNT = int.from_bytes(H[4], "big")
    ARCOUNT = int.from_bytes(H[5], "big")
    counts = (QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT)
    sections = [H[6]]

    for a in range(QDCOUNT):
        sections = parser.bytes_parse(sections[-1],
                                      (sections[-1].find(b"\x00") + 1, 2, 2))
    for a in range(ANCOUNT):
        tmp = sections[:-1]
        if (sections[-1][0] & 0b11000000):
            tmp += parser.bytes_parse(sections[-1], (2, 2, 2, 4, 2))
        else:
            tmp += parser.bytes_parse(
                sections[-1], (sections[-1].find(b"\x00") + 1, 2, 2, 4, 2))
        if (int.from_bytes(tmp[-2], "big") != len(tmp[-1])):
            tmp2 = tmp[:-1]
            tmp2 += parser.bytes_parse(tmp[-1],
                                       (int.from_bytes(tmp[-2], "big"), ))
            tmp = tmp2
        sections = tmp

    #for a in range(QDCOUNT):
    #print(str(sections[a*3:a*3+3]))
    servers = []
    for a in range(ANCOUNT):
        l = sections[3:][a * 6:a * 6 + 6]
        mail_server = l[-1][2:]
        preference = l[-1][:2]
        #print(int.from_bytes(preference, "big"), mail_server)
        name = b""
        i = 0
        while (i < len(mail_server)):
            leng = mail_server[i]
            if ((leng >> 6) == 0b11):
                cm = R[int.from_bytes(mail_server[i:i + 2], "big") & 0x3fff:]
                cm = cm[:cm.find(b"\x00") + 1]
                mail_server = mail_server[:i] + cm + mail_server[i + 3:]
            else:
                st = mail_server[i + 1:i + leng + 1]
                if (st != b"\x00"):
                    name += st + b"."
                i += leng + 1
        servers.append(
            [int.from_bytes(preference, "big"), name[:-2].decode("utf-8")])
    return servers