lextudio / sharpsnmplib

Sharp SNMP Library- Open Source SNMP for .NET
https://sharpsnmp.com
MIT License
356 stars 152 forks source link

SNMPv3 Authentication. #573

Closed lextudio-support closed 2 hours ago

lextudio-support commented 2 hours ago

Just a quick question about SNMPv3 . I wanted to secure my service so that only the privacy user can have access to the agent so in the SNMPD sample I commented out the neither and privacy users. I also commented out the v1 and v2 handlers.

When the agent is contacted it crashes when the MalformedPdu > RequestID is called. Looking through the stack it seems that this is because the authentication has failed , even though I have proved the correct privacy and authentication string.

I realise that this is a NOOB question , but any ideas?

Cheers

Steven

Original Reported Date: 2011-07-22T02:33:20.907-07:00 Original CodePlex Discussion Thread ID: 266170

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Hi Steven,

You provided too little information on the crash. The more you tell, the easier I can find out the cause.

  1. Exception call stack.
  2. The steps to reproduce it from a standard #SNMP code base.

Regards,

Lex

Original Posted Date: 2011-07-23T21:46:28.22-07:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Sorry

Ok I took the SNMPD example , cloned the unity markup to a new agent and removed all v1 and v2 handler references. I then modified program.cs to load the new agent. and commented out neither and authen

When the agent received the discovery packet it was crashing. It looked like the wrong get request has been loaded into the pipeline.

It seems to be okay with the neither account .But the privacy account causes a SharpMessageFactoryInnerExcpetion

Call Stack:

SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpEngine.ListenerExceptionRaised(object sender, Lextm.SharpSnmpLib.Messaging.ExceptionRaisedEventArgs e) Line 159 C#> SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.Listener.AddBinding.AnonymousMethod__1(object o, Lextm.SharpSnmpLib.Messaging.ExceptionRaisedEventArgs args) Line 239 + 0x1b bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleException(System.Exception exception) Line 366 + 0x52 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(Lextm.SharpSnmpLib.Messaging.MessageParams param) Line 386 + 0x10 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(object o) Line 371 + 0x2b bytes C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x9b bytes mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x61 bytes mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x4f bytes

Cheers

Steven

Original Posted Date: 2011-07-25T01:18:32.417-07:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Okay , some of the last issues were socket issues , I have fixed this by testing it on another port. Still unable to get the the privacy member to connect.

error from the browser.exe side.

Lextm.SharpSnmpLib.SnmpException: invalid v3 packet data hash detected at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessage(Int32 first, Stream stream, UserRegistry registry) in g:\sharpsnmplib\SharpSnmpLib\Messaging\MessageFactory.cs:line 190 at Lextm.SharpSnmpLib.Messaging.MessageFactory.ParseMessages(Byte[] buffer, Int32 index, Int32 length, UserRegistry registry) in g:\sharpsnmplib\SharpSnmpLib\Messaging\MessageFactory.cs:line 109 at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, UserRegistry registry, Socket udpSocket) in g:\sharpsnmplib\SharpSnmpLib\Messaging\SnmpMessageExtension.cs:line 428 at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, UserRegistry registry) in g:\sharpsnmplib\SharpSnmpLib\Messaging\SnmpMessageExtension.cs:line 285 at Lextm.SharpSnmpLib.Browser.SecureAgentProfile.Get(Variable variable) in g:\sharpsnmplib\Browser\SecureAgentProfile.cs:line 77 at Lextm.SharpSnmpLib.Browser.MibTreePanel.ActGetExecute(Object sender, EventArgs e) in g:\sharpsnmplib\Browser\MibTreePanel.cs:line 110

From Agent when Auth User is used with incorrect login:

SharpSnmpLib.dll!Lextm.SharpSnmpLib.MalformedPdu.RequestId.get() Line 53 + 0x29 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.RequestId(Lextm.SharpSnmpLib.Messaging.ISnmpMessage message) Line 75 + 0x64 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SecureSnmpContext.HandleAuthenticationFailure() Line 52 + 0x3e6 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpApplication.OnAuthenticateRequest() Line 118 + 0x3a bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpApplication.Process() Line 77 + 0xa bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpEngine.ListenerMessageReceived(object sender, Lextm.SharpSnmpLib.Messaging.MessageReceivedEventArgs e) Line 106 + 0x12 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.Listener.AddBinding.AnonymousMethod__2(object o, Lextm.SharpSnmpLib.Messaging.MessageReceivedEventArgs args) Line 247 + 0x1b bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(Lextm.SharpSnmpLib.Messaging.MessageParams param) Line 399 + 0x8d bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(object o) Line 371 + 0x2b bytes C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x9b bytes mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x61 bytes mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x4f bytes

From Agent with correct login when discovery is sent.

SharpSnmpLib.dll!Lextm.SharpSnmpLib.MalformedPdu.RequestId.get() Line 53 + 0x29 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.RequestId(Lextm.SharpSnmpLib.Messaging.ISnmpMessage message) Line 75 + 0x64 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SecureSnmpContext.HandleAuthenticationFailure() Line 52 + 0x3e6 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpApplication.OnAuthenticateRequest() Line 118 + 0x3a bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpApplication.Process() Line 77 + 0xa bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Pipeline.SnmpEngine.ListenerMessageReceived(object sender, Lextm.SharpSnmpLib.Messaging.MessageReceivedEventArgs e) Line 106 + 0x12 bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.Listener.AddBinding.AnonymousMethod__2(object o, Lextm.SharpSnmpLib.Messaging.MessageReceivedEventArgs args) Line 247 + 0x1b bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(Lextm.SharpSnmpLib.Messaging.MessageParams param) Line 399 + 0x8d bytes C# SharpSnmpLib.dll!Lextm.SharpSnmpLib.Messaging.ListenerBinding.HandleMessage(object o) Line 371 + 0x2b bytes C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x9b bytes mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x61 bytes mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x4f bytes

Original Posted Date: 2011-07-25T06:34:34.643-07:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Thanks for the details.

  1. "Lextm.SharpSnmpLib.SnmpException: invalid v3 packet data hash detected"

This exception was caused by a mistake in SecureSnmpContext.cs. I just fixed it in revision b3661af52e9e, http://code.google.com/p/sharpsnmplib/source/detail?r=b3661af52e9ed22f62bc01649d9d335036041006

2. The other exceptions may be caused by MalformedPdu.RequestId. I changed its implementation in 9d5693df47eb, so now another exception is raised, "Lextm.SharpSnmpLib.SnmpException: invalid v3 packet data hash detected". This is still unpleasant, as in such cases #SNMP should report authentication failure. It requires further changes in MessageFactory and I am still working on it.

Will post an update here when I finish.

Regards,

Lex

Original Posted Date: 2011-07-31T01:12:30.7-07:00

lextudio-support commented 2 hours ago

Marked as Answer Date: 2013-10-06T21:20:11.813-07:00