bettercap 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO.md +3 -3
- data/bettercap.gemspec +2 -0
- data/bin/bettercap +28 -5
- data/lib/bettercap.rb +4 -0
- data/lib/bettercap/context.rb +61 -21
- data/lib/bettercap/discovery/base.rb +22 -3
- data/lib/bettercap/firewalls/linux.rb +2 -2
- data/lib/bettercap/firewalls/redirection.rb +23 -0
- data/lib/bettercap/hw-prefixes +21240 -19565
- data/lib/bettercap/proxy/certstore.rb +1 -2
- data/lib/bettercap/proxy/proxy.rb +36 -139
- data/lib/bettercap/proxy/request.rb +10 -7
- data/lib/bettercap/proxy/response.rb +6 -4
- data/lib/bettercap/proxy/stream_logger.rb +41 -0
- data/lib/bettercap/proxy/streamer.rb +119 -0
- data/lib/bettercap/proxy/thread_pool.rb +265 -0
- data/lib/bettercap/version.rb +1 -1
- metadata +7 -3
@@ -0,0 +1,265 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
BETTERCAP
|
4
|
+
|
5
|
+
Author : Simone 'evilsocket' Margaritelli
|
6
|
+
Email : evilsocket@gmail.com
|
7
|
+
Blog : http://www.evilsocket.net/
|
8
|
+
|
9
|
+
This project is released under the GPL 3 license.
|
10
|
+
|
11
|
+
=end
|
12
|
+
require 'thread'
|
13
|
+
|
14
|
+
# Tnx to Puma ThreadPool!
|
15
|
+
module Proxy
|
16
|
+
class ThreadPool
|
17
|
+
|
18
|
+
# Maintain a minimum of +min+ and maximum of +max+ threads
|
19
|
+
# in the pool.
|
20
|
+
#
|
21
|
+
# The block passed is the work that will be performed in each
|
22
|
+
# thread.
|
23
|
+
#
|
24
|
+
def initialize(min, max, *extra, &block)
|
25
|
+
@not_empty = ConditionVariable.new
|
26
|
+
@not_full = ConditionVariable.new
|
27
|
+
@mutex = Mutex.new
|
28
|
+
|
29
|
+
@todo = []
|
30
|
+
|
31
|
+
@spawned = 0
|
32
|
+
@waiting = 0
|
33
|
+
|
34
|
+
@min = Integer(min)
|
35
|
+
@max = Integer(max)
|
36
|
+
@block = block
|
37
|
+
@extra = extra
|
38
|
+
|
39
|
+
@shutdown = false
|
40
|
+
|
41
|
+
@trim_requested = 0
|
42
|
+
|
43
|
+
@workers = []
|
44
|
+
|
45
|
+
@auto_trim = nil
|
46
|
+
@reaper = nil
|
47
|
+
|
48
|
+
@mutex.synchronize do
|
49
|
+
@min.times { spawn_thread }
|
50
|
+
end
|
51
|
+
|
52
|
+
@clean_thread_locals = false
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :spawned, :trim_requested
|
56
|
+
attr_accessor :clean_thread_locals
|
57
|
+
|
58
|
+
# How many objects have yet to be processed by the pool?
|
59
|
+
#
|
60
|
+
def backlog
|
61
|
+
@mutex.synchronize { @todo.size }
|
62
|
+
end
|
63
|
+
|
64
|
+
# :nodoc:
|
65
|
+
#
|
66
|
+
# Must be called with @mutex held!
|
67
|
+
#
|
68
|
+
def spawn_thread
|
69
|
+
@spawned += 1
|
70
|
+
|
71
|
+
th = Thread.new do
|
72
|
+
todo = @todo
|
73
|
+
block = @block
|
74
|
+
mutex = @mutex
|
75
|
+
not_empty = @not_empty
|
76
|
+
not_full = @not_full
|
77
|
+
|
78
|
+
extra = @extra.map { |i| i.new }
|
79
|
+
|
80
|
+
while true
|
81
|
+
work = nil
|
82
|
+
|
83
|
+
continue = true
|
84
|
+
|
85
|
+
mutex.synchronize do
|
86
|
+
while todo.empty?
|
87
|
+
if @trim_requested > 0
|
88
|
+
@trim_requested -= 1
|
89
|
+
continue = false
|
90
|
+
break
|
91
|
+
end
|
92
|
+
|
93
|
+
if @shutdown
|
94
|
+
continue = false
|
95
|
+
break
|
96
|
+
end
|
97
|
+
|
98
|
+
@waiting += 1
|
99
|
+
not_full.signal
|
100
|
+
not_empty.wait mutex
|
101
|
+
@waiting -= 1
|
102
|
+
end
|
103
|
+
|
104
|
+
work = todo.shift if continue
|
105
|
+
end
|
106
|
+
|
107
|
+
break unless continue
|
108
|
+
|
109
|
+
if @clean_thread_locals
|
110
|
+
Thread.current.keys.each do |key|
|
111
|
+
Thread.current[key] = nil unless key == :__recursive_key__
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
begin
|
116
|
+
block.call(work, *extra)
|
117
|
+
rescue Exception
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
mutex.synchronize do
|
122
|
+
@spawned -= 1
|
123
|
+
@workers.delete th
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
@workers << th
|
128
|
+
|
129
|
+
th
|
130
|
+
end
|
131
|
+
|
132
|
+
private :spawn_thread
|
133
|
+
|
134
|
+
# Add +work+ to the todo list for a Thread to pickup and process.
|
135
|
+
def <<(work)
|
136
|
+
@mutex.synchronize do
|
137
|
+
if @shutdown
|
138
|
+
raise "Unable to add work while shutting down"
|
139
|
+
end
|
140
|
+
|
141
|
+
@todo << work
|
142
|
+
|
143
|
+
if @waiting < @todo.size and @spawned < @max
|
144
|
+
spawn_thread
|
145
|
+
end
|
146
|
+
|
147
|
+
@not_empty.signal
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def wait_until_not_full
|
152
|
+
@mutex.synchronize do
|
153
|
+
until @todo.size - @waiting < @max - @spawned or @shutdown
|
154
|
+
@not_full.wait @mutex
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# If too many threads are in the pool, tell one to finish go ahead
|
160
|
+
# and exit. If +force+ is true, then a trim request is requested
|
161
|
+
# even if all threads are being utilized.
|
162
|
+
#
|
163
|
+
def trim(force=false)
|
164
|
+
@mutex.synchronize do
|
165
|
+
if (force or @waiting > 0) and @spawned - @trim_requested > @min
|
166
|
+
@trim_requested += 1
|
167
|
+
@not_empty.signal
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# If there are dead threads in the pool make them go away while decreasing
|
173
|
+
# spawned counter so that new healthy threads could be created again.
|
174
|
+
def reap
|
175
|
+
@mutex.synchronize do
|
176
|
+
dead_workers = @workers.reject(&:alive?)
|
177
|
+
|
178
|
+
dead_workers.each do |worker|
|
179
|
+
worker.kill
|
180
|
+
@spawned -= 1
|
181
|
+
end
|
182
|
+
|
183
|
+
@workers -= dead_workers
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class AutoTrim
|
188
|
+
def initialize(pool, timeout)
|
189
|
+
@pool = pool
|
190
|
+
@timeout = timeout
|
191
|
+
@running = false
|
192
|
+
end
|
193
|
+
|
194
|
+
def start!
|
195
|
+
@running = true
|
196
|
+
|
197
|
+
@thread = Thread.new do
|
198
|
+
while @running
|
199
|
+
@pool.trim
|
200
|
+
sleep @timeout
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def stop
|
206
|
+
@running = false
|
207
|
+
@thread.wakeup
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def auto_trim!(timeout=5)
|
212
|
+
@auto_trim = AutoTrim.new(self, timeout)
|
213
|
+
@auto_trim.start!
|
214
|
+
end
|
215
|
+
|
216
|
+
class Reaper
|
217
|
+
def initialize(pool, timeout)
|
218
|
+
@pool = pool
|
219
|
+
@timeout = timeout
|
220
|
+
@running = false
|
221
|
+
end
|
222
|
+
|
223
|
+
def start!
|
224
|
+
@running = true
|
225
|
+
|
226
|
+
@thread = Thread.new do
|
227
|
+
while @running
|
228
|
+
@pool.reap
|
229
|
+
sleep @timeout
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def stop
|
235
|
+
@running = false
|
236
|
+
@thread.wakeup
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def auto_reap!(timeout=5)
|
241
|
+
@reaper = Reaper.new(self, timeout)
|
242
|
+
@reaper.start!
|
243
|
+
end
|
244
|
+
|
245
|
+
# Tell all threads in the pool to exit and wait for them to finish.
|
246
|
+
#
|
247
|
+
def shutdown
|
248
|
+
threads = @mutex.synchronize do
|
249
|
+
@shutdown = true
|
250
|
+
@not_empty.broadcast
|
251
|
+
@not_full.broadcast
|
252
|
+
|
253
|
+
@auto_trim.stop if @auto_trim
|
254
|
+
@reaper.stop if @reaper
|
255
|
+
# dup workers so that we join them all safely
|
256
|
+
@workers.dup
|
257
|
+
end
|
258
|
+
|
259
|
+
threads.each(&:join)
|
260
|
+
|
261
|
+
@spawned = 0
|
262
|
+
@workers = []
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
data/lib/bettercap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bettercap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Margaritelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/bettercap/factories/spoofer_factory.rb
|
99
99
|
- lib/bettercap/firewalls/linux.rb
|
100
100
|
- lib/bettercap/firewalls/osx.rb
|
101
|
+
- lib/bettercap/firewalls/redirection.rb
|
101
102
|
- lib/bettercap/httpd/server.rb
|
102
103
|
- lib/bettercap/hw-prefixes
|
103
104
|
- lib/bettercap/logger.rb
|
@@ -108,6 +109,9 @@ files:
|
|
108
109
|
- lib/bettercap/proxy/proxy.rb
|
109
110
|
- lib/bettercap/proxy/request.rb
|
110
111
|
- lib/bettercap/proxy/response.rb
|
112
|
+
- lib/bettercap/proxy/stream_logger.rb
|
113
|
+
- lib/bettercap/proxy/streamer.rb
|
114
|
+
- lib/bettercap/proxy/thread_pool.rb
|
111
115
|
- lib/bettercap/shell.rb
|
112
116
|
- lib/bettercap/sniffer/parsers/base.rb
|
113
117
|
- lib/bettercap/sniffer/parsers/ftp.rb
|
@@ -154,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
158
|
requirements:
|
155
159
|
- - '>='
|
156
160
|
- !ruby/object:Gem::Version
|
157
|
-
version: '
|
161
|
+
version: '1.9'
|
158
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
163
|
requirements:
|
160
164
|
- - '>='
|