diff --git a/cowrie/core/config.py b/cowrie/core/config.py index 466e4c6..616c592 100644 --- a/cowrie/core/config.py +++ b/cowrie/core/config.py @@ -5,10 +5,10 @@ This module contains ... """ -import ConfigParser +import configparser def readConfigFile(cfgfile): - cfg = ConfigParser.ConfigParser() - cfg.readfp(open(cfgfile)) - return cfg + config = configparser.ConfigParser() + config.read(cfgfile) + return config diff --git a/cowrie/core/honeypot.py b/cowrie/core/honeypot.py index a33085a..ba799b5 100644 --- a/cowrie/core/honeypot.py +++ b/cowrie/core/honeypot.py @@ -333,33 +333,29 @@ class HoneyPotShell(object): """ if not self.interactive: return - # Example: srv03:~# - #prompt = '%s:%%(path)s' % self.protocol.hostname - # Example: root@svr03:~# (More of a "Debianu" feel) - prompt = '%s@%s:%%(path)s' % (self.protocol.user.username, self.protocol.hostname) + + cwd = self.protocol.cwd + homelen = len(self.protocol.user.avatar.home) + if cwd == self.protocol.user.avatar.home: + cwd = '~' + elif len(cwd) > (homelen+1) and \ + cwd[:(homelen+1)] == self.protocol.user.avatar.home + '/': + cwd = '~' + cwd[homelen:] + # Uncomment the three lines below for a 'better' CentOS look. + # Rather than '[root@svr03 /var/log]#' is shows '[root@svr03 log]#'. + #cwd = cwd.rsplit('/', 1)[-1] + #if not cwd: + # cwd = '/' + # Example: [root@svr03 ~]# (More of a "CentOS" feel) - #prompt = '[%s@%s %%(path)s]' % (self.protocol.user.username, self.protocol.hostname,) + # Example: root@svr03:~# (More of a "Debian" feel) + prompt = '{}@{}:{}'.format(self.protocol.user.username, self.protocol.hostname, cwd) if not self.protocol.user.uid: prompt += '# ' # "Root" user else: prompt += '$ ' # "Non-Root" user - - path = self.protocol.cwd - homelen = len(self.protocol.user.avatar.home) - if path == self.protocol.user.avatar.home: - path = '~' - elif len(path) > (homelen+1) and \ - path[:(homelen+1)] == self.protocol.user.avatar.home + '/': - path = '~' + path[homelen:] - # Uncomment the three lines below for a 'better' CentOS look. - # Rather than '[root@svr03 /var/log]#' is shows '[root@svr03 log]#'. - #path = path.rsplit('/', 1)[-1] - #if not path: - # path = '/' - - attrs = {'path': path} - self.protocol.terminal.write(prompt % attrs) - self.protocol.ps = (prompt % attrs , '> ') + self.protocol.terminal.write(prompt) + self.protocol.ps = (prompt , '> ') def eofReceived(self): diff --git a/cowrie/ssh/filetransfer.py b/cowrie/ssh/filetransfer.py index 9d0b777..5f81204 100644 --- a/cowrie/ssh/filetransfer.py +++ b/cowrie/ssh/filetransfer.py @@ -53,11 +53,11 @@ class CowrieSFTPFile(object): if flags & FXF_EXCL == FXF_EXCL: openFlags |= os.O_EXCL if "permissions" in attrs: - mode = attrs["permissions"] + filemode = attrs["permissions"] del attrs["permissions"] else: - mode = 0777 - fd = sftpserver.fs.open(filename, openFlags, mode) + filemode = 0777 + fd = sftpserver.fs.open(filename, openFlags, filemode) if attrs: self.sftpserver.setAttrs(filename, attrs) self.fd = fd diff --git a/twisted/plugins/cowrie_plugin.py b/twisted/plugins/cowrie_plugin.py index 795fa4d..eced952 100644 --- a/twisted/plugins/cowrie_plugin.py +++ b/twisted/plugins/cowrie_plugin.py @@ -111,9 +111,9 @@ class CowrieServiceMaker(object): if options['port'] != 0: listen_ssh_port = int(options["port"]) elif cfg.has_option('ssh', 'listen_port'): - listen_ssh_port = int(cfg.get('ssh', 'listen_port')) + listen_ssh_port = cfg.getint('ssh', 'listen_port') elif cfg.has_option('honeypot', 'listen_port'): - listen_ssh_port = int(cfg.get('honeypot', 'listen_port')) + listen_ssh_port = cfg.getint('honeypot', 'listen_port') else: listen_ssh_port = 2222 @@ -133,7 +133,7 @@ class CowrieServiceMaker(object): # Preference: 1, config, 2, default of 2223 if cfg.has_option('telnet', 'listen_port'): - listen_telnet_port = int(cfg.get('telnet', 'listen_port')) + listen_telnet_port = cfg.getint('telnet', 'listen_port') else: listen_telnet_port = 2223