Skip to content

Commit c937982

Browse files
David MaloneyDavid Maloney
authored andcommitted
Merge branch 'master' into bug/MSP-11592/blank-password-failure
2 parents bf1558d + 758fee6 commit c937982

File tree

14 files changed

+817
-52
lines changed

14 files changed

+817
-52
lines changed

.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.'

Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PATH
2222
tzinfo
2323
metasploit-framework-db (4.10.1.pre.dev)
2424
activerecord (< 4.0.0)
25-
metasploit-credential (~> 0.13.0)
25+
metasploit-credential (~> 0.12.0)
2626
metasploit-framework (= 4.10.1.pre.dev)
2727
metasploit_data_models (~> 0.21.1)
2828
pg (>= 0.11)
@@ -112,7 +112,7 @@ GEM
112112
metasploit-concern (0.3.0)
113113
activesupport (~> 3.0, >= 3.0.0)
114114
railties (< 4.0.0)
115-
metasploit-credential (0.13.1)
115+
metasploit-credential (0.12.0)
116116
metasploit-concern (~> 0.3.0)
117117
metasploit-model (~> 0.28.0)
118118
metasploit_data_models (~> 0.21.0)
@@ -135,12 +135,12 @@ GEM
135135
meterpreter_bins (0.0.10)
136136
method_source (0.8.2)
137137
mime-types (1.25.1)
138-
mini_portile (0.6.1)
138+
mini_portile (0.6.0)
139139
msgpack (0.5.9)
140140
multi_json (1.0.4)
141141
network_interface (0.0.1)
142-
nokogiri (1.6.4.1)
143-
mini_portile (~> 0.6.0)
142+
nokogiri (1.6.3.1)
143+
mini_portile (= 0.6.0)
144144
packetfu (1.1.9)
145145
pcaprub (0.11.3)
146146
pg (0.17.1)
@@ -175,7 +175,7 @@ GEM
175175
rb-readline (0.5.1)
176176
rdoc (3.12.2)
177177
json (~> 1.4)
178-
recog (1.0.5)
178+
recog (1.0.0)
179179
nokogiri
180180
redcarpet (3.1.2)
181181
rkelly-remix (0.0.6)
@@ -207,7 +207,7 @@ GEM
207207
simplecov-html (~> 0.5.3)
208208
simplecov-html (0.5.3)
209209
slop (3.6.0)
210-
sprockets (2.2.3)
210+
sprockets (2.2.2)
211211
hike (~> 1.2)
212212
multi_json (~> 1.0)
213213
rack (~> 1.0)
@@ -219,7 +219,7 @@ GEM
219219
treetop (1.4.15)
220220
polyglot
221221
polyglot (>= 0.3.1)
222-
tzinfo (0.3.42)
222+
tzinfo (0.3.41)
223223
xpath (2.0.0)
224224
nokogiri (~> 1.3)
225225
yard (0.8.7.4)

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/msf/core/auxiliary/scanner.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ def run
5959
@tl = []
6060

6161
#
62-
# Sanity check threading on different platforms
62+
# Sanity check threading given different conditions
6363
#
6464

65+
if datastore['CPORT'].to_i != 0 && threads_max > 1
66+
print_error("Warning: A maximum of one thread is possible when a source port is set (CPORT)")
67+
print_error("Thread count has been adjusted to 1")
68+
threads_max = 1
69+
end
70+
6571
if(Rex::Compat.is_windows)
6672
if(threads_max > 16)
6773
print_error("Warning: The Windows platform cannot reliably support more than 16 threads")
@@ -241,10 +247,10 @@ def scanner_progress
241247

242248
def scanner_show_progress
243249
pct = scanner_progress
244-
if(pct >= (@range_percent + @show_percent))
250+
if pct >= (@range_percent + @show_percent)
245251
@range_percent = @range_percent + @show_percent
246252
tdlen = @range_count.to_s.length
247-
print_status("Scanned #{"%.#{tdlen}d" % @range_done} of #{@range_count} hosts (#{"%.3d" % pct.to_i}% complete)")
253+
print_status(sprintf("Scanned %#{tdlen}d of %d hosts (%d%% complete)", @range_done, @range_count, pct))
248254
end
249255
end
250256

0 commit comments

Comments
 (0)