bettercap 1.1.10 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/TODO.md +8 -7
  3. data/bin/bettercap +8 -2
  4. data/lib/bettercap.rb +5 -4
  5. data/lib/bettercap/context.rb +54 -8
  6. data/lib/bettercap/discovery/agents/arp.rb +17 -4
  7. data/lib/bettercap/discovery/agents/base.rb +16 -52
  8. data/lib/bettercap/discovery/agents/icmp.rb +25 -17
  9. data/lib/bettercap/discovery/agents/udp.rb +9 -20
  10. data/lib/bettercap/discovery/{discovery.rb → thread.rb} +10 -9
  11. data/lib/bettercap/error.rb +1 -2
  12. data/lib/bettercap/factories/{firewall_factory.rb → firewall.rb} +11 -7
  13. data/lib/bettercap/factories/{parser_factory.rb → parser.rb} +13 -3
  14. data/lib/bettercap/factories/{spoofer_factory.rb → spoofer.rb} +10 -3
  15. data/lib/bettercap/firewalls/base.rb +76 -0
  16. data/lib/bettercap/firewalls/linux.rb +26 -16
  17. data/lib/bettercap/firewalls/osx.rb +22 -13
  18. data/lib/bettercap/firewalls/redirection.rb +15 -1
  19. data/lib/bettercap/httpd/server.rb +5 -0
  20. data/lib/bettercap/logger.rb +29 -8
  21. data/lib/bettercap/network.rb +105 -105
  22. data/lib/bettercap/options.rb +99 -41
  23. data/lib/bettercap/packet_queue.rb +92 -0
  24. data/lib/bettercap/proxy/certstore.rb +49 -43
  25. data/lib/bettercap/proxy/module.rb +4 -2
  26. data/lib/bettercap/proxy/proxy.rb +7 -2
  27. data/lib/bettercap/proxy/request.rb +28 -16
  28. data/lib/bettercap/proxy/response.rb +23 -2
  29. data/lib/bettercap/proxy/stream_logger.rb +6 -0
  30. data/lib/bettercap/proxy/streamer.rb +13 -5
  31. data/lib/bettercap/proxy/thread_pool.rb +6 -14
  32. data/lib/bettercap/shell.rb +5 -3
  33. data/lib/bettercap/sniffer/parsers/base.rb +7 -1
  34. data/lib/bettercap/sniffer/parsers/custom.rb +6 -1
  35. data/lib/bettercap/sniffer/parsers/ftp.rb +8 -5
  36. data/lib/bettercap/sniffer/parsers/httpauth.rb +4 -1
  37. data/lib/bettercap/sniffer/parsers/https.rb +4 -1
  38. data/lib/bettercap/sniffer/parsers/irc.rb +8 -5
  39. data/lib/bettercap/sniffer/parsers/mail.rb +8 -5
  40. data/lib/bettercap/sniffer/parsers/ntlmss.rb +21 -18
  41. data/lib/bettercap/sniffer/parsers/post.rb +4 -1
  42. data/lib/bettercap/sniffer/parsers/url.rb +4 -1
  43. data/lib/bettercap/sniffer/sniffer.rb +7 -3
  44. data/lib/bettercap/spoofers/arp.rb +69 -94
  45. data/lib/bettercap/spoofers/base.rb +132 -0
  46. data/lib/bettercap/spoofers/icmp.rb +200 -0
  47. data/lib/bettercap/spoofers/none.rb +8 -2
  48. data/lib/bettercap/target.rb +117 -90
  49. data/lib/bettercap/update_checker.rb +6 -0
  50. data/lib/bettercap/version.rb +3 -1
  51. metadata +24 -8
  52. data/lib/bettercap/base/ifirewall.rb +0 -46
  53. data/lib/bettercap/base/ispoofer.rb +0 -32
@@ -10,14 +10,21 @@ This project is released under the GPL 3 license.
10
10
 
11
11
  =end
12
12
  module BetterCap
13
+ # Class responsible for console and file logging.
13
14
  module Logger
14
15
  class << self
16
+ @@ctx = nil
15
17
  @@queue = Queue.new
16
18
  @@debug = false
17
19
  @@silent = false
18
20
  @@logfile = nil
19
21
  @@thread = nil
20
22
 
23
+ # Initialize the logging system.
24
+ # If +debug+ is true, debug logging will be enabled.
25
+ # If +logfile+ is not nil, every message will be saved to that file.
26
+ # If +silent+ is true, all messages will be suppressed if they're not errors
27
+ # or warnings.
21
28
  def init( debug, logfile, silent )
22
29
  @@debug = debug
23
30
  @@logfile = logfile
@@ -26,31 +33,41 @@ module Logger
26
33
  @@ctx = Context.get
27
34
  end
28
35
 
36
+ # Log an error +message+.
29
37
  def error(message)
30
38
  @@queue.push formatted_message(message, 'E').red
31
39
  end
32
40
 
41
+ # Log an information +message+.
33
42
  def info(message)
34
43
  @@queue.push( formatted_message(message, 'I') ) unless @@silent
35
44
  end
36
45
 
46
+ # Log a warning +message+.
37
47
  def warn(message)
38
48
  @@queue.push formatted_message(message, 'W').yellow
39
49
  end
40
50
 
51
+ # Log a debug +message+.
41
52
  def debug(message)
42
53
  if @@debug and not @@silent
43
54
  @@queue.push formatted_message(message, 'D').light_black
44
55
  end
45
56
  end
46
57
 
58
+ # Log a +message+ as it is.
47
59
  def raw(message)
48
60
  @@queue.push( message )
49
61
  end
50
62
 
63
+ # Wait for the messages queue to be empty.
51
64
  def wait!
52
65
  while not @@queue.empty?
53
- sleep 0.3
66
+ if @@thread.nil?
67
+ emit @@queue.pop
68
+ else
69
+ sleep 0.3
70
+ end
54
71
  end
55
72
  end
56
73
 
@@ -59,17 +76,21 @@ module Logger
59
76
  def worker
60
77
  loop do
61
78
  message = @@queue.pop
62
- if @@ctx.running
63
- puts message
64
- unless @@logfile.nil?
65
- f = File.open( @@logfile, 'a+t' )
66
- f.puts( message.gsub( /\e\[(\d+)(;\d+)*m/, '') + "\n")
67
- f.close
68
- end
79
+ if @@ctx.nil? or @@ctx.running
80
+ emit message
69
81
  end
70
82
  end
71
83
  end
72
84
 
85
+ def emit(message)
86
+ puts message
87
+ unless @@logfile.nil?
88
+ f = File.open( @@logfile, 'a+t' )
89
+ f.puts( message.gsub( /\e\[(\d+)(;\d+)*m/, '') + "\n")
90
+ f.close
91
+ end
92
+ end
93
+
73
94
  def formatted_message(message, message_type)
74
95
  "[#{message_type}] #{message}"
75
96
  end
@@ -12,142 +12,142 @@ This project is released under the GPL 3 license.
12
12
  require 'thread'
13
13
 
14
14
  module BetterCap
15
+ # Handles various network related tasks.
15
16
  class Network
16
- class << self
17
- def is_ip?(ip)
18
- if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ ip.to_s
19
- return $~.captures.all? {|i| i.to_i < 256}
20
- end
21
- false
17
+ class << self
18
+ # Return true if +ip+ is a valid IP address, otherwise false.
19
+ def is_ip?(ip)
20
+ if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ ip.to_s
21
+ return $~.captures.all? {|i| i.to_i < 256}
22
22
  end
23
+ false
24
+ end
23
25
 
24
- def is_mac?(mac)
25
- ( /^[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}$/i =~ mac.to_s )
26
- end
26
+ # Return true if +mac+ is a valid MAC address, otherwise false.
27
+ def is_mac?(mac)
28
+ ( /^[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}\:[a-f0-9]{1,2}$/i =~ mac.to_s )
29
+ end
27
30
 
28
- def get_gateway
29
- nstat = Shell.execute('netstat -nr')
31
+ # Return the current network gateway or nil.
32
+ def get_gateway
33
+ nstat = Shell.execute('netstat -nr')
30
34
 
31
- Logger.debug "NETSTAT:\n#{nstat}"
35
+ Logger.debug "NETSTAT:\n#{nstat}"
32
36
 
33
- out = nstat.split(/\n/).select {|n| n =~ /UG/ }
34
- gw = nil
35
- out.each do |line|
36
- if line.include?( Context.get.options.iface )
37
- tmp = line.split[1]
38
- if is_ip?(tmp)
39
- gw = tmp
40
- break
41
- end
37
+ out = nstat.split(/\n/).select {|n| n =~ /UG/ }
38
+ gw = nil
39
+ out.each do |line|
40
+ if line.include?( Context.get.options.iface )
41
+ tmp = line.split[1]
42
+ if is_ip?(tmp)
43
+ gw = tmp
44
+ break
42
45
  end
43
46
  end
44
- gw
45
47
  end
48
+ gw
49
+ end
46
50
 
47
- def get_local_ips
48
- ips = []
51
+ # Return a list of IP addresses associated to this device network interfaces.
52
+ def get_local_ips
53
+ ips = []
49
54
 
50
- Shell.ifconfig.split("\n").each do |line|
51
- if line =~ /inet [adr:]*([\d\.]+)/
52
- ips << $1
53
- end
55
+ Shell.ifconfig.split("\n").each do |line|
56
+ if line =~ /inet [adr:]*([\d\.]+)/
57
+ ips << $1
54
58
  end
55
-
56
- ips
57
59
  end
58
60
 
59
- def get_alive_targets( ctx, timeout = 5 )
60
- if ctx.options.should_discover_hosts?
61
- start_agents( ctx, timeout )
62
- else
63
- Logger.debug 'Using current ARP cache.'
64
- end
65
-
66
- ArpAgent.parse ctx
67
- end
61
+ ips
62
+ end
68
63
 
69
- def get_ip_address( ctx, mac, timeout = 5 )
70
- ip = ArpAgent.find_mac( mac )
71
- if ip.nil?
72
- start_agents( ctx, timeout )
73
- ip = ArpAgent.find_mac( mac )
74
- end
75
- ip
64
+ # Return a list of BetterCap::Target objects found on the network, given a
65
+ # BetterCap::Context ( +ctx+ ) and a +timeout+ in seconds for the operation.
66
+ def get_alive_targets( ctx )
67
+ if ctx.options.should_discover_hosts?
68
+ start_agents( ctx )
69
+ else
70
+ Logger.debug 'Using current ARP cache.'
76
71
  end
77
72
 
78
- =begin
79
- Apparently on Mac OSX the gem pcaprub ( or libpcap itself ) has
80
- a bug, so we can't use 'PacketFu::Utils::arp' since the funtion
81
- it's using:
73
+ Discovery::Agents::Arp.parse ctx
74
+ end
82
75
 
83
- if cap.save > 0
84
- ...
76
+ # Return the IP address associated with the +mac+ hardware address using the
77
+ # given BetterCap::Context ( +ctx+ ).
78
+ def get_ip_address( ctx, mac )
79
+ ip = Discovery::Agents::Arp.find_mac( mac )
80
+ if ip.nil?
81
+ start_agents( ctx )
82
+ ip = Discovery::Agents::Arp.find_mac( mac )
83
+ end
84
+ ip
85
85
  end
86
86
 
87
- won't catch anything, instead we're using cap.stream.each.
88
- =end
89
- def get_hw_address( iface, ip_address, attempts = 2 )
90
- hw_address = ArpAgent.find_address( ip_address )
91
-
92
- if hw_address.nil?
93
- attempts.times do
94
- arp_pkt = PacketFu::ARPPacket.new
95
-
96
- arp_pkt.eth_saddr = arp_pkt.arp_saddr_mac = iface[:eth_saddr]
97
- arp_pkt.eth_daddr = 'ff:ff:ff:ff:ff:ff'
98
- arp_pkt.arp_daddr_mac = '00:00:00:00:00:00'
99
- arp_pkt.arp_saddr_ip = iface[:ip_saddr]
100
- arp_pkt.arp_daddr_ip = ip_address
101
-
102
- cap_thread = Thread.new do
103
- target_mac = nil
104
- timeout = 0
105
-
106
- cap = PacketFu::Capture.new(
107
- iface: iface[:iface],
108
- start: true,
109
- filter: "arp src #{ip_address} and ether dst #{arp_pkt.eth_saddr}"
110
- )
111
- arp_pkt.to_w(iface[:iface])
112
-
113
- begin
114
- Logger.debug 'Attempting to get MAC from packet capture ...'
115
- target_mac = Timeout::timeout(0.5) { get_mac_from_capture(cap, ip_address) }
116
- rescue Timeout::Error
117
- timeout += 0.1
118
- retry if target_mac.nil? && timeout <= 5
119
- end
120
-
121
- target_mac
87
+ # Return the hardware address associated with the specified +ip_address+ using
88
+ # the +iface+ network interface.
89
+ # The resolution will be performed for the specified number of +attempts+.
90
+ def get_hw_address( iface, ip_address, attempts = 2 )
91
+ hw_address = Discovery::Agents::Arp.find_address( ip_address )
92
+
93
+ if hw_address.nil?
94
+ attempts.times do
95
+ arp_pkt = PacketFu::ARPPacket.new
96
+
97
+ arp_pkt.eth_saddr = arp_pkt.arp_saddr_mac = iface[:eth_saddr]
98
+ arp_pkt.eth_daddr = 'ff:ff:ff:ff:ff:ff'
99
+ arp_pkt.arp_daddr_mac = '00:00:00:00:00:00'
100
+ arp_pkt.arp_saddr_ip = iface[:ip_saddr]
101
+ arp_pkt.arp_daddr_ip = ip_address
102
+
103
+ cap_thread = Thread.new do
104
+ Context.get.packets.push(arp_pkt)
105
+
106
+ target_mac = nil
107
+ timeout = 0
108
+
109
+ cap = PacketFu::Capture.new(
110
+ iface: iface[:iface],
111
+ start: true,
112
+ filter: "arp src #{ip_address} and ether dst #{arp_pkt.eth_saddr}"
113
+ )
114
+
115
+ begin
116
+ Logger.debug 'Attempting to get MAC from packet capture ...'
117
+ target_mac = Timeout::timeout(0.5) { get_mac_from_capture(cap, ip_address) }
118
+ rescue Timeout::Error
119
+ timeout += 0.1
120
+ retry if target_mac.nil? && timeout <= 5
122
121
  end
123
- hw_address = cap_thread.value
124
122
 
125
- break unless hw_address.nil?
123
+ target_mac
126
124
  end
127
- end
125
+ hw_address = cap_thread.value
128
126
 
129
- hw_address
127
+ break unless hw_address.nil?
128
+ end
130
129
  end
131
130
 
132
- private
131
+ hw_address
132
+ end
133
133
 
134
- def start_agents( ctx, timeout )
135
- icmp = IcmpAgent.new timeout
136
- udp = UdpAgent.new ctx.ifconfig, ctx.gateway, ctx.ifconfig[:ip_saddr]
137
- arp = ArpAgent.new ctx.ifconfig, ctx.gateway, ctx.ifconfig[:ip_saddr]
134
+ private
138
135
 
139
- icmp.wait
140
- arp.wait
141
- udp.wait
136
+ def start_agents( ctx )
137
+ [ 'Icmp', 'Udp', 'Arp' ].each do |name|
138
+ Kernel.const_get("BetterCap::Discovery::Agents::#{name}").new( ctx )
142
139
  end
140
+ ctx.packets.wait_empty( ctx.timeout )
141
+ end
143
142
 
144
- def get_mac_from_capture( cap, ip_address )
145
- cap.stream.each do |p|
146
- arp_response = PacketFu::Packet.parse(p)
147
- target_mac = arp_response.arp_saddr_mac if arp_response.arp_saddr_ip == ip_address
148
- break target_mac unless target_mac.nil?
149
- end
143
+ def get_mac_from_capture( cap, ip_address )
144
+ cap.stream.each do |p|
145
+ arp_response = PacketFu::Packet.parse(p)
146
+ target_mac = arp_response.arp_saddr_mac if arp_response.arp_saddr_ip == ip_address
147
+ break target_mac unless target_mac.nil?
150
148
  end
151
149
  end
150
+
151
+ end
152
152
  end
153
153
  end
@@ -9,41 +9,79 @@ Blog : http://www.evilsocket.net/
9
9
  This project is released under the GPL 3 license.
10
10
 
11
11
  =end
12
+
12
13
  module BetterCap
14
+ # Parse command line arguments, set options and initialize +Context+
15
+ # accordingly.
13
16
  class Options
14
- attr_accessor :gateway,
15
- :iface,
16
- :spoofer,
17
- :half_duplex,
18
- :target,
19
- :logfile,
20
- :silent,
21
- :debug,
22
- :arpcache,
23
- :ignore,
24
- :sniffer,
25
- :sniffer_pcap,
26
- :sniffer_filter,
27
- :sniffer_src,
28
- :parsers,
29
- :custom_parser,
30
- :local,
31
- :proxy,
32
- :proxy_https,
33
- :proxy_port,
34
- :proxy_https_port,
35
- :proxy_pem_file,
36
- :proxy_module,
37
- :custom_proxy,
38
- :custom_proxy_port,
39
- :custom_https_proxy,
40
- :custom_https_proxy_port,
41
- :httpd,
42
- :httpd_port,
43
- :httpd_path,
44
- :check_updates,
45
- :no_target_nbns
46
-
17
+ # Gateway IP address.
18
+ attr_accessor :gateway
19
+ # Network interface.
20
+ attr_accessor :iface
21
+ # Name of the spoofer to use.
22
+ attr_accessor :spoofer
23
+ # If true half duplex mode is enabled.
24
+ attr_accessor :half_duplex
25
+ # Comma separated list of targets.
26
+ attr_accessor :target
27
+ # Log file name.
28
+ attr_accessor :logfile
29
+ # If true will suppress every log message which is not an error or a warning.
30
+ attr_accessor :silent
31
+ # If true will enable debug messages.
32
+ attr_accessor :debug
33
+ # If true will disable active network discovery, the program will just use
34
+ # the current ARP cache.
35
+ attr_accessor :arpcache
36
+ # Comma separated list of ip addresses to ignore.
37
+ attr_accessor :ignore
38
+ # If true the BetterCap::Sniffer will be enabled.
39
+ attr_accessor :sniffer
40
+ # PCAP file name to save captured packets to.
41
+ attr_accessor :sniffer_pcap
42
+ # BPF filter to apply to sniffed packets.
43
+ attr_accessor :sniffer_filter
44
+ # Input PCAP file, if specified the BetterCap::Sniffer will read packets
45
+ # from it instead of the network.
46
+ attr_accessor :sniffer_src
47
+ # Comma separated list of BetterCap::Parsers to enable.
48
+ attr_accessor :parsers
49
+ # Regular expression to use with the BetterCap::Parsers::Custom parser.
50
+ attr_accessor :custom_parser
51
+ # If true, bettercap will sniff packets from the local interface as well.
52
+ attr_accessor :local
53
+ # If true, HTTP transparent proxy will be enabled.
54
+ attr_accessor :proxy
55
+ # If true, HTTPS transparent proxy will be enabled.
56
+ attr_accessor :proxy_https
57
+ # HTTP proxy port.
58
+ attr_accessor :proxy_port
59
+ # HTTPS proxy port.
60
+ attr_accessor :proxy_https_port
61
+ # File name of the PEM certificate to use for the HTTPS proxy.
62
+ attr_accessor :proxy_pem_file
63
+ # File name of the transparent proxy module to load.
64
+ attr_accessor :proxy_module
65
+ # Custom HTTP transparent proxy address.
66
+ attr_accessor :custom_proxy
67
+ # Custom HTTP transparent proxy port.
68
+ attr_accessor :custom_proxy_port
69
+ # Custom HTTPS transparent proxy address.
70
+ attr_accessor :custom_https_proxy
71
+ # Custom HTTPS transparent proxy port.
72
+ attr_accessor :custom_https_proxy_port
73
+ # If true, BetterCap::HTTPD::Server will be enabled.
74
+ attr_accessor :httpd
75
+ # The port to bind BetterCap::HTTPD::Server to.
76
+ attr_accessor :httpd_port
77
+ # Web root of the BetterCap::HTTPD::Server.
78
+ attr_accessor :httpd_path
79
+ # If true, bettercap will check for updates then exit.
80
+ attr_accessor :check_updates
81
+ # If true, targets NBNS hostname resolution won't be performed.
82
+ attr_accessor :no_target_nbns
83
+
84
+ # Create a BetterCap::Options class instance using the specified network interface.
47
85
  def initialize( iface )
48
86
  @gateway = nil
49
87
  @iface = iface
@@ -86,6 +124,9 @@ class Options
86
124
  @check_updates = false
87
125
  end
88
126
 
127
+ # Initialize the BetterCap::Context, parse command line arguments and update program
128
+ # state accordingly.
129
+ # Will rise a BetterCap::Error if errors occurred.
89
130
  def self.parse!
90
131
  ctx = Context.get
91
132
 
@@ -101,7 +142,7 @@ class Options
101
142
  ctx.options.iface = v
102
143
  end
103
144
 
104
- opts.on( '-S', '--spoofer NAME', 'Spoofer module to use, available: ' + SpooferFactory.available.join(', ') + ' - default: ' + ctx.options.spoofer ) do |v|
145
+ opts.on( '-S', '--spoofer NAME', 'Spoofer module to use, available: ' + Factories::Spoofer.available.join(', ') + ' - default: ' + ctx.options.spoofer ) do |v|
105
146
  ctx.options.spoofer = v
106
147
  end
107
148
 
@@ -145,9 +186,9 @@ class Options
145
186
  ctx.options.sniffer_filter = v
146
187
  end
147
188
 
148
- opts.on( '-P', '--parsers PARSERS', 'Comma separated list of packet parsers to enable, "*" for all ( NOTE: Will set -X to true ), available: ' + ParserFactory.available.join(', ') + ' - default: *' ) do |v|
189
+ opts.on( '-P', '--parsers PARSERS', 'Comma separated list of packet parsers to enable, "*" for all ( NOTE: Will set -X to true ), available: ' + Factories::Parser.available.join(', ') + ' - default: *' ) do |v|
149
190
  ctx.options.sniffer = true
150
- ctx.options.parsers = ParserFactory.from_cmdline(v)
191
+ ctx.options.parsers = Factories::Parser.from_cmdline(v)
151
192
  end
152
193
 
153
194
  opts.on( '--custom-parser EXPRESSION', 'Use a custom regular expression in order to capture and show sniffed data ( NOTE: Will set -X to true ).' ) do |v|
@@ -281,26 +322,33 @@ class Options
281
322
  ctx
282
323
  end
283
324
 
325
+ # Return true if active host discovery is enabled, otherwise false.
284
326
  def should_discover_hosts?
285
327
  !@arpcache
286
328
  end
287
329
 
330
+ # Return true if a proxy module was specified, otherwise false.
288
331
  def has_proxy_module?
289
332
  !@proxy_module.nil?
290
333
  end
291
334
 
335
+ # Return true if a spoofer module was specified, otherwise false.
292
336
  def has_spoofer?
293
337
  @spoofer != 'NONE' and @spoofer != 'none'
294
338
  end
295
339
 
340
+ # Return true if the BetterCap::Parsers::URL is enabled, otherwise false.
296
341
  def has_http_sniffer_enabled?
297
342
  @sniffer and ( @parsers.include?'*' or @parsers.include?'URL' )
298
343
  end
299
344
 
345
+ # Return true if the +ip+ address needs to be ignored, otherwise false.
300
346
  def ignore_ip?(ip)
301
347
  !@ignore.nil? and @ignore.include?(ip)
302
348
  end
303
349
 
350
+ # Setter for the #ignore attribute, will raise a BetterCap::Error if one
351
+ # or more invalid IP addresses are specified.
304
352
  def ignore=(value)
305
353
  @ignore = value.split(",")
306
354
  valid = @ignore.select { |target| Network.is_ip?(target) }
@@ -317,16 +365,22 @@ class Options
317
365
  Logger.warn "Ignoring #{valid.join(", ")} ."
318
366
  end
319
367
 
368
+ # Setter for the #custom_proxy attribute, will raise a BetterCap::Error if
369
+ # +value+ is not a valid IP address.
320
370
  def custom_proxy=(value)
321
371
  @custom_proxy = value
322
372
  raise BetterCap::Error, 'Invalid custom HTTP upstream proxy address specified.' unless Network.is_ip? @custom_proxy
323
373
  end
324
374
 
375
+ # Setter for the #custom_https_proxy attribute, will raise a BetterCap::Error if
376
+ # +value+ is not a valid IP address.
325
377
  def custom_https_proxy=(value)
326
378
  @custom_https_proxy = value
327
379
  raise BetterCap::Error, 'Invalid custom HTTPS upstream proxy address specified.' unless Network.is_ip? @custom_https_proxy
328
380
  end
329
381
 
382
+ # Split specified targets and parse them ( either as IP or MAC ), will raise a
383
+ # BetterCap::Error if one or more invalid addresses are specified.
330
384
  def to_targets
331
385
  targets = @target.split(",")
332
386
  valid_targets = targets.select { |target| Network.is_ip?(target) or Network.is_mac?(target) }
@@ -341,20 +395,24 @@ class Options
341
395
  valid_targets.map { |target| Target.new(target) }
342
396
  end
343
397
 
398
+ # Parse spoofers and return a list of BetterCap::Spoofers objects. Raise a
399
+ # BetterCap::Error if an invalid spoofer name was specified.
344
400
  def to_spoofers
345
401
  spoofers = []
346
402
  spoofer_modules_names = @spoofer.split(",")
347
403
  spoofer_modules_names.each do |module_name|
348
- spoofers << SpooferFactory.get_by_name( module_name )
404
+ spoofers << Factories::Spoofer.get_by_name( module_name )
349
405
  end
350
406
  spoofers
351
407
  end
352
408
 
409
+ # Create a list of BetterCap::Firewalls::Redirection objects which are needed
410
+ # given the specified command line arguments.
353
411
  def to_redirections ifconfig
354
412
  redirections = []
355
413
 
356
414
  if @proxy
357
- redirections << Redirection.new( @iface,
415
+ redirections << Firewalls::Redirection.new( @iface,
358
416
  'TCP',
359
417
  80,
360
418
  ifconfig[:ip_saddr],
@@ -362,7 +420,7 @@ class Options
362
420
  end
363
421
 
364
422
  if @proxy_https
365
- redirections << Redirection.new( @iface,
423
+ redirections << Firewalls::Redirection.new( @iface,
366
424
  'TCP',
367
425
  443,
368
426
  ifconfig[:ip_saddr],
@@ -370,7 +428,7 @@ class Options
370
428
  end
371
429
 
372
430
  if @custom_proxy
373
- redirections << Redirection.new( @iface,
431
+ redirections << Firewalls::Redirection.new( @iface,
374
432
  'TCP',
375
433
  80,
376
434
  @custom_proxy,
@@ -378,7 +436,7 @@ class Options
378
436
  end
379
437
 
380
438
  if @custom_https_proxy
381
- redirections << Redirection.new( @iface,
439
+ redirections << Firewalls::Redirection.new( @iface,
382
440
  'TCP',
383
441
  443,
384
442
  @custom_https_proxy,