-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrdpprotocol
More file actions
228 lines (210 loc) · 7.14 KB
/
rdpprotocol
File metadata and controls
228 lines (210 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
97
98
99
100
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
145
146
147
148
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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
'
' vb script - 2013-09-04 - (c) 2013 walter muncaster
'
'
' title: Remote VBS bootstrapper
'
' comments: sets up local machine to download and execute remote desktop connection
'
' see syntax in unwind code below
'
' version: 2014-08-21 V2 - automatically default the prompts for trust this connection, bla, bla, bla
'
'
'
' get all user application data folder
'
Const ALL_USERS_APPLICATION_DATA = &H23&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ALL_USERS_APPLICATION_DATA)
Set objFolderItem = objFolder.Self
permanentbootfolder = objFolderItem.Path & "\Waldo"
'
' create a new protocol
'
Set wshShell = CreateObject( "WScript.Shell" )
wshShell.RegWrite "HKCR\rdp\",""
wshShell.RegWrite "HKCR\rdp\defaulticon\",""
wshShell.RegWrite "HKCR\rdp\shell\open\command\", ""
wshShell.RegWrite "HKCR\rdp\DefaultIcon\", "c:\windows\system32\wscript.exe", "REG_SZ"
wshShell.RegWrite "HKCR\rdp\shell\open\command\","wscript """ & permanentbootfolder & "\rdp.js"" ""%1""", "REG_SZ"
wshShell.RegWrite "HKCR\rdp\","URL:Remote VBS execute local", "REG_SZ"
wshShell.RegWrite "HKCR\rdp\URL Protocol","", "REG_SZ"
'
' create the protocol class handler at the permanent location
'
payload = "rdp.js"
payloadbase = replace( payload, ".js", "" )
'
' code below determines where to permanently park the payload script file ( ALL_USERS_APPLICATION_DATA )
'
Set ofso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H23&)
Set objFolderItem = objFolder.Self
payloadhome = objFolderItem.Path & "\Waldo"
on error resume next
ofso.CreateFolder( payloadhome )
on error goto 0
'
' unwind/windup the payload and park it in permanent home
'
unwindpayload "'payload 1", payloadhome & "\" & payload
wscript.echo "OK, you are ready to use; rdp alone for syntax"
wscript.quit
'----------------------------------------------------------------------------------------------
'
' unwinds payload code to a file ( "" if none ), returns buffer with unwound code
'
Function unwindpayload( payloadsentinal, payloadfile )
code = CreateObject("Scripting.FileSystemObject").opentextfile ( Wscript.ScriptFullName, 1 ).ReadAll
gulpcode = False
For each line In Split(code,vbCrLf)
If ( gulpcode = 1 ) And InStr( line, payloadsentinal ) = 1 Then gulpcode = 2
If ( gulpcode = 1 ) Then payloadcode = payloadcode & Mid( line, 2 ) & vbCrLf
If InStr( line, payloadsentinal ) = 1 Then gulpcode = gulpcode + 1
Next
If ( payloadfile <> "") Then
set payloadhandle = ofso.opentextfile( payloadfile, 2, True )
payloadhandle.writeline( payloadcode )
payloadhandle.close
End If
unwindpayload = payloadcode
End Function
'payload 1 - start each line of code that follows with '
'
'
'var shell=new ActiveXObject("WScript.Shell")
'var syntax = "\nExecute remote desktop as an external protocol\n\nSyntax:\nrdp://HOSTNAME[:portno] | RVBS://USERNAME:PASSWORD@HOSTNAME[:portno]\n\n\tHOSTNAME can be dns hostname or an IPV4 address\n\ncredentials only needed if need ;-)\ncan be invoked from browser, cmd, link or address bar in explorer";
'
'function main( URL ){
'
'
' URL = URL.replace( 'rdp://','' )
' URL = URL.replace( '/','' )
'
' var hostdata, justhostname, username, password, hostname, portno, scriptname
' hostdata="";
' justhostname="";
' username="";
' password="";
' hostname="";
' portno="3389";
' scriptname="";
'
' hostdata = URL;
'
'
' //
' // hostdata can contain embedded credentials and/or a port number
' //
' var co= hostdata.indexOf( ":" );
' var at= hostdata.lastIndexOf( "@" );
' var cocount = hostdata.split(":").length - 1;
'
' var fail=true;
'
' //
' // just a hostname
' //
' if ( (co==-1) && (at==-1) ){
' hostname = hostdata;
' justhostname = hostname;
' fail = false;
' }
' //
' // hostname:portno
' //
' if ( (co>-1) && (at==-1) && (cocount==1) ){
' hostname = getsplit( hostdata, co, 0 );
' portno = getsplit( hostdata, co, 1 );
' justhostname = hostname;
' fail = false;
' }
' //
' // username:password@hostname[:portno]
' //
' if ( (co>-1) && (at>-1) && (cocount) ){
' hostname = getsplit( hostdata, at,1 );
' var userpass = getsplit( hostdata, at,0 );
' username = getsplit( userpass, co, 0 );
' password = getsplit( userpass, co, 1 );
' if ( cocount==2 ){
' var hostport = hostname;
' co = hostport.indexOf( ":" );
' hostname = getsplit( hostport, co, 0 );
' portno = getsplit( hostport, co, 1 );
' justhostname = hostname;
' }
' fail = false;
' }
'
' // shell.Popup( "hostdata:(" + hostdata + ") username:(" + username + ") password:(" + password + ") hostname:(" + hostname + ") portno:(" + portno + ") cocount:(" + cocount + ")" );
'
' if ( fail == true ){
' syntaxdie();
' return;
' }
' //
' // we now have valid syntax - doit
' //
' justhostname = hostname;
'
' //
' // set user credentials if supplied.
' //
' if (( username ) && ( password )){
' shell.Run( '"cmdkey"' + ' /generic:TERMSRV/' + justhostname + ' /user:'+username + ' /pass:' + password );
' }
'
' //
' // kill prompt for do you trust this remote, bla, bla, bla...
' //
' var fso = new ActiveXObject("Scripting.FileSystemObject");
' var batchfilename="c:\\windows\\temp\\rdp-";
' for (var x=1; x<10; x++ ){
' batchfilename = batchfilename + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".substr( Math.round(Math.random()*(37-1)+1), 1 );
' }
' batchfilename = batchfilename + ".bat";
' BatchFile = fso.CreateTextFile(batchfilename, true);
' BatchFile.WriteLine( 'reg add \"HKLM\\SOFTWARE\\Microsoft\\Terminal Server Client" /f /v "AuthenticationLevelOverride" /t REG_DWORD /d 0 ' );
' BatchFile.WriteLine( 'reg add \"HKCU\\Software\\Microsoft\\Terminal Server Client" /f ' );
' BatchFile.WriteLine( 'reg add \"HKCU\\Software\\Microsoft\\Terminal Server Client\\LocalDevices" /f ' );
' BatchFile.WriteLine( 'reg add \"HKCU\\Software\\Microsoft\\Terminal Server Client\\LocalDevices" /f /v ' + justhostname + ' /t REG_DWORD /d 5 ' );
' BatchFile.WriteLine( 'reg add \"HKCU\\Software\\Microsoft\\Terminal Server Client\\Servers\" /f ' );
' BatchFile.WriteLine( 'reg add \"HKCU\\Software\\Microsoft\\Terminal Server Client\\Servers\\' + justhostname + '" /f ' );
' BatchFile.WriteLine( 'reg add \"HKCU\\Software\\Microsoft\\Terminal Server Client\\Servers\\' + justhostname + '" /f /v "CertHash" /t REG_BINARY /d 0000000000000000000000000000000000000000' );
' BatchFile.WriteLine( '(goto) 2>nul & del "%~f0"' );
' BatchFile.Close();
' shell.run( batchfilename, 1, false);
'
' //
' // now kick-off the RDP session
' //
' shell.Run( '"mstsc.exe"' + ' /v:' + justhostname + ":" + portno, 1, false);
'
'
' //
' // cleanup leftovers
' //
' if (( username ) && ( password )){
' shell.Run( '"cmdkey"' + ' /delete ' + justhostname );
' }
'}
'function getsplit( arg, delim, occurence ){
' var left = arg.substr( 0, delim );
' var right = arg.substr( delim+1 );
'
' return ( occurence == 0 ? left : right );
'}
'function syntaxdie(){
' shell.Popup( syntax );
'
'}
'var commandlineargs="";
'try{
' commandlineargs=WScript.Arguments.Item(0);
'} catch(err){}
'main( commandlineargs );
'
'payload 1 - start each line of code that follows with '