1. 程式人生 > 其它 >網路協議從入門到上癮--Scapy初探

網路協議從入門到上癮--Scapy初探

技術標籤:網路協議Scapy網路

什麼是Scapy?

沒有人能比Scapy的作者更好的介紹Scapy。

Scapy is a powerful interactive packet manipulation program. It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery

It also performs very well at a lot of other specific tasks that most other tools can't handle, like sending invalid frames, injecting your own 802.11 frames, combining technics (VLAN hopping+ARP cache poisoning, VOIP decoding on WEP encrypted channel, ...), etc.

Scapy是一個強大的互動式的資料包操作程式。它能夠偽造或解碼許多種類的協議包,並在網路中傳送,嗅探,過濾請求和應答等等。同時,它也能很輕鬆的實現傳統的網路任務,比如掃描,鏈路追蹤,刺探,單元測試,攻擊和網路發現等。

安裝Scapy

有很多種方法把Scapy安裝到你的系統平臺。最簡單的安裝方式如下:

pip install scapy
[[email protected] ~]# scapy
AutoCompletion, History are disabled.
                  
          aSPY//YASa   
      apyyyyCY//YCa    |
     sY//YSpcs scpCY//Pp   | Welcome to Scapy
ayp ayyyyyyySCP//Pp      syY//C  | Version 2.4.4
AYAsAYYYYYYYY///Ps       cY//S  |
    pCCCCY//p     cSSps y//Y  | https://github.com/secdev/scapy
    SPPPP///a     pP///AC//Y  |
      A//A      cyPC  | Have fun!
      p///Ac      sC///a  |
      PYCpc      A//A  | Craft packets like I craft my beer.
   scccccp///pSP///p     p//Y  |        -- Jean De Clerck
  sY/y caa      S//P  |
   cayCyayP//Ya       pY/Ya
   sY/PsYYCc     aC//Yp
    sc sccaCY//PCypaapyCP//YSs 
        spCPY//YPSps  
           ccaacs    
                  
>>>

Scapy指定網口

如果在你的電腦上有多個物理網口,或許你不得不檢查當前Scapy使用的是哪個預設網口。在Scapy終端,通過conf命令可以檢視預設網口:

>>> conf.iface
'ens192'

如果想修改Scapy使用的預設網口,可用使用如下命令:

>>> conf.iface = 'eth0'

Root許可權

一些處理髮送流量的Scapy函式需要用到root許可權,所以在啟動Scapy終端時,可以使用sudo scapy方式。如果是Python指令碼,則需要類似如下操作:

sudo python script.py

如果對雲端計算感興趣,可以關注我的微信公眾號: