日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

python如何通过以太网发送指令_用scapy在python中编写一个以太网桥

發(fā)布時間:2024/10/8 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何通过以太网发送指令_用scapy在python中编写一个以太网桥 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我想做這樣的事情:

10.1.1.0/24 10.1.2.0/24

------------ ------------ ------------

| | | | | |

| | | | | |

| A d ------- e B f ------- g C |

| | | | | |

| | | | | |

------------ ------------ ------------

d e f g

10.1.1.1 10.1.1.2 10.1.2.1 10.1.2.2

這樣Acan就可以通過B向C發(fā)送數(shù)據(jù)包了.

我嘗試通過在B上運(yùn)行一個可以嗅探端口e和f的scapy程序來構(gòu)建這個東西,并且在每種情況下修改數(shù)據(jù)包中的目標(biāo)IP和MAC地址,然后通過另一個接口發(fā)送它.就像是:

my_macs = [get_if_hwaddr(i) for i in get_if_list()]

pktcnt = 0

dest_mac_address = discover_mac_for_ip(dest_ip) #

output_mac = get_if_hwaddr(output_interface)

def process_packet(pkt):

# ignore packets that were sent from one of our own interfaces

if pkt[Ether].src in my_macs:

return

pktcnt = 1

p = pkt.copy()

# if this packet has an IP layer, change the dst field

# to our final destination

if IP in p:

p[IP].dst = dest_ip

# if this packet has an ethernet layer, change the dst field

# to our final destination. We have to worry about this since

# we're using sendp (rather than send) to send the packet. We

# also don't fiddle with it if it's a broadcast address.

if Ether in p and p[Ether].dst != 'ff:ff:ff:ff:ff:ff':

p[Ether].dst = dest_mac_address

p[Ether].src = output_mac

# use sendp to avoid ARP'ing and stuff

sendp(p, iface=output_interface)

sniff(iface=input_interface, prn=process_packet)

然而,當(dāng)我運(yùn)行這個東西(完整源碼here)時,各種瘋狂的事情開始發(fā)生……一些數(shù)據(jù)包通過,我甚至得到一些響應(yīng)(用ping測試)但是有一些類型的反饋循環(huán)導(dǎo)致要發(fā)送一堆重復(fù)的數(shù)據(jù)包……

有什么想法在這里發(fā)生了什么?嘗試這樣做是否很瘋狂?

我有點(diǎn)懷疑反饋循環(huán)是由于B正在對數(shù)據(jù)包進(jìn)行自己的一些處理這一事實(shí)…有什么方法可以阻止操作系統(tǒng)在我嗅探后處理數(shù)據(jù)包?

解決方法:

這樣做有點(diǎn)瘋狂,但花費(fèi)你的時間并不是一種糟糕的方式.你會學(xué)到很多有趣的東西.然而,您可能想要考慮將數(shù)據(jù)包掛得更低 – 我不認(rèn)為scapy能夠?qū)嶋H攔截數(shù)據(jù)包 – 所有l(wèi)ibpcap都設(shè)置為promisc并讓你看到一切,所以你和內(nèi)核都得到了相同的東西.如果您轉(zhuǎn)身并重新發(fā)送,那可能是您的數(shù)據(jù)包風(fēng)暴的原因.

但是,您可以設(shè)置一些創(chuàng)意防火墻規(guī)則,將每個接口彼此分開并以此方式處理數(shù)據(jù)包,或者使用類似divert sockets的內(nèi)容來實(shí)際將數(shù)據(jù)包從內(nèi)核中分離出來,以便您可以使用它們.來源:https://www.icode9.com/content-1-435101.html

總結(jié)

以上是生活随笔為你收集整理的python如何通过以太网发送指令_用scapy在python中编写一个以太网桥的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。