Class: Ownlan::Attack::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ownlan/attack/base.rb

Direct Known Subclasses

Client, FakeIpConflict, Gateway, Ntoa

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/ownlan/attack/base.rb', line 7

def initialize(config)
  @config  = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/ownlan/attack/base.rb', line 5

def config
  @config
end

#crafted_packetObject (readonly)

Returns the value of attribute crafted_packet.



5
6
7
# File 'lib/ownlan/attack/base.rb', line 5

def crafted_packet
  @crafted_packet
end

Instance Method Details

#ip_to_mac(ip = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ownlan/attack/base.rb', line 12

def ip_to_mac(ip = nil)
  if ip == ServiceObjects::NetworkInformation.self_ip(config.interface)
    mac = ServiceObjects::NetworkInformation.self_mac(config.interface)
  else
    mac = ::PacketFu::Utils::arp(ip, iface: config.interface)
    mac ||= raise ::Ownlan::VictimNotReachable, "#{ip}'s mac address cannot be guessed."
  end
rescue RuntimeError
  raise ::Ownlan::NotRoot, "Please rerun this tool with root privileges."
rescue ArgumentError
  raise ::Ownlan::WrongVictimIpFormat, "#{ip} is not a valid ip format."
rescue StandardError
  raise ::Ownlan::WrongInterace, "#{config.interface} is not ready? Retry again"
end