mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
Squashed commit of the following:
commit 79fff5332ba74bab40d0059e1051ca62614488ff Merge: 645f25f 39c9fa4 Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:46:09 2016 +0000 Merge branch 'configparser' of https://github.com/micheloosterhof/cowrie into configparser commit 645f25f6f22dbe374b544f08d69b7de2ef0dcb45 Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:37:46 2016 +0000 rewrite code for prompt. this had issues with unicode commit 99adf95f27ef03b229e592f1fa393cf66be3faf0 Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:15:10 2016 +0000 can't use "mode" commit bee2b6693fe009d361a0b117c67d11f37ed21c41 Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:09:57 2016 +0000 configparser changes. not working well yet on py2 commit 39c9fa406cca9ede51af8329280af81fff870e31 Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:37:46 2016 +0000 rewrite code for prompt. this had issues with unicode commit 3dd08206fcb4c7dd0a66d20b914e3279947c77de Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:15:10 2016 +0000 can't use "mode" commit f54272b239409b65ef0292ac328b0a2efccbe6cd Author: Michel Oosterhof <michel@oosterhof.net> Date: Sun Sep 18 14:09:57 2016 +0000 configparser changes. not working well yet on py2
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user