• scapy examples


    The following lists scapy examples based on experiments performed on the below topology. The topology contains two PC’s , Ubuntu and Windows 7. Scapy is setup on Ubuntu system.

    Example 1 – How to send a ping packet from Scapy on Ubuntu to Windows 7.

    ip=IP() # Creates an IP header
    ip.src=’192.168.1.25′ # Source address in the IP header is configured with IP address of ubuntu.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    icmp=ICMP() # Creates an ICMP header
    icmp.type=8 # Type value inserted in ICMP header as 8 for ping crafting
    icmp.code=0 # Code value inserted in ICMP header as 0 for ping crafting.
    send(ip/icmp) # Sending ping packet.

    Join our Course to Build Network Automation tools and scripts with Python and Scapy on Udemy

    Example 2 – How to send a ping packet from Scapy on Ubuntu to Windows 7 with Random Source address.

    ip=IP() # Creates an IP header
    ip.src=RandIP() # Configures the source address in the IP header with a random IP address.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    icmp=ICMP() # Creates an ICMP header
    icmp.type=8 # Type value inserted in ICMP header as 8 for ping crafting
    icmp.code=0 # Code value inserted in ICMP header as 0 for ping crafting.
    send(ip/icmp) # Sending ping packet.

    Join our Course to Build Network Automation tools and scripts with Python and Scapy on Udemy

    ——————————————————————————————————————-

    ——————————————————————————————————————-

    Example 3 – How to create a TCP SYN to port 80 on Windows 7 from Scapy on Ubuntu with Random Source address.

    tcp=TCP() # Creates a TCP header
    tcp.dport=80 # Configures the destination port in the TCP header with port 80.
    tcp.flags=’S’ # Configure the flag in the TCP header with the SYN bit.
    ip=IP() # Creates an IP header
    ip.src=’192.168.1.25′ # Source address in the IP header is configured with IP address of ubuntu.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    send(ip/tcp) # Sending tcp packet.

    ——————————————————————————————————————-
    Join our Course to Build Network Automation tools and scripts with Python and Scapy on Udemy

    ——————————————————————————————————————-

    Example 4 – How to print the TTL value of a received ping reply packet using Scapy

    ip=IP() # Creates an IP header
    ip.src=’192.168.1.25′ # Source address in the IP header is configured with IP address of ubuntu.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    icmp=ICMP() # Creates an ICMP header
    icmp.type=8 # Type value inserted in ICMP header as 8 for ping crafting
    icmp.code=0 # Code value inserted in ICMP header as 0 for ping crafting.
    p=sr1(ip/icmp) # Sends and receives the packet in the variable p
    p.ttl # Displays the ttl value in the received IP header.

    Example 4 – How to create an ARP request packet with Scapy on Ubuntu to Windows 7

    ether=Ether() # Creates an ethernet header
    ether.src=’00:e0:1c:3c:22:b4′ # Configures the source mac address in the ethernet header with the mac-address of ubuntu system
    ether.dst=’FF:FF:FF:FF:FF:FF’ Configures the destination mac address in the ethernet header with broadcast for ARP request packet
    arp=ARP() # Creates an ARP header
    arp.op=1 # Configures the ARP type as 1
    arp.hwsrc=’00:e0:1c:3c:22:b4′ # Configures the sender mac address in the ethernet header with the mac-address of ubuntu system
    arp.psrc=’192.168.1.25′ # Configures the sender IP address in the ethernet header with the IP address of ubuntu system
    arp.pdst=’192.168.1.100′ # Configures the target IP address in the ethernet header with the IP address of ubuntu system
    arp.hwdst=’00:00:00:00:00:00′ # Configures the target mac address in the ethernet header as NULL
    p=srp1(ether/arp) # Sends the packet at layer 2 using the command srp1, appending the ether and arp headers.

  • 相关阅读:
    右键点击任务栏程序没有锁定菜单
    CMD命令:不是内部或者外部命令也不是可运行的程序或批处理文件
    通道闸机
    Activex、OLE、COM、OCX、DLL之间区别、联系[转]
    C#图像显示实现拖拽、锚点缩放功能【转】
    顶级人生规划[转]
    jqGrid选择列控件向右拖拽超出边界处理
    强力推荐!那些你不能错过的 GitHub 插件和工具
    GitHub 托管的10款免费开源 windows 工具
    实现阶层跨越的捷径
  • 原文地址:https://www.cnblogs.com/dream397/p/13710218.html
Copyright © 2020-2023  润新知