Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snmpsimd: For SNMPv3 context name has to be specified. #88

Closed
Michael-Cui opened this issue Sep 6, 2019 · 8 comments
Closed

snmpsimd: For SNMPv3 context name has to be specified. #88

Michael-Cui opened this issue Sep 6, 2019 · 8 comments

Comments

@Michael-Cui
Copy link

When using snmpwalk to get information from real device, context name is unnecessary. But when get information from snmpsimd context name must be specified, otherwise nothing can be retrieved. It's better for snmpsimd to have the same behavior with real device?

@etingof
Copy link
Owner

etingof commented Sep 7, 2019

Looks totally reasonable to me!

Trouble is that default SNMPv3 context is an empty string. Given snmpsim's model of file-based agent addressing and unavailability of empty file name on most (?) file systems, may be we should iterate over all combinations of context-name / transport-ID / source-address .snmprec as noted in the doc e.g. try to find snmprec file by:

  • context-name / transport-ID / source-address .snmprec
  • transport-ID / source-address .snmprec
  • context-name / source-address .snmprec
  • source-address .snmprec
  • context-name / transport-ID .snmprec
  • context-name.snmprec
  • ...

That can cause conflicts, however perhaps resolvable in every particular situation...

Alternatively, may be we could solve this by adding context-engine-id into the mixture:

  • context-engine-id / context-name / transport-ID / source-address .snmprec

Then context-engine-id.snmprec would map to an empty context name (where context-engine-id here would be the same as snmp-engine-id of the snmpsim agent being simulated).

WDYT?

@etingof
Copy link
Owner

etingof commented Sep 8, 2019

It just occurred to be, that you can simulate empty SNMP context name by having your .snmprec files in form of transport-id.snmprec.

Anyway, I've added a hopefully clearer solution (#89) by introducing context-engine-id component into the search path (option two from the above comment).

For better usability actual SNMP context engine ID from request is automatically replaced with self if it equals to local SNMP engine ID. With #89, this path should map to empty SNMP community/context name:

self.snmprec

Let me know if that works for you.

@etingof etingof closed this as completed Sep 9, 2019
@Michael-Cui
Copy link
Author

yes,it works. Thank you very much.

@kuhnto
Copy link

kuhnto commented Apr 22, 2020

Hi,
I know it has been a while shince this was fixed, but I am having the same issue with my SNMP manager sending a blank ContextID. I am not sure how to get this new fix to work correctly. I have tried the following:

  • renamed MYMIB.snmprec to "self.snmprec"
  • renamed MYMIB.snmprec to [engineID].snmprec (I do not think this works becasue the EngineID changes)

I am using saved cache files, but I am not sure if that matters.

My startup is:

start snmpsimd.py --cache-dir=./cache --data-dir=./data --variation-modules-dir=./variation --v3-only ^
--v3-user=XYZ2008 ^
--v3-auth-key=XYZpassword ^
--v3-auth-proto=MD5 ^
--v3-priv-key=XYZpassword ^
--v3-priv-proto=DES ^
--agent-udpv4-endpoint=10.161.175.245:10001

When I set the snmrec file to self.snmprec, and have my cache files named as data_self.dbm.XXX, I get he following output:

--- SNMP Engine configuration
SNMPv3 EngineID: 0x80004fb80514b44fc8
--- Data directories configuration
SNMPv3 Context Engine ID: 0x80004fb80514b44fc8
...
Configuring c:\test\virtualspace\snmpsim\data\self.snmprec controller
SNMPv1/2c community name: self
SNMPv3 Context Name: 590f53e8699817c6fa498cc11a4cbe63 or self

If I use "590f53e8699817c6fa498cc11a4cbe63" or "self" for the context name I connect and get output like:

Using c:\test\virtualspace\snmpsim\data\self.snmprec controller selected by candidate b'590f53e8699817c6fa498cc11a4cbe63'; transport ID 1.3.6.1.6.1.1.0, source address 10.161.175.230, context name "b'590f53e8699817c6fa498cc11a4cbe63'"
SNMP EngineID 0x80004fb80514b44fc8, transportDomain (1, 3, 6, 1, 6, 1, 1, 0), transportAddress ('10.161.175.230', 56739), securityModel 3, securityName XYZ2008, securityLevel 3

but with "" as the Context ID I get:

Using <pysnmp.smi.instrum.MibInstrumController object at 0x000002497D5E6048> selected by contextName "", transport ID 1.3.6.1.6.1.1.0, source address 10.161.175.230
ERROR LCD access denied (contextName does not match any data file)

Any help on how to get this working correctly?

@tkekan
Copy link

tkekan commented Oct 12, 2020

@kuhnto I'm trying to use the snmpsim as v3 agent. Since the snmp labs is down, I don't have access to their documentation. Can you please help here on how to start the snmpsim as v3 . Also is there a way to start the agent as both v2 and v3 ?
i'm just looking for some examples on how this can be achieved.

Currently I'm starting the agent as v2 and that works fine as follows. ( I do get responses on writing snmp client / using snmpget as "snmpget -v 2c -c public 127.0.0.1:1024 sysUpTime.0")
snmpsim-command-responder --data-dir=./data --variation-modules-dir=./variation --agent-udpv4-endpoint=127.0.0.1:1024

@kuhnto
Copy link

kuhnto commented Oct 13, 2020

This is what I am starting my emulator with:

snmpsimd.py --cache-dir=c:\snmpsim\cache --data-dir=c:\snmpsim\data --variation-modules-dir=c:\snmpsim\variation --v3-only ^
--v3-user=user1234 ^
--v3-auth-key=password1234 ^
--v3-auth-proto=MD5 ^
--v3-priv-key=password1234 ^
--v3-priv-proto=DES ^
--agent-udpv4-endpoint=10.99.123.121:10001

@gainskills
Copy link

This is what I am starting my emulator with:

snmpsimd.py --cache-dir=c:\snmpsim\cache --data-dir=c:\snmpsim\data --variation-modules-dir=c:\snmpsim\variation --v3-only ^
--v3-user=user1234 ^
--v3-auth-key=password1234 ^
--v3-auth-proto=MD5 ^
--v3-priv-key=password1234 ^
--v3-priv-proto=DES ^
--agent-udpv4-endpoint=10.99.123.121:10001

try with the latest version.

@tkekan
Copy link

tkekan commented Nov 20, 2020

Thanks @kuhnto and @gainskills . I was able to launch the simulator in v3 mode.
SO when I launch this single simulator in v2 mode, I was able to simulate it like multiple devices by having separate snmprec file per device like device1.snmprec , device2.snmprec.

But when launching in v3 mode with CMD line similar to what you posted, I have seen it generates some transport-ID, eg as below

CMD: snmpsimd.py --v3-user=v3 --v3-auth-proto SHA --v3-priv-proto AES128 --v3-auth-key=test1234 --v3-priv-key=test1234 --data-dir=/usr/snmpsim/data --log-level=debug --logging-method=file:/logs/simulator.log --variation-modules-dir=/usr/snmpsim/variation --agent-udpv4-endpoint=127.0.0.1:1024

snmpsimd: Listening at UDP/IPv4 endpoint 127.0.0.1:1024, transport ID 1.3.6.1.6.1.1.0

Now for any snmget, it always fetches the file named 1.3.6.1.6.1.1.0/127.0.0.1.snmprec.
Is there a way to change this ? And how I can enforce v3 mode for multiple devices, such that it picks the responses from their respective snmprec files similar to what we can achieve when running in v2 mode ( or doing snmpget v2 queries ) only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants