Exemplo n.º 1
0
def arp_sender_process(STA, AP, Target):
    logger.info("ARP request process starts")

    ## generate an ARP request packet.
    arp_requested_packet = generate_arp_request_packet(STA, AP,
                                                       Target.IP_address)

    ## initialization for multi-thread process.
    executor = futures.ThreadPoolExecutor(max_workers=2)

    ## recieve process (worker 1)
    recv_thread = executor.submit(recv_arp_response_packet, STA, AP,
                                  Target.IP_address)

    ## sender process (worker 2)
    logger.info("send an ARP request packet.")
    send_thread = executor.submit(STA.send_packet, arp_requested_packet)

    send_thread.result()
    response_packet = recv_thread.result()

    if (response_packet):
        logger.info("An ARP response packet was successfully received")
        logger.info("ARP massage: " + Target.IP_address + " is at " +
                    response_packet[ARP].hwsrc)
        return response_packet
    else:
        logger.error("An ARP response DHCP offer packet was not received")
Exemplo n.º 2
0
def icmp_sender_process(STA, AP, Target_Interface):
    logger.info("ICMP sender process (to " + Target_Interface.IP_address + ")")

    ## generate a ICMP request packet.
    icmp_packet = generate_icmp_request(STA, AP, Target_Interface)

    ## initialization for multi-thread process.
    executor = futures.ThreadPoolExecutor(max_workers=2)

    ## recieve process (worker 1)
    recv_thread = executor.submit(recv_icmp_response_packet, STA,
                                  Target_Interface, AP)

    ## sender process (worker 2)
    logger.info("send an ICMP request packet.")
    send_thread = executor.submit(STA.send_packet, icmp_packet)

    ## synchronization
    a = send_thread.result()
    response_packet = recv_thread.result()

    if (response_packet):
        logger.info("ICMP sender process (to " + Target_Interface.IP_address +
                    ") has finished successsfully")
        return response_packet
    else:
        logger.error("ICMP sender process (to " + Target_Interface.IP_address +
                     ") has failed.")
Exemplo n.º 3
0
	def assoc_process(self):
		logger.info("association process will start");



		packet = radiotap / dot11 / AssocReq / Tagged_param;
		
		self.state = self.FAIL_COMMAND;
		self.STA.assoc_found = False;

		jobs = list();

		result_queue = mp.Queue();
		receive_process = mp.Process(target=self.__recv_assoc, args = (result_queue,) );

		jobs.append(receive_process);

		send_process = mp.Process(target=self.__send_assoc,args=(packet,))
		jobs.append(send_process)

		for job in jobs:
	        	job.start();

		for job in jobs:
			job.join();
		if result_queue.get():
			self.state = self.SUCCESS_COMMAND;
        
		if (self.state == self.SUCCESS_COMMAND):
			logger.info("association process was successful")
		elif (self.state == self.FAIL_COMMAND):
			logger.error("association process was fail");
		else:
			logger.error("Unexpected error has occured")
Exemplo n.º 4
0
def recv_association(STA, AP):
	logger.info("wait until I capture an authentication packet from " + AP.bssid + " (" + AP.essid + ") ...");
	packets = STA.recv_packet(filter=lambda x: (  (x.haslayer(Dot11AssoResp))) and (x[Dot11].addr2 == AP.bssid) and (STA.is_packet_for_me(x)));

	if(len(packets) == 0):
		logger.error("cannot capture an authentication packet from " + AP.bssid + " (" + AP.essid + ") ...");
		raise Exception("cannot capture an authentication packet packet from " + AP.bssid + " (" + AP.essid + ") ...");

	return packets[0];
Exemplo n.º 5
0
def recv_arp_response_packet(src, AP, IP_addr):
    logger.info("wait until I capture an arp response packet from " + IP_addr)
    packets = src.recv_packet(filter=lambda x: ((x.haslayer(ARP)) and (x[
        ARP].op == OP_RESPONSE_CODE) and (x[ARP].psrc == IP_addr) and (
            AP.is_packet_transmitted_by_me(x)) and (src.is_packet_for_me(x))))

    if (len(packets) == 0):
        logger.error("cannot capture an arp response from " + AP.bssid + " (" +
                     AP.essid + ") .")
        return

    return packets[0]
Exemplo n.º 6
0
def recv_arp_request_packet(src, dst, AP):
    logger.info("wait until I capture an arp request packet from " +
                dst.mac_address)
    packets = src.recv_packet(filter=lambda x: ((x.haslayer(ARP)) and (x[
        ARP].op == OP_REQUEST_CODE) and (x[ARP].hwsrc == dst.mac_address) and (
            AP.is_packet_transmitted_by_me(x)) and (src.is_packet_for_me(x))))

    if (len(packets) == 0):
        logger.error("cannot capture an arp request from " + AP.bssid + " (" +
                     AP.essid + ") .")
        return

    return packets[0]
Exemplo n.º 7
0
def arp_response_process(src, dst, AP):
    logger.info("An ARP response process starts")

    ## receive an arp request packet from dst.
    request_packet = recv_arp_request_packet(src, dst, AP)

    if (not request_packet):
        logger.error("cannot capture an ARP request packet")
        return

    response_packet = generate_arp_response_packet(src, AP, request_packet)
    src.send_packet(response_packet)
    logger.info("An ARP response process successfully finished")
Exemplo n.º 8
0
def recv_icmp_response_packet(src, dst, AP):
    logger.info("wait until I capture an arp request packet from " +
                dst.mac_address)
    packets = src.recv_packet(filter=lambda x: (
        (x.haslayer(ICMP)) and (x[ICMP].type == ICMP_TYPE_RESPONSE) and
        (x[Dot11].addr3 == dst.mac_address) and
        (AP.is_packet_transmitted_by_me(x)) and (src.is_packet_for_me(x))))

    if (len(packets) == 0):
        logger.error("cannot capture an arp request from " + AP.bssid + " (" +
                     AP.essid + ") .")
        return

    return packets[0]
Exemplo n.º 9
0
def scan_beacon_packet(STA, AP):
    logger.info("Beacon scan process will start")
    logger.info("please wait until a beacon packet is scanned from " +
                AP.bssid + " (" + AP.essid + ") ...")

    packets = STA.recv_packet(filter=lambda x: ((x.haslayer(Dot11Beacon)) and (
        x[Dot11].addr2 == AP.bssid) and (STA.is_packet_for_me(x))))

    if (len(packets) == 0):
        logger.error("cannot scan a beacon packet from " + AP.bssid + " (" +
                     AP.essid + ") ...")
        raise Exception("cannot scan a beacon packet from " + AP.bssid + " (" +
                        AP.essid + ") ...")

    logger.info("Beacon scan process has finished")
    return packets[0]
Exemplo n.º 10
0
def recv_probe_response_packet(_src_interface, _dst_interface):
    logger.info("wait until I capture a probe response packet from " +
                _dst_interface.bssid + " (" + _dst_interface.essid + ") ...")

    packets = _src_interface.recv_packet(
        filter=lambda x: ((x.haslayer(Dot11ProbeResp)) and
                          (x[Dot11].addr2 == _dst_interface.bssid) and
                          (_src_interface.is_packet_for_me(x))))

    if (len(packets) == 0):
        logger.error("cannot capture a probe response  packet from " +
                     _dst_interface.bssid + " (" + _dst_interface.essid +
                     ") ...")
        raise Exception("cannot capture a probe response  packet from " +
                        _dst_interface.bssid + " (" + _dst_interface.essid +
                        ") ...")

    return packets[0]
Exemplo n.º 11
0
def authentication_process(STA, AP):
    logger.info("authentication process will start")

    ## initialization for multi-thread process.
    executor = futures.ThreadPoolExecutor(max_workers=2)

    ## recieve process (worker 1)
    recv_thread = executor.submit(recv_authentication, STA, AP)

    ## sender process (worker 2)
    send_thread = executor.submit(send_authentication, STA, AP)

    send_thread.result()
    response_packet = recv_thread.result()

    if (response_packet[Dot11Auth].status == SUCCESS_STATE):
        logger.info("An authentication process successfully finished")
        return response_packet
    else:
        logger.error("An authentication process was fail")
Exemplo n.º 12
0
def association_process(STA, AP,elementTag = None):
	logger.info("association process will start");

	## initialization for multi-thread process.
	executor = futures.ThreadPoolExecutor(max_workers=2);

	## recieve process (worker 1)
	recv_thread = executor.submit(recv_association, STA, AP);

	## sender process (worker 2)
	send_thread = executor.submit(send_association, STA, AP,elementTag);

	send_thread.result();
	response_packet = recv_thread.result();

	if (response_packet[Dot11AssoResp].status == SUCCESS_STATE):
		logger.info("Association process successfully finished");
		return response_packet;
	else:
		logger.error("Association process was fail");
Exemplo n.º 13
0
def auto_receiver(STA, AP):
    taskContainer = [];
    try:
        while True:
            logger.info("waiting for a packet...")
            recv_packet = STA.recv_packet(filter=lambda x: (STA.is_packet_for_me(x) and (not x.haslayer(Dot11Beacon))),timeout = WAIT_TIME);

            if recv_packet:
                task_thread = Task_Thread(STA,AP,recv_packet[0]);
                taskContainer.append(task_thread);
                task_thread.start();

    except KeyboardInterrupt:
        print("try Exec")
        logger.info("Interruption has occurred.");
        logger.info("Stop auto receiver process");
        return;
    except Exception as e:
        from traceback import print_exc
        print_exc()
        logger.error("unexpected error has occurred.");
        logger.error("Stop auto receiver process");
Exemplo n.º 14
0
def DHCP_request_ack_process(STA, AP, offer_packet):

	logger.info("DHCP request-ack process will start");

	## initialization for multi-thread process.
	executor = futures.ThreadPoolExecutor(max_workers=2);

	## recieve process (worker 1)
	recv_thread = executor.submit(recv_dhcp_packet, STA, AP, ACK_MASSAGE);

	## sender process (worker 2)
	logger.info("sending a DHCP request packet.");
	send_thread = executor.submit(STA.send_packet, offer_packet);

	send_thread.result();
	response_packet = recv_thread.result();

	extract_dhcp_massage_from_packet(response_packet);

	if (extract_dhcp_massage_from_packet(response_packet) == ACK_MASSAGE):
		logger.info("A DHCP Ack packet was successfully received");
		return response_packet;
	else:
		logger.error("A DHCP Ack packet was not received");