Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Commit

Permalink
Fixes #222 : Hide MAC
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed May 25, 2016
1 parent b7f78d7 commit 0d7637a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/bettercap/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def initialize
@firewall = Firewalls::Base.get
@memory = Memory.new
@iface = nil
@original_mac = nil
@gateway = nil
@targets = []
@spoofer = nil
Expand All @@ -85,6 +86,17 @@ def update!
'correct network configuration, this could also happen if bettercap '\
'is launched from a virtual environment.' unless Network::Validator.is_ip?(gw)

unless @options.core.use_mac.nil?
cfg = PacketFu::Utils.ifconfig @options.core.iface
raise BetterCap::Error, "Could not determine IPv4 address of '#{@options.core.iface}', make sure this interface "\
'is active and connected.' if cfg[:ip4_obj].nil?

@original_mac = Network::Target.normalized_mac(cfg[:eth_saddr])

Logger.info "Changing interface MAC address to #{@options.core.use_mac}"

Shell.ifconfig( "#{@options.core.iface} ether #{@options.core.use_mac}")
end

cfg = PacketFu::Utils.ifconfig @options.core.iface
raise BetterCap::Error, "Could not determine IPv4 address of '#{@options.core.iface}', make sure this interface "\
Expand Down Expand Up @@ -183,6 +195,8 @@ def finalize

@dnsd.stop unless @dnsd.nil?
@httpd.stop unless @httpd.nil?

Shell.ifconfig( "#{@options.core.iface} ether #{@original_mac}") unless @original_mac.nil?
end

private
Expand Down
12 changes: 12 additions & 0 deletions lib/bettercap/options/core_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class CoreOptions
attr_accessor :packet_throttle
# If true, bettercap will check for updates then exit.
attr_accessor :check_updates
# If not nil, the interface MAC address will be changed to this value.
attr_accessor :use_mac

def initialize( iface )
@iface = iface
Expand All @@ -53,6 +55,7 @@ def initialize( iface )
@no_target_nbns = false
@packet_throttle = 0.0
@check_updates = false
@use_mac = nil
end

def parse!( ctx, opts )
Expand All @@ -64,6 +67,15 @@ def parse!( ctx, opts )
@iface = v
end

opts.on( '--use-mac ADDRESS', 'Change the interface MAC address to this value before performing the attack.' ) do |v|
@use_mac = v
raise BetterCap::Error, "Invalid MAC address specified." unless Network::Validator.is_mac?(@use_mac)
end

opts.on( '--random-mac', 'Change the interface MAC address to a random one before performing the attack.' ) do |v|
@use_mac = [format('%0.2x', rand(256) & ~1), (1..5).map { format('%0.2x', rand(256)) }].join(':')
end

opts.on( '-G', '--gateway ADDRESS', 'Manually specify the gateway address, if not specified the current gateway will be retrieved and used. ' ) do |v|
@gateway = v
raise BetterCap::Error, "The specified gateway '#{v}' is not a valid IPv4 address." unless Network::Validator.is_ip?(v)
Expand Down

0 comments on commit 0d7637a

Please sign in to comment.