Class: BetterCap::Spoofers::ICMPRedirectPacket

Inherits:
PacketFu::Packet show all
Includes:
PacketFu::EthHeaderMixin, PacketFu::ICMPHeaderMixin, PacketFu::IPHeaderMixin, PacketFu::UDPHeaderMixin
Defined in:
lib/bettercap/spoofers/icmp.rb

Overview

Class to create ICMP redirection packets.

Constant Summary collapse

ICMP_REDIRECT =
5
ICMP_REDIRECT_HOST =
1
IP_PROTO_ICMP =
1
IP_PROTO_UDP =
17

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PacketFu::Packet

#eth2s

Constructor Details

#initialize(args = {}) ⇒ ICMPRedirectPacket

Create a ICMPRedirectPacket instance.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bettercap/spoofers/icmp.rb', line 32

def initialize(args={})
  @eth_header = PacketFu::EthHeader.new(args).read(args[:eth])

  @ip_header          = PacketFu::IPHeader.new(args).read(args[:ip])
  @ip_header.ip_proto = IP_PROTO_ICMP

  @icmp_header           = PacketFu::ICMPHeader.new(args).read(args[:icmp])
  @icmp_header.icmp_type = ICMP_REDIRECT
  @icmp_header.icmp_code = ICMP_REDIRECT_HOST

  @ip_encl_header          = PacketFu::IPHeader.new(args).read(args[:ip])
  @ip_encl_header.ip_proto = IP_PROTO_UDP

  @udp_dummy         = PacketFu::UDPPacket.new
  @udp_dummy.udp_src = 53
  @udp_dummy.udp_dst = 53

  @ip_header.body = @icmp_header
  @eth_header.body = @ip_header

  @headers = [@eth_header, @ip_header, @icmp_header]
  super
end

Instance Attribute Details

#eth_headerObject

Returns the value of attribute eth_header.



29
30
31
# File 'lib/bettercap/spoofers/icmp.rb', line 29

def eth_header
  @eth_header
end

#icmp_headerObject

Returns the value of attribute icmp_header.



29
30
31
# File 'lib/bettercap/spoofers/icmp.rb', line 29

def icmp_header
  @icmp_header
end

#ip_encl_headerObject

Returns the value of attribute ip_encl_header.



29
30
31
# File 'lib/bettercap/spoofers/icmp.rb', line 29

def ip_encl_header
  @ip_encl_header
end

#ip_headerObject

Returns the value of attribute ip_header.



29
30
31
# File 'lib/bettercap/spoofers/icmp.rb', line 29

def ip_header
  @ip_header
end

Instance Method Details

#update!(gateway, target, local, address2redirect) ⇒ Object

Update this packet with the correct gateway, target, local address and address2redirect.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bettercap/spoofers/icmp.rb', line 58

def update!( gateway, target, local, address2redirect )
  @eth_header.eth_src = PacketFu::EthHeader.mac2str(gateway.mac)
  @ip_header.ip_saddr = gateway.ip

  @eth_header.eth_dst = PacketFu::EthHeader.mac2str(target.mac)
  @ip_header.ip_daddr = target.ip

  @udp_dummy.ip_saddr = target.ip
  @udp_dummy.ip_daddr = address2redirect
  @udp_dummy.recalc

  @icmp_header.body = local.split('.').collect(&:to_i).pack('C*') +
                      @udp_dummy.ip_header.to_s

  recalc
end