I'm trying to bruteforce (a rootme challenge don't worry :p) an SNMPv3 authentication password using this python script : https://github.com/cysboy/SnmpCrack/blob/master/SnmpCrack.py
Nevertheless, I have an error loading a scapy snmp module line 72 on this code
snmp = pkt[SNMP]
I printed the error by adding
except Exception as e :
print("Continuing")
print(e)
continue
In the followed try catch.
I get this error : Layer [<class 'scapy.layers.snmp.SNMP'>] not found
So I tried to search where this class should have been declared.
I found a file under /usr/lib/python2.7/dist-packages/scapy/layers/snmp.py where the class is defined.
I tried to import this file manually and other modules with
import sys
sys.path.insert(0, "/usr/lib/python2.7/dist-packages/scapy/layers/")
import snmp
from scapy.all import *
from scapy.layers import *
from scapy.layers.snmp import * #SNMP, SNMPresponse, SNMPvarbind
But I don't really know what I'm doing exactly.
Is there a way to be sure this file is included as a scapy submodule / class ?
I'm running under the latest Kali 64 bit. I tried with python3 aswell without success.
I'm running this script with python 2.7.14+
Thanks if you can help me with that :)
Have a good day
Quite old question already.
As you can see in the code source,
https://github.com/secdev/scapy/blob/master/scapy/layers/snmp.py
the fields do exist in recent versions.
Try uninstalling scapy from apt, and install it via github or via
pip install scapy
It may be a problem of versioning...
Related
I'm trying to test a python module which is part of a windows service setup in a production server. However, the module I'm trying to test imports other python modules which, in turn, import libraries that only exist in a production server. Example below:
ModuleAlpha.py:
import A
import B
class X(object):
pass
A.py:
import _winreg as reg
import pymqi
import CMQC
class Y(object):
pass
MyTestModule.py:
from ModuleAlpha import X
I receive the following error when I try to run MyTestModule.py:
ImportError: No module named pymqi
I understand why I get the import error. My question is: is there a way to circumvent the module import that creates my problem?
Worth to mention that commenting out the use of pymqi in module A is not possible due to how the code is written.
So - there's two answers to this. The right answer and the wrong answer.
The right answer, is to sell your company on the benefits of having a pre-prod environment as similar as possible to prod. Having libraries in use in prod that aren't available in pre-prod is.... sub-optimal ("sub-optimal" is my way of being polite. The honest word is significantly less polite).
The wrong answer is to catch the ImportError exception. There are a couple of approaches you could take here.
try:
import pymqi
HAVE_PYMQI = True
except ImportError:
HAVE_PYMQI = False
if HAVE_PYMQI:
blah()
OR
try:
import pymqi
except ImportError:
import fakepymqi as pymqi
Obviously for the latter wrong solution, you'd need to implement fakepymqi yourself.
I'm having a challenging time getting the Python azure-cosmos library to correctly load for the purposes of locally testing a function in VS Code.
The specific error I'm getting (with the file path shortened) is: Exception: ImportError: cannot import name 'exceptions' from 'azure.cosmos' ([shortened]/.venv/lib/python3.8/site-packages/azure/cosmos/__init__.py)
Things I've checked/tried so far:
Check that requirements.txt specifies azure-cosmos
Manually go into python for each of the interpreters available within VS code and ensure I can manually import azure.cosmos
As instructed here, attempt to reinstall the azure-cosmos library using pip3 and ensuring the --pre flag is used.
[Updated] Verified I can successfully import azure.cosmos.cosmos_client as cosmos_client without any errors
Any ideas? Thanks! Below is the relevant section of my code.
import datetime
import logging
import tempfile
import requests
import os
import zipfile
import pandas as pd
import azure.functions as func
from azure.cosmos import exceptions, CosmosClient, PartitionKey
def main(mytimer: func.TimerRequest, calendars: func.Out[func.Document]) -> None:
logging.info("Timer function has initiated.")
This is what you face now:
This is the offcial doc:
https://github.com/Azure-Samples/azure-cosmos-db-python-getting-started
This doc tells you how to solve this problem.
So the solution is to install pre version.(George Chen's solution is right.)
Didn't install the pre version is the root reason, but please notice that, you need to first delete the package. Otherwise, the pre version will not be installed.(Only run install pre will not solve this problem, you need to delete all of the related packages first. And then install the pre package.)
Whether azure.cosmos is needed depends on whether function binding meets your needs, if the binding could do what you want suppose you don't need to use azure.cosmos.
About this import error, I could reproduce this exception, and I check the github solution it have to add a --pre flag.
So my solution is go to task.json under .vscde, add the flag to the command like below.
If you want to get more details about cosmos binding you could refer to this doc:Azure Cosmos DB trigger and bindings
In a project I need to import RLock from threading module in Python3.6
But no matter what I do, I still have the same error :
from threading import RLock
ImportError: cannot import name 'RLock'
Each time I want to import this module (threading) I have this error.
I already upgraded pip, but it doesn't work.
If someone has a solution for me I would be very grateful.
Edit
This error doesn't depend on the folder in which I am located. I notice that when I am running the command in Python2.7 :
import threading
It works.
But if I am running this command under Python3.6 it doesn't work, still with the same output error.
I checked and the only threading.py files I have are :
/snap/core/6673/usr/lib/python3.5/threading.py
/snap/core/6818/usr/lib/python3.5/threading.py
/snap/core/6964/usr/lib/python3.5/threading.py
/snap/core18/941/usr/lib/python3.6/threading.py
/snap/core18/970/usr/lib/python3.6/threading.py
/snap/docker/384/usr/lib/python2.7/threading.py
/snap/docker/384/usr/lib/python3.5/threading.py
/snap/gnome-3-26-1604/74/usr/lib/python3.5/threading.py
/snap/gnome-3-26-1604/82/usr/lib/python3.5/threading.py
/snap/gnome-3-28-1804/36/usr/lib/python3.6/threading.py
/snap/gnome-3-28-1804/40/usr/lib/python3.6/threading.py
/snap/libxml2/69/usr/lib/python2.7/threading.py
/usr/lib/python2.7/threading.py
/usr/lib/python2.7/threading.pyc
/usr/lib/python3.6/threading.py
/usr/lib/python3.7/threading.py
I think you have a Python file which called threading. You should rename your file and the import will work. I have just tried it with Python3.6.6 and it works as expected.
Code
from threading import RLock
rl = RLock()
print(rl)
Output:
>>>python other.py
<_RLock owner=None count=0>
I found the origin of the problem by looking at the complete error logs (which I should have specified here, I apologize). Turns out I have a file named token.py. By renaming it the error disappears.
Thank you for your answers.
I'm trying to run a python script on Ubuntu 16.04; the script runs fine on Ubuntu 14.04, but I keep getting kind of a vague object has no attribute error.
It seems this exception class is still active so not sure what the problem is. I've installed python-urllib3 and python3-urllib3 (even though python on the 16.04 system is a symlink to python-2.7) with no luck.
This is my error and line 507 from the code. Any way to get more info about the error?
Traceback (most recent call last):
File "./jsontest.py", line 507, in <module>
except urllib.error.URLError as e:
AttributeError: 'module' object has no attribute 'error'
#!/usr/bin/python
import urllib
import re
import json
import sys
import getopt
...
# line 507
except urllib.error.URLError as e:
print "fail: ", e.reason
...
update: As noted by #a_guest. Had to make this change. Why it runs fine on 14.04 I don't know. Maybe this was the difference bewteen 2.7.6 and 2.7.12:
except urllib2.error.URLError as e:
You linked the documentation for Python 3 however you seem to be using Python 2. urllib on Python 2 doesn't have that error module, just as the error states.
urllib2 on the other hand has this class, so you can use urllib2.URLError instead.
That error means that the urllib module contains nothing called error.
My urllib doesn't have an error submodule.
Note that Ubuntu 16.04 /usr/bin/python is a symlink to python2. If you want to use python 3.x, you should change the first line of your script from
#!/usr/bin/python
to
#!/usr/bin/python3
(Note: the "#!" at the beginning of this line is called "shebang".)
Alternatively you can create a virtual environment so that when you activate it, it will run python 3.
I am using newest Kali and importing scapy ssl_tls package like this:
from scapy.layers.ssl_tls import *
But I get an error: WARNING: can't import layer ssl_tls: No module named ssl_tls
or
ImportError: No module named ssl_tls.
Also, to verify installation, I go into Scapy prompt and type TLS or SSL I get:
>>> TLS
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'TLS' is not defined
So it makes me believe that I didn't install it correctly. However I tried all 3 installation methods from official page and all worked without any errors.
I also have SSL installed: apt-get install libssl-dev
My system:
Linux kali 3.18.0-kali3-amd64 #1 SMP Debian 3.18.6-1~kali2 (2015-03-02) x86_64 GNU/Linux
Python2.7
Scapy version 2.2.1. Also tried 2.3.1.
scapy-ssl_tls version - current from https://github.com/tintinweb/scapy-ssl_tls
root#kali:~/Downloads# pip freeze | grep scapy
Warning: cannot find svn location for distribute==0.6.24dev-r0
scapy==2.2.0-dev
scapy-ssl-tls==1.2.1
NOTE: I have same exact python code running good on different Kali machine, on the same Python, Scapy and scapy-ssl_tls versions.
I just installed ssl_tls using pip. Using this installation method in my case config.py was not updated with added layer, which means that running scapy does not import ssl_tls automatically thus it is not possible to do from scapy.layers.ssl_tls import *. Your case sounds similar.
There are 2 options:
Update scapy's config.py (location depends on the way you installed scapy) by adding ssl_tls module. See https://github.com/tintinweb/scapy-ssl_tls#option-3-manual-installation for example
Import module using from scapy_ssl_tls.ssl_tls import * after importing scapy (or running scapy directly)
github/scapy-ssl_tls PR #55 fixes an issue where setup.py would not find all scapy installation dirs in case you have multiple locations for site-packages. Also see the updated installation instructions and troubleshooting. The fix is in master and will be in scapy-ssl_tls > 1.2.2. Please give it a try and raise a bug on github if this does not fix the issue for you. thanks
Please make sure your python version is > 2.7.6 and then run 'pip install scapy-ssl_tls'