rewrite uname. store config in [shell]

This commit is contained in:
Michel Oosterhof 2018-06-18 10:32:42 +00:00
parent 293d6ff9e8
commit 2156c72196
2 changed files with 96 additions and 51 deletions

View File

@ -109,12 +109,6 @@ interactive_timeout = 180
# (default: shell) # (default: shell)
backend = shell backend = shell
# Modify the response of '/bin/uname'
# Default (uname -a): Linux <hostname> <kernel_version> <kernel_build_string> <hardware_platform> 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 # Network Specific Options
@ -278,6 +272,12 @@ arch = linux-x64-lsb
# NO SPACE BETWEEN ELEMENTS! # 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 # 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 <hostname> <kernel_version> <kernel_build_string> <hardware_platform> <operating system>
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
# ============================================================================ # ============================================================================

View File

@ -1,18 +1,72 @@
# # Copyright (c) 2010 Upi Tamminen <desaster@gmail.com>
# See the COPYRIGHT file for more information
"""
uname command
"""
from __future__ import division, absolute_import from __future__ import division, absolute_import
from cowrie.core.config import CONFIG
from configparser import NoOptionError from configparser import NoOptionError
from cowrie.core.config import CONFIG
from cowrie.shell.honeypot import HoneyPotCommand from cowrie.shell.honeypot import HoneyPotCommand
commands = {} 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. Print certain system information. With no OPTION, same as -s.
-a, --all print all information, in the following order, -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: <http://www.gnu.org/software/coreutils/> GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/uname> Full documentation at: <http://www.gnu.org/software/coreutils/uname>
or available locally via: info '(coreutils) uname invocation'\n 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): def full_uname(self):
return 'Linux %s %s %s %s %s\n' % ( self.protocol.hostname, """
self.kernel_version(), """
self.kernel_build_string(), return '{} {} {} {} {} {}\n'.format(kernel_name(),
self.hardware_platform(), self.protocol.hostname,
self.operating_system() ) kernel_version(),
kernel_build_string(),
hardware_platform(),
operating_system())
def call(self): 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()) self.write(self.full_uname())
elif len(self.args) and self.args[0].strip() in ('-r', '--kernel-release'): elif self.args[0].strip() in ('-s', '--kernel-name'):
self.write( '%s\n' % self.kernel_version() ) self.write('{}\n'.format(kernel_name()))
elif len(self.args) and self.args[0].strip() in ('-o', '--operating-system'): elif self.args[0].strip() in ('-r', '--kernel-release'):
self.write( '%s\n' % self.operating_system() ) self.write('{}\n'.format(kernel_version()))
elif len(self.args) and self.args[0].strip() in ('-n', '--nodename'): elif self.args[0].strip() in ('-o', '--operating-system'):
self.write( '%s\n' % self.protocol.hostname ) self.write('{}\n'.format(operating_system()))
elif len(self.args) and self.args[0].strip() in ('-m', '--machine', '-p', '--processor', '-i', '--hardware-platform'): elif self.args[0].strip() in ('-n', '--nodename'):
self.write( '%s\n' % self.hardware_platform() ) self.write('{}\n'.format(self.protocol.hostname))
elif len(self.args) and self.args[0].strip() in ('-h', '--help'): elif self.args[0].strip() in ('-m', '--machine', '-p', '--processor', '-i', '--hardware-platform'):
self.write( self.help() ) self.write('{}\n'.format(hardware_platform()))
else: elif self.args[0].strip() in ('-h', '--help'):
self.write('Linux\n') self.write(uname_help())
commands['/bin/uname'] = command_uname commands['/bin/uname'] = command_uname