1- import config
1+ from core import config
22from cmd import Cmd
33import os
44import glob
55import sys
6+ import importlib
67import shlex
78import hashlib
89import signal
10+ import platform
911from utils import prettify
1012from utils .normalize_args import normalize_args
1113from utils .random_string import random_generator
@@ -28,9 +30,13 @@ class SharPyShellPrompt(Cmd):
2830
2931 def __init__ (self , password , channel_enc_mode , default_shell , url , user_agent ,
3032 cookies , custom_headers , insecure_ssl , proxy ):
31- reload (sys )
32- sys .setdefaultencoding ('utf8' )
33- signal .signal (signal .SIGTSTP , lambda s , f : self .do_quit ())
33+ importlib .reload (sys )
34+ #sys.setdefaultencoding('utf8')
35+ password = password .encode ('utf-8' )
36+ if platform .system () == 'Windows' :
37+ signal .signal (signal .SIGTERM , lambda s , f : self .do_quit ())
38+ else :
39+ signal .signal (signal .SIGTSTP , lambda s , f : self .do_quit ())
3440 Cmd .__init__ (self )
3541 if channel_enc_mode == 'aes128' :
3642 self .password = hashlib .md5 (password ).hexdigest ()
@@ -80,7 +86,7 @@ def onecmd(self, line):
8086 return self .emptyline ()
8187 if cmd .startswith ('#' ):
8288 response = self .onecmd_custom (cmd .lstrip ('#' ), args )
83- print response
89+ print ( response )
8490 return response
8591 if cmd in self .helper_commands :
8692 func = getattr (self , 'do_' + cmd .lstrip ('#' ))
@@ -113,7 +119,7 @@ def do_cd(self, arg):
113119 """Change the current working directory."""
114120 working_directory = self .modules_settings ['working_directory' ]
115121 if arg == "" or arg == " " or arg == '.' :
116- print working_directory
122+ print ( working_directory )
117123 return
118124 if arg == '..' :
119125 arg = working_directory .split ('\\ ' )
@@ -127,7 +133,7 @@ def do_cd(self, arg):
127133 elif len (arg ) > 0 :
128134 arg = '\\ ' .join (arg )
129135 else :
130- print "Empty Path."
136+ print ( "Empty Path." )
131137 return
132138 else :
133139 if '/' in arg :
@@ -143,25 +149,25 @@ def do_cd(self, arg):
143149 if '{{{SharPyShellError}}}' not in response :
144150 self .modules_settings ['working_directory' ] = arg
145151 else :
146- print response
152+ print ( response )
147153 return response
148154
149155 def do_help (self , arg ):
150156 """List available commands."""
151157 if arg and arg .lstrip ('#' ) in self .modules_loaded_tree :
152- print self .modules_loaded [arg .lstrip ('#' )].complete_help
158+ print ( self .modules_loaded [arg .lstrip ('#' )].complete_help )
153159 else :
154- print "\n \n " + self .doc_header + "\n "
160+ print ( "\n \n " + self .doc_header + "\n " )
155161 data = [['\n Commands\n ' , '\n Desc\n ' ]]
156162 for module_name in sorted (self .modules_loaded_tree ):
157163 data .append (['#%s' % module_name , self .modules_loaded [module_name ].short_help ])
158- print prettify .tablify (data , table_border = False )
164+ print ( prettify .tablify (data , table_border = False ) )
159165 print
160- print "\n " + "SharPyShell Helper Commands:" + "\n "
166+ print ( "\n " + "SharPyShell Helper Commands:" + "\n " )
161167 data = [['\n Commands\n ' , '\n Desc\n ' ]]
162168 for module_name in sorted (self .helper_commands ):
163169 data .append (['%s' % module_name , getattr (self , 'do_' + module_name ).__doc__ ])
164- print prettify .tablify (data , table_border = False )
170+ print ( prettify .tablify (data , table_border = False ) )
165171 print
166172
167173 def complete_help (self , text , line , start_index , end_index ):
@@ -217,10 +223,10 @@ def default(self, line):
217223 return
218224 # Clean trailing newline if existent to prettify output
219225 result = result [:- 1 ] if (
220- isinstance (result , basestring ) and
226+ isinstance (result , str ) and
221227 result .endswith ('\n ' )
222228 ) else result
223- print result
229+ print ( result )
224230
225231 def cmdloop (self , intro = None ):
226232 """Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -251,7 +257,7 @@ def cmdloop(self, intro=None):
251257 else :
252258 if self .use_rawinput :
253259 try :
254- line = raw_input (self .prompt )
260+ line = input (self .prompt )
255261 except EOFError :
256262 line = 'EOF'
257263 else :
@@ -279,10 +285,10 @@ def cmdloop(self, intro=None):
279285 def do_quit (self , args = []):
280286 """Quit the program."""
281287 if self .online :
282- print "\n \n Quitting...\n "
283- print self .env_obj .clear_env (self .modules_settings )
288+ print ( "\n \n Quitting...\n " )
289+ print ( self .env_obj .clear_env (self .modules_settings ) )
284290 else :
285- print args [0 ] + "\n \n \n Target Offline...\n "
291+ print ( args [0 ] + "\n \n \n Target Offline...\n " )
286292 raise SystemExit
287293
288294 def do_exit (self , args = []):
0 commit comments