■ ■ ■ ■ ■ ■
core/SharPyShellPrompt.py
1 | | - | import config |
| 1 | + | from core import config |
2 | 2 | | from cmd import Cmd |
3 | 3 | | import os |
4 | 4 | | import glob |
5 | 5 | | import sys |
| 6 | + | import importlib |
6 | 7 | | import shlex |
7 | 8 | | import hashlib |
8 | 9 | | import signal |
| skipped 19 lines |
28 | 29 | | |
29 | 30 | | def __init__(self, password, channel_enc_mode, default_shell, url, user_agent, |
30 | 31 | | cookies, custom_headers, insecure_ssl, proxy): |
31 | | - | reload(sys) |
32 | | - | sys.setdefaultencoding('utf8') |
| 32 | + | importlib.reload(sys) |
| 33 | + | #sys.setdefaultencoding('utf8') |
| 34 | + | password = password.encode('utf-8') |
33 | 35 | | signal.signal(signal.SIGTSTP, lambda s, f: self.do_quit()) |
34 | 36 | | Cmd.__init__(self) |
35 | 37 | | if channel_enc_mode == 'aes128': |
| skipped 44 lines |
80 | 82 | | return self.emptyline() |
81 | 83 | | if cmd.startswith('#'): |
82 | 84 | | response = self.onecmd_custom(cmd.lstrip('#'), args) |
83 | | - | print response |
| 85 | + | print (response) |
84 | 86 | | return response |
85 | 87 | | if cmd in self.helper_commands: |
86 | 88 | | func = getattr(self, 'do_' + cmd.lstrip('#')) |
| skipped 26 lines |
113 | 115 | | """Change the current working directory.""" |
114 | 116 | | working_directory = self.modules_settings['working_directory'] |
115 | 117 | | if arg == "" or arg == " " or arg == '.': |
116 | | - | print working_directory |
| 118 | + | print (working_directory) |
117 | 119 | | return |
118 | 120 | | if arg == '..': |
119 | 121 | | arg = working_directory.split('\\') |
| skipped 7 lines |
127 | 129 | | elif len(arg) > 0: |
128 | 130 | | arg = '\\'.join(arg) |
129 | 131 | | else: |
130 | | - | print "Empty Path." |
| 132 | + | print ("Empty Path.") |
131 | 133 | | return |
132 | 134 | | else: |
133 | 135 | | if '/' in arg: |
| skipped 9 lines |
143 | 145 | | if '{{{SharPyShellError}}}' not in response: |
144 | 146 | | self.modules_settings['working_directory'] = arg |
145 | 147 | | else: |
146 | | - | print response |
| 148 | + | print (response) |
147 | 149 | | return response |
148 | 150 | | |
149 | 151 | | def do_help(self, arg): |
150 | 152 | | """List available commands.""" |
151 | 153 | | if arg and arg.lstrip('#') in self.modules_loaded_tree: |
152 | | - | print self.modules_loaded[arg.lstrip('#')].complete_help |
| 154 | + | print (self.modules_loaded[arg.lstrip('#')].complete_help) |
153 | 155 | | else: |
154 | | - | print "\n\n" + self.doc_header + "\n" |
| 156 | + | print ("\n\n" + self.doc_header + "\n") |
155 | 157 | | data = [['\nCommands\n', '\nDesc\n']] |
156 | 158 | | for module_name in sorted(self.modules_loaded_tree): |
157 | 159 | | data.append(['#%s' % module_name, self.modules_loaded[module_name].short_help]) |
158 | | - | print prettify.tablify(data, table_border=False) |
| 160 | + | print (prettify.tablify(data, table_border=False)) |
159 | 161 | | print |
160 | | - | print "\n" + "SharPyShell Helper Commands:" + "\n" |
| 162 | + | print ("\n" + "SharPyShell Helper Commands:" + "\n") |
161 | 163 | | data = [['\nCommands\n', '\nDesc\n']] |
162 | 164 | | for module_name in sorted(self.helper_commands): |
163 | 165 | | data.append(['%s' % module_name, getattr(self, 'do_'+module_name).__doc__]) |
164 | | - | print prettify.tablify(data, table_border=False) |
| 166 | + | print (prettify.tablify(data, table_border=False)) |
165 | 167 | | print |
166 | 168 | | |
167 | 169 | | def complete_help(self, text, line, start_index, end_index): |
| skipped 49 lines |
217 | 219 | | return |
218 | 220 | | # Clean trailing newline if existent to prettify output |
219 | 221 | | result = result[:-1] if ( |
220 | | - | isinstance(result, basestring) and |
| 222 | + | isinstance(result, str) and |
221 | 223 | | result.endswith('\n') |
222 | 224 | | ) else result |
223 | | - | print result |
| 225 | + | print (result) |
224 | 226 | | |
225 | 227 | | def cmdloop(self, intro=None): |
226 | 228 | | """Repeatedly issue a prompt, accept input, parse an initial prefix |
| skipped 24 lines |
251 | 253 | | else: |
252 | 254 | | if self.use_rawinput: |
253 | 255 | | try: |
254 | | - | line = raw_input(self.prompt) |
| 256 | + | line = input(self.prompt) |
255 | 257 | | except EOFError: |
256 | 258 | | line = 'EOF' |
257 | 259 | | else: |
| skipped 21 lines |
279 | 281 | | def do_quit(self, args=[]): |
280 | 282 | | """Quit the program.""" |
281 | 283 | | if self.online: |
282 | | - | print "\n\nQuitting...\n" |
283 | | - | print self.env_obj.clear_env(self.modules_settings) |
| 284 | + | print ("\n\nQuitting...\n") |
| 285 | + | print (self.env_obj.clear_env(self.modules_settings)) |
284 | 286 | | else: |
285 | | - | print args[0] + "\n\n\nTarget Offline...\n" |
| 287 | + | print (args[0] + "\n\n\nTarget Offline...\n") |
286 | 288 | | raise SystemExit |
287 | 289 | | |
288 | 290 | | def do_exit(self, args=[]): |
| skipped 3 lines |