Skip to content

Commit

Permalink
log information when SNMP packet cannot be decoded
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-sahlmann committed Jul 12, 2023
1 parent c0e5ca7 commit 0a37ac5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mb_netmgmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with mb-netmgmt. If not, see <https://www.gnu.org/licenses/

"""Network Management Protocols for Mountebank"""
__version__ = "0.0.66"
__version__ = "0.0.67"

import os
import subprocess
Expand Down
8 changes: 7 additions & 1 deletion mb_netmgmt/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
# along with mb-netmgmt. If not, see <https://www.gnu.org/licenses/

import binascii
import logging
from base64 import b64decode, b64encode
from socket import SOCK_DGRAM, socket
from socketserver import DatagramRequestHandler, ThreadingUDPServer, UDPServer

from scapy.asn1.asn1 import ASN1_Class_UNIVERSAL
from scapy.asn1.ber import BER_Decoding_Error
from scapy.layers.snmp import SNMP, SNMPbulk, SNMPresponse, SNMPvarbind

from mb_netmgmt.__main__ import Protocol
Expand Down Expand Up @@ -60,7 +62,11 @@ def open_upstream(self, to):

def read_proxy_response(self):
bytes_response = self.upstream_socket.recv(UDPServer.max_packet_size)
snmp_response = SNMP(bytes_response)
try:
snmp_response = SNMP(bytes_response)
except BER_Decoding_Error:
logging.error(bytes_response)
raise
result = dict()
for varbind in snmp_response.PDU.varbindlist:
result[varbind.oid.val] = {
Expand Down

0 comments on commit 0a37ac5

Please sign in to comment.