Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scapy/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scapy/fwdmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 43 additions & 2 deletions scapy/layers/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading