etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
582 stars 200 forks source link

Is SNMP TRAP Notification source address spoofing possible? #289

Closed amartiresST closed 5 years ago

amartiresST commented 5 years ago

Hi, I need to develop a script that generates snmp traps from syslog messages and I was thinking that maybe I could pass the syslog message to a python script that would generate a snmp trap, but I need the trap to have the original message host address and not the syslog server address.

Is it possible to spoof the source address when sending a notification with pysnmp?

Thanks!

etingof commented 5 years ago

Hey, yes! This should work at least on UNIX and if you are not using asyncio. Here is an example for SNMP GET, but it should be similar for notifications.

amartiresST commented 5 years ago

Thanks a lot @etingof! I think I got the gist of it.

I'm having some trouble finding how to replace this part in order to send a TRAP Notification...

# Prepare and send a request message
cmdgen.GetCommandGenerator().sendVarBinds(
    snmpEngine,
    'my-router',
    None, '',  # contextEngineId, contextName
    [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
    cbFun
)

I suppose I need to generate a command for sending a trap, but I can't seem to find and adequate class.

Am I on the wrong path here? Can you give me some clue?

etingof commented 5 years ago

Look for notification originator - that's the SNMP parlance.

amartiresST commented 5 years ago

@etingof, I will look into that. Thanks!

amartiresST commented 5 years ago

I got it to work.

Basically all I needed to do was to add the sourceAddress=('1.2.3.4', 0) to config.addTargetAddr() following the example in the notification originator.

Thanks a lot for you help! Cheers!

etingof commented 5 years ago

Awesome!