mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-18 22:44:29 +01:00
move realm out of ssh
This commit is contained in:
53
cowrie/core/realm.py
Normal file
53
cowrie/core/realm.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in the
|
||||||
|
# documentation and/or other materials provided with the distribution.
|
||||||
|
# 3. The names of the author(s) may not be used to endorse or promote
|
||||||
|
# products derived from this software without specific prior written
|
||||||
|
# permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
# SUCH DAMAGE.
|
||||||
|
|
||||||
|
from zope.interface import implements
|
||||||
|
|
||||||
|
import twisted
|
||||||
|
from twisted.conch import interfaces as conchinterfaces
|
||||||
|
from twisted.python import log
|
||||||
|
|
||||||
|
from . import protocol
|
||||||
|
from . import server
|
||||||
|
from . import ssh
|
||||||
|
|
||||||
|
class HoneyPotRealm:
|
||||||
|
implements(twisted.cred.portal.IRealm)
|
||||||
|
|
||||||
|
def __init__(self, cfg):
|
||||||
|
self.cfg = cfg
|
||||||
|
self.myserver = server.CowrieServer(self.cfg)
|
||||||
|
|
||||||
|
def requestAvatar(self, avatarId, mind, *interfaces):
|
||||||
|
log.msg( "reqAva: %s" % (repr( mind )))
|
||||||
|
if conchinterfaces.IConchUser in interfaces:
|
||||||
|
return interfaces[0], \
|
||||||
|
ssh.HoneyPotAvatar(avatarId, self.myserver), lambda: None
|
||||||
|
else:
|
||||||
|
raise Exception("No supported interfaces found.")
|
||||||
|
|
||||||
@@ -255,21 +255,6 @@ class HoneyPotSSHFactory(factory.SSHFactory):
|
|||||||
t.factory = self
|
t.factory = self
|
||||||
return t
|
return t
|
||||||
|
|
||||||
class HoneyPotRealm:
|
|
||||||
implements(twisted.cred.portal.IRealm)
|
|
||||||
|
|
||||||
def __init__(self, cfg):
|
|
||||||
self.cfg = cfg
|
|
||||||
self.myserver = server.CowrieServer(self.cfg)
|
|
||||||
|
|
||||||
def requestAvatar(self, avatarId, mind, *interfaces):
|
|
||||||
log.msg( "reqAva: %s" % (repr( mind )))
|
|
||||||
if conchinterfaces.IConchUser in interfaces:
|
|
||||||
return interfaces[0], \
|
|
||||||
HoneyPotAvatar(avatarId, self.myserver), lambda: None
|
|
||||||
else:
|
|
||||||
raise Exception("No supported interfaces found.")
|
|
||||||
|
|
||||||
class HoneyPotTransport(transport.SSHServerTransport):
|
class HoneyPotTransport(transport.SSHServerTransport):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from twisted.cred import portal
|
|||||||
from cowrie.core.config import readConfigFile
|
from cowrie.core.config import readConfigFile
|
||||||
from cowrie import core
|
from cowrie import core
|
||||||
import cowrie.core.ssh
|
import cowrie.core.ssh
|
||||||
|
import cowrie.core.realm
|
||||||
import cowrie.core.checkers
|
import cowrie.core.checkers
|
||||||
|
|
||||||
class Options(usage.Options):
|
class Options(usage.Options):
|
||||||
@@ -51,7 +52,7 @@ class CowrieServiceMaker(object):
|
|||||||
listen_port = 2222
|
listen_port = 2222
|
||||||
|
|
||||||
factory = core.ssh.HoneyPotSSHFactory(cfg)
|
factory = core.ssh.HoneyPotSSHFactory(cfg)
|
||||||
factory.portal = portal.Portal(core.ssh.HoneyPotRealm(cfg))
|
factory.portal = portal.Portal(core.realm.HoneyPotRealm(cfg))
|
||||||
factory.portal.registerChecker(cowrie.core.checkers.HoneypotPublicKeyChecker(cfg))
|
factory.portal.registerChecker(cowrie.core.checkers.HoneypotPublicKeyChecker(cfg))
|
||||||
factory.portal.registerChecker(cowrie.core.checkers.HoneypotPasswordChecker(cfg))
|
factory.portal.registerChecker(cowrie.core.checkers.HoneypotPasswordChecker(cfg))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user