Class: PacketGen::Utils::ARPSpoofer
- Inherits:
-
Object
- Object
- PacketGen::Utils::ARPSpoofer
- Defined in:
- lib/packetgen/utils/arp_spoofer.rb
Overview
This class is provided for test purpose.
Utility class to make ARP spoofing.
spoofer = PacketGen::Utils::ARPSpoofer.new
# start an ARP spoof: send forged ARP packets to target to spoof spoofed_ip
spoofer.start target_ip, spoofed_ip
# start another ARP spoof. Say to target2 spoofed_ip has given MAC address
spoofer.start target2_ip, spoofed_ip, mac: '00:00:00:00:00:01'
# stop spoofing on target2
spoofer.stop target2_ip
# stop all spoofings
spoofer.stop_all
Instance Method Summary collapse
-
#active?(target_ip) ⇒ Boolean
Say if spoofing on given target is active or not.
-
#active_targets ⇒ Array<String>
Get active targets (registered with #start, or all after using #start_all).
-
#add(target_ip, spoofed_ip, options = {}) ⇒ void
Add a target to spoofer, without starting attack.
-
#initialize(timeout: nil, interval: 1.0, iface: nil) ⇒ ARPSpoofer
constructor
A new instance of ARPSpoofer.
- #registered_targets ⇒ Array<String>
-
#remove(target_ip) ⇒ void
Remove target from spoofer.
-
#start(target_ip, spoofed_ip, options = {}) ⇒ void
Start spoofing on given target.
-
#start_all ⇒ void
Start spoofing on all targets added with #add.
-
#stop(target_ip) ⇒ void
Stop spoofing on given target.
-
#stop_all ⇒ void
Stop spoofing on all targets.
-
#wait ⇒ Object
Wait for spoofing to finish.
Constructor Details
#initialize(timeout: nil, interval: 1.0, iface: nil) ⇒ ARPSpoofer
Returns a new instance of ARPSpoofer.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 30 def initialize(timeout: nil, interval: 1.0, iface: nil) @timeout = timeout @timeout = @timeout.to_f if @timeout @interval = interval @iface = iface || PacketGen.default_iface @targets = {} @arp_packets = {} @spoof_thread = nil @queue = Queue.new end |
Instance Method Details
#active?(target_ip) ⇒ Boolean
Say if spoofing on given target is active or not
117 118 119 120 121 122 123 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 117 def active?(target_ip) # rubocop:disable Style/ReturnNilInPredicateMethodDefinition return unless @targets.key?(target_ip) # rubocop:enable Style/ReturnNilInPredicateMethodDefinition @targets[target_ip][:active] end |
#active_targets ⇒ Array<String>
Get active targets (registered with #start, or all after using #start_all)
72 73 74 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 72 def active_targets @arp_packets.keys end |
#add(target_ip, spoofed_ip, options = {}) ⇒ void
This method returns an undefined value.
Add a target to spoofer, without starting attack. Spoofing should be enabled with #start_all.
51 52 53 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 51 def add(target_ip, spoofed_ip, ={}) @targets[target_ip] = .merge(spoofed_ip: spoofed_ip, active: false) end |
#registered_targets ⇒ Array<String>
65 66 67 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 65 def registered_targets @targets.keys end |
#remove(target_ip) ⇒ void
This method returns an undefined value.
Remove target from spoofer.
58 59 60 61 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 58 def remove(target_ip) @targets.delete target_ip @arp_packets.delete target_ip end |
#start(target_ip, spoofed_ip, options = {}) ⇒ void
This method returns an undefined value.
Start spoofing on given target
85 86 87 88 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 85 def start(target_ip, spoofed_ip, ={}) add target_ip, spoofed_ip, activate target_ip end |
#start_all ⇒ void
This method returns an undefined value.
Start spoofing on all targets added with #add.
100 101 102 103 104 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 100 def start_all @targets.each_key do |target_ip| activate target_ip end end |
#stop(target_ip) ⇒ void
This method returns an undefined value.
Stop spoofing on given target
93 94 95 96 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 93 def stop(target_ip) deactivate target_ip remove target_ip end |
#stop_all ⇒ void
This method returns an undefined value.
Stop spoofing on all targets.
108 109 110 111 112 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 108 def stop_all @targets.each_key do |target_ip| deactivate target_ip end end |
#wait ⇒ Object
Wait for spoofing to finish. Wait forever if no timeout
options was set on #initialize.
127 128 129 |
# File 'lib/packetgen/utils/arp_spoofer.rb', line 127 def wait @spoof_thread.join end |