Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/test/thirdparty/msf/unit/tc_metasploit.rb
1873 views
1
#
2
# Copyright (c) 2006-2026 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
require 'test/unit'
7
require 'pp'
8
9
class TC_Metasploit < Test::Unit::TestCase
10
11
def setup
12
$root_dir="../../../../"
13
$:.unshift File.join( %w{ ../../../../ } )
14
require 'core/loader'
15
end
16
17
def teardown
18
$root_dir = nil
19
end
20
21
#
22
# Test the api is functional
23
#
24
def test_requires
25
assert_nothing_raised do
26
require 'msfrpc-client'
27
end
28
end
29
30
#
31
# Load the config for testing
32
#
33
def load_config
34
BeEF::Core::Configuration.new("#{$root_dir}/config.yaml")
35
BeEF::Core::Configuration.instance.load_extensions_config
36
@config = BeEF::Core::Configuration.instance.get('beef.extension.metasploit')
37
end
38
39
# Create an api instance
40
def new_api
41
load_config
42
require 'extensions/metasploit/extension.rb'
43
@api = BeEF::Extension::Metasploit::RpcClient.instance
44
@api.unit_test_init()
45
end
46
47
#
48
# Verify that the config file has required information
49
#
50
def test_config
51
load_config
52
assert(@config.key?('user'))
53
assert(@config.key?('pass'))
54
assert(@config.key?('port'))
55
assert(@config.key?('uri'))
56
assert(@config.key?('callback_host'))
57
assert(@config.key?('autopwn_url'))
58
end
59
60
#
61
# Verify that we can create an API instance
62
#
63
def test_api_create
64
assert_nothing_raised do
65
new_api
66
end
67
end
68
69
#
70
# Verify that the login is working
71
#
72
def test_login
73
new_api
74
assert(@api.login)
75
end
76
77
def test_call
78
new_api
79
@api.login
80
assert(@api.call('core.version'))
81
end
82
83
def test_browser_exploits
84
new_api
85
@api.login
86
exploits = nil
87
assert_nothing_raised do
88
exploits = @api.browser_exploits()
89
end
90
assert(exploits.length > 5)
91
end
92
93
def test_exploit_info
94
new_api
95
@api.login
96
info = nil
97
assert_nothing_raised do
98
info = @api.get_exploit_info('windows/dcerpc/ms03_026_dcom')
99
end
100
assert( info['name'].nil? != true)
101
end
102
103
def test_get_options
104
new_api
105
@api.login
106
info = nil
107
assert_nothing_raised do
108
info = @api.get_options('windows/dcerpc/ms03_026_dcom')
109
end
110
assert( info['RHOST'].nil? != true)
111
end
112
113
def test_payloads
114
new_api
115
@api.login
116
payloads = nil
117
assert_nothing_raised do
118
payloads = @api.payloads
119
end
120
assert( payloads.length > 5 )
121
end
122
123
def test_launch_exploit
124
new_api
125
@api.login
126
opts = { 'PAYLOAD' => 'windows/meterpreter/bind_tcp', 'URIPATH' => '/test1','SRVPORT' => 8080}
127
ret = nil
128
assert_nothing_raised do
129
ret = @api.launch_exploit('windows/browser/adobe_utilprintf',opts)
130
end
131
assert(ret['job_id'] != nil )
132
end
133
134
def test_launch_autopwn
135
new_api
136
@api.login
137
ret = nil
138
assert_nothing_raised do
139
ret = @api.launch_autopwn
140
end
141
assert(ret['job_id'] != nil )
142
end
143
end
144
145