Scapy:交互式數(shù)據(jù)包處理工具
Scapy是一款強(qiáng)大的交互式數(shù)據(jù)包處理工具、數(shù)據(jù)包生成器、網(wǎng)絡(luò)掃描器、網(wǎng)絡(luò)發(fā)現(xiàn)工具和包嗅探工具。它提供多種類別的交互式生成數(shù)據(jù)包或數(shù)據(jù)包集合、對(duì)數(shù)據(jù)包進(jìn)行操作、發(fā)送數(shù)據(jù)包、包嗅探、應(yīng)答和反饋匹配等等功能。Python解釋器提供交互功能,所以要用到Python編程知識(shí)(例如variables、loops、和functions)。支持生成報(bào)告,且報(bào)告生成簡單。
下載鏈接:http://down.51cto.com/data/148110
>>去網(wǎng)絡(luò)安全工具百寶箱看看其它安全工具
scapy2.X安裝
linux下比較方便,直接執(zhí)行下面shell命令即可
- $ cd /tmp
- $ wget scapy.net
- $ unzip scapy-latest.zip
- $ cd scapy-2.*
- $ sudo python setup.py install
安裝完后,可以直接從shell里啟動(dòng):(需要root權(quán)限)
- root@D-Lab:~/python# scapy
- INFO: Can't import python gnuplot wrapper . Won't be able to plot.
- INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
- WARNING: No route found for IPv6 destination :: (no default route?)
- Welcome to Scapy (2.1.0)
- >>>也可以從Python中導(dǎo)入:
- inpython:
- >>> from scapy import TCP
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ImportError: cannot import name TCP
- >>> from scapy.all import TCP
- WARNING: No route found for IPv6 destination :: (no default route?)
- >>>
注意導(dǎo)入形式,TCP是里面的一個(gè)對(duì)象,使用from scapy import TCP 時(shí)python報(bào)錯(cuò),要使用from scapy.all import TCP.
Scapy基本使用
conf 命令查看當(dāng)前配置,包括本機(jī)的網(wǎng)絡(luò)配置,其值均為變量,可以修改,例如
conf.verb=1
ls命令
這個(gè)ls命令不是linux里的ls,是在scapy環(huán)境中的命令,其作用也是list show,ls()不帶參數(shù),可以顯示所有支持的數(shù)據(jù)包對(duì)象,種類太多了截取一點(diǎn)點(diǎn)貼出來,常見的包都有,包括Ether ,ip,tcp,udp,icmp,smb等等。
- >>> ls()
- ARP : ARP
- ASN1_Packet : None
- BOOTP : BOOTP
- CookedLinux : cooked linux
- DHCP : DHCP options
- DHCP6 : DHCPv6 Generic Message)
- DHCP6OptAuth : DHCP6 Option - Authentication
- DHCP6OptBCMCSDomains : DHCP6 Option - BCMCS Domain Name List
- DHCP6OptBCMCSServers : DHCP6 Option - BCMCS Addresses List
- DHCP6OptClientFQDN : DHCP6 Option - Client FQDN
ls(),同時(shí)還可以查看具體的包結(jié)構(gòu),我覺得通過這個(gè)軟件學(xué)習(xí)TCP/IP也是很方便的,例如ls(IP)
- >>> ls(IP)
- version : BitField = (4)
- ihl : BitField = (None)
- tos : XByteField = (0)
- len : ShortField = (None)
- id : ShortField = (1)
- flags : FlagsField = (0)
- frag : BitField = (0)
- ttl : ByteField = (64)
- proto : ByteEnumField = (0)
- chksum : XShortField = (None)
- src : Emph = (None)
- dst : Emph = ('127.0.0.1')
- options : PacketListField = ([])
- >>>
可以看到IP包頭的結(jié)構(gòu),很清晰,“=”后面的是默認(rèn)屬性,在對(duì)象被建立時(shí)或者建立后我們都可以修改。
- >>> myip=IP(dst='www.d-up.org',src='192.168.73.1')
- >>> ls(myip)
- version : BitField = 4 (4)
- ihl : BitField = None (None)
- tos : XByteField = 0 (0)
- len : ShortField = None (None)
- id : ShortField = 1 (1)
- flags : FlagsField = 0 (0)
- frag : BitField = 0 (0)
- ttl : ByteField = 64 (64)
- proto : ByteEnumField = 0 (0)
- chksum : XShortField = None (None)
- src : Emph = '192.168.73.1' (None)
- dst : Emph = Net('www.d-up.org') ('127.0.0.1')
- options : PacketListField = [] ([])
- >>>