diff --git a/scapy/automaton.py b/scapy/automaton.py index 2aae9168725..5f3ffcc12cd 100644 --- a/scapy/automaton.py +++ b/scapy/automaton.py @@ -681,6 +681,9 @@ def recv(self, n=MTU, **kwargs): # type: ignore r = self.spb.recv(n) if self.proto is not None and r is not None: r = self.proto(r, **kwargs) + if self.atmt.atmt_session is not None: + # Apply session if provided + r = self.atmt.atmt_session.process(r) return r def close(self): @@ -962,7 +965,8 @@ def parse_args(self, debug=0, store=0, session=None, **kargs): self.debug_level = debug if debug: conf.logLevel = logging.DEBUG - self.atmt_session = session + if session: + self.atmt_session = session self.socket_kargs = kargs self.store_packets = store diff --git a/scapy/fwdmachine.py b/scapy/fwdmachine.py index 10c2f6a4e92..3e75cef8e88 100644 --- a/scapy/fwdmachine.py +++ b/scapy/fwdmachine.py @@ -341,7 +341,7 @@ def handler(self, sock, addr, dest): # Wrap both server and peer sockets in SSL if self.tls: # Build client SSL context - clisslcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) + clisslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS) clisslcontext.load_default_certs() clisslcontext.check_hostname = False clisslcontext.verify_mode = ssl.CERT_NONE diff --git a/scapy/layers/snmp.py b/scapy/layers/snmp.py index d6a8bf69e56..713a65a46b8 100644 --- a/scapy/layers/snmp.py +++ b/scapy/layers/snmp.py @@ -15,7 +15,7 @@ from scapy.asn1.asn1 import ASN1_Class_UNIVERSAL, ASN1_Codecs, ASN1_NULL, \ ASN1_SEQUENCE from scapy.asn1.ber import BERcodec_SEQUENCE -from scapy.sendrecv import sr1 +from scapy.sendrecv import sr, sr1 from scapy.volatile import RandShort, IntAutoTime from scapy.layers.inet import UDP, IP, ICMP @@ -287,10 +287,51 @@ def answers(self, other): bind_layers(UDP, SNMP, sport=161, dport=161) +def snmpget(dst, oid="1.0.8802.1.1.1.1.1.2.1.2.29", community="public"): + """ + SNMP get. + + This can be used to perform a SNMP scan:: + + >>> snmpget("192.168.0.0/16", community="public") + """ + ans, _ = sr( + IP(dst=dst) / UDP(sport=RandShort()) / SNMP( + community=community, + PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=oid)]), + ), + timeout=2, + chainCC=1, + verbose=0, + retry=2, + ) + for r in ans: + if ICMP in r.answer: + print(repr(r.answer)) + return + print("[%-10s] %-40s: %r" % ( + r.query.dst, + r.answer[SNMPvarbind].oid.val, + r.answer[SNMPvarbind].value, + )) + + def snmpwalk(dst, oid="1", community="public"): + """ + SNMP walk + """ try: while True: - r = sr1(IP(dst=dst) / UDP(sport=RandShort()) / SNMP(community=community, PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=oid)])), timeout=2, chainCC=1, verbose=0, retry=2) # noqa: E501 + r = sr1( + IP(dst=dst) / UDP(sport=RandShort()) / SNMP( + community=community, + PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=oid)]), + ), + timeout=2, + chainCC=1, + verbose=0, + retry=2, + ) if r is None: print("No answers") break