move fscopy out of sftp/protocol into avatar. rename user to avatar

This commit is contained in:
Michel Oosterhof
2014-11-09 17:28:06 +04:00
parent 92013388da
commit ad91243658
3 changed files with 17 additions and 17 deletions

View File

@ -2,10 +2,10 @@
# See the COPYRIGHT file for more information # See the COPYRIGHT file for more information
import twisted import twisted
from copy import deepcopy, copy
import os import os
import shlex import shlex
import re import re
import copy.copy
from twisted.python import log from twisted.python import log
from kippo.core import fs from kippo.core import fs
@ -97,7 +97,7 @@ class HoneyPotShell(object):
return return
# probably no reason to be this comprehensive for just PATH... # probably no reason to be this comprehensive for just PATH...
envvars = copy(self.envvars) envvars = copy.copy(self.envvars)
cmd = None cmd = None
while len(cmdAndArgs): while len(cmdAndArgs):
piece = cmdAndArgs.pop(0) piece = cmdAndArgs.pop(0)

View File

@ -5,13 +5,13 @@ import os
import random import random
import time import time
import struct import struct
import copy.copy
from twisted.conch import recvline from twisted.conch import recvline
from twisted.conch.ssh import transport from twisted.conch.ssh import transport
from twisted.conch.insults import insults from twisted.conch.insults import insults
from twisted.internet import protocol from twisted.internet import protocol
from twisted.python import log from twisted.python import log
from copy import deepcopy, copy
from kippo.core import ttylog, fs from kippo.core import ttylog, fs
from kippo.core.config import config from kippo.core.config import config
@ -20,13 +20,13 @@ import kippo.core.honeypot
from kippo import core from kippo import core
class HoneyPotBaseProtocol(insults.TerminalProtocol): class HoneyPotBaseProtocol(insults.TerminalProtocol):
def __init__(self, user, env): def __init__(self, avatar, env):
self.user = user self.user = avatar
self.env = env self.env = env
self.hostname = self.env.cfg.get('honeypot', 'hostname') self.hostname = self.env.cfg.get('honeypot', 'hostname')
self.fs = fs.HoneyPotFilesystem(deepcopy(self.env.fs)) self.fs = avatar.fs
if self.fs.exists(user.home): if self.fs.exists(avatar.home):
self.cwd = user.home self.cwd = avatar.home
else: else:
self.cwd = '/' self.cwd = '/'
# commands is also a copy so we can add stuff on the fly # commands is also a copy so we can add stuff on the fly
@ -134,9 +134,9 @@ class HoneyPotBaseProtocol(insults.TerminalProtocol):
class HoneyPotExecProtocol(HoneyPotBaseProtocol): class HoneyPotExecProtocol(HoneyPotBaseProtocol):
def __init__(self, user, env, execcmd): def __init__(self, avatar, env, execcmd):
self.execcmd = execcmd self.execcmd = execcmd
HoneyPotBaseProtocol.__init__(self, user, env) HoneyPotBaseProtocol.__init__(self, avatar, env)
def connectionMade(self): def connectionMade(self):
HoneyPotBaseProtocol.connectionMade(self) HoneyPotBaseProtocol.connectionMade(self)
@ -153,9 +153,9 @@ class HoneyPotExecProtocol(HoneyPotBaseProtocol):
class HoneyPotInteractiveProtocol(HoneyPotBaseProtocol, recvline.HistoricRecvLine): class HoneyPotInteractiveProtocol(HoneyPotBaseProtocol, recvline.HistoricRecvLine):
def __init__(self, user, env): def __init__(self, avatar, env):
recvline.HistoricRecvLine.__init__(self) recvline.HistoricRecvLine.__init__(self)
HoneyPotBaseProtocol.__init__(self, user, env) HoneyPotBaseProtocol.__init__(self, avatar, env)
def connectionMade(self): def connectionMade(self):
HoneyPotBaseProtocol.connectionMade(self) HoneyPotBaseProtocol.connectionMade(self)

View File

@ -5,6 +5,7 @@ import os
import copy import copy
import time import time
import uuid import uuid
import copy.deepcopy
from zope.interface import implementer from zope.interface import implementer
@ -261,17 +262,17 @@ class HoneyPotAvatar(avatar.ConchUser):
avatar.ConchUser.__init__(self) avatar.ConchUser.__init__(self)
self.username = username self.username = username
self.env = env self.env = env
self.fs = fs.HoneyPotFilesystem(copy.deepcopy(self.env.fs))
self.channelLookup.update({'session': HoneyPotSSHSession}) self.channelLookup.update({'session': HoneyPotSSHSession})
self.channelLookup['direct-tcpip'] = KippoOpenConnectForwardingClient self.channelLookup['direct-tcpip'] = KippoOpenConnectForwardingClient
userdb = core.auth.UserDB()
self.uid = self.gid = userdb.getUID(self.username)
# sftp support enabled only when option is explicitly set # sftp support enabled only when option is explicitly set
if self.env.cfg.has_option('honeypot', 'sftp_enabled'): if self.env.cfg.has_option('honeypot', 'sftp_enabled'):
if ( self.env.cfg.get('honeypot', 'sftp_enabled') == "true" ): if ( self.env.cfg.get('honeypot', 'sftp_enabled') == "true" ):
self.subsystemLookup['sftp'] = filetransfer.FileTransferServer self.subsystemLookup['sftp'] = filetransfer.FileTransferServer
self.uid = self.gid = core.auth.UserDB().getUID(self.username)
if not self.uid: if not self.uid:
self.home = '/root' self.home = '/root'
else: else:
@ -445,8 +446,7 @@ class KippoSFTPServer:
def __init__(self, avatar): def __init__(self, avatar):
self.avatar = avatar self.avatar = avatar
# FIXME we should not copy fs here, but do this at avatar instantiation self.fs = self.avatar.env.fs
self.fs = fs.HoneyPotFilesystem(copy.deepcopy(self.avatar.env.fs))
def _absPath(self, path): def _absPath(self, path):
home = self.avatar.home home = self.avatar.home