I am trying to run vulnerability testing for a class and the first line of code in the script is:
from metasploit.msfrpc import MsfRpcClient
However, when I try to run the program, I get "ModuleNotFoundError: No Module named 'metasploit'"
I am running on Kali Linux; metasploit comes standard, but either I am doing something wrong or am missing a module. Has anyone run into this and can maybe suggest a resolution?
first,
pip3 install --user pymetasploit3
$ msfrpcd -P yourpassword -S
and then in python,
from pymetasploit3.msfrpc import MsfRpcClient
It can work. Good luck.
Related
If I run this on my (Linux) command line.
python3 -m serial.tools.list_ports
I get the result:
/dev/ttyUSB0
1 ports found.
What files (or sequence of files) are run by this -m switch?
I have various python directories in my /usr/ directory but no specific serial.py file (I can see serialcli.py & serialutil.py, serialize.py etc) so the command is being 'turned' into some form to use a 'serial based' file, but which one?.
How does it generate the output?
In python code when I use this command no output is generated so I guess the -m switch taps into an output routine??
The output from this command (and other examples) is quite useful and I may want to use it in python itself rather than from BASH.
I am aware it's not meant for this but for testing purposes, but still... ;)
Q: So what files are actually 'tapped into' in this 'serial' example?
The -m flag in python is used for:
-m mod : run library module as a script (terminates option list)
What does "terminates option list" mean?
It means that, any future options get passed to the program you are providing and not to python.
So in your scenario, it's running the list_ports module as a script
python3 -m serial.tools.list_ports
How can you use it in python itself?
You can import the serial module and call functions inside list_ports. I am very sure, you have these files in your workspace / environment, because you have installed pyserial
Alternatively - you can also install pyserial in a virtual environment, and run some experiments.
If you "really, really" want to use this like a bash command, within a python script? Do take a look at the subprocess module.
Subprocess
Pyserial - serial.tools.list_ports
Hy guys, i am trying to use vscode in kali linux.
But I ran into a problem.
The moment I start the python file from the play symbol in the terminal it gives me a permission error.
But if I boot from the terminal using sudo python main.py it works fine.
Would you know how to help me fix this problem?
i am used to launch with play, i find it annoying to type in the terminal every time.
Screen error
I also tried the solution found on the internet of sudo code --user-data-dir = "~ / .vscode-root" my/path, but it doesn't solve the problem.
the code to execute:
import socket
import struct
import binascii
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0800))
while True:
print (s.recvfrom(2048))
Try to use :
sudo code
in the terminal
If it doesn't work try to remove it and install it again.
I am working with my Raspberry Pi 2 B+ and I am using Raspbian. I have a python script located at /home/pi/Desktop/control/gpio.py
When I type /home/pi/Desktop/control/gpio.py into the command line, I get the message
bash: /home/pi/Desktop/control/gpio.py Permission denied
I have tried running sudo -s before running that command also but that doesnt work. My python script is using the Rpi.GPIO library.
If someone could please explain why I am getting this error it would be appreciated!
You will get this error because you do not have the execute permission on your file. There are two ways to solve it:
Not executing the file in the first place. By running python gpio.py python will load the file by reading it, so you don't need to have execute permission.
Granting yourself execute permission. You do this by running chmod u+x yourfile.py.
However, doing so will not work unless you add a shebang at the top of your python program. It will let your linux know which interpreter it should start. For instance:
#!/usr/bin/env python
This would try to run python using your current $PATH settings. If you know which python you want, put it here instead.
#!/usr/bin/python3
Remember the shebang must be the very first line of your program.
do like this maybe work:
cd /home/pi/Desktop/control/
python gpio.py
Because gpio.py is not a executable file, you should run it by python instead
I followed a guide about how to operate a fingerprint sensor using python. It works fine when using the terminal to execute the example files. But whenever I try to use it with a Thorny or Python IDLE. It keeps saying:
from pyfingerprint.pyfingerprint import PyFingerprint
ImportError: No module named 'pyfingerprint'
I would appreciate it so much if anyone can help me run those examples on a python idle.
Check the exact version( including minor version) of Python you're running in the command line .
In Geany (that's what I use) under menu Build>Set Build Commands , in the Compile and Execute fields set to that Python version eg python3.5 . Then you can be sure command line and IDE are compiling/executing against the same version.
I've searched online to find answers to this, but I've come up short. Other examples are different enough to not get me to a solution. This is on a Raspberry Pi 3b, Raspbian, Jessie.
I have a kivy app that uses a bluetooth (ble) peripheral device. My BLE class has to scan for BLE devices which requires root privileges. The BLE class works using sudo outside of kivy so I don't 'think' there is a fundamental problem with the BLE code. FYI, the BLE class uses bluepy (btle). In order to get the peripheral working correctly I have to run:
scanner = btle.Scanner()
dev = scanner.scan(3)
The scan requires running as root. If I didn't need it I would remove it, but then the behavior of the program changes.
My problem is that running my program (w/ BLE class AND kivy) from command prompt like this: python3 FS_run.py runs the application w/out connecting to the BLE peripheral. However, when I run it like this: sudo python3 FS_run.py, I get:
Traceback (most recent call last):
File "FS_run.py", line 1, in <module>
from kivy.app import App
ImportError: No module named 'kivy'
I've seen a lot of posts where successfully running kivy w/ sudo makes the buttons not work. I've changed the permissions (chmod) of the BLE class file and tried running again w/out sudo, but that didn't help. I'm open to other suggestions to circumvent the use of sudo. Perhaps running the BLE in a subprocess, but I wouldn't know how to make it join the rest of the program. Also, I'm fairly new to BLE, I just got the BLE class to work yesterday. Suffice it to say I'm a bit out of my league here.
I'm not a linux guy so I am not sure where to focus my energy to solve this. Not sure if this is helpful, but I saw this on another post so I'll just add it:
which python3 gives /usr/bin/python3
sudo which python3 gives /usr/bin/python3
EDIT:
python -c "import sys; print(sys.path)"
prints different output than when run with sudo.
'/home/pi/kivy' is missing when run with sudo. How do I go about fixing this?
EDIT 2:
Other posts said this fixed it:
sudo cp /home/pi/.kivy/config.ini /root/.kivy/config.ini
Didn't work for me. I got:
cp: cannot create regularfile '/root/.kivy/config.ini': No such file or directory
So then I manually created the .kivy directory in root and then did a sudo cp to copy the file over. Still does not work.
I got it to work by adding at the end of the file "/root/profile"
the line :
export PYTHONPATH=/home/pi/Documents/kivy/kivy:$PYTHONPATH
Then before launching the app :
sudo su
source ~/.profile
I don't know if it helped but I have also :
sudo cp /home/pi/.kivy/config.ini /root/.kivy/config.ini