Skip to content

Commit e79eac9

Browse files
committed
Beautify scritpedshell
1 parent 71d5ae6 commit e79eac9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ssh_mitm_plugins/ssh/scriptedshell.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import re
34

45
from ssh_proxy_server.forwarders.ssh import SSHForwarder
56

@@ -36,7 +37,8 @@ def forward_stdin(self):
3637
self.executing = False
3738
self.script.close()
3839
self.output.close()
39-
super(SSHScriptedForwarder, self).forward_stdin()
40+
# Resets Shell prompt for user (OpenSSH Server Last Login is omitted)
41+
self.server_channel.sendall(b'\n')
4042
elif line != "":
4143
self.server_channel.sendall(line)
4244
return
@@ -46,8 +48,11 @@ def forward_stdin(self):
4648
super(SSHScriptedForwarder, self).forward_stdin()
4749

4850
def stdout(self, text):
51+
def escape_ansi(line):
52+
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
53+
return ansi_escape.sub('', line)
4954
if self.executing:
50-
self.output.write(text.decode('utf-8'))
55+
self.output.write(escape_ansi(text.decode('utf-8')))
5156
return ""
5257
return text
5358

0 commit comments

Comments
 (0)