diff --git a/cowrie.cfg.dist b/cowrie.cfg.dist index 2a78764b..1c2d5a0c 100644 --- a/cowrie.cfg.dist +++ b/cowrie.cfg.dist @@ -109,12 +109,6 @@ interactive_timeout = 180 # (default: shell) backend = shell -# Modify the response of '/bin/uname' -# Default (uname -a): Linux GNU/Linux -kernel_version = 3.2.0-4-amd64 -kernel_build_string = #1 SMP Debian 3.2.68-1+deb7u1 -hardware_platform = x86_64 - # ============================================================================ # Network Specific Options @@ -278,6 +272,12 @@ arch = linux-x64-lsb # NO SPACE BETWEEN ELEMENTS! # arch = bsd-aarch64-lsb,bsd-aarch64-msb,bsd-bfin-msb,bsd-mips-lsb,bsd-mips-msb,bsd-mips64-lsb,bsd-mips64-msb,bsd-powepc-msb,bsd-powepc64-lsb,bsd-riscv64-lsb,bsd-sparc-msb,bsd-sparc64-msb,bsd-x32-lsb,bsd-x64-lsb,linux-aarch64-lsb,linux-aarch64-msb,linux-alpha-lsb,linux-am33-lsb,linux-arc-lsb,linux-arc-msb,linux-arm-lsb,linux-arm-msb,linux-avr32-lsb,linux-bfin-lsb,linux-c6x-lsb,linux-c6x-msb,linux-cris-lsb,linux-frv-msb,linux-h8300-msb,linux-hppa-msb,linux-hppa64-msb,linux-ia64-lsb,linux-m32r-msb,linux-m68k-msb,linux-microblaze-msb,linux-mips-lsb,linux-mips-msb,linux-mips64-lsb,linux-mips64-msb,linux-mn10300-lsb,linux-nios-lsb,linux-nios-msb,linux-powerpc-lsb,linux-powerpc-msb,linux-powerpc64-lsb,linux-powerpc64-msb,linux-riscv64-lsb,linux-s390x-msb,linux-sh-lsb,linux-sh-msb,linux-sparc-msb,linux-sparc64-msb,linux-tilegx-lsb,linux-tilegx-msb,linux-tilegx64-lsb,linux-tilegx64-msb,linux-x64-lsb,linux-x86-lsb,linux-xtensa-msb,osx-x32-lsb,osx-x64-lsb +# Modify the response of '/bin/uname' +# Default (uname -a): Linux +kernel_version = 3.2.0-4-amd64 +kernel_build_string = #1 SMP Debian 3.2.68-1+deb7u1 +hardware_platform = x86_64 +operating_system = GNU/Linux # ============================================================================ diff --git a/cowrie/commands/uname.py b/cowrie/commands/uname.py index 920a056a..6cc9699a 100644 --- a/cowrie/commands/uname.py +++ b/cowrie/commands/uname.py @@ -1,18 +1,72 @@ -# +# Copyright (c) 2010 Upi Tamminen +# See the COPYRIGHT file for more information + +""" +uname command +""" from __future__ import division, absolute_import - -from cowrie.core.config import CONFIG from configparser import NoOptionError +from cowrie.core.config import CONFIG from cowrie.shell.honeypot import HoneyPotCommand commands = {} -class command_uname(HoneyPotCommand): +def hardware_platform(): + """ + """ + try: + return CONFIG.get('shell', 'hardware_platform') + except NoOptionError: + return 'x86_64' - def help(self): - return '''Usage: uname [OPTION]... + + +def kernel_name(): + """ + """ + try: + return CONFIG.get('shell', 'kernel_name') + except NoOptionError: + return 'Linux' + + + +def kernel_version(): + """ + """ + try: + return CONFIG.get('shell', 'kernel_version') + except NoOptionError: + return '3.2.0-4-amd64' + + + +def kernel_build_string(): + """ + """ + try: + return CONFIG.get('shell', 'kernel_build_string') + except NoOptionError: + return '#1 SMP Debian 3.2.68-1+deb7u1' + + + +def operating_system(): + """ + """ + try: + return CONFIG.get('shell', 'operating_system') + except NoOptionError: + return 'GNU/Linux' + + + +def uname_help(): + """ + """ + return """Usage: uname [OPTION]... Print certain system information. With no OPTION, same as -s. -a, --all print all information, in the following order, @@ -31,52 +85,43 @@ Print certain system information. With no OPTION, same as -s. GNU coreutils online help: Full documentation at: or available locally via: info '(coreutils) uname invocation'\n -''' +""" - def hardware_platform(self): - try: - return CONFIG.get("honeypot", "hardware_platform") - except NoOptionError: - return 'x86_64' - def kernel_version(self): - try: - return CONFIG.get("honeypot", "kernel_version") - except NoOptionError: - return '3.2.0-4-amd64' - - def kernel_build_string(self): - try: - return CONFIG.get("honeypot", "kernel_build_string") - except NoOptionError: - return '#1 SMP Debian 3.2.68-1+deb7u1' - - def operating_system(self): - return 'GNU/Linux' +class command_uname(HoneyPotCommand): + """ + """ def full_uname(self): - return 'Linux %s %s %s %s %s\n' % ( self.protocol.hostname, - self.kernel_version(), - self.kernel_build_string(), - self.hardware_platform(), - self.operating_system() ) + """ + """ + return '{} {} {} {} {} {}\n'.format(kernel_name(), + self.protocol.hostname, + kernel_version(), + kernel_build_string(), + hardware_platform(), + operating_system()) def call(self): - if len(self.args) and self.args[0].strip() in ('-a', '--all'): + """ + TODO: getopt style parsing + """ + if not self.args: + self.write('{}\n'.format(kernel_name())) + elif self.args[0].strip() in ('-a', '--all'): self.write(self.full_uname()) - elif len(self.args) and self.args[0].strip() in ('-r', '--kernel-release'): - self.write( '%s\n' % self.kernel_version() ) - elif len(self.args) and self.args[0].strip() in ('-o', '--operating-system'): - self.write( '%s\n' % self.operating_system() ) - elif len(self.args) and self.args[0].strip() in ('-n', '--nodename'): - self.write( '%s\n' % self.protocol.hostname ) - elif len(self.args) and self.args[0].strip() in ('-m', '--machine', '-p', '--processor', '-i', '--hardware-platform'): - self.write( '%s\n' % self.hardware_platform() ) - elif len(self.args) and self.args[0].strip() in ('-h', '--help'): - self.write( self.help() ) - else: - self.write('Linux\n') + elif self.args[0].strip() in ('-s', '--kernel-name'): + self.write('{}\n'.format(kernel_name())) + elif self.args[0].strip() in ('-r', '--kernel-release'): + self.write('{}\n'.format(kernel_version())) + elif self.args[0].strip() in ('-o', '--operating-system'): + self.write('{}\n'.format(operating_system())) + elif self.args[0].strip() in ('-n', '--nodename'): + self.write('{}\n'.format(self.protocol.hostname)) + elif self.args[0].strip() in ('-m', '--machine', '-p', '--processor', '-i', '--hardware-platform'): + self.write('{}\n'.format(hardware_platform())) + elif self.args[0].strip() in ('-h', '--help'): + self.write(uname_help()) commands['/bin/uname'] = command_uname -