Skip to content

Commit

Permalink
Fix regression in telnet service
Browse files Browse the repository at this point in the history
A regression in the telnet service occured where the Realm/portal
required by AuthenticatingTelnetProtocol in twisted was removed.
  • Loading branch information
thinkst-francois committed Oct 30, 2023
1 parent 5c1663e commit b7579b7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions opencanary/modules/telnet.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
from opencanary.modules import CanaryService

from zope.interface import implementer
from twisted.application import internet
from twisted.internet.error import ConnectionDone, ConnectionLost
from twisted.internet import protocol
from twisted.cred import portal
from twisted.cred import credentials
from twisted.conch.telnet import AuthenticatingTelnetProtocol
from twisted.conch.telnet import ITelnetProtocol
from twisted.conch.telnet import TelnetTransport
from twisted.conch.telnet import ECHO

@implementer(portal.IRealm)
class Realm:
def requestAvatar(self, avatarId, mind, *interfaces):
if ITelnetProtocol in interfaces:
av = MyTelnet()
av.state = 'Command'
return ITelnetProtocol, av, lambda:None
raise NotImplementedError("Not supported by this realm")

class CanaryTelnetTransport(TelnetTransport):
def dataReceived(self, data):
Expand All @@ -24,7 +34,6 @@ def connectionLost(self, reason):
return
TelnetTransport.connectionLost(self, reason)


class AlertAuthTelnetProtocol(AuthenticatingTelnetProtocol):
def connectionMade(self):
# p/Cisco telnetd/ d/router/ o/IOS/ cpe:/a:cisco:telnet/ cpe:/o:cisco:ios/a
Expand Down Expand Up @@ -68,9 +77,11 @@ def __init__(self, config=None, logger=None):
self.banner += b"\n"

def getService(self):
r = Realm()
p = portal.Portal(r)
f = protocol.ServerFactory()
f.canaryservice = self
f.logger = self.logger
f.banner = self.banner
f.protocol = lambda: CanaryTelnetTransport(AlertAuthTelnetProtocol)
f.protocol = lambda: CanaryTelnetTransport(AlertAuthTelnetProtocol, p)
return internet.TCPServer(self.port, f, interface=self.listen_addr)

0 comments on commit b7579b7

Please sign in to comment.