xettercap 1.5.7xerob
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/xettercap +61 -0
- data/lib/bettercap/banner +2 -0
- data/lib/bettercap/context.rb +259 -0
- data/lib/bettercap/discovery/agents/arp.rb +37 -0
- data/lib/bettercap/discovery/agents/base.rb +73 -0
- data/lib/bettercap/discovery/agents/icmp.rb +44 -0
- data/lib/bettercap/discovery/agents/udp.rb +30 -0
- data/lib/bettercap/discovery/thread.rb +128 -0
- data/lib/bettercap/error.rb +16 -0
- data/lib/bettercap/firewalls/base.rb +103 -0
- data/lib/bettercap/firewalls/bsd.rb +74 -0
- data/lib/bettercap/firewalls/linux.rb +65 -0
- data/lib/bettercap/firewalls/redirection.rb +42 -0
- data/lib/bettercap/loader.rb +27 -0
- data/lib/bettercap/logger.rb +131 -0
- data/lib/bettercap/memory.rb +56 -0
- data/lib/bettercap/monkey/celluloid/actor.rb +23 -0
- data/lib/bettercap/monkey/celluloid/io/udp_socket.rb +26 -0
- data/lib/bettercap/monkey/em-proxy/proxy.rb +23 -0
- data/lib/bettercap/monkey/openssl/server.rb +35 -0
- data/lib/bettercap/monkey/packetfu/pcap.rb +51 -0
- data/lib/bettercap/monkey/packetfu/utils.rb +210 -0
- data/lib/bettercap/monkey/system.rb +25 -0
- data/lib/bettercap/network/arp_reader.rb +91 -0
- data/lib/bettercap/network/hw-prefixes +21326 -0
- data/lib/bettercap/network/network.rb +102 -0
- data/lib/bettercap/network/packet_queue.rb +129 -0
- data/lib/bettercap/network/protos/base.rb +154 -0
- data/lib/bettercap/network/protos/dhcp.rb +227 -0
- data/lib/bettercap/network/protos/mysql.rb +40 -0
- data/lib/bettercap/network/protos/ntlm.rb +97 -0
- data/lib/bettercap/network/protos/snmp.rb +49 -0
- data/lib/bettercap/network/protos/teamviewer.rb +119 -0
- data/lib/bettercap/network/servers/dnsd.rb +152 -0
- data/lib/bettercap/network/servers/httpd.rb +55 -0
- data/lib/bettercap/network/services +2182 -0
- data/lib/bettercap/network/target.rb +168 -0
- data/lib/bettercap/network/validator.rb +96 -0
- data/lib/bettercap/options/core_options.rb +197 -0
- data/lib/bettercap/options/options.rb +165 -0
- data/lib/bettercap/options/proxy_options.rb +314 -0
- data/lib/bettercap/options/server_options.rb +73 -0
- data/lib/bettercap/options/sniff_options.rb +90 -0
- data/lib/bettercap/options/spoof_options.rb +71 -0
- data/lib/bettercap/pluggable.rb +37 -0
- data/lib/bettercap/proxy/http/module.rb +105 -0
- data/lib/bettercap/proxy/http/modules/injectcss.rb +79 -0
- data/lib/bettercap/proxy/http/modules/injecthtml.rb +80 -0
- data/lib/bettercap/proxy/http/modules/injectjs.rb +79 -0
- data/lib/bettercap/proxy/http/proxy.rb +184 -0
- data/lib/bettercap/proxy/http/request.rb +192 -0
- data/lib/bettercap/proxy/http/response.rb +226 -0
- data/lib/bettercap/proxy/http/ssl/authority.rb +182 -0
- data/lib/bettercap/proxy/http/ssl/bettercap-ca.pem +49 -0
- data/lib/bettercap/proxy/http/ssl/server.rb +63 -0
- data/lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb +67 -0
- data/lib/bettercap/proxy/http/sslstrip/lock.ico +0 -0
- data/lib/bettercap/proxy/http/sslstrip/strip.rb +325 -0
- data/lib/bettercap/proxy/http/streamer.rb +225 -0
- data/lib/bettercap/proxy/stream_logger.rb +181 -0
- data/lib/bettercap/proxy/tcp/module.rb +75 -0
- data/lib/bettercap/proxy/tcp/proxy.rb +123 -0
- data/lib/bettercap/proxy/thread_pool.rb +194 -0
- data/lib/bettercap/shell.rb +70 -0
- data/lib/bettercap/sniffer/parsers/base.rb +87 -0
- data/lib/bettercap/sniffer/parsers/cookie.rb +45 -0
- data/lib/bettercap/sniffer/parsers/creditcard.rb +62 -0
- data/lib/bettercap/sniffer/parsers/custom.rb +26 -0
- data/lib/bettercap/sniffer/parsers/dhcp.rb +45 -0
- data/lib/bettercap/sniffer/parsers/dict.rb +37 -0
- data/lib/bettercap/sniffer/parsers/ftp.rb +24 -0
- data/lib/bettercap/sniffer/parsers/httpauth.rb +44 -0
- data/lib/bettercap/sniffer/parsers/https.rb +42 -0
- data/lib/bettercap/sniffer/parsers/irc.rb +24 -0
- data/lib/bettercap/sniffer/parsers/mail.rb +24 -0
- data/lib/bettercap/sniffer/parsers/mpd.rb +36 -0
- data/lib/bettercap/sniffer/parsers/mysql.rb +27 -0
- data/lib/bettercap/sniffer/parsers/nntp.rb +24 -0
- data/lib/bettercap/sniffer/parsers/ntlmss.rb +34 -0
- data/lib/bettercap/sniffer/parsers/pgsql.rb +36 -0
- data/lib/bettercap/sniffer/parsers/post.rb +33 -0
- data/lib/bettercap/sniffer/parsers/redis.rb +39 -0
- data/lib/bettercap/sniffer/parsers/rlogin.rb +45 -0
- data/lib/bettercap/sniffer/parsers/snmp.rb +44 -0
- data/lib/bettercap/sniffer/parsers/snpp.rb +37 -0
- data/lib/bettercap/sniffer/parsers/teamviewer.rb +30 -0
- data/lib/bettercap/sniffer/parsers/url.rb +30 -0
- data/lib/bettercap/sniffer/parsers/whatsapp.rb +33 -0
- data/lib/bettercap/sniffer/sniffer.rb +142 -0
- data/lib/bettercap/spoofers/arp.rb +150 -0
- data/lib/bettercap/spoofers/base.rb +152 -0
- data/lib/bettercap/spoofers/icmp.rb +202 -0
- data/lib/bettercap/spoofers/none.rb +57 -0
- data/lib/bettercap/update_checker.rb +57 -0
- data/lib/bettercap/version.rb +18 -0
- data/lib/bettercap.rb +70 -0
- metadata +276 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
module BetterCap
|
14
|
+
module Firewalls
|
15
|
+
# Base class for BetterCap::Firewalls objects.
|
16
|
+
class Base
|
17
|
+
# Instance of the loaded firewall.
|
18
|
+
@@instance = nil
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# Save and return an instance of the appropriate BetterCap::Firewalls object.
|
22
|
+
def get
|
23
|
+
return @@instance unless @@instance.nil?
|
24
|
+
|
25
|
+
if RUBY_PLATFORM =~ /.+bsd/ or RUBY_PLATFORM =~ /darwin/
|
26
|
+
@@instance = Firewalls::BSD.new
|
27
|
+
elsif RUBY_PLATFORM =~ /linux/
|
28
|
+
@@instance = Firewalls::Linux.new
|
29
|
+
else
|
30
|
+
raise BetterCap::Error, 'Unsupported operating system'
|
31
|
+
end
|
32
|
+
|
33
|
+
@@instance
|
34
|
+
end
|
35
|
+
|
36
|
+
# Clear the instance of the BetterCap::Firewalls object.
|
37
|
+
def clear
|
38
|
+
@@instance = nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Initialize the firewall object.
|
43
|
+
# Raise NotImplementedError
|
44
|
+
def initialize
|
45
|
+
@frwd_initial_state = forwarding_enabled?
|
46
|
+
end
|
47
|
+
|
48
|
+
# If +enabled+ is true will enable packet forwarding, otherwise it will
|
49
|
+
# disable it.
|
50
|
+
# Raise NotImplementedError
|
51
|
+
def enable_forwarding(enabled)
|
52
|
+
not_implemented_method!
|
53
|
+
end
|
54
|
+
|
55
|
+
# If +enabled+ is true will enable icmp_echo_ignore_broadcasts, otherwise it will
|
56
|
+
# disable it.
|
57
|
+
# Raise NotImplementedError
|
58
|
+
def enable_icmp_bcast(enabled)
|
59
|
+
not_implemented_method!
|
60
|
+
end
|
61
|
+
|
62
|
+
# If +enabled+ is true will enable send_redirects, otherwise it will
|
63
|
+
# disable it.
|
64
|
+
# Raise NotImplementedError
|
65
|
+
def enable_send_redirects(enabled)
|
66
|
+
not_implemented_method!
|
67
|
+
end
|
68
|
+
|
69
|
+
# Return true if packet forwarding is currently enabled, otherwise false.
|
70
|
+
# Raise NotImplementedError
|
71
|
+
def forwarding_enabled?
|
72
|
+
not_implemented_method!
|
73
|
+
end
|
74
|
+
|
75
|
+
# Apply the +r+ BetterCap::Firewalls::Redirection port redirection object.
|
76
|
+
# Raise NotImplementedError
|
77
|
+
def add_port_redirection( r )
|
78
|
+
not_implemented_method!
|
79
|
+
end
|
80
|
+
|
81
|
+
# Remove the +r+ BetterCap::Firewalls::Redirection port redirection object.
|
82
|
+
# Raise NotImplementedError
|
83
|
+
def del_port_redirection( r )
|
84
|
+
not_implemented_method!
|
85
|
+
end
|
86
|
+
|
87
|
+
# Restore the system's original packet forwarding state.
|
88
|
+
# Raise NotImplementedError
|
89
|
+
def restore
|
90
|
+
if forwarding_enabled? != @frwd_initial_state
|
91
|
+
enable_forwarding @frwd_initial_state
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
# Method used to raise NotImplementedError exception.
|
98
|
+
def not_implemented_method!
|
99
|
+
raise NotImplementedError, 'Firewalls::Base: Unimplemented method!'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
module BetterCap
|
15
|
+
module Firewalls
|
16
|
+
# *BSD and OSX Firewall class.
|
17
|
+
class BSD < Base
|
18
|
+
# If +enabled+ is true will enable packet forwarding, otherwise it will
|
19
|
+
# disable it.
|
20
|
+
def enable_forwarding(enabled)
|
21
|
+
Shell.execute("sysctl -w net.inet.ip.forwarding=#{enabled ? 1 : 0}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# If +enabled+ is true will enable packet icmp_echo_ignore_broadcasts, otherwise it will
|
25
|
+
# disable it.
|
26
|
+
def enable_icmp_bcast(enabled)
|
27
|
+
Shell.execute("sysctl -w net.inet.icmp.bmcastecho=#{enabled ? 1 : 0}")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return true if packet forwarding is currently enabled, otherwise false.
|
31
|
+
def forwarding_enabled?
|
32
|
+
Shell.execute('sysctl net.inet.ip.forwarding').strip.split(' ')[1] == '1'
|
33
|
+
end
|
34
|
+
|
35
|
+
# This method is ignored on OSX.
|
36
|
+
def enable_send_redirects(enabled); end
|
37
|
+
|
38
|
+
# If +enabled+ is true, the PF firewall will be enabled, otherwise it will
|
39
|
+
# be disabled.
|
40
|
+
def enable(enabled)
|
41
|
+
Shell.execute("pfctl -#{enabled ? 'e' : 'd'} >/dev/null 2>&1")
|
42
|
+
rescue
|
43
|
+
end
|
44
|
+
|
45
|
+
# Apply the +r+ BetterCap::Firewalls::Redirection port redirection object.
|
46
|
+
def add_port_redirection( r )
|
47
|
+
# create the pf config file
|
48
|
+
config_file = "/tmp/bettercap_pf_#{Process.pid}.conf"
|
49
|
+
|
50
|
+
File.open( config_file, 'a+t' ) do |f|
|
51
|
+
f.write "rdr pass on #{r.interface} proto #{r.protocol} from any to #{r.src_address.nil? ? 'any' : r.src_address} port #{r.src_port} -> #{r.dst_address} port #{r.dst_port}\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
# load the rule
|
55
|
+
Shell.execute("pfctl -f #{config_file} >/dev/null 2>&1")
|
56
|
+
# enable pf
|
57
|
+
enable true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Remove the +r+ BetterCap::Firewalls::Redirection port redirection object.
|
61
|
+
def del_port_redirection( r )
|
62
|
+
# FIXME: This should search for multiple rules inside the
|
63
|
+
# file and remove only this one.
|
64
|
+
|
65
|
+
# disable pf
|
66
|
+
enable false
|
67
|
+
|
68
|
+
# remove the pf config file
|
69
|
+
File.delete( "/tmp/bettercap_pf_#{Process.pid}.conf" )
|
70
|
+
rescue
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
module BetterCap
|
15
|
+
module Firewalls
|
16
|
+
# Linux firewall class.
|
17
|
+
class Linux < Base
|
18
|
+
|
19
|
+
IPV4_PATH = "/proc/sys/net/ipv4"
|
20
|
+
IP_FORWARD_PATH = IPV4_PATH + "/ip_forward"
|
21
|
+
ICMP_BCAST_PATH = IPV4_PATH + "/icmp_echo_ignore_broadcasts"
|
22
|
+
SEND_REDIRECTS_PATH = IPV4_PATH + "/conf/all/send_redirects"
|
23
|
+
# If +enabled+ is true will enable packet forwarding, otherwise it will
|
24
|
+
# disable it.
|
25
|
+
def enable_forwarding(enabled)
|
26
|
+
File.open(IP_FORWARD_PATH,'w') { |f| f.puts "#{enabled ? 1 : 0}" }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return true if packet forwarding is currently enabled, otherwise false.
|
30
|
+
def forwarding_enabled?
|
31
|
+
File.open(IP_FORWARD_PATH) { |f| f.read.strip == '1' }
|
32
|
+
end
|
33
|
+
|
34
|
+
# If +enabled+ is true will enable packet icmp_echo_ignore_broadcasts, otherwise it will
|
35
|
+
# disable it.
|
36
|
+
def enable_icmp_bcast(enabled)
|
37
|
+
File.open(ICMP_BCAST_PATH,'w') { |f| f.puts "#{enabled ? 1 : 0}" }
|
38
|
+
end
|
39
|
+
|
40
|
+
# If +enabled+ is true will enable send_redirects, otherwise it will
|
41
|
+
# disable it.
|
42
|
+
def enable_send_redirects(enabled)
|
43
|
+
File.open(SEND_REDIRECTS_PATH,'w') { |f| f.puts "#{enabled ? 1 : 0}" }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Apply the +r+ BetterCap::Firewalls::Redirection port redirection object.
|
47
|
+
def add_port_redirection( r )
|
48
|
+
# post route
|
49
|
+
Shell.execute('iptables -t nat -I POSTROUTING -s 0/0 -j MASQUERADE')
|
50
|
+
# accept all
|
51
|
+
Shell.execute('iptables -P FORWARD ACCEPT')
|
52
|
+
# add redirection
|
53
|
+
Shell.execute("iptables -t nat -A PREROUTING -i #{r.interface} -p #{r.protocol} #{r.src_address.nil? ? '' : "-d #{r.src_address}"} --dport #{r.src_port} -j DNAT --to #{r.dst_address}:#{r.dst_port}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# Remove the +r+ BetterCap::Firewalls::Redirection port redirection object.
|
57
|
+
def del_port_redirection( r )
|
58
|
+
# remove post route
|
59
|
+
Shell.execute('iptables -t nat -D POSTROUTING -s 0/0 -j MASQUERADE')
|
60
|
+
# remove redirection
|
61
|
+
Shell.execute("iptables -t nat -D PREROUTING -i #{r.interface} -p #{r.protocol} #{r.src_address.nil? ? '' : "-d #{r.src_address}"} --dport #{r.src_port} -j DNAT --to #{r.dst_address}:#{r.dst_port}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
module BetterCap
|
14
|
+
module Firewalls
|
15
|
+
# This class represents a firewall port redirection rule.
|
16
|
+
class Redirection
|
17
|
+
# Network interface name.
|
18
|
+
attr_reader :interface
|
19
|
+
# Protocol name.
|
20
|
+
attr_reader :protocol
|
21
|
+
# Source address.
|
22
|
+
attr_reader :src_address
|
23
|
+
# Source port.
|
24
|
+
attr_reader :src_port
|
25
|
+
# Destination address.
|
26
|
+
attr_reader :dst_address
|
27
|
+
# Destionation port.
|
28
|
+
attr_reader :dst_port
|
29
|
+
|
30
|
+
# Create the redirection rule for the specified +interface+ and +protocol+.
|
31
|
+
# Redirect +src_address+:+src_port+ to +dst_address+:+dst_port+
|
32
|
+
def initialize( interface, protocol, src_address, src_port, dst_address, dst_port )
|
33
|
+
@interface = interface
|
34
|
+
@protocol = protocol
|
35
|
+
@src_address = src_address
|
36
|
+
@src_port = src_port
|
37
|
+
@dst_address = dst_address
|
38
|
+
@dst_port = dst_port
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
module BetterCap
|
15
|
+
# This class is responsible for dynamically loading modules.
|
16
|
+
class Loader
|
17
|
+
# Dynamically load a class given its +name+.
|
18
|
+
# @see https://github.com/evilsocket/bettercap/issues/88
|
19
|
+
def self.load(name)
|
20
|
+
root = Kernel
|
21
|
+
name.split('::').each do |part|
|
22
|
+
root = root.const_get(part)
|
23
|
+
end
|
24
|
+
root
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
module BetterCap
|
14
|
+
# Class responsible for console and file logging.
|
15
|
+
module Logger
|
16
|
+
class << self
|
17
|
+
@@ctx = nil
|
18
|
+
@@queue = Queue.new
|
19
|
+
@@debug = false
|
20
|
+
@@timestamp = false
|
21
|
+
@@silent = false
|
22
|
+
@@logfile = nil
|
23
|
+
@@thread = nil
|
24
|
+
|
25
|
+
# Initialize the logging system.
|
26
|
+
def init( ctx )
|
27
|
+
@@debug = ctx.options.core.debug
|
28
|
+
@@logfile = ctx.options.core.logfile
|
29
|
+
@@silent = ctx.options.core.silent
|
30
|
+
@@timestamp = ctx.options.core.log_timestamp
|
31
|
+
@@ctx = ctx
|
32
|
+
@@thread = Thread.new { worker }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Log the exception +e+, if this is a beta version, log it as a warning,
|
36
|
+
# otherwise as a debug message.
|
37
|
+
def exception(e)
|
38
|
+
msg = "Exception : #{e.class}\n" +
|
39
|
+
"Message : #{e.message}\n" +
|
40
|
+
"Backtrace :\n\n #{e.backtrace.join("\n ")}\n"
|
41
|
+
|
42
|
+
if BetterCap::VERSION.end_with?('b')
|
43
|
+
self.warn(msg)
|
44
|
+
else
|
45
|
+
self.debug(msg)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Log an error +message+.
|
50
|
+
def error(message)
|
51
|
+
@@queue.push formatted_message(message, 'E').red
|
52
|
+
end
|
53
|
+
|
54
|
+
# Log an information +message+.
|
55
|
+
def info(message)
|
56
|
+
@@queue.push( formatted_message(message, 'I') ) unless @@silent
|
57
|
+
end
|
58
|
+
|
59
|
+
# Log a warning +message+.
|
60
|
+
def warn(message)
|
61
|
+
@@queue.push formatted_message(message, 'W').yellow
|
62
|
+
end
|
63
|
+
|
64
|
+
# Log a debug +message+.
|
65
|
+
def debug(message)
|
66
|
+
if @@debug and not @@silent
|
67
|
+
@@queue.push formatted_message(message, 'D').light_black
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Log a +message+ as it is.
|
72
|
+
def raw(message)
|
73
|
+
@@queue.push( formatted_message( message, nil ) )
|
74
|
+
end
|
75
|
+
|
76
|
+
# Wait for the messages queue to be empty.
|
77
|
+
def wait!
|
78
|
+
while not @@queue.empty?
|
79
|
+
if @@thread.nil?
|
80
|
+
emit @@queue.pop
|
81
|
+
else
|
82
|
+
sleep 0.3
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# Main logger logic.
|
90
|
+
def worker
|
91
|
+
loop do
|
92
|
+
message = @@queue.pop
|
93
|
+
if @@ctx.nil? or @@ctx.running
|
94
|
+
begin
|
95
|
+
emit message
|
96
|
+
rescue Exception => e
|
97
|
+
Logger.warn "Logger error: #{e.message}"
|
98
|
+
Logger.exception e
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Emit the +message+.
|
105
|
+
def emit(message)
|
106
|
+
# puts message
|
107
|
+
unless @@logfile.nil?
|
108
|
+
f = File.open( @@logfile, 'a+t' )
|
109
|
+
f.puts( message.gsub( /\e\[(\d+)(;\d+)*m/, '') + "\n")
|
110
|
+
f.close
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Format +message+ for the given +message_type+.
|
115
|
+
def formatted_message(message, message_type)
|
116
|
+
# raw message?
|
117
|
+
if message_type.nil?
|
118
|
+
if @@timestamp and !message.strip.empty?
|
119
|
+
"[#{Time.now}] #{message}"
|
120
|
+
else
|
121
|
+
message
|
122
|
+
end
|
123
|
+
elsif @@timestamp
|
124
|
+
"[#{Time.now}] [#{message_type}] #{message}"
|
125
|
+
else
|
126
|
+
"[#{message_type}] #{message}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
module BetterCap
|
15
|
+
# This class is responsible for garbage collection and memory stats printing.
|
16
|
+
class Memory
|
17
|
+
def initialize
|
18
|
+
GC.enable
|
19
|
+
s = GC.stat
|
20
|
+
@total_allocs = s[:total_allocated_objects]
|
21
|
+
@total_freed = s[:total_freed_objects]
|
22
|
+
end
|
23
|
+
|
24
|
+
def optimize!
|
25
|
+
GC.start
|
26
|
+
begin
|
27
|
+
s = GC.stat
|
28
|
+
new_allocs = s[:total_allocated_objects]
|
29
|
+
new_freed = s[:total_freed_objects]
|
30
|
+
allocs_d = nil
|
31
|
+
freed_d = nil
|
32
|
+
|
33
|
+
if new_allocs < @total_allocs
|
34
|
+
allocs_d = new_allocs.to_s.green
|
35
|
+
elsif new_allocs > @total_allocs
|
36
|
+
allocs_d = new_allocs.to_s.red
|
37
|
+
else
|
38
|
+
allocs_d = new_allocs
|
39
|
+
end
|
40
|
+
|
41
|
+
if new_freed < @total_freed
|
42
|
+
freed_d = new_freed.to_s.red
|
43
|
+
elsif new_freed > @total_freed
|
44
|
+
freed_d = new_freed.to_s.green
|
45
|
+
else
|
46
|
+
freed_d = new_freed
|
47
|
+
end
|
48
|
+
|
49
|
+
# Logger.debug "GC: allocd objects: #{allocs_d} freed objects: #{freed_d}"
|
50
|
+
|
51
|
+
@total_allocs = new_allocs
|
52
|
+
@total_freed = new_freed
|
53
|
+
rescue; end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
# Monkey patching to remove Internals::Logger.crash calls.
|
15
|
+
module Celluloid
|
16
|
+
class Actor
|
17
|
+
# Handle any exceptions that occur within a running actor
|
18
|
+
def handle_crash(exception)
|
19
|
+
shutdown ExitEvent.new(behavior_proxy, exception)
|
20
|
+
rescue
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
# Monkey patching fix for https://github.com/evilsocket/bettercap/issues/154
|
15
|
+
module Celluloid
|
16
|
+
module IO
|
17
|
+
class UDPSocket
|
18
|
+
def initialize(address_family = ::Socket::AF_INET)
|
19
|
+
@socket = ::UDPSocket.new(address_family)
|
20
|
+
rescue Errno::EMFILE
|
21
|
+
sleep 0.5
|
22
|
+
retry
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Proxy
|
2
|
+
|
3
|
+
def self.start(options, &blk)
|
4
|
+
# epoll is not supported on OSX!
|
5
|
+
# EM.epoll
|
6
|
+
EM.run do
|
7
|
+
# We'll take care of this.
|
8
|
+
#
|
9
|
+
# trap("TERM") { stop }
|
10
|
+
# trap("INT") { stop }
|
11
|
+
|
12
|
+
EventMachine::start_server(options[:host], options[:port],
|
13
|
+
EventMachine::ProxyServer::Connection, options) do |c|
|
14
|
+
c.instance_eval(&blk)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.stop
|
20
|
+
EventMachine.stop
|
21
|
+
rescue
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
# Add accept_nonblock method to OpenSSL::SSL::SSLServer
|
15
|
+
module OpenSSL
|
16
|
+
module SSL
|
17
|
+
class SSLServer
|
18
|
+
unless public_method_defined? :accept_nonblock
|
19
|
+
def accept_nonblock
|
20
|
+
sock = @svr.accept_nonblock
|
21
|
+
|
22
|
+
begin
|
23
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
|
24
|
+
ssl.sync_close = true
|
25
|
+
ssl.accept if @start_immediately
|
26
|
+
ssl
|
27
|
+
rescue SSLError => ex
|
28
|
+
sock.close
|
29
|
+
raise ex
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
|
4
|
+
BETTERCAP
|
5
|
+
|
6
|
+
Author : Simone 'evilsocket' Margaritelli
|
7
|
+
Email : evilsocket@gmail.com
|
8
|
+
Blog : http://www.evilsocket.net/
|
9
|
+
|
10
|
+
This project is released under the GPL 3 license.
|
11
|
+
|
12
|
+
=end
|
13
|
+
module PacketFu
|
14
|
+
|
15
|
+
class PcapHeader
|
16
|
+
# Reads a string to populate the object.
|
17
|
+
# Conversion from big to little shouldn't be that big of a deal.
|
18
|
+
def read(str)
|
19
|
+
force_binary(str)
|
20
|
+
return self if str.nil?
|
21
|
+
str.force_encoding(Encoding::BINARY) if str.respond_to? :force_encoding
|
22
|
+
|
23
|
+
# Handle little endian pcap
|
24
|
+
if str[0,4] == self[:magic].to_s
|
25
|
+
self[:magic].read str[0,4]
|
26
|
+
self[:ver_major].read str[4,2]
|
27
|
+
self[:ver_minor].read str[6,2]
|
28
|
+
self[:thiszone].read str[8,4]
|
29
|
+
self[:sigfigs].read str[12,4]
|
30
|
+
self[:snaplen].read str[16,4]
|
31
|
+
self[:network].read str[20,4]
|
32
|
+
# Handle big endian pcap
|
33
|
+
elsif str[0,4] == MAGIC_BIG.to_s
|
34
|
+
# Since PcapFile.read uses our endianess, set it to 'big' anyway.
|
35
|
+
self[:endian] = :big
|
36
|
+
|
37
|
+
self[:magic].read str[0,4].reverse
|
38
|
+
self[:ver_major].read str[4,2].reverse
|
39
|
+
self[:ver_minor].read str[6,2].reverse
|
40
|
+
self[:thiszone].read str[8,4].reverse
|
41
|
+
self[:sigfigs].read str[12,4].reverse
|
42
|
+
self[:snaplen].read str[16,4].reverse
|
43
|
+
self[:network].read str[20,4].reverse
|
44
|
+
else
|
45
|
+
raise "Incorrect magic for libpcap"
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|