Class: BetterCap::Spoofers::Icmp
- Defined in:
- lib/bettercap/spoofers/icmp.rb
Overview
This class is responsible of performing ICMP redirect attack on the network.
Instance Method Summary collapse
-
#initialize ⇒ Icmp
constructor
Initialize the BetterCap::Spoofers::Icmp object.
-
#send_spoofed_packet(target) ⇒ Object
Send ICMP redirect to the
target
, redirecting the gateway ip and everything in the @entries list of addresses to us. -
#start ⇒ Object
Start the ICMP redirect spoofing.
-
#stop ⇒ Object
Stop the ICMP redirect spoofing, reset firewall state.
Methods inherited from Base
available, get_by_name, inherited
Constructor Details
#initialize ⇒ Icmp
Initialize the BetterCap::Spoofers::Icmp object.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bettercap/spoofers/icmp.rb', line 79 def initialize @ctx = Context.get @forwarding = @ctx.firewall.forwarding_enabled? @spoof_thread = nil @watch_thread = nil @running = false @entries = [ '8.8.8.8', '8.8.4.4', # Google DNS '208.67.222.222', '208.67.220.220' ] # OpenDNS update_gateway! end |
Instance Method Details
#send_spoofed_packet(target) ⇒ Object
Send ICMP redirect to the target
, redirecting the gateway ip and everything in the @entries list of addresses to us.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/bettercap/spoofers/icmp.rb', line 93 def send_spoofed_packet( target ) ( [@ctx.gateway.ip] + @entries ).each do |address| begin Logger.debug "Sending ICMP Redirect to #{target.to_s_compact} redirecting #{address} to us ..." pkt = ICMPRedirectPacket.new pkt.update!( @ctx.gateway, target, @ctx.iface.ip, address ) @ctx.packets.push(pkt) rescue Exception => e Logger.debug "#{self.class.name} : #{e.}" end end end |
#start ⇒ Object
Start the ICMP redirect spoofing.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/bettercap/spoofers/icmp.rb', line 108 def start Logger.debug "Starting ICMP redirect spoofer ..." stop() if @running @running = true if @ctx..spoof.kill Logger.warn "Disabling packet forwarding." @ctx.firewall.enable_forwarding(false) if @forwarding else @ctx.firewall.enable_forwarding(true) unless @forwarding end @ctx.firewall.enable_send_redirects(false) @spoof_thread = Thread.new { icmp_spoofer } @watch_thread = Thread.new { dns_watcher } end |
#stop ⇒ Object
Stop the ICMP redirect spoofing, reset firewall state.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/bettercap/spoofers/icmp.rb', line 128 def stop raise 'ICMP redirect spoofer is not running' unless @running Logger.debug 'Stopping ICMP redirect spoofer ...' Logger.debug "Resetting packet forwarding to #{@forwarding} ..." @ctx.firewall.enable_forwarding( @forwarding ) @running = false begin @spoof_thread.exit rescue; end begin @workers.map(&:exit) rescue; end end |