猴子补丁
2016-09-24 13:30
176 查看
猴子补丁
在运行时更改Python 对象属性的过程被称为猴子补丁。Python 是一种动态语言,完全支持在运行时更改程序和代码。一旦恶意模块通过某种方式进入其中,任何现有的可变对象都有可能在不知不觉中被恶意修改。考虑以下情况︰
$ cat nowrite.py
import builtins
def malicious_open(*args, **kwargs):
if len(args) > 1 and args[1] == ‘w’:
args = (‘/dev/null’,) + args[1:]
return original_open(*args, **kwargs)
original_open, builtins.open = builtins.open, malicious_open
如果上面的代码被 Python 解释器执行,那么一切写入文件都不会被存储到文件系统中︰
import nowrite
open(‘data.txt’, ‘w’).write(‘data to store’)
5
open(‘data.txt’, ‘r’)
Traceback (most recent call last):
…
FileNotFoundError: [Errno 2] No such file or directory: ‘data.txt’
攻击者可以利用 Python 垃圾回收器 (gc.get_objects()) 掌握所有现有对象,并破解任意对象。
在运行时更改Python 对象属性的过程被称为猴子补丁。Python 是一种动态语言,完全支持在运行时更改程序和代码。一旦恶意模块通过某种方式进入其中,任何现有的可变对象都有可能在不知不觉中被恶意修改。考虑以下情况︰
$ cat nowrite.py
import builtins
def malicious_open(*args, **kwargs):
if len(args) > 1 and args[1] == ‘w’:
args = (‘/dev/null’,) + args[1:]
return original_open(*args, **kwargs)
original_open, builtins.open = builtins.open, malicious_open
如果上面的代码被 Python 解释器执行,那么一切写入文件都不会被存储到文件系统中︰
import nowrite
open(‘data.txt’, ‘w’).write(‘data to store’)
5
open(‘data.txt’, ‘r’)
Traceback (most recent call last):
…
FileNotFoundError: [Errno 2] No such file or directory: ‘data.txt’
攻击者可以利用 Python 垃圾回收器 (gc.get_objects()) 掌握所有现有对象,并破解任意对象。
相关文章推荐
- 什么是猴子补丁(monkey patch)
- Pyhon基础:Monkey Patch(猴子补丁)
- Python Monkey patch猴子补丁
- 原型污染和猴子补丁 Prototype Pollution and Monkey-Patching,monkeypatching
- JS 原型污染和猴子补丁
- 详解Python编程中对Monkey Patch猴子补丁开发方式的运用
- python基础===猴子补丁
- 什么是Monkey Patch猴子补丁
- python monkey 猴子补丁技术编程,修改python json dumps方法。
- 什么是猴子补丁(monkey patch)
- 基础入门_Python-模块和包.Gevent异步/状态获取/超时设置/猴子补丁?
- 什么是猴子补丁(monkey patch)
- [Effective JavaScript 笔记]第42条:避免使用轻率的猴子补丁
- 基础入门_Python—Gevent异步/状态获取/超时设置/猴子补丁
- python 模块会导入几次?猴子补丁为什么可以实现?
- 第二种方式,修改python unittest的执行顺序,使用猴子补丁
- 什么是猴子补丁(monkey patch)
- Python 猴子补丁
- python设计模式之猴子补丁模式
- Ruby使用Monkey Patch猴子补丁方式进行程序开发的示例