Skip to content

Commit 03a988b

Browse files
committed
Land rapid7#4150, adds getsid command
Fixes rapid7#3787
2 parents 88810ce + eb830cb commit 03a988b

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module Sys
2020
###
2121
class Config
2222

23+
SYSTEM_SID = 'S-1-5-18'
24+
2325
def initialize(client)
2426
self.client = client
2527
end
@@ -33,6 +35,22 @@ def getuid
3335
client.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_USER_NAME) )
3436
end
3537

38+
#
39+
# Gets the SID of the current process/thread.
40+
#
41+
def getsid
42+
request = Packet.create_request('stdapi_sys_config_getsid')
43+
response = client.send_request(request)
44+
response.get_tlv_value(TLV_TYPE_SID)
45+
end
46+
47+
#
48+
# Determine if the current process/thread is running as SYSTEM
49+
#
50+
def is_system?
51+
getsid == SYSTEM_SID
52+
end
53+
3654
#
3755
# Returns a hash of requested environment variables, along with their values.
3856
# If a requested value doesn't exist in the response, then the value wasn't found.

lib/rex/post/meterpreter/extensions/stdapi/tlv.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ module Stdapi
116116
TLV_TYPE_USER_NAME = TLV_META_TYPE_STRING | 1042
117117
TLV_TYPE_ARCHITECTURE = TLV_META_TYPE_STRING | 1043
118118
TLV_TYPE_LANG_SYSTEM = TLV_META_TYPE_STRING | 1044
119+
TLV_TYPE_SID = TLV_META_TYPE_STRING | 1045
119120

120121
# Environment
121122
TLV_TYPE_ENV_VARIABLE = TLV_META_TYPE_STRING | 1100

lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def cmd_snarf_hashes(*args)
221221
end
222222

223223
def system_privilege_check
224-
if (client.sys.config.getuid != "NT AUTHORITY\\SYSTEM")
224+
unless client.sys.config.is_system?
225225
print_line("[-] Warning: Not currently running as SYSTEM, not all tokens will be available")
226226
print_line(" Call rev2self if primary process token is SYSTEM")
227227
end

lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def commands
8888
"getpid" => "Get the current process identifier",
8989
"getprivs" => "Attempt to enable all privileges available to the current process",
9090
"getuid" => "Get the user that the server is running as",
91+
"getsid" => "Get the SID of the user that the server is running as",
9192
"getenv" => "Get one or more environment variable values",
9293
"kill" => "Terminate a process",
9394
"ps" => "List running processes",
@@ -107,6 +108,7 @@ def commands
107108
"getpid" => [ "stdapi_sys_process_getpid" ],
108109
"getprivs" => [ "stdapi_sys_config_getprivs" ],
109110
"getuid" => [ "stdapi_sys_config_getuid" ],
111+
"getsid" => [ "stdapi_sys_config_getsid" ],
110112
"getenv" => [ "stdapi_sys_config_getenv" ],
111113
"kill" => [ "stdapi_sys_process_kill" ],
112114
"ps" => [ "stdapi_sys_process_get_processes" ],
@@ -279,6 +281,13 @@ def cmd_getuid(*args)
279281
print_line("Server username: #{client.sys.config.getuid}")
280282
end
281283

284+
#
285+
# Display the SID of the user that the server is running as.
286+
#
287+
def cmd_getsid(*args)
288+
print_line("Server SID: #{client.sys.config.getsid}")
289+
end
290+
282291
#
283292
# Get the value of one or more environment variables from the target.
284293
#

0 commit comments

Comments
 (0)