http://d-up.org/man/2010/01/scapy0x01/
Scapy系列学习笔记(未完) 来自 www.d-up.org/man
0×01.初识sacpy:http://d-up.org/man/2010/01/scapy0×01/
0×02.创造数据包:http://d-up.org/man/2010/02/scapy0×02/
0×03.发送数据包:http://d-up.org/man/2010/02/scapy0×03/
0×04.SYN扫描器:http://d-up.org/man/2010/03/scapy0×04/
………………(本人不断更新中,转载请保留此信息)
scapy是一个很强大的数据包调试工具,居然是基于PYTHON的,我很高兴。
把学习的过程记录下,方便大家查询,,现在中文资料还比较少.www.d-up.org
官方网站:http://www.secdev.org/projects/scapy/
linux下比较方便,直接执行下面shell命令即可
$ cd /tmp
$ wget scapy.net
$ unzip scapy-latest.zip
$ cd scapy-2.*
$ sudo python setup.py install
安装完后,可以直接从shell里启动:(需要root权限)
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中导入:
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?)
>>>
注意导入形式,TCP是里面的一个对象,使用from scapy import TCP 时python报错,要使用from scapy.all import TCP.
conf 命令查看当前配置,包括本机的网络配置,其值均为变量,可以修改,例如
conf.verb=1
这个ls命令不是linux里的ls,是在scapy环境中的命令,其作用也是list show,ls()不带参数,可以显示所有支持的数据包对象,种类太多了截取一点点贴出来,常见的包都有,包括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(),同时还可以查看具体的包结构,我觉得通过这个软件学习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包头的结构,很清晰,“=”后面的是默认属性,在对象被建立时或者建立后我们都可以修改。
>>> 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 = [] ([])
>>>