Running Wireshark as a non root user

From http://softsmith.blogspot.com/2008/10/running-wireshark-as-non-root-user.html

In general, we have to run "
sudo wireshark" to capture packets. It is very annoying. Luckily,
I found solutions that work on my Ubuntu box.

Solution 1:

The simplest way is to run "
sudo chmod u+s /usr/bin/dumpcap" once. That's all! Because "dumpcap" is the only part that need root privileges. However, it is not a good practice to enable all to run an executable that has root privileges.

Solution 2:

The better solution is to create a group and allow the members of the group to run "dumpcap" with root privileges:

  1. "sudo vi /etc/group" to create a new group, say "wireshark", and enroll yourself to this group
  2. "sudo chgrp wireshark /usr/bin/dumpcap"
  3. "sudo chmod 4754 /usr/bin/dumpcap"

Logout and login again to take the new groupship and you can use Wireshark to capture packets as a non-root user.
---------------
My Solution:

sudo addgroup wireshark
sudo adduser myName wireshark
sudo chgrp wireshark /usr/bin/dumpcap
sudo chmod 4754 /usr/bin/dumpcap

 

### 解决Wireshark因管理员权限导致的Lua加载错误问题 在使用Wireshark时,如果以超级用户(root)身份运行,可能会遇到Lua脚本加载失败的问题,提示信息类似于“dofile has been disabled due to running Wireshark as superuser”[^1]。这是因为Wireshark出于安全考虑,禁止了以超级用户身份运行时加载Lua脚本的功能。为了解决这一问题,可以从以下几个方面入手: #### 1. 使用普通用户权限运行Wireshark 推荐的方式是避免以超级用户身份运行Wireshark。可以通过配置文件或命令行工具调整捕获权限,使普通用户能够执行网络捕获操作。具体步骤如下: - **安装`wireshark-common`和`dumpcap`**:确保系统中已安装这些工具,并赋予普通用户捕获权限。 - **创建捕获组并添加用户**: ```bash sudo groupadd wireshark sudo usermod -a -G wireshark $USER ``` - **设置`dumpcap`权限**: ```bash sudo chgrp wireshark /usr/bin/dumpcap sudo chmod 750 /usr/bin/dumpcap sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap ``` - **重新登录**:完成上述配置后,注销并重新登录以使组权限生效。 通过以上配置,普通用户可以运行Wireshark并进行网络捕获,同时避免了超级用户权限带来的限制[^3]。 #### 2. 修改`init.lua`文件 如果必须以超级用户身份运行Wireshark,可以尝试修改`init.lua`文件,绕过`dofile`禁用的限制。但需要注意,这种方法可能带来安全隐患,应谨慎使用。 - 打开`/usr/share/wireshark/init.lua`文件,找到类似以下代码: ```lua if not can_run_as_superuser() then error("dofile has been disabled due to running Wireshark as superuser.") end ``` - 注释掉或移除上述代码片段,保存文件后重启Wireshark。此方法虽然可以解决问题,但强烈建议仅在测试环境中使用[^4]。 #### 3. 使用`tshark`替代Wireshark 对于需要自动化处理或批量分析的任务,可以使用`tshark`命令行工具代替图形界面的Wireshark。通过配置普通用户的捕获权限,同样可以避免超级用户权限带来的问题。 示例命令: ```bash tshark -i eth0 -w capture.pcap ``` #### 示例代码:检查当前用户是否为超级用户 在Lua脚本中,可以通过以下代码检测当前用户是否为超级用户,并根据结果采取不同的操作: ```lua local function is_superuser() local handle = io.popen("whoami") local user = handle:read("*a"):gsub("%s+", "") handle:close() return user == "root" end if is_superuser() then print("Running as superuser is not recommended!") else print("Running as a regular user.") end ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值