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',
|
'busybox',
|
||||||
'curl',
|
'curl',
|
||||||
'dice',
|
'dice',
|
||||||
|
'env',
|
||||||
'ethtool',
|
'ethtool',
|
||||||
'fs',
|
'fs',
|
||||||
'gcc',
|
'gcc',
|
||||||
|
@ -55,7 +55,7 @@ class command_busybox(HoneyPotCommand):
|
|||||||
line = ' '.join(args)
|
line = ' '.join(args)
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
cmdclass = self.protocol.getCommand(cmd, self.env['PATH'].split(':'))
|
cmdclass = self.protocol.getCommand(cmd, self.environ['PATH'].split(':'))
|
||||||
if cmdclass:
|
if cmdclass:
|
||||||
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
||||||
self.protocol.call_command(cmdclass, *args)
|
self.protocol.call_command(cmdclass, *args)
|
||||||
|
@ -92,7 +92,7 @@ Sudoers I/O plugin version 1.8.5p2''')
|
|||||||
line = ' '.join(args)
|
line = ' '.join(args)
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
cmdclass = self.protocol.getCommand(cmd, self.env['PATH'].split(':'))
|
cmdclass = self.protocol.getCommand(cmd, self.environ['PATH'].split(':'))
|
||||||
if cmdclass:
|
if cmdclass:
|
||||||
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
||||||
self.protocol.call_command(cmdclass, *args)
|
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 """
|
""" Look up all the arguments on PATH and print each (first) result """
|
||||||
|
|
||||||
# No arguments, just exit
|
# 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
|
return
|
||||||
|
|
||||||
# Look up each file
|
# Look up each file
|
||||||
for f in self.args:
|
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)
|
resolved = self.fs.resolve_path(f, path)
|
||||||
|
|
||||||
if self.fs.exists(resolved):
|
if self.fs.exists(resolved):
|
||||||
|
@ -21,7 +21,7 @@ class HoneyPotCommand(object):
|
|||||||
def __init__(self, protocol, *args):
|
def __init__(self, protocol, *args):
|
||||||
self.protocol = protocol
|
self.protocol = protocol
|
||||||
self.args = args
|
self.args = args
|
||||||
self.env = self.protocol.cmdstack[0].envvars
|
self.environ = self.protocol.cmdstack[0].environ
|
||||||
self.writeln = self.protocol.writeln
|
self.writeln = self.protocol.writeln
|
||||||
self.write = self.protocol.terminal.write
|
self.write = self.protocol.terminal.write
|
||||||
self.nextLine = self.protocol.terminal.nextLine
|
self.nextLine = self.protocol.terminal.nextLine
|
||||||
@ -92,9 +92,7 @@ class HoneyPotShell(object):
|
|||||||
self.interactive = interactive
|
self.interactive = interactive
|
||||||
self.showPrompt()
|
self.showPrompt()
|
||||||
self.cmdpending = []
|
self.cmdpending = []
|
||||||
self.envvars = {
|
self.environ = protocol.environ
|
||||||
'PATH': '/bin:/usr/bin:/sbin:/usr/sbin',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
@ -146,13 +144,13 @@ 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.copy(self.envvars)
|
environ = copy.copy(self.environ)
|
||||||
cmd = None
|
cmd = None
|
||||||
while len(cmdAndArgs):
|
while len(cmdAndArgs):
|
||||||
piece = cmdAndArgs.pop(0)
|
piece = cmdAndArgs.pop(0)
|
||||||
if piece.count('='):
|
if piece.count('='):
|
||||||
key, value = piece.split('=', 1)
|
key, value = piece.split('=', 1)
|
||||||
envvars[key] = value
|
environ[key] = value
|
||||||
continue
|
continue
|
||||||
cmd = piece
|
cmd = piece
|
||||||
break
|
break
|
||||||
@ -169,7 +167,7 @@ class HoneyPotShell(object):
|
|||||||
rargs.extend(matches)
|
rargs.extend(matches)
|
||||||
else:
|
else:
|
||||||
rargs.append(arg)
|
rargs.append(arg)
|
||||||
cmdclass = self.protocol.getCommand(cmd, envvars['PATH'].split(':'))
|
cmdclass = self.protocol.getCommand(cmd, environ['PATH'].split(':'))
|
||||||
if cmdclass:
|
if cmdclass:
|
||||||
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
log.msg(eventid='KIPP0005', input=line, format='Command found: %(input)s')
|
||||||
self.protocol.call_command(cmdclass, *rargs)
|
self.protocol.call_command(cmdclass, *rargs)
|
||||||
|
@ -26,6 +26,7 @@ class HoneyPotBaseProtocol(insults.TerminalProtocol, TimeoutMixin):
|
|||||||
|
|
||||||
def __init__(self, avatar):
|
def __init__(self, avatar):
|
||||||
self.user = avatar
|
self.user = avatar
|
||||||
|
self.environ = avatar.environ
|
||||||
self.cfg = self.user.cfg
|
self.cfg = self.user.cfg
|
||||||
self.hostname = avatar.server.hostname
|
self.hostname = avatar.server.hostname
|
||||||
self.fs = avatar.server.fs
|
self.fs = avatar.server.fs
|
||||||
|
@ -567,13 +567,16 @@ class SSHSessionForCowrieUser:
|
|||||||
requests. Uses the default reactor if None.
|
requests. Uses the default reactor if None.
|
||||||
"""
|
"""
|
||||||
self.protocol = None
|
self.protocol = None
|
||||||
self.environ = {'PATH': '/bin:/usr/bin:/usr/local/bin'}
|
|
||||||
self.avatar = avatar
|
self.avatar = avatar
|
||||||
self.server = avatar.server
|
self.server = avatar.server
|
||||||
self.cfg = avatar.cfg
|
self.cfg = avatar.cfg
|
||||||
self.uid = avatar.uid
|
self.uid = avatar.uid
|
||||||
self.gid = avatar.gid
|
self.gid = avatar.gid
|
||||||
self.username = avatar.username
|
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):
|
def openShell(self, proto):
|
||||||
@ -588,6 +591,7 @@ class SSHSessionForCowrieUser:
|
|||||||
def getPty(self, terminal, windowSize, attrs):
|
def getPty(self, terminal, windowSize, attrs):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
self.environ['TERM'] = terminal
|
||||||
log.msg(eventid='KIPP0010', width=windowSize[0], height=windowSize[1],
|
log.msg(eventid='KIPP0010', width=windowSize[0], height=windowSize[1],
|
||||||
format='Terminal Size: %(width)s %(height)s')
|
format='Terminal Size: %(width)s %(height)s')
|
||||||
self.windowSize = windowSize
|
self.windowSize = windowSize
|
||||||
|
Reference in New Issue
Block a user