Exemplo n.º 1
0
def inmem_capture():
    return pyshark.InMemCapture()
Exemplo n.º 2
0
async def greet(packets):
    for g in packets:
        c = pyshark.InMemCapture()
        p = c.parse_packet(g)
        print(p)
        c.close()
Exemplo n.º 3
0
def loop():
    imc = pyshark.InMemCapture(linktype=228,
                               custom_parameters={"-J": "lte_rrc"})

    source = os.open(_pipe, os.O_RDONLY | os.O_NONBLOCK)

    poll = select.poll()
    poll.register(source, select.POLLIN)

    _ip_base = "172.17.0."
    _ip_pool = iter(range(5, 128))
    handover_start = False
    handover_complete = False
    cell_id = None

    test_mode = os.getenv('TEST_SETUP')
    if test_mode == None or not (test_mode
                                 in ['mptcp', 'tcpwo', 'tcp', 'sip', 'sipwo']):
        print("TEST_SETUP env variable not set")
        return
    else:
        print('Test mode: {}'.format(test_mode))

    while True:
        if (source, select.POLLIN) in poll.poll(2000):  # 2s
            ts, pkt = get_packet(source)
        else:
            continue

        pkt = imc.parse_packet(pkt)
        # print("timestamp:", ts, pkt, dir(pkt.lte_rrc))

        # cell id
        new_cell_id = None
        try:
            new_cell_id = pkt.lte_rrc.lte_rrc_physcellid
        except AttributeError:
            pass

        if new_cell_id != None:
            cell_id = new_cell_id

        # Check handover completes
        if handover_start:
            handover_complete = False
            try:
                handover_complete = pkt.lte_rrc.lte_rrc_rrcconnectionreconfigurationcomplete_element == 'rrcConnectionReconfigurationComplete'
            except AttributeError:
                pass

            # Record
            if handover_complete:
                print("***** Handover completes! *****")
                try:
                    ip = _ip_base + str(next(_ip_pool))
                except StopIteration:
                    _ip_pool = iter(range(5, 128))
                    ip = _ip_base + str(next(_ip_pool))

                if not (test_mode in ['tcpwo', 'sipwo']):
                    #ho.do(new_ip=ip, lat=32.072 * 1e-3, name="uec_new2")
                    ho.do(new_ip=ip, lat=96.0 * 1e-3, name="uec_new2")

            handover_start = False

        # handover start
        try:
            handover_start = pkt.lte_rrc.lte_rrc_mobilitycontrolinfo_element == 'mobilityControlInfo'
            if handover_start:
                print("***** Handover starts! *****")
        except AttributeError:
            pass

        # TBD which timestamp
        event = 'RRC'
        if handover_complete:
            event = 'HO_END'
        if handover_start:
            event = 'HO_START'

        print(time.time(), event, cell_id)

        # Reset handover completes
        if handover_complete:
            handover_complete = False
Exemplo n.º 4
0
cap = pyshark.FileCapture('../challenge/pingpong.pcap')

stream_count = {}

i = 0

for pkt in cap:
    data = binascii.unhexlify(pkt['ICMP'].data)

    if i == 5:
        challenge = data[5:]
    if i == 6:
        target_digest = data[5:]

    if len(data) > 50:
        c = pyshark.InMemCapture()
        offset = 5  # magic word
        ethernet_header = b'\x00' * 12 + b'\x08' + b'\x00'

        pkt_inner = c.parse_packet(ethernet_header + data[offset:])
        print(pkt_inner)
        if 'ICMP' in pkt_inner:
            print(binascii.unhexlify(pkt_inner['ICMP'].data))
        print('-' * 100)

    i += 1

password = crack_password(challenge, target_digest)
print('Password was "{}"'.format(password))