转自:http://blog.csdn.net/sandflee/article/details/5839832
官方网站:http://www.secdev.org/projects/scapy/
1.scapy2.X下载及安装
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 "", line 1, in
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.
2.Scapy基本使用
conf 命令查看当前配置,包括本机的网络配置,其值均为变量,可以修改,例如
conf.verb=1
ls命令
这个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='',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('') ('127.0.0.1')
options : PacketListField = [] ([])
>>>
阅读(1790) | 评论(0) | 转发(0) |