scapy:网络数据包操作

scapy 是具有超强功能的数据包操作工具,不仅具有无数个协议的解码功能,还可以 传输修改后的数据包.scapy的最大特点就是可以执行多种功能。例如:创建网络扫描、数据包转储、数据包攻击时需要利用多个不同的工具,而只要一个scapy就够了。

Welcome to Scapy (2.3.2)
>>> lsc()
arpcachepoison      : Poison target's cache with (your MAC,victim's IP) couple

arping              : Send ARP who-has requests to determine which hosts are up查看主机的活动状态

bind_layers         : Bind 2 layers on some specific 
fields' values 将特定字段值绑定在2layer

bridge_and_sniff    : Forward traffic between two interfaces and sniff packets exchanged

corrupt_bits        : Flip a given percentage or number of bits from a string

corrupt_bytes       : Corrupt a given percentage or number of bytes from a string

defrag              : defrag(plist) -> ([not fragmented], [defragmented],

defragment          : defrag(plist) -> plist defragmented as much as possible 

dyndns_add          : Send a DNS add message to a nameserver for "name" to have a new "rdata"利用新"rdata"向名称服务器传输“name”相关信息

dyndns_del          : Send a DNS delete message to a nameserver for "name"向名称服务器传输有关“name”的DNS 删除信息

etherleak           : Exploit Etherleak flaw利用 Etherleak 漏洞

fletcher16_checkbytes:  Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string.

fletcher16_checksum :  Calculates Fletcher-16 checksum of the given buffer.

fragment            : Fragment a big IP datagram 分割大的IP 数据信息

fuzz                : Transform a layer into a fuzzy layer by replacing some default values by random objects

getmacbyip          : Return MAC address corresponding to a given IP address 显示特定IP的mac地址

hexdiff             : Show differences between 2 binary strings  显示二进制符号串的差异

hexdump             : --

hexedit             : --

is_promisc          : Try to guess if target is in Promisc mode. The target is provided by its ip. 查看猜测对象网卡是不是混杂模式


linehexdump         : --

ls                  : List  available layers, or infos on a 
given layeri显示当前支持的层次信息

promiscping         : Send ARP who-has requests to determine which hosts are in promiscuous mode为查看混杂模式主机而发送ARP请求

rdpcap              : Read a pcap file and return a packet list 读取pcap数据并显示数据包列表

send                : Send packets at layer 3

sendp               : Send packets at layer 2

sendpfast           : Send packets at layer 2 using tcpreplay for performance 为测试layer2的性能而利用tcpreplay传输数据包

sniff               : Sniff packets  嗅探数据包

split_layers        : Split 2 layers previously bound

sr                  : Send and receive packets at layer 3传输并结束layer3数据包

sr1                 : Send packets at layer 3 and return only the first answer传输layer3数据包后并显示第一个回应

srbt                : send and receive using a bluetooth sockete利用蓝牙套接字传输和接收数据包

srbt1               : send and receive 1 packet using a bluetooth socket利用蓝牙套接字传输和接收一个数据包

srflood             : Flood and receive packets at layer 3

srloop              : Send a packet at layer 3 in loop and 
print the answer each time

srp                 : Send and receive packets at layer 2

srp1                : Send and receive packets at layer 2 and return only the first answer

srpflood            : Flood and receive packets at layer 2

srploop             : Send a packet at layer 2 in loop and print the answer each time

traceroute          : Instant TCP traceroute

tshark              : Sniff packets and print them calling pkt.show(), a bit like text wireshark嗅探数据包后利用pkt.show()进行类似wireshark的输出

wireshark           : Run wireshark on a list of packets

wrpcap              : Write a list of packets to a pcap file 保存为pcap文件

查看支持的层次形态时输入:ls()

需要查看scapy的环境设置时,输入:conf
需要把iface的网络接口eth1 变为eth0时,只需要输入命令:
conf.iface=’eth0’

利用sniff 转储数据包

默认的数据包转储命令:

sniff()

输入sniff()不会发生任何的变化,但实际已处于数据包转储状态要停止数据包转储是请执行 “Ctrl + c”
停止后显示:

>>> sniff()
^C<Sniffed: TCP:2 UDP:0 ICMP:0 Other:0>

在这一阶段为了更详细的进行数据包转储,可以利用sniff以及filter选项选择TCP/UDP/ICMP,而且通过count 选项指定需要转储的数据包。

>>> sniff(filter="tcp",count=15)
15 UDP:0 ICMP:0 Other:0>

需要 转储特定IP数据包,可以使用命令:

>>> IP()

>>> a=IP(dst="192.168.2.2")
>>> a.dst
'192.168.2.2'
>>> a.ttl
64
>>> 

设置好a 后:

sniff("a")

另一种方法是为需要转储的IP地址添加筛选器

sinff(filter="host 192.168.102.147")

转储的内容并没有被包括到特定的变量,而是记录在”_”中,使用
print _ 输出内容
使用变量整理:

>>> b= _
>>> b.nsummary()

如果要查看转储的数据包8

b[8]

想要树状结构表示导出的结果,选择show()选项

b[8].show()

需要用HEX表示转储数据包的16进制时,使用hexdump()

hexdump(b[8])

scapy可以查看IP路径的traceroute功能

traceroute("google.com")

你可能感兴趣的:(kali)