etingof / snmpsim

SNMP Simulator
http://snmplabs.com/snmpsim/
BSD 2-Clause "Simplified" License
376 stars 119 forks source link

decodeMessageVersion takes 3 positional arguments but 4 were given. Cannot connect to the agent using SNMP Walk #171

Closed Scrafya closed 1 year ago

Scrafya commented 1 year ago

Adsız I have been getting this issue whilst running both snmpsim and normal snmp services. While running snmp sim invoking the

snmpsim-command-responder --data-dir=./data --agent-udpv4-endpoint=127.0.0.1:1024

The server runs, also invoking the responder.py file with related commands successfully opens the service,

While using snmpwalk or cmd2rec however the server side crashes with the provided image. I am guessing its a dependancy issue that i couldnt get a hold of. I am running python 3.10.6 with the latest versions of whatever software is required.

lextm commented 1 year ago

There are quite a few pysnmp packages out there on PyPI. Which packages did you install for this test? Please use pip list to show that.

Scrafya commented 1 year ago

Solved the issue, the problem was installation. I thought just an installation would do the trick but i guess you do need a venv. If you can however answer how i can set oid values to selected oid that'd be great.

Scrafya commented 1 year ago

Screenshot_15

Running the server and trying to access the oid by snmpset returns me No such Instance error. I have also tried launching it with variation module options to create a db for the changes to no avail.

EricChandia commented 1 year ago

Got the same error: image

Installed with:

virtualenv venv
source venv/bin/activate
pip install snmpsim

Running local or inside a docker container. Running with: snmpsimd.py --data-dir=./data --agent-udpv4-endpoint=127.0.0.1:1024

norrisjeremy commented 1 year ago

I see similar problems on macOS with python3.11 from Homebrew when executing snmprec:

python3 -m venv venv
. venv/bin/activate
pip install snmpsim

snmprec.py ...

Also tried using python3.8 from Homebrew, but same issue:

python3.8 -m venv venv
. venv/bin/activate
pip install snmpsim

snmprec.py ...

I eventually gave up and just launched an Ubuntu 22.04 container in Docker and used apt-get install snmpsim to get something functional.

EricChandia commented 1 year ago

I see similar problems on macOS with python3.11 from Homebrew when executing snmprec:

python3 -m venv venv
. venv/bin/activate
pip install snmpsim

snmprec.py ...

Also tried using python3.8 from Homebrew, but same issue:

python3.8 -m venv venv
. venv/bin/activate
pip install snmpsim

snmprec.py ...

I eventually gave up and just launched an Ubuntu 22.04 container in Docker and used apt-get install snmpsim to get something functional.

please, can you show your Dockerfile and how to run the container to make it work?

norrisjeremy commented 1 year ago

There wasn't a Dockerfile involved, it was just an interactive container so I could grab a few snmprec recordings:

docker image pull ubuntu:22.04
docker run -it --rm ubuntu:22.04

apt-get update
apt-get install snmpsim
snmprec ...

docker cp <containerid>:/<snmprec_file> ./<snmprec_file>
Scrafya commented 1 year ago

For those that are experiencing this issue, do the tutorial step by step. You need to run it on a venv with the right dependancies.

norrisjeremy commented 1 year ago

Can you point at where the tutorial is located? Trying to navigate to http://snmplabs.com/snmpsim/ as linked in the README.md (https://github.com/etingof/snmpsim#documentation) leads to a redirect that is blocked by uBlock Origin in my browser, which doesn't inspire confidence...

Scrafya commented 1 year ago

https://snmplabs.thola.io/snmpsim/

Scrafya commented 1 year ago

Keep in mind that while this tool is good for just serverside applications its not very useful for customization for individual devices. I would recommend using https://github.com/delimitry/snmp-server alongside docker to achieve multiple agent support whilst being able to customize the codebase to your needs.

norrisjeremy commented 1 year ago

What part of the following does not match https://snmplabs.thola.io/snmpsim/quickstart.html#installation?

python3 -m venv venv
. venv/bin/activate
pip install snmpsim

snmprec.py --agent-udpv4-endpoint=w.x.y.z:161 --community=xxx --start-object=1.3.6.1.2.1.1.1 --stop-object=1.3.6.1.2.1.1.5 --output-file=foo
...
ERROR TypeError: decodeMessageVersion.<locals>.<lambda>() takes 3 positional arguments but 4 were given; 

Am I missing something?

Scrafya commented 1 year ago

Its been a while since ive solved the issue my memory doesnt serve me well but i think i installed it manually from this repo and not from snmpsim. I remember seeing that the install of the snmpsim library is not up to date. If this is not the case i would suggest using ChatGPT to debug as it pointed out where the dependency issues were.

norrisjeremy commented 1 year ago

So the problem appears to be the latest version of pyasn1 (0.5.0) that gets installed if you just pip install snmpsim is not compatible.

The fix appears to be manually install the older 0.4.8 release first:

python3 -m venv venv
. venv/bin/activate
pip install pyasn1==0.4.8
pip install snmpsim
Scrafya commented 1 year ago

Has this solved the issue?

norrisjeremy commented 1 year ago

If you use the forked package snmpsim-lextudio and https://pysnmp.com, you might find there are less troubles.

More details can be found in etingof/pysnmp#429

Yes, this seems to work for me w/o any of the previous issues, thank you!

python3 -m venv venv
. venv/bin/activate
pip install snmpsim-lextudio

snmpsim-record-commands --agent-udpv4-endpoint=w.x.y.z:161 --community=xxx --start-object=1.3.6.1.2.1.1.1 --stop-object=1.3.6.1.2.1.1.5 --output-file=foo
EricChandia commented 1 year ago

So the problem appears to be the latest version of pyasn1 (0.5.0) that gets installed if you just pip install snmpsim is not compatible.

The fix appears to be manually install the older 0.4.8 release first:

python3 -m venv venv
. venv/bin/activate
pip install pyasn1==0.4.8
pip install snmpsim

Thank you so much, this worked! So the problem is with pyasn1 (0.5.0), just need to downgrade the version, for anyone who still having issues.

lextm commented 1 year ago

A summary of the issue is,

  1. @Scrafya for some reason installed pyasn1 0.5.0-rc, and that broke pysnmp and snmpsim. By switching to a virtual environment, probably that environment only pulled down production pyasn1 (0.4.x at that time), so the issue was resolved and closed.
  2. pyasn1 0.5.0 was released by its new maintainers a few days ago, which in turn breaks more pysnmp 4.4.x users like @EricChandia and @norrisjeremy. The solution you found is of course to downgrade pyasn1 to 0.4.x.

In the long run, we will see what happens on pyasn1 side. The maintainers are so new that they probably need more time to learn enough about the package.

If you like, you can read https://github.com/etingof/pysnmp/issues/429 to learn more about the entire ecosystem today. Sites like https://snmplabs.thola.io/snmpsim/ are rather problematic as their owners didn't really want to take over the bits. You might check out https://pysnmp.com and the *-lextudio packages maintained by my team.