Scapy之ARP询问
引言
校園網(wǎng)中,有同學遭受永恒之藍攻擊,但是被殺毒軟件查下,并知道了攻擊者的ip也是校園網(wǎng)。所以我想看一下,這個ip是PC,還是路由器。
在ip視角,路由器和pc沒什么差別。
實現(xiàn)
首先是構造arp報文,進行廣播
send.py
from scapy.all import *myarp = ARP()myarp.psrc = '172.17.132.176' myarp.pdst = '172.17.174.73'myarp.op = 1while True:send(myarp)構造arp報文,填寫我的本機ip172.17.132.176 ,釋放永恒之藍的ip 172.17.174.73 ,op 為1代表查詢,為2代表回應,這里我們是查詢。
攻擊者終端收到arp請求后,會相應arp,里面攜帶有攻擊者的mac
receive.py
from scapy.all import *while True:PTKS = sniff(store = 1,timeout = 0.1)PTKS.show()可以從終端看到打印的arp回應,攜帶有mac。如下:
查詢mac為什么設備
將以上mac在 https://mac.51240.com/ 輸入查詢,可得到廠商,基本就知道終端為路由器或者PC
例如:
進階
import logging logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import *def scapy_arp_request(ip_address , ifname = 'eth0',queue = None):result_raw = srp(Ether(dst = 'FF:FF:FF:FF:FF:FF')#srp 二層幀/ARP(op = 1,hwdst = '00:00:00:00:00:00',pdst = ip_address),#ARP詢問操作,op置1timeout = 1,#等待1siface = ifname,#二層一定要填寫接口verbose = False)#關閉發(fā)送數(shù)據(jù)提示信息 #result_raw接收到的數(shù)據(jù)如:(<Results: TCP:0 UDP:0 ICMP:0 Other:1>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>) #[0]為相應的數(shù)據(jù),[1]為未相應的數(shù)據(jù)(等待1s,所以有可能會產(chǎn)生未響應的數(shù)據(jù))try:result_list = result_raw[0].res #把響應的數(shù)據(jù)包對,產(chǎn)生為清單 #result_list數(shù)據(jù)為展開的信息,如:[(<Ether dst=FF:FF:FF:FF:FF:FF type=0x806 |<ARP op=who-has hwdst=00:00:00:00:00:00 pdst=172.17.174.73 |>>, <Ether dst=e0:3f:49:a1:99:6c src=58:69:6c:5e:70:ec type=0x806 |<ARP hwtype=0x1 ptype=0x800 hwlen=6 plen=4 op=is-at hwsrc=58:69:6c:5e:70:ec psrc=172.17.174.73 hwdst=e0:3f:49:a1:99:6c pdst=172.17.171.178 |<Padding load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |>>>)]#可以看到,result_list中只有一組數(shù)據(jù),下標為0。在這一組里,[1]代表接收到的包,[0]代表發(fā)送的數(shù)據(jù)包 #[2]ARP頭部字段的['hwsrc']字段,作為返回值返回if queue == None:#return result_list[0][1][1].fields['hwsrc']return result_list[0][1].getlayer(ARP).fields['hwsrc']else:queue.put((ip_address,result_list[0][1].getlayer(ARP).fields['hwsrc']))except:return if __name__ == "__main__":import sysprint(scapy_arp_request(sys.argv[1],sys.argv[2]))執(zhí)行程序,后面跟著參數(shù) 需要查詢mac的ip ,網(wǎng)口名稱 ,即可打印目標mac
send()函數(shù)將會在第3層發(fā)送數(shù)據(jù)包。也就是說它會為你處理路由和第2層的數(shù)據(jù)。sendp()函數(shù)將會工作在第2層。選擇合適的接口和正確的鏈路層協(xié)議都取決于你。
sr()函數(shù)是用來發(fā)送數(shù)據(jù)包和接收應答。該函數(shù)返回一對數(shù)據(jù)包及其應答,還有無應答的數(shù)據(jù)包。srp()則是使用第2層報文(以太網(wǎng),802.3等)。
參考
推薦:https://www.jianshu.com/p/8eab70118fad
https://zhuanlan.zhihu.com/p/34843290
https://github.com/Larryxi/Scapy_zh-cn
轉(zhuǎn)載于:https://www.cnblogs.com/maskerk/p/10011923.html
總結(jié)
以上是生活随笔為你收集整理的Scapy之ARP询问的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于'java' 不是内部或外部命令,也
- 下一篇: 2018哪种方式分期买iphone11最