mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
sort out env variables.
This commit is contained in:
@ -8,6 +8,7 @@ __all__ = [
|
||||
'busybox',
|
||||
'curl',
|
||||
'dice',
|
||||
'env',
|
||||
'ethtool',
|
||||
'fs',
|
||||
'gcc',
|
||||
|
@ -55,7 +55,7 @@ class command_busybox(HoneyPotCommand):
|
||||
line = ' '.join(args)
|
||||
cmd = args[0]
|
||||
args = args[1:]
|
||||
cmdclass = self.protocol.getCommand(cmd, self.env['PATH'].split(':'))
|
||||
cmdclass = self.protocol.getCommand(cmd, self.environ['PATH'].split(':'))
|
||||
if cmdclass:
|
||||
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
||||
self.protocol.call_command(cmdclass, *args)
|
||||
|
@ -92,7 +92,7 @@ Sudoers I/O plugin version 1.8.5p2''')
|
||||
line = ' '.join(args)
|
||||
cmd = args[0]
|
||||
args = args[1:]
|
||||
cmdclass = self.protocol.getCommand(cmd, self.env['PATH'].split(':'))
|
||||
cmdclass = self.protocol.getCommand(cmd, self.environ['PATH'].split(':'))
|
||||
if cmdclass:
|
||||
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
||||
self.protocol.call_command(cmdclass, *args)
|
||||
|
@ -12,12 +12,12 @@ class command_which(HoneyPotCommand):
|
||||
""" Look up all the arguments on PATH and print each (first) result """
|
||||
|
||||
# No arguments, just exit
|
||||
if not len(self.args) or not 'PATH' in self.env:
|
||||
if not len(self.args) or not 'PATH' in self.environ:
|
||||
return
|
||||
|
||||
# Look up each file
|
||||
for f in self.args:
|
||||
for path in self.env['PATH'].split(':'):
|
||||
for path in self.environ['PATH'].split(':'):
|
||||
resolved = self.fs.resolve_path(f, path)
|
||||
|
||||
if self.fs.exists(resolved):
|
||||
|
@ -21,7 +21,7 @@ class HoneyPotCommand(object):
|
||||
def __init__(self, protocol, *args):
|
||||
self.protocol = protocol
|
||||
self.args = args
|
||||
self.env = self.protocol.cmdstack[0].envvars
|
||||
self.environ = self.protocol.cmdstack[0].environ
|
||||
self.writeln = self.protocol.writeln
|
||||
self.write = self.protocol.terminal.write
|
||||
self.nextLine = self.protocol.terminal.nextLine
|
||||
@ -92,9 +92,7 @@ class HoneyPotShell(object):
|
||||
self.interactive = interactive
|
||||
self.showPrompt()
|
||||
self.cmdpending = []
|
||||
self.envvars = {
|
||||
'PATH': '/bin:/usr/bin:/sbin:/usr/sbin',
|
||||
}
|
||||
self.environ = protocol.environ
|
||||
|
||||
|
||||
def lineReceived(self, line):
|
||||
@ -146,13 +144,13 @@ class HoneyPotShell(object):
|
||||
return
|
||||
|
||||
# Probably no reason to be this comprehensive for just PATH...
|
||||
envvars = copy.copy(self.envvars)
|
||||
environ = copy.copy(self.environ)
|
||||
cmd = None
|
||||
while len(cmdAndArgs):
|
||||
piece = cmdAndArgs.pop(0)
|
||||
if piece.count('='):
|
||||
key, value = piece.split('=', 1)
|
||||
envvars[key] = value
|
||||
environ[key] = value
|
||||
continue
|
||||
cmd = piece
|
||||
break
|
||||
@ -169,7 +167,7 @@ class HoneyPotShell(object):
|
||||
rargs.extend(matches)
|
||||
else:
|
||||
rargs.append(arg)
|
||||
cmdclass = self.protocol.getCommand(cmd, envvars['PATH'].split(':'))
|
||||
cmdclass = self.protocol.getCommand(cmd, environ['PATH'].split(':'))
|
||||
if cmdclass:
|
||||
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
||||
self.protocol.call_command(cmdclass, *rargs)
|
||||
|
@ -26,6 +26,7 @@ class HoneyPotBaseProtocol(insults.TerminalProtocol, TimeoutMixin):
|
||||
|
||||
def __init__(self, avatar):
|
||||
self.user = avatar
|
||||
self.environ = avatar.environ
|
||||
self.cfg = self.user.cfg
|
||||
self.hostname = avatar.server.hostname
|
||||
self.fs = avatar.server.fs
|
||||
|
@ -567,13 +567,16 @@ class SSHSessionForCowrieUser:
|
||||
requests. Uses the default reactor if None.
|
||||
"""
|
||||
self.protocol = None
|
||||
self.environ = {'PATH': '/bin:/usr/bin:/usr/local/bin'}
|
||||
self.avatar = avatar
|
||||
self.server = avatar.server
|
||||
self.cfg = avatar.cfg
|
||||
self.uid = avatar.uid
|
||||
self.gid = avatar.gid
|
||||
self.username = avatar.username
|
||||
self.environ = {'PATH': '/bin:/usr/bin:/usr/local/bin',
|
||||
'LOGNAME': self.username,
|
||||
'USER': self.username,
|
||||
'HOME': self.avatar.home}
|
||||
|
||||
|
||||
def openShell(self, proto):
|
||||
@ -588,6 +591,7 @@ class SSHSessionForCowrieUser:
|
||||
def getPty(self, terminal, windowSize, attrs):
|
||||
"""
|
||||
"""
|
||||
self.environ['TERM'] = terminal
|
||||
log.msg(eventid='KIPP0010', width=windowSize[0], height=windowSize[1],
|
||||
format='Terminal Size: %(width)s %(height)s')
|
||||
self.windowSize = windowSize
|
||||
|
Reference in New Issue
Block a user