以非root用户身份运行python-iptables(iptc)

时间:2020-08-27 11:17:27

标签: python iptc python-iptables

我试图以非root用户身份运行python-iptables。

我的脚本是test.py:

import iptc
import os

uid = os.getuid()
print("Real user ID of the current process:", uid)

table = iptc.Table(iptc.Table.FILTER)
print("Table is:".format(table))

我尝试过:

  1. 将能力CAP_NET_ADMIN赋予/usr/bin/python2.7(结果是:$ getcap /usr/bin/python2.7 /usr/bin/python2.7 = cap_net_admin+eip)并按照Python Scapy sniff without root
  2. 中的说明执行/usr/bin/python2.7 ./test.py
  3. 使用https://gist.github.com/tomix86/32394a43be70c337cbf1e0c0a56cbd8d中定义的环境功能进行编译和运行,并执行./ambient -c '12' /usr/bin/python2.7 ./test.py
  4. 我尚未使用python-prctl进行测试,但是我很快打算按照Unable to get CAP_CHOWN and CAP_DAC_OVERRIDE working for regular user
  5. 中所述进行测试

日志为:

('Real user ID of the current process:', 1000)
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    table = iptc.Table(iptc.Table.FILTER)
  File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 1566, in __new__
    obj._init(name, autocommit)
  File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 1582, in _init
    self.refresh()
  File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 1619, in refresh
    self.strerror()))
iptc.ip4tc.IPTCError: can't initialize filter: Permission denied (you must be root)

我的内核是:

$ uname -r
4.4.224-1.el7.elrepo.x86_64

我的python版本是:

Python 2.7.5

我的python-iptables版本是:

python-iptables            0.12.0

我可以以非root用户身份成功运行“ iptables -L”,但不能以非root用户身份成功运行iptc python命令。

是否还有其他方法可以提供我的python脚本功能,或者它与iptc代码有关?

是否会因为需要其他功能而失败?

0 个答案:

没有答案