Skip to content

Commit

Permalink
Various bug fixes (#1261)
Browse files Browse the repository at this point in the history
* can't append bytes to strings
* log when people run funny execcmd's
* testing python-3.8-rc -> python-3.8
  • Loading branch information
micheloosterhof committed Nov 5, 2019
1 parent dfa28b8 commit 1de7794
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ workflows:
jobs:
- test-3.6-buster
- test-3.7-buster
- test-3.8-rc-buster
- test-3.8-buster
jobs:
test-3.7-buster: &test-template
docker:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
<<: *test-template
docker:
- image: circleci/python:3.6-buster
test-3.8-rc-buster:
test-3.8-buster:
<<: *test-template
docker:
- image: circleci/python:3.8-rc-buster
- image: circleci/python:3.8-buster
4 changes: 4 additions & 0 deletions src/cowrie/commands/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def get_dir_files(self, path):

def do_ls_normal(self, path):
files = self.get_dir_files(path)
if not files:
return

line = [x[fs.A_NAME] for x in files]
if not line:
Expand All @@ -111,6 +113,8 @@ def do_ls_normal(self, path):

def do_ls_l(self, path):
files = self.get_dir_files(path)
if not files:
return

filesize_str_extent = 0
if len(files):
Expand Down
6 changes: 5 additions & 1 deletion src/cowrie/shell/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ def __init__(self, avatar, execcmd):
Before this, execcmd is 'bytes'. Here it converts to 'string' and
commands work with string rather than bytes.
"""
self.execcmd = execcmd.decode('utf8')
try:
self.execcmd = execcmd.decode('utf8')
except UnicodeDecodeError:
log.err("Unusual execcmd: {}".format(repr(execcmd)))

HoneyPotBaseProtocol.__init__(self, avatar)

def connectionMade(self):
Expand Down
14 changes: 7 additions & 7 deletions src/cowrie/ssh/forwarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def channelOpen(self, specificData):
Modifies the original to send a TCP tunnel request via the CONNECT method
"""
forwarding.SSHConnectForwardingChannel.channelOpen(self, specificData)
dst = self.dstport[0] + b':' + str(self.dstport[1])
connect_hdr = b'CONNECT ' + dst + b" HTTP/1.1\r\n\r\n"
dst = self.dstport[0] + ':' + str(self.dstport[1])
connect_hdr = b'CONNECT ' + dst.encode('ascii') + b' HTTP/1.1\r\n\r\n'
forwarding.SSHConnectForwardingChannel.dataReceived(self, connect_hdr)

def dataReceived(self, data):
Expand All @@ -128,20 +128,20 @@ def dataReceived(self, data):

def write(self, data):
"""
Modifies the original to stip off the TCP tunnel response
Modifies the original to strip off the TCP tunnel response
"""
if not self.tunnel_established and data[:4].lower() == b'http':
# Check proxy response code
try:
res_code = int(data.split(' ')[1], 10)
res_code = int(data.split(b' ')[1], 10)
except ValueError:
log.err('Failed to parse TCP tunnel response code')
log.err("Failed to parse TCP tunnel response code")
self._close("Connection refused")
if res_code != 200:
log.err('Unexpected response code: {}'.format(res_code))
log.err("Unexpected response code: {}".format(res_code))
self._close("Connection refused")
# Strip off rest of packet
eop = data.find("\r\n\r\n")
eop = data.find(b'\r\n\r\n')
if eop > -1:
data = data[eop + 4:]
# This only happens once when the channel is opened
Expand Down

0 comments on commit 1de7794

Please sign in to comment.