非root运行wireshark
CAP_NET_ADMIN – Allow various network-related operations (e.g., setting privileged socket options, enabling multicasting, interface configuration, modifying routing tables).
CAP_NET_RAW – Permit use of RAW and PACKET sockets.
CAP_NET_ADMIN allows us to set an interface to promiscuous mode, and CAP_NET_RAW permits raw access to an interface for capturing directly off the wire. These capabilities are assigned using the setcap utility.
Enabling Non-root Capture
如果没有 setcap 这个程序,请自行安装。
1首先下载libcap
2.如果系统里面没有 wireshark 组,创建一个,然后把自己添加到这个组:
sudo groupadd wireshark
sudo usermod -a -G wireshark jieen
# 或者sudo gpasswd -a jieen
在把自己添加到wireshark 组之后,通常情况下你要登出然后再登入才能生效,
你还可以运行这个来强制使新创建的组生效(注意,等下你要在同一个terminal中
运行 wireshark 命令来启动wireshark才能成功):
newgrp wireshark
下面我们修改dumpcap 的权限,使它属于 wireshark 组,然后,我们让这个组
拥有执行权限:
sudo chgrp wireshark /usr/local/bin/dumpcap
sudo chmod 754 /usr/local/bin/dumpcap
3.Grant Capabilities
sudo setcap cap_net_raw,cap_net_admin=eip /usr/local/bin/dumpcap
# 或者:
sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/local/bin/dumpcap
然后 我们看下:
sudo getcap /usr/local/bin/dumpcap
/usr/local/bin/dumpcap = cap_net_admin,cap_net_raw+eip
然后运行下wireshark , 是不是不要root也能抓包啦.