Skip to content

Commit e04ccc6

Browse files
committed
arp_mitm: fix range iteration
1 parent da2658b commit e04ccc6

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

scapy/layers/l2.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ class Dot1AD(Dot1Q):
733733
def arpcachepoison(
734734
target, # type: Union[str, List[str]]
735735
addresses, # type: Union[str, Tuple[str, str], List[Tuple[str, str]]]
736+
broadcast=False, # type: bool
736737
interval=15, # type: int
737738
):
738739
# type: (...) -> None
@@ -745,6 +746,7 @@ def arpcachepoison(
745746
with the local interface's MAC. If it's a tuple,
746747
it's ("IP", "MAC"). It it's a list, it's [("IP", "MAC")].
747748
"IP" can be a subnet of course.
749+
:param broadcast: Use broadcast ethernet
748750
749751
Examples for target "192.168.0.2"::
750752
@@ -769,8 +771,9 @@ def arpcachepoison(
769771
else:
770772
couple_list = addresses
771773
p = [
772-
Ether(src=y) / ARP(op="who-has", psrc=x, pdst=targets,
773-
hwsrc=y, hwdst="00:00:00:00:00:00")
774+
Ether(src=y, dst="ff:ff:ff:ff:ff:ff" if broadcast else None) /
775+
ARP(op="who-has", psrc=x, pdst=targets,
776+
hwsrc=y, hwdst="00:00:00:00:00:00")
774777
for x, y in couple_list
775778
]
776779
try:
@@ -852,16 +855,22 @@ def _tups(ip, mac):
852855
# We loop who-has requests
853856
srploop(
854857
list(itertools.chain(
855-
(Ether(dst=maca, src=target_mac) /
858+
(x
859+
for ipa, maca in tup1
860+
for ipb, _ in tup2
861+
for x in
862+
Ether(dst=maca, src=target_mac) /
856863
ARP(op="who-has", psrc=ipb, pdst=ipa,
857864
hwsrc=target_mac, hwdst="00:00:00:00:00:00")
858-
for ipa, maca in tup1
859-
for ipb, _ in tup2),
860-
(Ether(dst=macb, src=target_mac) /
865+
),
866+
(x
867+
for ipb, macb in tup2
868+
for ipa, _ in tup1
869+
for x in
870+
Ether(dst=macb, src=target_mac) /
861871
ARP(op="who-has", psrc=ipa, pdst=ipb,
862872
hwsrc=target_mac, hwdst="00:00:00:00:00:00")
863-
for ipb, macb in tup2
864-
for ipa, _ in tup1),
873+
),
865874
)),
866875
filter="arp and arp[7] = 2",
867876
inter=inter,
@@ -873,16 +882,22 @@ def _tups(ip, mac):
873882
print("Restoring...")
874883
sendp(
875884
list(itertools.chain(
876-
(Ether(dst=maca, src=macb) /
885+
(x
886+
for ipa, maca in tup1
887+
for ipb, macb in tup2
888+
for x in
889+
Ether(dst=maca, src=macb) /
877890
ARP(op="who-has", psrc=ipb, pdst=ipa,
878891
hwsrc=macb, hwdst="00:00:00:00:00:00")
892+
),
893+
(x
894+
for ipb, macb in tup2
879895
for ipa, maca in tup1
880-
for ipb, macb in tup2),
881-
(Ether(dst=macb, src=maca) /
896+
for x in
897+
Ether(dst=macb, src=maca) /
882898
ARP(op="who-has", psrc=ipa, pdst=ipb,
883899
hwsrc=maca, hwdst="00:00:00:00:00:00")
884-
for ipb, macb in tup2
885-
for ipa, maca in tup1),
900+
),
886901
)),
887902
iface=iface
888903
)

0 commit comments

Comments
 (0)