Skip to content

Commit 69043d5

Browse files
committed
Merge branch 'master' into feature/MSP-11147/thread-leak-detection
MSP-11147
2 parents 44f78c2 + e05cd95 commit 69043d5

File tree

100 files changed

+3723
-1806
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+3723
-1806
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Gemfile.local.lock
77
.sublime-project
88
# RVM control file, keep this to avoid backdooring Metasploit
99
.rvmrc
10+
# Allow for a local choice of (unsupported / semi-supported) ruby versions
11+
# See PR #4136 for usage, but example usage for rvm:
12+
# rvm --create --versions-conf use 2.1.4@metasploit-framework
13+
# Because rbenv doesn't use .versions.conf, to achieve this same functionality, run:
14+
# rbenv shell 2.1.4
15+
.versions.conf
1016
# YARD cache directory
1117
.yardoc
1218
# Mac OS X files

.rubocop.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# inherit_from: .rubocop_todo.yml
1010

11-
Style/ClassLength:
11+
Metrics/ClassLength:
1212
Description: 'Most Metasploit modules are quite large. This is ok.'
1313
Enabled: true
1414
Exclude:
@@ -25,14 +25,14 @@ Style/Encoding:
2525
Description: 'We prefer binary to UTF-8.'
2626
EnforcedStyle: 'when_needed'
2727

28-
Style/LineLength:
28+
Metrics/LineLength:
2929
Description: >-
3030
Metasploit modules often pattern match against very
3131
long strings when identifying targets.
3232
Enabled: true
3333
Max: 180
3434

35-
Style/MethodLength:
35+
Metrics/MethodLength:
3636
Enabled: true
3737
Description: >-
3838
While the style guide suggests 10 lines, exploit definitions
@@ -44,6 +44,11 @@ Style/MethodLength:
4444
Style/Encoding:
4545
Enabled: false
4646

47+
# %q() is super useful for long strings split over multiple lines and
48+
# is very common in module constructors for things like descriptions
49+
Style/UnneededPercentQ:
50+
Enabled: false
51+
4752
Style/NumericLiterals:
4853
Enabled: false
4954
Description: 'This often hurts readability for exploit-ish code.'

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
# Next Release
4+
* Enhancements
5+
* [#4045](https://github.com/rapid7/metasploit-framework/pull/4045): Reorganize Msf::Module into submodule of related methods to reduce file size and allow for easier understanding of functionality - [@limhoff-r7](https://github.com/limhoff-r7)
6+
* Bug Fixes
7+
* Deprecations
8+
* Incompatible Changes

Gemfile

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
source 'https://rubygems.org'
22
# Add default group gems to `metasploit-framework.gemspec`:
33
# spec.add_runtime_dependency '<name>', [<version requirements>]
4-
gemspec
5-
6-
gem 'rb-readline', require: false
4+
gemspec name: 'metasploit-framework'
75

86
group :db do
9-
# Needed for Msf::DbManager
10-
gem 'activerecord', '>= 3.0.0', '< 4.0.0'
11-
12-
# Metasploit::Credential database models
13-
gem 'metasploit-credential', '~> 0.12.0'
14-
# Database models shared between framework and Pro.
15-
gem 'metasploit_data_models', '~> 0.21.1'
16-
# Needed for module caching in Mdm::ModuleDetails
17-
gem 'pg', '>= 0.11'
7+
gemspec name: 'metasploit-framework-db'
188
end
199

2010
group :development do
@@ -45,9 +35,7 @@ group :development, :test do
4535
end
4636

4737
group :pcap do
48-
gem 'network_interface', '~> 0.0.1'
49-
# For sniffer and raw socket modules
50-
gem 'pcaprub'
38+
gemspec name: 'metasploit-framework-pcap'
5139
end
5240

5341
group :test do

Gemfile.lock

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ PATH
2020
rubyzip (~> 1.1)
2121
sqlite3
2222
tzinfo
23+
metasploit-framework-db (4.10.1.pre.dev)
24+
activerecord (< 4.0.0)
25+
metasploit-credential (~> 0.13.0)
26+
metasploit-framework (= 4.10.1.pre.dev)
27+
metasploit_data_models (~> 0.21.1)
28+
pg (>= 0.11)
29+
metasploit-framework-pcap (4.10.1.pre.dev)
30+
metasploit-framework (= 4.10.1.pre.dev)
31+
network_interface (~> 0.0.1)
32+
pcaprub
2333

2434
GEM
2535
remote: https://rubygems.org/
@@ -102,7 +112,7 @@ GEM
102112
metasploit-concern (0.3.0)
103113
activesupport (~> 3.0, >= 3.0.0)
104114
railties (< 4.0.0)
105-
metasploit-credential (0.12.0)
115+
metasploit-credential (0.13.2)
106116
metasploit-concern (~> 0.3.0)
107117
metasploit-model (~> 0.28.0)
108118
metasploit_data_models (~> 0.21.0)
@@ -125,12 +135,12 @@ GEM
125135
meterpreter_bins (0.0.10)
126136
method_source (0.8.2)
127137
mime-types (1.25.1)
128-
mini_portile (0.6.0)
138+
mini_portile (0.6.1)
129139
msgpack (0.5.9)
130140
multi_json (1.0.4)
131141
network_interface (0.0.1)
132-
nokogiri (1.6.3.1)
133-
mini_portile (= 0.6.0)
142+
nokogiri (1.6.4.1)
143+
mini_portile (~> 0.6.0)
134144
packetfu (1.1.9)
135145
pcaprub (0.11.3)
136146
pg (0.17.1)
@@ -165,7 +175,7 @@ GEM
165175
rb-readline (0.5.1)
166176
rdoc (3.12.2)
167177
json (~> 1.4)
168-
recog (1.0.0)
178+
recog (1.0.5)
169179
nokogiri
170180
redcarpet (3.1.2)
171181
rkelly-remix (0.0.6)
@@ -197,7 +207,7 @@ GEM
197207
simplecov-html (~> 0.5.3)
198208
simplecov-html (0.5.3)
199209
slop (3.6.0)
200-
sprockets (2.2.2)
210+
sprockets (2.2.3)
201211
hike (~> 1.2)
202212
multi_json (~> 1.0)
203213
rack (~> 1.0)
@@ -209,7 +219,7 @@ GEM
209219
treetop (1.4.15)
210220
polyglot
211221
polyglot (>= 0.3.1)
212-
tzinfo (0.3.41)
222+
tzinfo (0.3.42)
213223
xpath (2.0.0)
214224
nokogiri (~> 1.3)
215225
yard (0.8.7.4)
@@ -218,21 +228,16 @@ PLATFORMS
218228
ruby
219229

220230
DEPENDENCIES
221-
activerecord (>= 3.0.0, < 4.0.0)
222231
aruba
223232
cucumber-rails
224233
factory_girl (>= 4.1.0)
225234
factory_girl_rails
226235
fivemat (= 1.2.1)
227-
metasploit-credential (~> 0.12.0)
228236
metasploit-framework!
229-
metasploit_data_models (~> 0.21.1)
230-
network_interface (~> 0.0.1)
231-
pcaprub
232-
pg (>= 0.11)
237+
metasploit-framework-db!
238+
metasploit-framework-pcap!
233239
pry
234240
rake (>= 10.0.0)
235-
rb-readline
236241
redcarpet
237242
rspec (>= 2.12, < 3.0.0)
238243
rspec-rails (>= 2.12, < 3.0.0)
618 Bytes
Binary file not shown.

data/logos/metasploit-trail.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%clr
2+
%mag .~+P``````-o+:. -o+:.%clr
3+
%mag.+oooyysyyssyyssyddh++os-````` ``````````````` `%clr
4+
%mag+++++++++++++++++++++++sydhyoyso/:.````...`...-///::+ohhyosyyosyy/+om++:ooo///o%clr
5+
%mag++++///////~~~~///////++++++++++++++++ooyysoyysosso+++++++++++++++++++///oossosy%clr
6+
%mag--.` .-.-...-////+++++++++++++++////////~~//////++++++++++++///%clr
7+
%mag `...............` `...-/////...`%clr
8+
%clr
9+
%clr
10+
%whi .::::::::::-. .::::::-%clr
11+
%whi .hmMMMMMMMMMMNddds\...//M\\.../hddddmMMMMMMNo%clr
12+
%whi :Nm-/NMMMMMMMMMMMMM%blu$$%whiNMMMMm%blu&&%whiMMMMMMMMMMMMMMy%clr
13+
%whi .sm/`-yMMMMMMMMMMMM%blu$$%whiMMMMMN%blu&&%whiMMMMMMMMMMMMMh`%clr
14+
%whi -Nd` :MMMMMMMMMMM%blu$$%whiMMMMMN%blu&&%whiMMMMMMMMMMMMh`%clr
15+
%whi -Nh` .yMMMMMMMMMM%blu$$%whiMMMMMN%blu&&%whiMMMMMMMMMMMm/%clr
16+
%whi `oo/``-hd: `` .sNd :MMMMMMMMMM%blu$$%whiMMMMMN%blu&&%whiMMMMMMMMMMm/%clr
17+
%whi .yNmMMh%dred//%whi+syysso-`````` -mh` :MMMMMMMMMM%blu$$%whiMMMMMN%blu&&%whiMMMMMMMMMMd%clr
18+
%whi .shMMMMN%dred//%whidmNMMMMMMMMMMMMs` `:```-o++++oooo+:/ooooo+:+o+++oooo++/%clr
19+
%whi `///omh%dred//%whidMMMMMMMMMMMMMMMN/%dred:::::/+ooso--/ydh//+s+/ossssso:--syN///os:%clr
20+
%whi /MMMMMMMMMMMMMMMMMMd. %dred`/++-.-yy/%whi...%dredosydh/-+oo:-`o//%whi...%dredoyodh+%clr
21+
%whi -hMMmssddd+:dMMmNMMh. %dred`.-=mmk.%whi//^^^\\%dred.^^`:++:^^o:%whi//^^^\\%dred`::%clr
22+
%whi .sMMmo. -dMd--:mN/` %whi||--X--||%clr %dred%whi||--X--||%clr
23+
%whi........../yddy/:...+hmo-...hdd:............%whi\\=v=//%clr............%dred%whi\\=v=//%clr.........
24+
%grn================================================================================%clr
25+
%grn=====================%whi+--------------------------------+%grn=========================%clr
26+
%grn=====================%whi| Session one died of dysentery. |%grn=========================%clr
27+
%grn=====================%whi+--------------------------------+%grn=========================%clr
28+
%grn================================================================================%clr
29+
%clr
30+
%clr %grnPress ENTER to size up the situation%clr
31+
%clr
32+
%whi%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clr
33+
%whi%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Date: April 25, 1848 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clr
34+
%whi%%%%%%%%%%%%%%%%%%%%%%%%%% Weather: It's always cool in the lab %%%%%%%%%%%%%%%%%clr
35+
%whi%%%%%%%%%%%%%%%%%%%%%%%%%%% Health: Overweight %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clr
36+
%whi%%%%%%%%%%%%%%%%%%%%%%%%% Caffeine: 12975 mg %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clr
37+
%whi%%%%%%%%%%%%%%%%%%%%%%%%%%% Hacked: All the things %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clr
38+
%whi%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clr
39+
%clr
40+
%clr %whiPress SPACE BAR to continue%clr
41+
%clr

data/meterpreter/ext_server_stdapi.py

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ class SYSTEM_INFO(ctypes.Structure):
215215
("wProcessorLevel", ctypes.c_uint16),
216216
("wProcessorRevision", ctypes.c_uint16)]
217217

218+
class TOKEN_USER(ctypes.Structure):
219+
_fields_ = [("User", SID_AND_ATTRIBUTES)]
220+
218221
#
219222
# Linux Structures
220223
#
@@ -364,6 +367,7 @@ class RTATTR(ctypes.Structure):
364367
TLV_TYPE_OS_NAME = TLV_META_TYPE_STRING | 1041
365368
TLV_TYPE_USER_NAME = TLV_META_TYPE_STRING | 1042
366369
TLV_TYPE_ARCHITECTURE = TLV_META_TYPE_STRING | 1043
370+
TLV_TYPE_SID = TLV_META_TYPE_STRING | 1045
367371

368372
##
369373
# Environment
@@ -525,6 +529,36 @@ def get_stat_buffer(path):
525529
st_buf += struct.pack('<II', blksize, blocks)
526530
return st_buf
527531

532+
def get_token_user(handle):
533+
TOKEN_QUERY = 0x0008
534+
TokenUser = 1
535+
advapi32 = ctypes.windll.advapi32
536+
advapi32.OpenProcessToken.argtypes = [ctypes.c_void_p, ctypes.c_uint32, ctypes.POINTER(ctypes.c_void_p)]
537+
538+
token_handle = ctypes.c_void_p()
539+
if not advapi32.OpenProcessToken(handle, TOKEN_QUERY, ctypes.byref(token_handle)):
540+
return None
541+
token_user_buffer = (ctypes.c_byte * 4096)()
542+
dw_returned = ctypes.c_uint32()
543+
result = advapi32.GetTokenInformation(token_handle, TokenUser, ctypes.byref(token_user_buffer), ctypes.sizeof(token_user_buffer), ctypes.byref(dw_returned))
544+
ctypes.windll.kernel32.CloseHandle(token_handle)
545+
if not result:
546+
return None
547+
return cstruct_unpack(TOKEN_USER, token_user_buffer)
548+
549+
def get_username_from_token(token_user):
550+
user = (ctypes.c_char * 512)()
551+
domain = (ctypes.c_char * 512)()
552+
user_len = ctypes.c_uint32()
553+
user_len.value = ctypes.sizeof(user)
554+
domain_len = ctypes.c_uint32()
555+
domain_len.value = ctypes.sizeof(domain)
556+
use = ctypes.c_ulong()
557+
use.value = 0
558+
if not ctypes.windll.advapi32.LookupAccountSidA(None, token_user.User.Sid, user, ctypes.byref(user_len), domain, ctypes.byref(domain_len), ctypes.byref(use)):
559+
return None
560+
return str(ctypes.string_at(domain)) + '\\' + str(ctypes.string_at(user))
561+
528562
def netlink_request(req_type):
529563
import select
530564
# See RFC 3549
@@ -632,11 +666,6 @@ def channel_open_stdapi_net_tcp_server(request, response):
632666
response += tlv_pack(TLV_TYPE_CHANNEL_ID, channel_id)
633667
return ERROR_SUCCESS, response
634668

635-
@meterpreter.register_function
636-
def stdapi_sys_config_getuid(request, response):
637-
response += tlv_pack(TLV_TYPE_USER_NAME, getpass.getuser())
638-
return ERROR_SUCCESS, response
639-
640669
@meterpreter.register_function
641670
def stdapi_sys_config_getenv(request, response):
642671
for env_var in packet_enum_tlvs(request, TLV_TYPE_ENV_VARIABLE):
@@ -649,6 +678,32 @@ def stdapi_sys_config_getenv(request, response):
649678
response += tlv_pack(TLV_TYPE_ENV_GROUP, pgroup)
650679
return ERROR_SUCCESS, response
651680

681+
@meterpreter.register_function_windll
682+
def stdapi_sys_config_getsid(request, response):
683+
token = get_token_user(ctypes.windll.kernel32.GetCurrentProcess())
684+
if not token:
685+
return ERROR_FAILURE, response
686+
sid_str = ctypes.c_char_p()
687+
if not ctypes.windll.advapi32.ConvertSidToStringSidA(token.User.Sid, ctypes.byref(sid_str)):
688+
return ERROR_FAILURE, response
689+
sid_str = str(ctypes.string_at(sid_str))
690+
response += tlv_pack(TLV_TYPE_SID, sid_str)
691+
return ERROR_SUCCESS, response
692+
693+
@meterpreter.register_function
694+
def stdapi_sys_config_getuid(request, response):
695+
if has_windll:
696+
token = get_token_user(ctypes.windll.kernel32.GetCurrentProcess())
697+
if not token:
698+
return ERROR_FAILURE, response
699+
username = get_username_from_token(token)
700+
if not username:
701+
return ERROR_FAILURE, response
702+
else:
703+
username = getpass.getuser()
704+
response += tlv_pack(TLV_TYPE_USER_NAME, username)
705+
return ERROR_SUCCESS, response
706+
652707
@meterpreter.register_function
653708
def stdapi_sys_config_sysinfo(request, response):
654709
uname_info = platform.uname()
@@ -821,26 +876,10 @@ def stdapi_sys_process_get_processes_via_windll(request, response):
821876
exe_path = ctypes.string_at(exe_path)
822877
else:
823878
exe_path = ''
824-
complete_username = ''
825-
tkn_h = ctypes.c_long()
826-
tkn_len = ctypes.c_uint32()
827-
if ctypes.windll.advapi32.OpenProcessToken(proc_h, TOKEN_QUERY, ctypes.byref(tkn_h)):
828-
ctypes.windll.advapi32.GetTokenInformation(tkn_h, TokenUser, None, 0, ctypes.byref(tkn_len))
829-
buf = (ctypes.c_ubyte * tkn_len.value)()
830-
if ctypes.windll.advapi32.GetTokenInformation(tkn_h, TokenUser, ctypes.byref(buf), ctypes.sizeof(buf), ctypes.byref(tkn_len)):
831-
user_tkn = SID_AND_ATTRIBUTES()
832-
ctypes.memmove(ctypes.byref(user_tkn), buf, ctypes.sizeof(user_tkn))
833-
username = (ctypes.c_char * 512)()
834-
domain = (ctypes.c_char * 512)()
835-
u_len = ctypes.c_uint32()
836-
u_len.value = ctypes.sizeof(username)
837-
d_len = ctypes.c_uint32()
838-
d_len.value = ctypes.sizeof(domain)
839-
use = ctypes.c_ulong()
840-
use.value = 0
841-
ctypes.windll.advapi32.LookupAccountSidA(None, user_tkn.Sid, username, ctypes.byref(u_len), domain, ctypes.byref(d_len), ctypes.byref(use))
842-
complete_username = str(ctypes.string_at(domain)) + '\\' + str(ctypes.string_at(username))
843-
k32.CloseHandle(tkn_h)
879+
process_username = ''
880+
process_token_user = get_token_user(proc_h)
881+
if process_token_user:
882+
process_username = get_username_from_token(process_token_user) or ''
844883
parch = windll_GetNativeSystemInfo()
845884
is_wow64 = ctypes.c_ubyte()
846885
is_wow64.value = 0
@@ -851,7 +890,7 @@ def stdapi_sys_process_get_processes_via_windll(request, response):
851890
pgroup = bytes()
852891
pgroup += tlv_pack(TLV_TYPE_PID, pe32.th32ProcessID)
853892
pgroup += tlv_pack(TLV_TYPE_PARENT_PID, pe32.th32ParentProcessID)
854-
pgroup += tlv_pack(TLV_TYPE_USER_NAME, complete_username)
893+
pgroup += tlv_pack(TLV_TYPE_USER_NAME, process_username)
855894
pgroup += tlv_pack(TLV_TYPE_PROCESS_NAME, pe32.szExeFile)
856895
pgroup += tlv_pack(TLV_TYPE_PROCESS_PATH, exe_path)
857896
pgroup += tlv_pack(TLV_TYPE_PROCESS_ARCH, parch)

lib/metasploit/framework/require.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,18 @@ def self.optionally_include_metasploit_credential_creation(including_module)
8080
# @return [void]
8181
def self.optionally_require_metasploit_db_gem_engines
8282
optionally(
83-
'metasploit/credential/engine',
84-
'metasploit-credential not in the bundle',
85-
)
83+
'metasploit/credential',
84+
'metasploit-credential not in the bundle',
85+
) do
86+
require 'metasploit/credential/engine'
87+
end
88+
8689
optionally(
87-
'metasploit_data_models/engine',
88-
'metaspoit_data_models not in the bundle'
89-
)
90+
'metasploit_data_models',
91+
'metasploit_data_models not in the bundle'
92+
) do
93+
require 'metasploit_data_models/engine'
94+
end
9095
end
9196

9297
#

0 commit comments

Comments
 (0)