I'm trying to do a live capture with pyshark, but it wants to run tshark using sudo. I'm not sure how to run sudo out of python. The github thread states: "you can create a 'script' that just runs "sudo tshark" and tell pyshark to run that instead of tshark."
Buuuuut I'm not too sure how to do that. I was looking at Using sudo with Python script
but again not sure how to "run that instead of tshark"
Has anyone done this? Can anyone advise?
Bit more info here: If you're an admin user, you don' t need sudo to run "tshark -c 100 -i en0". If you "sudo chmod 777 /dev/bpf*" that works for things like Carnivore in Processing, but does zip all for Pyshark. Trying to edit Startup items to give you read access is moot on OSX because Yosemite tossed it.
Other info: https://apple.stackexchange.com/questions/138694/what-is-access-bpf-group
I'm really starting to think something is just up w/ PyShark itself.
Thanks
Don't use sudo to run Wireshark. Instead, configure your user account to be able to use Wireshark without root access. Detailed instructions are here: https://ask.wireshark.org/questions/7976/wireshark-setup-linux-for-nonroot-user
WELP. turns out it was just because I hadn't used 'en0' Marking this as solved. HA.
Related
Wish You all beautiful sunny day! :D,
I have a question for You guys. I have following python "script":
import os
os.system('ubuntu.exe')
Which opens Ubuntu running on my WSL. And now, when the Ubuntu terminal appears:
I would like to execute following commands: sudo /etc/init.d/dbus start and sudo /etc/init.d/xrdp start using my python script (just do them automatically). However, when I run one of the commands above, terminal requests my password:
So the script should be also able to enter the password.
Is there any way, how to do it?
Kind regards,
D.
While the question/answers linked in the comments is a good read (sudoers in particular), there's a better method for WSL. Instead of using ubuntu.exe, use the newer wsl.exe replacement. The wsl command offers more control over the startup, including being able to change the user:
import os
os.system('wsl ~ -u root -e sh -c "nohup service xrdp start"')
os.system('wsl -u root service dbus start')
The nohup is needed because of what seems to be a timing issue. When starting up via the WSL command, the shell (owning process) will terminate before xrdp gets a chance to fork. nohup just makes sure that the full xrdp init script gets a chance to run before that happens. This really isn't a WSL issue, per se. It can also be replicated if you were do something similar with exec sh -c "sudo service xrdp start".
A couple of other notes. First, this does not require a password, since WSL doesn't have the concept of "login." The /init process (WSL's PID1 and initialization) is responsible for setting the owning user for each session. This is not considered a security risk since even the root WSL user runs with no greater than the permissions of the Windows user.
Also note that, in my experience, it's not necessary to start dbus for xrdp access, even though I've seen instructions that say it is. Ultimately it will depend on what you want to run within the xrdp session, of course.
So, I have been playing around with my Raspberry Pi Zero and tshark in SSH when I thought, why not make a script that did all the work for me? So I used nano and created a python file called script.py and inside I wrote:
import os
os.system('sudo tshark -i eth0 -w capture-output.pcap')
I then did /python script.py which started off well but when it got to capturing on eth0 it stopped and said:
tshark: Couldn't create child process: cannot allocate memory.
Sorry about my python newbieness but please help because I am designing a Hak5 Packet squrriel clone. Thank you anyway and I look forward to hearing from you soon, Thomas
EDIT
So, I have kind of resolved this issue by doing sudo -i then creating a sh file instead of a python one but I prefer the python language so would really like to know what was happening. Thank you very much, Thomas
The problem I've run into is that I want to temporarily get into the sudo user, run a couple of commands, and then go back to a normal user and run the commands in that mode.
You can find the script I'm gonna use it in here: https://github.com/Greduan/dotfiles/blob/master/scripts/symlinks.py
Basically, when I'm installing the scripts under the /bin folder of my dotfiles I need sudo access in order to make a symlink to that folder. You can find this part of the script under the last for statement in the code.
However, since I do depend on some commands that use the current user as a guideline to do stuff, I can't just run the entire script as sudo. Last time I tried I got a lot of errors about a folder not existing.
Thanks for all the help you can provide.
If you don't mind installing an external dependency, the sh module makes this pretty simple:
import sh
sh.cp('foo.txt', 'bar.txt')
with sh.sudo:
sh.cp('foo2.txt', 'bar2.txt')
In the end I tried #Blender's solution, but it didn't work or I wasn't able to figure it out.
So Instead I did the following:
subprocess.Popen('sudo rm ' + final_dest, shell=True)
and:
subprocess.Popen('sudo ln -s ' + final_src + ' ' + final_dest, shell=True)
This works correctly as I expected it and it has no extra dependencies. Thanks for your answer #Blender but it didn't work for me. ;|
Okay, I've been working on a pythonbased 'hacktool' with helps penetration testers install some basic tools on Mac.
Now most of these tools require a root user to be activated, so I need an easy way to activate the root user (On mac this can be done by 'passwd root' sadly that requires another input to be typed)
Need some help here guys, running low on time and the internet won't give me any helpful answers. :S
There is a command in OSX called 'dsenableroot' which did exactly what I wanted it to do. The command works like this:
dsenableroot -u yourusername -p yourpassword -r rootpassword
It does exactly what it is supposed to do, now I just need a workaround on the 'yourpassword' part, since I don't know the password of the Users computer. Will post updates here!
I need a python lib to execute ssh command. I also need the output.
I tried paramiko: It was exactly what i needed but no way to execute sudo commands there. there are some online posts for that but none seem to work.
I also tried fabric: The problem is there is no way to capture output also sometimes it shows error while setting env.
Can anybody suggest something. A example of exec some sudo cmd over ssh will be good enough.
Fabric's operation.run captures stdout and also stderr if you pass combine_stderr to run(). See http://docs.fabfile.org/en/1.3.4/api/core/operations.html#fabric.operations.run