Skip to content

Commit 55ed184

Browse files
committed
Land rapid7#5646 : Make getsystem more verbose
2 parents a37ac1b + a17b27e commit 55ed184

File tree

1 file changed

+49
-15
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/priv

1 file changed

+49
-15
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ class Console::CommandDispatcher::Priv::Elevate
1717

1818
include Console::CommandDispatcher
1919

20-
ELEVATE_TECHNIQUE_NONE = -1
21-
ELEVATE_TECHNIQUE_ANY = 0
22-
ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE = 1
23-
ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2 = 2
24-
ELEVATE_TECHNIQUE_SERVICE_TOKENDUP = 3
25-
26-
ELEVATE_TECHNIQUE_DESCRIPTION = [ "All techniques available",
27-
"Service - Named Pipe Impersonation (In Memory/Admin)",
28-
"Service - Named Pipe Impersonation (Dropper/Admin)",
29-
"Service - Token Duplication (In Memory/Admin)"
30-
]
20+
ELEVATE_TECHNIQUE_NONE = -1
21+
ELEVATE_TECHNIQUE_ANY = 0
22+
ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE = 1
23+
ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2 = 2
24+
ELEVATE_TECHNIQUE_SERVICE_TOKENDUP = 3
25+
26+
ELEVATE_TECHNIQUE_DESCRIPTION =
27+
[
28+
"All techniques available",
29+
"Named Pipe Impersonation (In Memory/Admin)",
30+
"Named Pipe Impersonation (Dropper/Admin)",
31+
"Token Duplication (In Memory/Admin)"
32+
]
33+
3134
#
3235
# List of supported commands.
3336
#
@@ -45,6 +48,25 @@ def name
4548
end
4649

4750

51+
#
52+
# Returns the description of the technique(s)
53+
#
54+
def translate_technique_index(index)
55+
translation = ''
56+
57+
case index
58+
when 0
59+
desc = ELEVATE_TECHNIQUE_DESCRIPTION.dup
60+
desc.shift
61+
translation = desc
62+
else
63+
translation = [ ELEVATE_TECHNIQUE_DESCRIPTION[index] ]
64+
end
65+
66+
translation
67+
end
68+
69+
4870
#
4971
# Attempt to elevate the meterpreter to that of local system.
5072
#
@@ -73,17 +95,29 @@ def cmd_getsystem( *args )
7395
}
7496

7597
if( technique < 0 or technique >= ELEVATE_TECHNIQUE_DESCRIPTION.length )
76-
print_error( "Technique '#{technique}' is out of range." );
98+
print_error( "Technique '#{technique}' is out of range." )
7799
return false;
78100
end
79101

80-
result = client.priv.getsystem( technique )
102+
begin
103+
result = client.priv.getsystem( technique )
104+
rescue Rex::Post::Meterpreter::RequestError => e
105+
print_error("#{e.message} The following was attempted:")
106+
translate_technique_index(technique).each do |desc|
107+
print_error(desc)
108+
end
109+
elog("#{e.class} #{e.message} (Technique: #{technique})\n#{e.backtrace * "\n"}")
110+
return
111+
end
81112

82113
# got system?
83114
if result[0]
84-
print_line( "...got system (via technique #{result[1]})." );
115+
print_line( "...got system via technique #{result[1]} (#{translate_technique_index(result[1]).first})." )
85116
else
86-
print_line( "...failed to get system." );
117+
print_line( "...failed to get system while attempting the following:" )
118+
translate_technique_index(technique).each do |desc|
119+
print_error(desc)
120+
end
87121
end
88122

89123
return result

0 commit comments

Comments
 (0)