mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-17 05:54:21 +01:00
more Py2->Py3
This commit is contained in:
@@ -25,37 +25,37 @@ class command_adduser(HoneyPotCommand):
|
||||
self.username = arg
|
||||
break
|
||||
if self.username is None:
|
||||
self.write('adduser: Only one or two names allowed.\n')
|
||||
self.write(b'adduser: Only one or two names allowed.\n')
|
||||
self.exit()
|
||||
return
|
||||
|
||||
self.output = [
|
||||
(O_O, 'Adding user `%(username)s\' ...\n'),
|
||||
(O_O, 'Adding new group `%(username)s\' (1001) ...\n'),
|
||||
(O_O, 'Adding new user `%(username)s\' (1001) with group `%(username)s\' ...\n'),
|
||||
(O_O, 'Creating home directory `/home/%(username)s\' ...\n'),
|
||||
(O_O, 'Copying files from `/etc/skel\' ...\n'),
|
||||
(O_P, 'Password: '),
|
||||
(O_P, 'Password again: '),
|
||||
(O_O, '\nChanging the user information for %(username)s\n'),
|
||||
(O_O, 'Enter the new value, or press ENTER for the default\n'),
|
||||
(O_Q, ' Username []: '),
|
||||
(O_Q, ' Full Name []: '),
|
||||
(O_Q, ' Room Number []: '),
|
||||
(O_Q, ' Work Phone []: '),
|
||||
(O_Q, ' Home Phone []: '),
|
||||
(O_Q, ' Mobile Phone []: '),
|
||||
(O_Q, ' Country []: '),
|
||||
(O_Q, ' City []: '),
|
||||
(O_Q, ' Language []: '),
|
||||
(O_Q, ' Favorite movie []: '),
|
||||
(O_Q, ' Other []: '),
|
||||
(O_Q, 'Is the information correct? [Y/n] '),
|
||||
(O_O, 'ERROR: Some of the information you entered is invalid\n'),
|
||||
(O_O, 'Deleting user `%(username)s\' ...\n'),
|
||||
(O_O, 'Deleting group `%(username)s\' (1001) ...\n'),
|
||||
(O_O, 'Deleting home directory `/home/%(username)s\' ...\n'),
|
||||
(O_Q, 'Try again? [Y/n] '),
|
||||
(O_O, b'Adding user `%(username)s\' ...\n'),
|
||||
(O_O, b'Adding new group `%(username)s\' (1001) ...\n'),
|
||||
(O_O, b'Adding new user `%(username)s\' (1001) with group `%(username)s\' ...\n'),
|
||||
(O_O, b'Creating home directory `/home/%(username)s\' ...\n'),
|
||||
(O_O, b'Copying files from `/etc/skel\' ...\n'),
|
||||
(O_P, b'Password: '),
|
||||
(O_P, b'Password again: '),
|
||||
(O_O, b'\nChanging the user information for %(username)s\n'),
|
||||
(O_O, b'Enter the new value, or press ENTER for the default\n'),
|
||||
(O_Q, b' Username []: '),
|
||||
(O_Q, b' Full Name []: '),
|
||||
(O_Q, b' Room Number []: '),
|
||||
(O_Q, b' Work Phone []: '),
|
||||
(O_Q, b' Home Phone []: '),
|
||||
(O_Q, b' Mobile Phone []: '),
|
||||
(O_Q, b' Country []: '),
|
||||
(O_Q, b' City []: '),
|
||||
(O_Q, b' Language []: '),
|
||||
(O_Q, b' Favorite movie []: '),
|
||||
(O_Q, b' Other []: '),
|
||||
(O_Q, b'Is the information correct? [Y/n] '),
|
||||
(O_O, b'ERROR: Some of the information you entered is invalid\n'),
|
||||
(O_O, b'Deleting user `%(username)s\' ...\n'),
|
||||
(O_O, b'Deleting group `%(username)s\' (1001) ...\n'),
|
||||
(O_O, b'Deleting home directory `/home/%(username)s\' ...\n'),
|
||||
(O_Q, b'Try again? [Y/n] '),
|
||||
]
|
||||
self.do_output()
|
||||
|
||||
@@ -95,9 +95,9 @@ class command_adduser(HoneyPotCommand):
|
||||
return
|
||||
elif self.item == 20 and line.strip() not in ('y', 'yes'):
|
||||
self.item = 7
|
||||
self.write('Ok, starting over\n')
|
||||
self.write(b'Ok, starting over\n')
|
||||
elif not len(line) and self.output[self.item][0] == O_Q:
|
||||
self.write('Must enter a value!\n')
|
||||
self.write(b'Must enter a value!\n')
|
||||
else:
|
||||
self.item += 1
|
||||
self.schedule_next()
|
||||
|
||||
@@ -16,7 +16,7 @@ class command_faked_package_class_factory(object):
|
||||
def getCommand(name):
|
||||
class command_faked_installation(HoneyPotCommand):
|
||||
def call(self):
|
||||
self.write("%s: Segmentation fault\n" % name)
|
||||
self.write(b"%s: Segmentation fault\n" % name)
|
||||
return command_faked_installation
|
||||
|
||||
class command_aptget(HoneyPotCommand):
|
||||
@@ -45,7 +45,7 @@ class command_aptget(HoneyPotCommand):
|
||||
return d
|
||||
|
||||
def do_version(self):
|
||||
self.write('''apt 1.0.9.8.1 for amd64 compiled on Jun 10 2015 09:42:06
|
||||
self.write(b'''apt 1.0.9.8.1 for amd64 compiled on Jun 10 2015 09:42:06
|
||||
Supported modules:
|
||||
*Ver: Standard .deb
|
||||
*Pkg: Debian dpkg interface (Priority 30)
|
||||
@@ -61,7 +61,7 @@ Supported modules:
|
||||
return
|
||||
|
||||
def do_help(self):
|
||||
self.write('''apt 1.0.9.8.1 for amd64 compiled on Jun 10 2015 09:42:06
|
||||
self.write(b'''apt 1.0.9.8.1 for amd64 compiled on Jun 10 2015 09:42:06
|
||||
Usage: apt-get [options] command
|
||||
apt-get [options] install|remove pkg1 [pkg2 ...]
|
||||
apt-get [options] source pkg1 [pkg2 ...]
|
||||
@@ -110,7 +110,7 @@ pages for more information and options.
|
||||
@inlineCallbacks
|
||||
def do_install(self,*args):
|
||||
if len(self.args) <= 1:
|
||||
self.write('0 upgraded, 0 newly installed, 0 to remove and %s not upgraded.\n' % random.randint(200,300))
|
||||
self.write(b'0 upgraded, 0 newly installed, 0 to remove and %s not upgraded.\n' % random.randint(200,300))
|
||||
self.exit()
|
||||
return
|
||||
|
||||
@@ -125,38 +125,38 @@ pages for more information and options.
|
||||
}
|
||||
totalsize = sum([packages[x]['size'] for x in packages])
|
||||
|
||||
self.write('Reading package lists... Done\n')
|
||||
self.write('Building dependency tree\n')
|
||||
self.write('Reading state information... Done\n')
|
||||
self.write('The following NEW packages will be installed:\n')
|
||||
self.write(' %s ' % ' '.join(packages) + '\n')
|
||||
self.write('0 upgraded, %d newly installed, 0 to remove and 259 not upgraded.\n' % \
|
||||
self.write(b'Reading package lists... Done\n')
|
||||
self.write(b'Building dependency tree\n')
|
||||
self.write(b'Reading state information... Done\n')
|
||||
self.write(b'The following NEW packages will be installed:\n')
|
||||
self.write(b' %s ' % ' '.join(packages) + '\n')
|
||||
self.write(b'0 upgraded, %d newly installed, 0 to remove and 259 not upgraded.\n' % \
|
||||
len(packages))
|
||||
self.write('Need to get %s.2kB of archives.\n' % (totalsize))
|
||||
self.write('After this operation, %skB of additional disk space will be used.\n' % \
|
||||
self.write(b'Need to get %s.2kB of archives.\n' % (totalsize))
|
||||
self.write(b'After this operation, %skB of additional disk space will be used.\n' % \
|
||||
(totalsize * 2.2,))
|
||||
i = 1
|
||||
for p in packages:
|
||||
self.write('Get:%d http://ftp.debian.org stable/main %s %s [%s.2kB]\n' % \
|
||||
self.write(b'Get:%d http://ftp.debian.org stable/main %s %s [%s.2kB]\n' % \
|
||||
(i, p, packages[p]['version'], packages[p]['size']))
|
||||
i += 1
|
||||
yield self.sleep(1, 2)
|
||||
self.write('Fetched %s.2kB in 1s (4493B/s)''\n' % (totalsize))
|
||||
self.write('Reading package fields... Done\n')
|
||||
self.write(b'Fetched %s.2kB in 1s (4493B/s)''\n' % (totalsize))
|
||||
self.write(b'Reading package fields... Done\n')
|
||||
yield self.sleep(1, 2)
|
||||
self.write('Reading package status... Done\n')
|
||||
self.write('(Reading database ... 177887 files and directories currently installed.)\n')
|
||||
self.write(b'Reading package status... Done\n')
|
||||
self.write(b'(Reading database ... 177887 files and directories currently installed.)\n')
|
||||
yield self.sleep(1, 2)
|
||||
for p in packages:
|
||||
self.write('Unpacking %s (from .../archives/%s_%s_i386.deb) ...\n' % \
|
||||
self.write(b'Unpacking %s (from .../archives/%s_%s_i386.deb) ...\n' % \
|
||||
(p, p, packages[p]['version']))
|
||||
yield self.sleep(1, 2)
|
||||
self.write('Processing triggers for man-db ...\n')
|
||||
self.write(b'Processing triggers for man-db ...\n')
|
||||
yield self.sleep(2)
|
||||
for p in packages:
|
||||
self.write('Setting up %s (%s) ...\n' % \
|
||||
self.write(b'Setting up %s (%s) ...\n' % \
|
||||
(p, packages[p]['version']))
|
||||
self.fs.mkfile('/usr/bin/%s' % p,
|
||||
self.fs.mkfile(b'/usr/bin/%s' % p,
|
||||
0, 0, random.randint(10000, 90000), 33188)
|
||||
self.protocol.commands['/usr/bin/%s' % p] = \
|
||||
command_faked_package_class_factory.getCommand(p)
|
||||
@@ -164,18 +164,18 @@ pages for more information and options.
|
||||
self.exit()
|
||||
|
||||
def do_moo(self):
|
||||
self.write(' (__)\n')
|
||||
self.write(' (oo)\n')
|
||||
self.write(' /------\\/\n')
|
||||
self.write(' / | ||\n')
|
||||
self.write(' * /\\---/\\ \n')
|
||||
self.write(' ~~ ~~\n')
|
||||
self.write('...."Have you mooed today?"...\n')
|
||||
self.write(b' (__)\n')
|
||||
self.write(b' (oo)\n')
|
||||
self.write(b' /------\\/\n')
|
||||
self.write(b' / | ||\n')
|
||||
self.write(b' * /\\---/\\ \n')
|
||||
self.write(b' ~~ ~~\n')
|
||||
self.write(b'...."Have you mooed today?"...\n')
|
||||
self.exit()
|
||||
|
||||
def do_locked(self):
|
||||
self.errorWrite('E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)\n')
|
||||
self.errorWrite('E: Unable to lock the list directory\n')
|
||||
self.errorWrite(b'E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)\n')
|
||||
self.errorWrite(b'E: Unable to lock the list directory\n')
|
||||
self.exit()
|
||||
commands['/usr/bin/apt-get'] = command_aptget
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class command_help(HoneyPotCommand):
|
||||
def call(self):
|
||||
"""
|
||||
"""
|
||||
self.write("""GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
|
||||
self.write(b"""GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
|
||||
These shell commands are defined internally. Type `help' to see this list.
|
||||
Type `help name' to find out more about the function `name'.
|
||||
Use `info bash' to find out more about the shell in general.
|
||||
|
||||
@@ -6,7 +6,7 @@ from cowrie.core.honeypot import HoneyPotCommand,StdOutStdErrEmulationProtocol
|
||||
from twisted.python import log
|
||||
commands = {}
|
||||
|
||||
busybox_help=('''
|
||||
busybox_help=(b'''
|
||||
BusyBox v1.20.2 (Debian 1:1.20.0-7) multi-call binary.
|
||||
Copyright (C) 1998-2011 Erik Andersen, Rob Landley, Denys Vlasenko
|
||||
and others. Licensed under GPLv2.
|
||||
@@ -55,7 +55,7 @@ class command_busybox(HoneyPotCommand):
|
||||
"""
|
||||
"""
|
||||
for ln in busybox_help:
|
||||
self.errorWrite(ln+'\n')
|
||||
self.errorWrite(ln+b'\n')
|
||||
|
||||
|
||||
def call(self):
|
||||
@@ -86,7 +86,7 @@ class command_busybox(HoneyPotCommand):
|
||||
if self.input_data:
|
||||
self.write(self.input_data)
|
||||
else:
|
||||
self.write('{}: applet not found\n'.format(cmd))
|
||||
self.write(b'{}: applet not found\n'.format(cmd))
|
||||
|
||||
commands['busybox'] = command_busybox
|
||||
commands['/bin/busybox'] = command_busybox
|
||||
|
||||
@@ -38,8 +38,8 @@ class command_curl(HoneyPotCommand):
|
||||
[ 'help', 'manual', 'silent' ] )
|
||||
except getopt.GetoptError as err:
|
||||
# TODO: should be 'unknown' instead of 'not recognized'
|
||||
self.write("curl: {}\n".format(err))
|
||||
self.write("curl: try 'curl --help' or 'curl --manual' for more information\n")
|
||||
self.write(b"curl: {}\n".format(err))
|
||||
self.write(b"curl: try 'curl --help' or 'curl --manual' for more information\n")
|
||||
self.exit()
|
||||
return
|
||||
|
||||
@@ -54,7 +54,7 @@ class command_curl(HoneyPotCommand):
|
||||
if args[0] is not None:
|
||||
url = str(args[0]).strip()
|
||||
else:
|
||||
self.write("curl: try 'curl --help' or 'curl --manual' for more information\n")
|
||||
self.write(b"curl: try 'curl --help' or 'curl --manual' for more information\n")
|
||||
self.exit()
|
||||
return
|
||||
|
||||
@@ -69,7 +69,7 @@ class command_curl(HoneyPotCommand):
|
||||
if opt[0] == '-O':
|
||||
outfile = urldata.path.split('/')[-1]
|
||||
if outfile is None or not len(outfile.strip()) or not urldata.path.count('/'):
|
||||
self.write('curl: Remote file name has no length!\n')
|
||||
self.write(b'curl: Remote file name has no length!\n')
|
||||
self.exit()
|
||||
return
|
||||
|
||||
@@ -79,7 +79,7 @@ class command_curl(HoneyPotCommand):
|
||||
if not path or \
|
||||
not self.fs.exists(path) or \
|
||||
not self.fs.isdir(path):
|
||||
self.write('curl: %s: Cannot open: No such file or directory\n' % \
|
||||
self.write(b'curl: %s: Cannot open: No such file or directory\n' % \
|
||||
(outfile,))
|
||||
self.exit()
|
||||
return
|
||||
@@ -110,7 +110,7 @@ class command_curl(HoneyPotCommand):
|
||||
"""
|
||||
"""
|
||||
|
||||
self.write("""Usage: curl [options...] <url>
|
||||
self.write(b"""Usage: curl [options...] <url>
|
||||
Options: (H) means HTTP/HTTPS only, (F) means FTP only
|
||||
--anyauth Pick "any" authentication method (H)
|
||||
-a, --append Append to target file when uploading (F/SFTP)
|
||||
@@ -279,7 +279,7 @@ Options: (H) means HTTP/HTTPS only, (F) means FTP only
|
||||
if scheme != 'http' and scheme != 'https':
|
||||
raise NotImplementedError
|
||||
except:
|
||||
self.write('%s: Unsupported scheme.\n' % (url,))
|
||||
self.write(b'%s: Unsupported scheme.\n' % (url,))
|
||||
self.exit()
|
||||
return None
|
||||
|
||||
@@ -303,7 +303,7 @@ Options: (H) means HTTP/HTTPS only, (F) means FTP only
|
||||
def handle_CTRL_C(self):
|
||||
"""
|
||||
"""
|
||||
self.write('^C\n')
|
||||
self.write(b'^C\n')
|
||||
self.connection.transport.loseConnection()
|
||||
|
||||
|
||||
@@ -353,7 +353,7 @@ Options: (H) means HTTP/HTTPS only, (F) means FTP only
|
||||
"""
|
||||
if hasattr(error, 'getErrorMessage'): # Exceptions
|
||||
error = error.getErrorMessage()
|
||||
self.write(error+'\n')
|
||||
self.write(error+b'\n')
|
||||
# Real curl also adds this:
|
||||
# self.write('%s ERROR 404: Not Found.\n' % \
|
||||
# time.strftime('%Y-%m-%d %T'))
|
||||
@@ -411,8 +411,8 @@ class HTTPProgressDownloader(client.HTTPDownloader):
|
||||
self.nomore = True
|
||||
|
||||
if self.fakeoutfile:
|
||||
self.curl.write(' % Total % Received % Xferd Average Speed Time Time Time Current\n')
|
||||
self.curl.write(' Dload Upload Total Spent Left Speed\n')
|
||||
self.curl.write(b' % Total % Received % Xferd Average Speed Time Time Time Current\n')
|
||||
self.curl.write(b' Dload Upload Total Spent Left Speed\n')
|
||||
|
||||
return client.HTTPDownloader.gotHeaders(self, headers)
|
||||
|
||||
@@ -452,7 +452,7 @@ class HTTPProgressDownloader(client.HTTPDownloader):
|
||||
return client.HTTPDownloader.pageEnd(self)
|
||||
|
||||
if self.fakeoutfile:
|
||||
self.curl.write("\r100 %d 100 %d 0 0 %d 0 --:--:-- --:--:-- --:--:-- %d\n" % \
|
||||
self.curl.write(b"\r100 %d 100 %d 0 0 %d 0 --:--:-- --:--:-- --:--:-- %d\n" % \
|
||||
(self.currentlength, self.currentlength , 63673, 65181)
|
||||
)
|
||||
|
||||
@@ -462,7 +462,7 @@ class HTTPProgressDownloader(client.HTTPDownloader):
|
||||
self.curl.safeoutfile)
|
||||
else:
|
||||
with open(self.curl.safeoutfile, 'r') as f:
|
||||
self.curl.write(f.read()+'\n')
|
||||
self.curl.write(f.read()+b'\n')
|
||||
|
||||
self.curl.fileName = self.fileName
|
||||
return client.HTTPDownloader.pageEnd(self)
|
||||
|
||||
@@ -36,7 +36,7 @@ class command_env(HoneyPotCommand):
|
||||
"""
|
||||
"""
|
||||
for i in list(self.environ.keys()):
|
||||
self.write("%s=%s\n" % (i,self.environ[i]))
|
||||
self.write(b"%s=%s\n" % (i,self.environ[i]))
|
||||
|
||||
|
||||
commands['/usr/bin/env'] = command_env
|
||||
|
||||
Reference in New Issue
Block a user