bettercap 1.1.10 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO.md +8 -7
- data/bin/bettercap +8 -2
- data/lib/bettercap.rb +5 -4
- data/lib/bettercap/context.rb +54 -8
- data/lib/bettercap/discovery/agents/arp.rb +17 -4
- data/lib/bettercap/discovery/agents/base.rb +16 -52
- data/lib/bettercap/discovery/agents/icmp.rb +25 -17
- data/lib/bettercap/discovery/agents/udp.rb +9 -20
- data/lib/bettercap/discovery/{discovery.rb → thread.rb} +10 -9
- data/lib/bettercap/error.rb +1 -2
- data/lib/bettercap/factories/{firewall_factory.rb → firewall.rb} +11 -7
- data/lib/bettercap/factories/{parser_factory.rb → parser.rb} +13 -3
- data/lib/bettercap/factories/{spoofer_factory.rb → spoofer.rb} +10 -3
- data/lib/bettercap/firewalls/base.rb +76 -0
- data/lib/bettercap/firewalls/linux.rb +26 -16
- data/lib/bettercap/firewalls/osx.rb +22 -13
- data/lib/bettercap/firewalls/redirection.rb +15 -1
- data/lib/bettercap/httpd/server.rb +5 -0
- data/lib/bettercap/logger.rb +29 -8
- data/lib/bettercap/network.rb +105 -105
- data/lib/bettercap/options.rb +99 -41
- data/lib/bettercap/packet_queue.rb +92 -0
- data/lib/bettercap/proxy/certstore.rb +49 -43
- data/lib/bettercap/proxy/module.rb +4 -2
- data/lib/bettercap/proxy/proxy.rb +7 -2
- data/lib/bettercap/proxy/request.rb +28 -16
- data/lib/bettercap/proxy/response.rb +23 -2
- data/lib/bettercap/proxy/stream_logger.rb +6 -0
- data/lib/bettercap/proxy/streamer.rb +13 -5
- data/lib/bettercap/proxy/thread_pool.rb +6 -14
- data/lib/bettercap/shell.rb +5 -3
- data/lib/bettercap/sniffer/parsers/base.rb +7 -1
- data/lib/bettercap/sniffer/parsers/custom.rb +6 -1
- data/lib/bettercap/sniffer/parsers/ftp.rb +8 -5
- data/lib/bettercap/sniffer/parsers/httpauth.rb +4 -1
- data/lib/bettercap/sniffer/parsers/https.rb +4 -1
- data/lib/bettercap/sniffer/parsers/irc.rb +8 -5
- data/lib/bettercap/sniffer/parsers/mail.rb +8 -5
- data/lib/bettercap/sniffer/parsers/ntlmss.rb +21 -18
- data/lib/bettercap/sniffer/parsers/post.rb +4 -1
- data/lib/bettercap/sniffer/parsers/url.rb +4 -1
- data/lib/bettercap/sniffer/sniffer.rb +7 -3
- data/lib/bettercap/spoofers/arp.rb +69 -94
- data/lib/bettercap/spoofers/base.rb +132 -0
- data/lib/bettercap/spoofers/icmp.rb +200 -0
- data/lib/bettercap/spoofers/none.rb +8 -2
- data/lib/bettercap/target.rb +117 -90
- data/lib/bettercap/update_checker.rb +6 -0
- data/lib/bettercap/version.rb +3 -1
- metadata +24 -8
- data/lib/bettercap/base/ifirewall.rb +0 -46
- data/lib/bettercap/base/ispoofer.rb +0 -32
data/lib/bettercap/logger.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/bettercap/network.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
31
|
+
# Return the current network gateway or nil.
|
32
|
+
def get_gateway
|
33
|
+
nstat = Shell.execute('netstat -nr')
|
30
34
|
|
31
|
-
|
35
|
+
Logger.debug "NETSTAT:\n#{nstat}"
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
48
|
-
|
51
|
+
# Return a list of IP addresses associated to this device network interfaces.
|
52
|
+
def get_local_ips
|
53
|
+
ips = []
|
49
54
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
123
|
+
target_mac
|
126
124
|
end
|
127
|
-
|
125
|
+
hw_address = cap_thread.value
|
128
126
|
|
129
|
-
|
127
|
+
break unless hw_address.nil?
|
128
|
+
end
|
130
129
|
end
|
131
130
|
|
132
|
-
|
131
|
+
hw_address
|
132
|
+
end
|
133
133
|
|
134
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
data/lib/bettercap/options.rb
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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: ' +
|
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: ' +
|
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 =
|
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 <<
|
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,
|