for i in range(3):
    # Warning : afin de tester, message non divisible par 3 peut avoir des pertes d'informations
    fragmentSize = int(len(message) / 3)
    # Découpe le message en fragments
    fragmentMessage = message[fragmentSize * i:fragmentSize * (i + 1)]
    # Calcul de l'ICV du fragment actuel
    icv = zlib.crc32(fragmentMessage).to_bytes(4, byteorder='little')

    # On chiffre le fragment + icv.
    seed = iv + key
    cipher = RC4(seed, streaming=False)
    encrypted_message = cipher.crypt(fragmentMessage + icv)

    # On crée un nouveau packet avec les bonnes valeurs.
    wepdata = encrypted_message[:-4]
    encrypted_icv = int.from_bytes(encrypted_message[-4:], byteorder='big')
    # Si ce n'est pas le dernier fragment (!= 2) l'on rajout MF (More Fragments) à notre frame Dot11
    if i != 2:
        pck = RadioTap() / Dot11(type='Data',
                                 FCfield='to-DS+protected+MF') / Dot11WEP(
                                     iv=iv, wepdata=wepdata, icv=encrypted_icv)
    else:
        pck = RadioTap() / Dot11(type='Data',
                                 FCfield='to-DS+protected') / Dot11WEP(
                                     iv=iv, wepdata=wepdata, icv=encrypted_icv)

    pck.SC = i
    # On ajoute le fragment dans une capture pcap.
    wrpcap('ex3.cap', pck, append=True)
    print(pck.show())
Пример #2
0
def send_beacon(iface, ssid, mac_address, count, list_path):
    if count is None:
        count = 1

    if ssid is None:
        ssid = random_mac()

    if mac_address is None:
        mac_address = random_mac()

    if list_path is not None:
        file = open(list_path)
        data = json.load(file)

        for single_count in range(0, count):
            for single_data in data:
                dot11 = Dot11(type=0, subtype=8, addr1='ff:ff:ff:ff:ff:ff', addr2='22:22:22:22:22:22',
                              addr3=single_data['mac'])

                beacon = Dot11Beacon(cap='ESS+privacy')

                essid = Dot11Elt(ID='SSID', info=single_data['ssid'], len=len(single_data['ssid']))

                rsn = Dot11Elt(ID='RSNinfo', info=(
                    '\x01\x00'
                    '\x00\x0f\xac\x02'
                    '\x02\x00'
                    '\x00\x0f\xac\x04'
                    '\x00\x0f\xac\x02'
                    '\x01\x00'
                    '\x00\x0f\xac\x02'
                    '\x00\x00'))

                frame = RadioTap() / dot11 / beacon / essid / rsn

                frame.show()

                sendp(frame, iface=iface, count=1)

    if list_path is None:
        dot11 = Dot11(type=0, subtype=8, addr1='ff:ff:ff:ff:ff:ff', addr2='22:22:22:22:22:22', addr3=mac_address)

        beacon = Dot11Beacon(cap='ESS+privacy')

        essid = Dot11Elt(ID='SSID', info=ssid, len=len(ssid))

        rsn = Dot11Elt(ID='RSNinfo', info=(
            '\x01\x00'
            '\x00\x0f\xac\x02'
            '\x02\x00'
            '\x00\x0f\xac\x04'
            '\x00\x0f\xac\x02'
            '\x01\x00'
            '\x00\x0f\xac\x02'
            '\x00\x00'))

        frame = RadioTap() / dot11 / beacon / essid / rsn

        frame.show()

        sendp(frame, iface=iface, count=count)