예제 #1
0
def get_tcp_packet(sip=None, dip=None, sport=None, dport=None, pkt_len=60):
    eth = scapy.Ether(src=scapy.RandMAC()._fix(), dst=scapy.RandMAC()._fix())
    ip = scapy.IP(src=sip if sip else scapy.RandIP()._fix(),
                  dst=dip if dip else scapy.RandIP()._fix())
    tcp = scapy.TCP(sport=sport if sport else random.randrange(pow(2, 16)),
                    dport=dport if dport else random.randrange(pow(2, 16)))
    header = eth / ip / tcp
    payload = '0' * (pkt_len - len(header))
    return header / payload
예제 #2
0
def generate_DHCP():
	global all_given_leases

	x_id = random.randrange(1, 1000000)
	hw = "00:00:5e" + str(scapy.RandMAC())[8:]
	hw_str = scapy.mac2str(hw)
	# print(hw)
	# print(hw_str)
	dhcp_discover_pkt = scapy.Ether(dst='ff:ff:ff:ff:ff:ff', src=hw) / scapy.IP(src='0.0.0.0', dst='255.255.255.255') / scapy.UDP(sport=68, dport=67) / scapy.BOOTP(op=1, xid=x_id, chaddr=hw_str) / scapy.DHCP(options=[('message-type', 'discover'), ('end')])
	ans, unans = scapy.srp(dhcp_discover_pkt, iface=interface, timeout=2.5, verbose=0)

	# print(ans)
	# print(unans)
	# print(ans.summary())
	# print(ans[0][1][scapy.BOOTP].yiaddr)

	offered_ip = ans[0][1][scapy.BOOTP].yiaddr

	dhcp_request_pkt = scapy.Ether(dst='ff:ff:ff:ff:ff:ff', src=hw) / scapy.IP(src='0.0.0.0', dst='255.255.255.255') / scapy.UDP(sport=68, dport=67) / scapy.BOOTP(op=1, xid=x_id, chaddr=hw_str) / scapy.DHCP(options=[('message-type', 'request'),('requested_addr', offered_ip), ('end')])
	ans, unans = scapy.srp(dhcp_discover_pkt, iface=interface, timeout=2.5, verbose=0)

	# print(ans)
	# print(unans)
	# print(ans.summary())
	# print(ans[0][1][scapy.BOOTP].yiaddr)
	# print(ans[0][1][scapy.IP].src)

	offered_ack_ip = ans[0][1][scapy.BOOTP].yiaddr
	server_ip = ans[0][1][scapy.IP].src

	all_given_leases.append(offered_ack_ip)
	server_id.append(server_ip)
	client_mac.append(hw)

	return all_given_leases, server_id, client_mac
 def __create_mac(self, n, ip):
     ip = ip.split(".")
     mac = scapy.RandMAC()
     mac = mac.split(":")
     mac[-1] = hex(n ^ int(ip[-1])).replace("0x", "")
     if len(mac[-1]) == 1:
         mac[-1] = "0" + mac[-1]
     return ':'.join(i for i in mac)
예제 #4
0
파일: dot11.py 프로젝트: skizap/hackerman
 def __init__(self, ssid, cap="ESS+privacy"):
     dot11 = scapy.Dot11(type=0,
                         subtype=8,
                         addr1=broadcast,
                         addr2=str(scapy.RandMAC()),
                         addr3=str(scapy.RandMAC()))
     beacon = scapy.Dot11Beacon(cap=cap)
     essid = scapy.Dot11Elt(ID="SSID", info=ssid, len=len(ssid))
     rsn = scapy.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'))
     self.pkt = scapy.RadioTap() / dot11 / beacon / essid / rsn
예제 #5
0
    def test_calc_intrusion(self, mock_time, mock_log):
        """
        Test calc_intrusion.
        """
        # delta_time = 1
        mock_time.return_value = 11
        self.cam.start_time = 10

        # Case 1: Threshold within the limit range
        self.cam.calc_intrusion()
        self.assertFalse(mock_log.called)

        # Case 2: Replicate attack
        for _ in range(50):
            self.cam.cam_list.append(scapy.RandMAC())

        self.cam.calc_intrusion()
        mock_log.assert_called_with("Possible CAM table attack detected",
                                    logtype="warning")
예제 #6
0
파일: dot11.py 프로젝트: skizap/hackerman
	def __init__(self, channel="covert", iface="wlan0", sender=str(scapy.RandMAC())):
		self.channel = channel
		self.ssid = ssid
		self.iface = iface
		self.sender = sender
		self.buf = b''