I'm testing out a library called packetgen
on my machine. The problem is not the library itself; I'm trying to inject a single packet on my network just for a simple test. However when I inject it, it raises and error:
Traceback (most recent call last):
3: from packet.rb:5:in `<main>'
2: from /home/COM-COM/.rvm/gems/ruby-2.5.1/gems/packetgen-2.8.6/lib /packetgen/packet.rb:240:in `to_w'
1: from /home/COM-COM/.rvm/gems/ruby-2.5.1/gems/packetgen-2.8.6/lib/ packetgen/header/eth.rb:95:in `to_w'
/home/COM_COM/.rvm/gems/ruby-2.5.1/gems/packetgen-2.8.6/lib/packetgen /header/eth.rb:95:in `open_live': wlp2s0: You don't have permission to capture on that device (socket: Operation not permitted) (RuntimeError)
I need superuser privileges to capture or inject packets on the network, but if I run sudo 'ruby packet.rb'
it raises and a different error becausepacketgen
isn't installed on my machine's version of ruby. I'm running a version of ruby different from my machine's preinstalled version courtesy of RVM (Ruby Version Mananger). Does anyone have a workaround or a way to run this program without sudo? Thanks!
RVM has sudo integration, see here.
By default, when you use sudo your current shell environment is not passed through to the session created by it, but RVM already allows for easier access to sudo calls with rvmsudo. However, sudo's defaults are very strict and you might end up getting password prompts on commands that are set to use the sudo NOPASSWD directive.