python scapy學習筆記

1. ubuntu下安裝gnuplot 

轉自:http://blog.163.com/gz_ricky/blog/static/182049118201362501316961/


2.安裝PyX
sudo pip install pyx==0.12.1

3.安裝scapy
pip install scapy

二.SCAPY
參考文檔 http://www.secdev.org/projects/scapy/doc/usage.html
主要函數:
send,sendp, sr,sr1 ,  sniff, rdpcap,   make_table,
sr(IP(dst="192.168.1.1")/TCP(sport=RandShort(),dport=[440,441,442,443],flags="S"))
ans,unans = sr(IP(dst=["192.168.1.1","yahoo.com","slashdot.org"])/TCP(dport=[22,80,443],flags="S"))
 ans.summay, ans.filter,
 a=rdpcap("/spare/captures/isakmp.cap")

   sniff(iface="wifi0", filter='icmp and host 1.1.1.1',prn=lambda x: x.summary()) #x.show
   
   pkts = sniff(prn=lambda x:x.sprintf("{IP:%IP.src% -> %IP.dst%\n}{Raw:%Raw.load%\n}"))
   
   
   p = sniff(iface="wifi0", filter='tcp and host 1.1.1.1',count=1)
   p.show()
   p[0]
   p[0].src , p[0].dst,


sniff 如何抓取vlan:

>>> conf.use_pcap = True                      #步驟1
>>> import scapy.arch.pcapdnet    #步驟2
>>> conf.L2listen
<L2pcapListenSocket: read packets at layer 2 using libpcap>   #確認此處爲libpcap
>>> p = sniff(iface='eth0',count=2,filter='udp',timeout=10)
WARNING: __del__: don't know how to close the file descriptor. Bugs ahead ! Please report this bug.         #報錯原因未知
>>>
>>> p[0]         #結果如下,抓到vlan 100
<Ether  dst=00:d0:f8:00:00:01 src=00:d0:f8:00:00:02 type=0x8100 |<Dot1Q  prio=3L id=0L vlan=100L type=0x800 |<IP  version=4L ihl=5L tos=0x42 len=136 id=0 flags= frag=0L ttl=64 proto=udp chksum=0xf712 src=192.168.1.102 dst=192.1.1.1 options=[] |<UDP  sport=12 dport=457 len=116 chksum=0xff87 |<Raw  load='\x00p8\xbcP\x00\x00\x003c\x00\x00\x00\x00\x00\x00\x00\x00\xbe\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |>>>>>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章