msgbartop
PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 – 左手代码 右手诗
msgbarbottom

18 Feb 12 Taint-0.3.0(A XSS codes sniffer) released

最近几天忙里偷闲, 一直在完善taint, 今天我觉得终于算做到了80%的满意了, 根据80:20原则, 我觉得可以做为一个里程碑的版本了 :) .

什么是Taint? An extension used for detecting XSS codes(tainted string), And also can be used to spot sql injection vulnerabilities, shell inject, etc.

经过我实际测试, Taint-0.3.0能检测出实际的一些开源产品的(别问是什么)隐藏的XSS code, SQL注入, Shell注入等漏洞, 并且这些漏洞如果要用静态分析工具去排查, 将会非常困难, 比如对于如下的例子:

<?php
   $name = $_GET["name"];
   $value = strval($_GET["tainted"]);

   echo $$name;

对于请求:


http://****.com/?name=value&tainted=xxx

静态分析工具, 往往无能为力, 而Taint却可以准确无误的爆出这类型问题.

Warning: main() [function.echo]:
     Attempt to echo a string that might be tainted in %s.php on line %d

现在0.3.0已经发布, 我想短时间内, 我不会再添加新功能了. enjoy, PHP Taint.

另外, 多说一句, Taint可以说是, 我完成的扩展中最为复杂的一个, 使用了各种tricky技巧, 大家如果有兴趣做扩展开发, 可以用来作为一个很好的高级教材.

附录:

A. Tainted String

所有来自$_GET, $_POST, $_COOKIE的变量, 都被认为是Tainted String

B. taint检测的函数/语句列表, 当这些函数使用tainted string参数的时候, taint会给出警告:

1. 输出函数/语句系列

echo
print
printf
file_put_contents

2. 文件系统函数

fopen
opendir
basename
dirname
file
pathinfo

3. 数据库系列函数/方法

mysql_query
mysqli_query
sqlite_query
sqlite_single_query
oci_parse
Mysqli::query
SqliteDataBase::query
SqliteDataBase::SingleQuery
PDO::query
PDO::prepare

4. 命令行系列

system
exec
proc_open
passthru
shell_exec

5. 语法结构

eval
include(_once)
require(_once)

C. 消除tainted信息的函数, 调用这些函数以后, tainted string就会变成合法的string:

escapeshellcmd
htmlspecialchars
escapeshellcmd
addcslashes
addslashes
mysqli_escape_string
mysql_real_escape_string
mysql_escape_string
sqlite_escape_string
PDO::quote
Mysqli::escape_string
Mysql::real_escape_string

D. 调用中保持tainted信息的函数/语句, 调用这些函数/语句时, 如果输入是tainted string, 则输出也为tainted string:

= (assign)
. (concat)
"{$var}" (variable substitution)
.= (assign concat)
strval
explode
implode
sprintf
vsprintf
trim(as of 0.4.0)
rtrim(as of 0.4.0)
ltrim(as of 0.4.0)

E. 链接:


分享到:



Related Posts:

Tags: , , ,

36 Responses to “Taint-0.3.0(A XSS codes sniffer) released”

Pages: [4] 3 2 1 » Show All

  1. virgins |

    我觉得这个网站的内容真心好

  2. shirne |

    但是,我还是想问问,是什么–!

  3. liut |

    请问有没有编译好win32 dll,我本人用mac,但组员大部分用windows

  4. pangee |

    赞!

  5. skybyte |

    这个不能记录日志到文件啊,我这样设置日志里面没得
    error_reporting = E_ALL & ~E_NOTICE
    error_log=php.log
    display_errors=Off

    改成display_errors=on就直接显示到浏览器了

  6. 雪候鸟 |

    @liut 多谢反馈, 已经在svn修复了. http://svn.php.net/viewvc/pecl/taint/trunk/taint.c?r1=325027&r2=325026&pathrev=325027

Pages: [4] 3 2 1 » Show All

Leave a Reply

*