Skip to content

Commit

Permalink
Fix git (thinkst#196)
Browse files Browse the repository at this point in the history
* Will make git protocol buffer incoming data

* .

* .

* Added extra check for git protocol
  • Loading branch information
jayjb committed Jun 29, 2022
1 parent 78e124c commit a477af1
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions opencanary/modules/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class ProtocolError(Exception):
pass

class GitCommandLengthMismatch(Exception):
pass


class GitProtocol(Protocol):
"""
Expand All @@ -18,10 +21,10 @@ def _checkDataLength(self, data):
try:
actual_length = len(data)
indata_length = int(data[0:4],base=16)
if actual_length == indata_length:
return True
else:
return False
if actual_length < indata_length:
raise GitCommandLengthMismatch()
elif actual_length > indata_length:
raise ProtocolError()
except ValueError:
return False

Expand All @@ -44,11 +47,23 @@ def dataReceived(self, data):
Received data is unbuffered so we buffer it for telnet.
"""
try:
git_command = data[4:]
if self._checkDataLength(data) and git_command[:15] == b'git-upload-pack':
self._buildResponseAndSend(git_command.decode('utf-8'))
else:
raise ProtocolError()
try:
if not hasattr(self, '_data'):
self._data = data
else:
self._data += data

self._checkDataLength(self._data)

git_command = self._data[4:]
if git_command[:15] == b'git-upload-pack':
self._buildResponseAndSend(git_command.decode('utf-8'))
else:
raise ProtocolError()

except GitCommandLengthMismatch:
pass

except ProtocolError:
self.transport.loseConnection()
return
Expand Down

0 comments on commit a477af1

Please sign in to comment.