Skip to content

Commit da49709

Browse files
committed
Add yarddoc
1 parent 8e22255 commit da49709

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

lib/msf/core/post/windows/mssql.rb

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ module Msf
77
class Post
88
module Windows
99
module MSSQL
10+
11+
# @return [String, nil] contains the identified SQL command line client
1012
attr_accessor :sql_client
1113

1214
include Msf::Exploit::Remote::MSSQL_COMMANDS
1315
include Msf::Post::Windows::Services
1416
include Msf::Post::Windows::Priv
1517

18+
# Identifies the Windows Service matching the SQL Server instance name
19+
#
20+
# @param [String] instance the SQL Server instance name to locate
21+
# @return [Hash, nil] the Windows Service instance
1622
def check_for_sqlserver(instance = nil)
1723
target_service = nil
1824
each_service do |service|
@@ -39,6 +45,11 @@ def check_for_sqlserver(instance = nil)
3945
target_service
4046
end
4147

48+
# Identifies a valid SQL Server command line client on the host and sets
49+
# @sql_client
50+
#
51+
# @see #sql_client
52+
# @return [String, nil] the SQL command line client
4253
def get_sql_client
4354
client = nil
4455

@@ -52,12 +63,18 @@ def get_sql_client
5263
client
5364
end
5465

66+
# Attempts to run the osql command line tool
67+
#
68+
# @return [Boolean] true if osql is present
5569
def check_osql
5670
running_services1 = run_cmd("osql -?")
5771
services_array1 = running_services1.split("\n")
5872
services_array1.join =~ /(SQL Server Command Line Tool)|(usage: osql)/i
5973
end
6074

75+
# Attempts to run the sqlcmd command line tool
76+
#
77+
# @return [Boolean] true if sqlcmd is present
6178
def check_sqlcmd
6279
running_services = run_cmd("sqlcmd -?")
6380
services_array = running_services.split("\n")
@@ -66,6 +83,12 @@ def check_sqlcmd
6683
end
6784
end
6885

86+
# Runs a SQL query using the identified command line tool
87+
#
88+
# @param [String] query the query to execute
89+
# @param [String] instance the SQL instance to target
90+
# @param [String] server the SQL server to target
91+
# @return [String] the result of query
6992
def run_sql(query, instance = nil, server = '.')
7093
target = server
7194
if instance && instance.downcase != 'mssqlserver'
@@ -76,13 +99,15 @@ def run_sql(query, instance = nil, server = '.')
7699
run_cmd(cmd)
77100
end
78101

79-
## ----------------------------------------------
80-
## Method for executing cmd and returning the response
81-
##
82-
## Note: This may fail as SYSTEM if the current process
83-
## doesn't have sufficient privileges to duplicate a token,
84-
## e.g. SeAssignPrimaryToken
85-
##----------------------------------------------
102+
# Executes a hidden command
103+
#
104+
# @param [String] cmd the command line to execute
105+
# @param [Boolean] token use the current thread token
106+
# @return [String] the results from the command
107+
#
108+
# @note This may fail as SYSTEM if the current process
109+
# doesn't have sufficient privileges to duplicate a token,
110+
# e.g. SeAssignPrimaryToken
86111
def run_cmd(cmd, token = true)
87112
opts = { 'Hidden' => true, 'Channelized' => true, 'UseThreadToken' => token }
88113
process = session.sys.process.execute("cmd.exe /c #{cmd}", nil, opts)
@@ -97,6 +122,15 @@ def run_cmd(cmd, token = true)
97122
res
98123
end
99124

125+
# Attempts to impersonate the user of the supplied service
126+
# If the process has the appropriate privileges it will attempt to
127+
# steal a token to impersonate, otherwise it will attempt to migrate
128+
# into the service process.
129+
#
130+
# @note This may cause the meterpreter session to migrate!
131+
#
132+
# @param [Hash] service the service to target
133+
# @return [Boolean] true if impersonated successfully
100134
def impersonate_sql_user(service)
101135
pid = service[:pid]
102136
vprint_status("Current user: #{session.sys.config.getuid}")
@@ -140,11 +174,15 @@ def impersonate_sql_user(service)
140174
true
141175
end
142176

177+
# Attempts to escalate the meterpreter session to SYSTEM
178+
#
179+
# @return [Boolean] true if escalated successfully or user is already SYSTEM
143180
def get_system
144181
print_status("Checking if user is SYSTEM...")
145182

146183
if is_system?
147184
print_good("User is SYSTEM")
185+
return true
148186
else
149187
# Attempt to get LocalSystem privileges
150188
print_warning("Attempting to get SYSTEM privileges...")

0 commit comments

Comments
 (0)