8000 Brackets by micheloosterhof · Pull Request #1217 · cowrie/cowrie · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Brackets #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/cowrie/shell/honeypot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,40 @@ def lineReceived(self, line):
self.lexer.wordchars += '@%{}=$:+^,()'
tokens = []
parc_tokens = [] # stack of parcial command substitution tokens
last_token = False # control the command substitution tokens processing
subshell_tokens = [] # stack of subshell tokens
last_parc_token = False # control the command substitution tokens processing
last_subshell_token = False # control the subshell token processing
while True:
try:
if not last_token:
if not last_parc_token:
# if we are processing the command substitution dont read token
tok = self.lexer.get_token()
# log.msg("tok: %s" % (repr(tok)))

if len(subshell_tokens):
if tok:
if tok.endswith(')'):
subshell_tokens.append(tok[:-1])
last_subshell_token = True
else:
subshell_tokens.append(tok)

if not tok or last_subshell_token:
cmds = " ".join(subshell_tokens)
self.cmdpending.append((subshell_tokens))
last_subshell_token = False
subshell_tokens = []
continue

if len(parc_tokens):
if tok:
if tok.endswith(')'):
parc_tokens.append(tok[:-1])
8000 last_token = True
last_parc_token = True
else:
parc_tokens.append(tok)

if not tok or last_token:
if not tok or last_parc_token:
cmds = " ".join(parc_tokens)
# instantiate new shell with redirect output
self.protocol.cmdstack.append(HoneyPotShell(self.protocol, interactive=False, redirect=True))
Expand All @@ -67,7 +84,7 @@ def lineReceived(self, line):
# remove the shell
result = self.protocol.cmdstack.pop()
tokens.append(result.protocol.pp.redirected_data.decode()[:-1])
last_token = False
last_parc_token = False
parc_tokens = []

continue
Expand Down Expand Up @@ -108,14 +125,22 @@ def lineReceived(self, line):
break
elif tok == '$?':
tok = "0"

elif tok[0] == '(':
subshell_tokens.append(tok[1:])
if tok[-1] == ')':
last_parc_token = True
tok = None
continue

elif tok[0] == '$':
envRex = re.compile(r'^\$\(([_a-zA-Z0-9]+)*')
envSearch = envRex.search(tok)
if envSearch is not None:
envMatch = envSearch.group(1)
parc_tokens.append(envMatch)
if tok[-1] == ')':
last_token = True
last_parc_token = True
tok = None
continue
envRex = re.compile(r'^\$([_a-zA-Z0-9]+)$')
Expand Down
14 changes: 14 additions & 0 deletions src/cowrie/test/test_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,19 @@ def test_echo_command_017(self):
self.proto.lineReceived(b'echo echo test | bash')
self.assertEquals(self.tr.value(), b'test\n' + PROMPT)

def test_echo_command_018(self):
"""
echo $(echo test)
"""
self.proto.lineReceived(b'echo $(echo test)')
self.assertEquals(self.tr.value(), b'test\n' + PROMPT)

def test_echo_command_019(self):
"""
(echo test)
"""
self.proto.lineReceived(b'(echo test)')
self.assertEquals(self.tr.value(), b'test\n' + PROMPT)

def tearDown(self):
self.proto.connectionLost("tearDown From Unit Test")
0