示例#1
0
def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="FF:FF:FF:FF:FF:FF")
    arp_request_broadcast = broadcast/arp_request
    answered, unanswered = scapy.srp(arp_request_broadcast, timeout=1)
def fetch_mac(ip):
    arpb = scapy.Ether(dst="ff:ff:ff:ff:ff:ff") / scapy.ARP(
        op=1, pdst=ip)  #op=1 is who-has
    received = scapy.srp(arpb, timeout=2, verbose=False)
    return received[0][0][1].hwsrc
示例#3
0
 def traffic_sender(linkid, vlanid):
     payload = s.Ether() / s.Dot1Q(vlan=int(vlanid)) / s.IP() / s.ICMP()
     s.sendp(payload, iface=linkid, count=number_of_packets)
示例#4
0
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)
    sniffer2 = Sniffer(args, check_icmp6_error_2)

    ########################################################################
    #
    # Two fragments with payload and offset set to add up to >64k.
    #
    # Make a first fragment arrive and a second to explode everything.
    #
    # A:  Reassembly failure.
    # R:  ICMPv6 param prob, param header.
    # R:  ICMPv6 timeout (1st frag, off=0)
    #
    data = "6" * 1280
    ip6f01 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=7) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    ip6f02 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0x1fff, m=1, id=7) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
        ip6f02.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
    sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

    sleep(1.00)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
    #
    # A fragment with payload and offset set to add up to >64k.
    #
    # Try again with the first packet to make things explode.
    #
    # A:  Reassembly failure.
    # R:  ICMPv6 param prob, param header.
    #

    # Start sniffing on recvif
    sniffer = Sniffer(args, check_icmp6_error)

    ip6f01 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0]) / \
     sp.IPv6ExtHdrFragment(offset=0x1fff, m=1, id=0x7001) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

    sleep(0.10)
    sniffer.setEnd()
    sniffer.join()
    if not sniffer.foundCorrectPacket:
        sys.exit(1)

    # Wait for expiry from first test run.
    sleep(75)
    sniffer2.setEnd()
    sniffer2.join()
    if not sniffer2.foundCorrectPacket:
        sys.exit(1)

    sys.exit(0)
示例#5
0
文件: client.py 项目: charlee593/bess
                2: "PTCH_REQ",
                3: "DATA_FNSD",
                4: "PTCH_DATA",
                5: "DATA",
                6: "FEEDBACK"
            },
        ),
        scapy.XByteField("appID", 2),
        scapy.XByteField("dataID", 0),
        scapy.XByteField("sn", 0),
        scapy.XByteField("dataSize", 11),
    ]


data_eth = scapy.Ether(src="aa:bb:cc:dd:ee:01",
                       dst="11:22:33:44:55:01",
                       type=0x0800)
print("Size of data_eth:", len(bytes(data_eth)))
data_ip = scapy.IP(src="10.1.0.1", dst="10.0.0.1")
print("Size of data_ip:", len(bytes(data_ip)))
data_udp = scapy.UDP(sport=10001, dport=10002)
print("Size of data_udp:", len(bytes(data_udp)))
unlabeled_data_mdc = MDCData(addr=0x1A1B, mode=0x02, label=0x01)
print("Size of unlabeled_data_mdc:", len(bytes(unlabeled_data_mdc)))

unlabeled_data_pkt = data_eth / data_ip / data_udp / unlabeled_data_mdc
print("Sendiing unlabeled_data_mdc_header: ", bytes(unlabeled_data_mdc))
print("Size of unlabeled_data_pkt:", len(bytes(unlabeled_data_pkt)))

print("Connecting...")
if os.path.exists("/tmp/mdc_dp_p.sock"):
示例#6
0
    #-- define spark usual and streaming contexts
    cont_0 = pyspark.SparkContext(appName="pkt_dissector")
    cont_0.setLogLevel("ERROR")
    s_cont_0 = pyspark_streaming.StreamingContext(cont_0, 5)

    #-- kafka integration (notice, that we receive packets as a bytes struct)
    brokers = "192.168.122.71:9092,192.168.122.72:9092,192.168.122.73:9092"
    kafka_dstream = pyspark_kafka.KafkaUtils.createDirectStream(
        s_cont_0, ["test1"], {"metadata.broker.list": brokers},
        valueDecoder=lambda x: bytes(x))

    #
    # Lazy evaluation rules
    #
    #-- Kafka message comes as a 2-tuple: (key, value). The code below will
    #-- select the actual message (i.e. packet) and dissects it.
    pkts = kafka_dstream.map(lambda x: scapy.Ether(x[1]))
    filtered_pkts = pkts.filter(common._pkt_filter). \
            map(lambda x: (x, x.summary()))

    #-- DEBUG
    #-- print to the console
    filtered_pkts.pprint()

    #
    # Driver code
    #
    #-- start the stream and wait until it is terminated
    s_cont_0.start()
    s_cont_0.awaitTermination()
示例#7
0
def getmac(ip):
    arp_request_header = scapy.ARP(pdst = ip)
    ether_header = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_packet = ether_header/arp_request_header
    answered_list = scapy.srp(arp_request_packet,timeout=1,verbose=False)[0]
    return  answered_list[0][1].hwsrc
示例#8
0
def scan(ip):
    arp_request = scapy.ARP(op=1, pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast / arp_request
    scan_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    return scan_list
示例#9
0
import sys
import scapy.all as scapy

if sys.version_info.major == 3:
    input("Press Enter to continue...")
else:
    raw_input("Press Enter to continue...")

scapy.sendp(scapy.Ether(type=0x9999) /
            "\x70\x6c\x61\x69\x6e\x20\x74\x65\x78\x74\x20\x20\x20\x20\x20\x20",
            count=1000)
示例#10
0
文件: arp.py 项目: awlways/loom
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import scapy.all as scapy

## CRASH TESTS ##
m0 = ArpResponder()
CRASH_TEST_INPUTS.append([m0, 1, 1])

## OUTPUT TESTS ##
m1 = ArpResponder()
eth_header = scapy.Ether(src='02:1e:67:9f:4d:ae', dst='ff:ff:ff:ff:ff:ff')
arp_header = scapy.ARP(op=1, pdst='1.2.3.4')
arp_req = eth_header / arp_header

m1.add(ip='1.2.3.4', mac_addr='A0:22:33:44:55:66')

arp_reply = arp_req.copy()
arp_reply[scapy.Ether].src = 'A0:22:33:44:55:66'
arp_reply[scapy.Ether].dst = '02:1e:67:9f:4d:ae'
arp_reply[scapy.ARP].op = 2

arp_reply[scapy.ARP].hwdst = arp_req[scapy.ARP].hwsrc
arp_reply[scapy.ARP].hwsrc = 'A0:22:33:44:55:66'

arp_reply[scapy.ARP].pdst = arp_req[scapy.ARP].psrc
arp_reply[scapy.ARP].psrc = '1.2.3.4'
示例#11
0
import scapy.all as scapy

# program to check promiscous mode of network interface.
# scan for all network devices using custom ARP packet. If we get response from network then
# it confirms that the network interface is indeed in promiscous mode.

net_iface = "enp0s3"  # set your interface name
my_mac = "60:36:DD:98:B6:53"  # set custom source MAC address to be used in ARP packet.
ip_range = "192.168.0.0/24"  # set IP address range to scan. Use your network IP range.

# Send an ARP request
pkt = scapy.Ether(src=my_mac, dst="FF:FF:FF:FF:FF:FF") / scapy.ARP(
    pdst=ip_range, hwsrc=my_mac)
ans, unans = scapy.srp(pkt, timeout=2, iface=net_iface)
if ans:
    ans.summary(lambda (s, r): r.sprintf("%Ether.dst% %ARP.psrc%"))
示例#12
0
def scan(ip):
    arp_packet = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')
    arp_packet_broadcast = broadcast / arp_packet
    ans, unans = scapy.srp(arp_packet_broadcast, timeout=1)
    print(ans.summary())
示例#13
0
def get_mac(ip):
    pack = scapy.ARP(pdst=ip)
    frame = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')
    arp_req = frame / pack
    answerd = scapy.srp(arp_req, timeout=1, verbose=False)[0]
    return answerd[0][1].hwsrc
示例#14
0
def scan_arp_answer_only(ip):
    return scapy.srp(scapy.Ether(dst='ff:ff:ff:ff:ff:ff') / scapy.ARP(pdst=ip),
                     timeout=1,
                     verbose=False)[0]
示例#15
0
    def generate_from_server_to_t1(self):
        """
        @summary: Generate (not send) the packets to be sent from server to T1
        """
        logger.info("Generating server to T1 packets")
        if self.tor_vlan_intf:
            vlan_src_intfs = [self.tor_vlan_intf]
            # If destination VLAN intf is specified,
            # use only the connected server
        else:
            # Otherwise send packets to all servers
            vlan_src_intfs = self.vlan_interfaces

        ptf_intf_to_mac_map = {}

        for ptf_intf in self.ptf_intf_to_server_ip_map.keys():
            ptf_intf_to_mac_map[ptf_intf] = self.ptfadapter.dataplane.get_mac(
                0, ptf_intf)

        logger.info("-" * 20 + "Server to T1 packet" + "-" * 20)
        if self.tor_vlan_intf is None:
            src_mac = 'random'
            src_ip = 'random'
        else:
            ptf_port = self.tor_to_ptf_intf_map[self.tor_vlan_intf]
            src_mac = ptf_intf_to_mac_map[ptf_port]
            src_ip = self.ptf_intf_to_server_ip_map[ptf_port]
        logger.info("Ethernet address: dst: {} src: {}".format(
            self.vlan_mac, src_mac))
        logger.info("IP address: dst: {} src: {}".format('random', src_ip))
        logger.info("TCP port: dst: {} src: 1234".format(TCP_DST_PORT))
        logger.info("Active ToR MAC: {}, Standby ToR MAC: {}".format(
            self.active_mac, self.standby_mac))
        logger.info("VLAN MAC: {}".format(self.vlan_mac))
        logger.info("-" * 50)

        self.packets_list = []

        # Create packet #1 for each server and append to the list,
        # then packet #2 for each server, etc.
        # This way, when sending packets we continuously send for all servers
        # instead of sending all packets for server #1, then all packets for
        # server #2, etc.
        tcp_tx_packet_orig = testutils.simple_tcp_packet(
            eth_dst=self.vlan_mac, tcp_dport=TCP_DST_PORT)
        tcp_tx_packet_orig = scapyall.Ether(str(tcp_tx_packet_orig))
        payload_suffix = "X" * 60
        for i in range(self.packets_per_server):
            for vlan_intf in vlan_src_intfs:
                ptf_src_intf = self.tor_to_ptf_intf_map[vlan_intf]
                server_ip = self.ptf_intf_to_server_ip_map[ptf_src_intf]
                eth_src = ptf_intf_to_mac_map[ptf_src_intf]
                payload = str(i) + payload_suffix
                packet = tcp_tx_packet_orig.copy()
                packet[scapyall.Ether].src = eth_src
                packet[scapyall.IP].src = server_ip
                packet[scapyall.IP].dst = self.random_host_ip()
                packet.load = payload
                packet[scapyall.TCP].chksum = None
                packet[scapyall.IP].chksum = None
                self.packets_list.append((ptf_src_intf, str(packet)))
        self.sent_pkt_dst_mac = self.vlan_mac
        self.received_pkt_src_mac = [self.active_mac, self.standby_mac]
示例#16
0
def get_mac(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_req_brd = broadcast/arp_request
    ans = scapy.srp(arp_req_brd, timeout=1, verbose=False)[0]
    return ans[0][1].hwsrc
示例#17
0
def get_mac_address(ip_address):
    broadcast_layer = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')
    arp_layer = scapy.ARP(pdst=ip_address)
    get_mac_packet = broadcast_layer/arp_layer
    answer = scapy.srp(get_mac_packet, timeout=2, verbose=False)[0]
    return answer[0][1].hwsrc
示例#18
0
 def createBroadCastPacket(self):
     """paket yayını yapmak için broadcast paketleri oluşturur"""
     return scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
示例#19
0
def createPacket(ip):
    arp_request = scapy.ARP(pdst=ip)  # create a ARP request object by scapy
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")  # We have set the destination
    arp_request_broadcast = broadcast / arp_request
    return (arp_request_broadcast)
示例#20
0
def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    mac_request = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_mac_request = mac_request / arp_request
    answered = scapy.srp(arp_mac_request, timeout=1, verbose=False)[0]
    return answered
示例#21
0
def main():
    parser = argparse.ArgumentParser(
        "frag6.py", description="IPv6 fragementation test tool")
    parser.add_argument(
        '--sendif',
        nargs=1,
        required=True,
        help='The interface through which the packet will be sent')
    parser.add_argument('--recvif',
                        nargs=1,
                        required=True,
                        help='The interface on which to check for the packet')
    parser.add_argument('--src',
                        nargs=1,
                        required=True,
                        help='The source IP address')
    parser.add_argument('--to',
                        nargs=1,
                        required=True,
                        help='The destination IP address')
    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='Enable test debugging')

    args = parser.parse_args()

    ########################################################################
    #
    # Two fragments with different ECN (Traffic Clas) bits to trigger
    # error cases.
    #
    # A:  Reassembly failure.
    # R:  ip6f02 dropped / Timeout (not waiting for).
    #
    data = "6" * 8
    # IPTOS_ECN_NOTECT
    ip6f01 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0], tc=0x00) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=13) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    # IPTOS_ECN_CE
    ip6f02 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0], tc=0x03) / \
     sp.IPv6ExtHdrFragment(offset=16, m=0, id=13) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
        ip6f02.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
    sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
    #
    # Two fragments with different ECN (Traffic Clas) bits to trigger
    # error cases.
    #
    # A:  Reassembly failure.
    # R:  ip6f02 dropped / Timeout (not waiting for).
    #
    # IPTOS_ECN_ECT1
    ip6f01 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0], tc=0x01) / \
     sp.IPv6ExtHdrFragment(offset=0, m=1, id=0x1301) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    # IPTOS_ECN_NOTECT
    ip6f02 = \
     sp.Ether() / \
     sp.IPv6(src=args.src[0], dst=args.to[0], tc=0x00) / \
     sp.IPv6ExtHdrFragment(offset=16, m=0, id=0x1301) / \
     sp.UDP(dport=3456, sport=6543) / \
     data
    if args.debug:
        ip6f01.display()
        ip6f02.display()
    sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
    sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

    # Wait for expiry.
    sleep(75)
    sys.exit(0)
示例#22
0
 def mac_bul(self, ip):
     arp_istek = scapy.ARP(pdst=ip)
     broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
     arp_istek_broadcast = broadcast / arp_istek
     cevap = scapy.srp(arp_istek_broadcast, timeout=1, verbose=False)[0]
     return cevap[0][1].hwsrc
示例#23
0
 def get_mac(ip): #get mac address from the network
   request = scapy.ARP(pdst = ip)
   brodcast = scapy.Ether(dst = "ff:ff:ff:ff:ff:ff")
   arp_brodcast = brodcast/request
   useful = scapy.srp(arp_brodcast, timeout = 1,verbose = False)[0]
   return useful[0][1].hwsrc
示例#24
0
def get_mac(ip):
    arp_packet = scapy.ARP(pdst=ip)
    broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_broadcast_packet = broadcast_packet/arp_packet
    answered_list = scapy.srp(arp_broadcast_packet, timeout=1, verbose=False)[0]
    return answered_list[0][1].hwsrc
示例#25
0
def main():
	parser = argparse.ArgumentParser("frag6.py",
		description="IPv6 fragementation test tool")
	parser.add_argument('--sendif', nargs=1,
		required=True,
		help='The interface through which the packet will be sent')
	parser.add_argument('--recvif', nargs=1,
		required=True,
		help='The interface on which to check for the packet')
	parser.add_argument('--src', nargs=1,
		required=True,
		help='The source IP address')
	parser.add_argument('--to', nargs=1,
		required=True,
		help='The destination IP address')
	parser.add_argument('--debug',
		required=False, action='store_true',
		help='Enable test debugging')

	args = parser.parse_args()


	# Start sniffing on recvif
	sniffer = Sniffer(args, check_icmp6_error)


	########################################################################
	#
	# Send a proper first fragment (off=0) and a second fragment which
	# just fits the 64k.  The re-send the first fragment with an extra
	# unfragmentable part making the 64k to exceed the limit.
	# This is to make sure we don't allow to update meta-data for a
	# 1st fragmented packet should a second arrive but given the
	# fragmentable part is an exact duplicate only that fragment
	# will be silently discarded.
	#
	# A:  Reassembly failure, timeout after
	# R:  ICMPv6 time exceeded / statistics for the duplicate
	#
	data = "6" * 8
	ip6f00 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0, m=1, id=20) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	data = "6" * 15
	ip6f01 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrFragment(offset=0x1ffc, m=0, id=20) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	data = "6" * 8
	ip6f02 = \
		sp.Ether() / \
		sp.IPv6(src=args.src[0], dst=args.to[0]) / \
		sp.IPv6ExtHdrDestOpt(options = \
		    sp.PadN(optdata="\x00\x00\x00\x00\x00\x00")) / \
		sp.IPv6ExtHdrFragment(offset=0, m=1, id=20) / \
		sp.UDP(dport=3456, sport=6543) / \
		data
	if args.debug :
		ip6f00.display()
		ip6f01.display()
		ip6f02.display()
	sp.sendp(ip6f00, iface=args.sendif[0], verbose=False)
	sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)
	sp.sendp(ip6f02, iface=args.sendif[0], verbose=False)

	sleep(75)
	sniffer.setEnd()
	sniffer.join()
	if not sniffer.foundCorrectPacket:
		sys.exit(1)

	sys.exit(0)
示例#26
0
def main():
	parser = argparse.ArgumentParser("frag6.py",
		description="IPv6 fragementation test tool")
	parser.add_argument('--sendif', nargs=1,
		required=True,
		help='The interface through which the packet will be sent')
	parser.add_argument('--recvif', nargs=1,
		required=True,
		help='The interface on which to check for the packet')
	parser.add_argument('--src', nargs=1,
		required=True,
		help='The source IP address')
	parser.add_argument('--to', nargs=1,
		required=True,
		help='The destination IP address')
	parser.add_argument('--debug',
		required=False, action='store_true',
		help='Enable test debugging')

	args = parser.parse_args()


	########################################################################
	#
	# Sysctl set to accept maximum 3 segments on a fragmented packet.
	# The 4th packet will flush the entire q6.
	#
	# A:  4 Discarded.
	# R:  Silence (statistics only) no ICMPv6 as we skip the off=0 segment.
	#
	data = "66666666"
	for i in range(4):
		foffset=16 + (i * (0x100 + (int)(16 / 8)))
		ip6f01 = sp.Ether() / \
			sp.IPv6(src=args.src[0], dst=args.to[0]) / \
			sp.IPv6ExtHdrFragment(offset=foffset, m=1, id=15) / \
			sp.UDP(dport=3456, sport=6543) / \
			data
		if args.debug :
			ip6f01.display()
		sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)


	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
	#
	# Sysctl set to accept maximum 3 segments on a fragmented packet.
	# The 4th packet will flush the entire q6.
	# This time we play proper offset/length games on the packets in order
	# to trigger the 2nd test case, with the last packet still having m=1.
	#
	# A:  4 Discarded.
	# R:  ICMPv6 timeout expired.
	#
	data = "66666666"
	for i in range(4):
		foffset=(i * (int)(16 / 8))
		ip6f01 = sp.Ether() / \
			sp.IPv6(src=args.src[0], dst=args.to[0]) / \
			sp.IPv6ExtHdrFragment(offset=foffset, m=1, id=0x1501) / \
			sp.UDP(dport=3456, sport=6543) / \
			data
		if args.debug :
			ip6f01.display()
		sp.sendp(ip6f01, iface=args.sendif[0], verbose=False)

	sys.exit(0)
示例#27
0
def get_mac(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    mac_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
    return mac_list[0][1].hwsrc
示例#28
0
    def generate_from_t1_to_server(self):
        """
        @summary: Generate (not send) the packets to be sent from T1 to server
        """
        logger.info("Generating T1 to server packets")
        eth_dst = self.dut_mac
        ip_ttl = 255

        if self.tor_pc_intf and self.tor_pc_intf in self.tor_pc_intfs:
            # If a source portchannel intf is specified,
            # get the corresponding PTF info
            ptf_t1_src_intf = self.tor_to_ptf_intf_map[self.tor_pc_intf]
            eth_src = self.ptfadapter.dataplane.get_mac(0, ptf_t1_src_intf)
            random_source = False
        else:
            # If no source portchannel specified, randomly choose one
            # during packet generation
            logger.info('Using random T1 source intf')
            ptf_t1_src_intf = None
            eth_src = None
            random_source = True

        if self.tor_vlan_intf:
            # If destination VLAN intf is specified,
            # use only the connected server
            ptf_port = self.tor_to_ptf_intf_map[self.tor_vlan_intf]
            server_ip_list = [self.ptf_intf_to_server_ip_map[ptf_port]]
        else:
            # Otherwise send packets to all servers
            server_ip_list = self.ptf_intf_to_server_ip_map.values()

        logger.info("-" * 20 + "T1 to server packet" + "-" * 20)
        logger.info("PTF source intf: {}".format(
            'random' if random_source else ptf_t1_src_intf))
        logger.info("Ethernet address: dst: {} src: {}".format(
            eth_dst, 'random' if random_source else eth_src))
        logger.info("IP address: dst: {} src: random".format(
            'all' if len(server_ip_list) > 1 else server_ip_list[0]))
        logger.info("TCP port: dst: {}".format(TCP_DST_PORT))
        logger.info("DUT mac: {}".format(self.dut_mac))
        logger.info("VLAN mac: {}".format(self.vlan_mac))
        logger.info("-" * 50)

        self.packets_list = []

        # Create packet #1 for each server and append to the list,
        # then packet #2 for each server, etc.
        # This way, when sending packets we continuously send for all servers
        # instead of sending all packets for server #1, then all packets for
        # server #2, etc.
        tcp_tx_packet_orig = testutils.simple_tcp_packet(
            eth_dst=eth_dst,
            eth_src=eth_src,
            ip_ttl=ip_ttl,
            tcp_dport=TCP_DST_PORT)
        tcp_tx_packet_orig = scapyall.Ether(str(tcp_tx_packet_orig))
        payload_suffix = "X" * 60
        for i in range(self.packets_per_server):
            for server_ip in server_ip_list:
                packet = tcp_tx_packet_orig.copy()
                if random_source:
                    tor_pc_src_intf = random.choice(self.tor_pc_intfs)
                    ptf_t1_src_intf = self.tor_to_ptf_intf_map[tor_pc_src_intf]
                    eth_src = self.ptfadapter.dataplane.get_mac(
                        0, ptf_t1_src_intf)
                packet[scapyall.Ether].src = eth_src
                packet[scapyall.IP].src = self.random_host_ip()
                packet[scapyall.IP].dst = server_ip
                payload = str(i) + payload_suffix
                packet.load = payload
                packet[scapyall.TCP].chksum = None
                packet[scapyall.IP].chksum = None
                self.packets_list.append((ptf_t1_src_intf, str(packet)))

        self.sent_pkt_dst_mac = self.dut_mac
        self.received_pkt_src_mac = [self.vlan_mac]
示例#29
0
import sys

import scapy.all as scapy
from time import sleep

if sys.version_info.major == 3:
    input("Press Enter to continue...")
else:
    raw_input("Press Enter to continue...")

for n in range(0, 1000):
    #print("\nTriggering Key {}".format(n))
    sleep(0.100)
    scapy.srp1(scapy.Ether(type=0x812) / ("\x00" * 33), timeout=0)
示例#30
0
def getMAC(ip):
    arp_req = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_req_broadcast = broadcast / arp_req
    answered_list = scapy.srp(arp_req_broadcast, timeout=1)[0]
    return answered_list[0][1].hwsrc