English 中文(简体)
粉碎。 Unchroot Directory
原标题:Python. Unchroot directory

我使用以下指挥方法收集目录:

os.chroot("/mydir")

How to return to directory to previous - before chrooting? Maybe it is possible to unchroot directory?

感谢Phihag。 我找到了解决办法。 简单例子:

import os
os.mkdir( /tmp/new_dir )
dir1 = os.open( . , os.O_RDONLY)
dir2 = os.open( /tmp/new_dir , os.O_RDONLY)

os.getcwd()                # we are in  tmp 
os.chroot( /tmp/new_dir )  # chrooting  new_dir  directory
os.fchdir(dir2)
os.getcwd()                # we are in chrooted directory, but path is  / . It s OK.
os.fchdir(dir1)
os.getcwd()                # we came back to not chrooted  tmp  directory

os.close(dir1)
os.close(dir2)

最佳回答

如果你没有改变你目前的工作名录,你可以简单地叫你。

os.chroot( ../.. ) # Add  ../  as needed

Of course, this requires the CAP_SYS_CHROOT capability (usually only given to root).

如果您改变了工作名录,你可以http://www.bpfh.net/simes/computing/chroot-break.html” rel=“nofollow”> ,但更难以:

os.mkdir( tmp )
os.chroot( tmp )
os.chdir( ../../ ) # Add  ../  as needed
os.chroot( . )

chroot 修改现行工作名录,通过开放名录,并使用fchdir

当然,如果你打算从正常方案(即不进行示威或利用安全)中抽走,你就应当重新思考你的方案。 首先,你是否真的需要逃脱ch? 为什么你要把必要的信息事先复制到这里?

此外,考虑采用另一种程序,这种程序不停留在案卷之外,并对案头的要求做出答复。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签