我想做這樣的事情:
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上運行一個可以嗅探端口e和f的scapy程序來構建這個東西,并且在每種情況下修改數(shù)據(jù)包中的目標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)
然而,當我運行這個東西(完整源碼here)時,各種瘋狂的事情開始發(fā)生……一些數(shù)據(jù)包通過,我甚至得到一些響應(用ping測試)但是有一些類型的反饋循環(huán)導致要發(fā)送一堆重復的數(shù)據(jù)包……
有什么想法在這里發(fā)生了什么?嘗試這樣做是否很瘋狂?
我有點懷疑反饋循環(huán)是由于B正在對數(shù)據(jù)包進行自己的一些處理這一事實…有什么方法可以阻止操作系統(tǒng)在我嗅探后處理數(shù)據(jù)包? 解決方法: 這樣做有點瘋狂,但花費你的時間并不是一種糟糕的方式.你會學到很多有趣的東西.然而,您可能想要考慮將數(shù)據(jù)包掛得更低 – 我不認為scapy能夠實際攔截數(shù)據(jù)包 – 所有l(wèi)ibpcap都設置為promisc并讓你看到一切,所以你和內核都得到了相同的東西.如果您轉身并重新發(fā)送,那可能是您的數(shù)據(jù)包風暴的原因.
但是,您可以設置一些創(chuàng)意防火墻規(guī)則,將每個接口彼此分開并以此方式處理數(shù)據(jù)包,或者使用類似divert sockets的內容來實際將數(shù)據(jù)包從內核中分離出來,以便您可以使用它們. 來源:https://www./content-1-435101.html
|