Skip to content

Commit 27323bc

Browse files
committed
Fix rapid7#3852, make enable_rdp with other languages
1 parent 488f46c commit 27323bc

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

modules/post/windows/manage/enable_rdp.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,21 @@ def addrdpusr(username, password,cleanup_rc)
116116
print_status "Setting user account for logon"
117117
print_status "\tAdding User: #{username} with Password: #{password}"
118118
begin
119+
if check_user(username)
120+
print_error("\tThe user #{username} already exists")
121+
return
122+
end
123+
124+
user_added = false
119125
addusr_out = cmd_exec("cmd.exe", "/c net user #{username} #{password} /add")
126+
120127
if addusr_out =~ /success/i
128+
user_added = true
129+
elsif check_user(username)
130+
user_added = true
131+
end
132+
133+
if user_added
121134
file_local_write(cleanup_rc,"execute -H -f cmd.exe -a \"/c net user #{username} /delete\"")
122135
print_status "\tAdding User: #{username} to local group '#{rdu}'"
123136
cmd_exec("cmd.exe","/c net localgroup \"#{rdu}\" #{username} /add")
@@ -136,8 +149,17 @@ def addrdpusr(username, password,cleanup_rc)
136149
print_error("\t#{l.chomp}")
137150
end
138151
end
139-
rescue::Exception => e
152+
rescue ::Exception => e
140153
print_status("The following Error was encountered: #{e.class} #{e}")
141154
end
142155
end
156+
157+
def check_user(user)
158+
output = cmd_exec('cmd.exe', '/c net user')
159+
if output.include?(user)
160+
return true
161+
end
162+
163+
false
164+
end
143165
end

0 commit comments

Comments
 (0)