如何使用Python访问Ring 0? [英] How can I access Ring 0 with Python?

查看:189
本文介绍了如何使用Python访问Ring 0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案表明,由于特殊特权,未完成Python中类的命名,

This answer, stating that the naming of classes in Python is not done because of special privileges, here confuses me.

  1. 如何在Python中访问较低的环?
  2. 用于访问较低级别环的低级别io是吗?
  3. 如果是,我可以使用哪只戒指?
  4. 语句"This function is intended for low-level I/O."是指较低级别的振铃还是其他内容?
  5. 在操作系统编程中,
  6. C往往是突出的语言.当Python中有OS类时,是否意味着我可以通过该类访问C代码?
  7. 假设我正在使用奇怪的机器语言代码,并且想以某种方式理解它的含义. Python中有一些我可以用来分析这些东西的工具吗?如果没有,我是否仍可以通过某种方式使用Python控制某些控制怪异机器语言的工具? [注释中建议的ctypes]
  8. 如果Python与低级特权无关,那么它是否仍提供一些包装器来控制特权?
  1. How can I access lower rings in Python?
  2. Is the low-level io for accessing lower level rings?
  3. If it is, which rings I can access with that?
  4. Is the statement "This function is intended for low-level I/O." referring to lower level rings or to something else?
  5. C tends to be prominent language in os -programming. When there is the OS -class in Python, does it mean that I can access C -code through that class?
  6. Suppose I am playing with bizarre machine-language code and I want to somehow understand what it means. Are there some tools in Python which I can use to analyze such things? If there is not, is there some way that I could still use Python to control some tool which controls the bizarre machine language? [ctypes suggested in comments]
  7. If Python has nothing to do with the low-level privileged stuff, do it still offers some wrappers to control the privileged?

推荐答案

Windows和Linux都将环0用于内核代码,将环3用于用户进程.这样做的好处是用户进程可以彼此隔离,因此即使进程崩溃,系统也可以继续运行.相比之下,Ring 0代码中的错误有可能使整个计算机崩溃.

Windows and Linux both use ring 0 for kernel code and ring 3 for user processes. The advantage of this is that user processes can be isolated from one another, so the system continues to run even if a process crashes. By contrast, a bug in ring 0 code can potentially crash the entire machine.

原因 环0之一非常重要,以至于它可以直接访问硬件.相比之下,当用户模式(第3环)进程需要从磁盘读取某些数据时:

One of the reasons ring 0 code is so critical is that it can access hardware directly. By contrast, when a user-mode (ring 3) process needs to read some data from a disk:

  1. 该进程执行一条特殊指令,告诉CPU它想进行系统调用
  2. CPU切换到环0,并开始执行内核代码
  3. 内核检查是否允许该进程执行该操作
  4. 如果允许,则执行操作
  5. 内核告诉CPU它已经完成
  6. CPU切换回第3环,并将控制权返回给进程

属于特权"用户(例如root/Administrator)的进程在环3中运行,就像其他任何用户模式代码一样;唯一的区别是步骤3的检查始终成功.这是一件好事,因为:

Processes belonging to "privileged" users (e.g. root/Administrator) run in ring 3 just like any other user-mode code; the only difference is that the check at step 3 always succeeds. This is a good thing because:

  • root拥有的进程可以崩溃,而不会导致整个系统瘫痪
  • 许多用户模式功能在内核中不可用,例如可交换内存,专用地址空间

至于在低端运行Python代码-内核模式是一个非常不同的环境,并且Python解释器根本不旨在在其中运行,例如分配内存的过程完全不同.

As for running Python code in lower rings - kernel-mode is a very different environment, and the Python interpreter simply isn't designed to run in it, e.g. the procedure for allocating memory is completely different.

在您引用的另一个问题中,os.open()open()都最终使打开()系统调用,它检查是否允许该进程打开相应的文件并执行实际操作.

In the other question you reference, both os.open() and open() end up making the open() system call, which checks whether the process is allowed to open the corresponding file and performs the actual operation.

这篇关于如何使用Python访问Ring 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆