I'm using netcat to create a backdoor running a python script with the following command:
netcat -l -p 1234 -e 'python /script.py'
then I'm connecting to the backdoor with another shell using:
netcat localhost 1234
script.py is a simple loop that reads input, saves it to a file, and then prints it back. Now whatever I write in the second shell goes to the script and is successfully saved to a file. However, I don't see the output of the script on the second shell. I tried both the
print
and sys.stdout.write
methods of python and both seem to fail. I don't know why the output is relayed back to the second shell if I use this:
netcat localhost 1234 /bin/bash
But not with my script. I'm obviously missing something important. Here is my script:
import sys
while 1:
kbInput = sys.stdin.readline()
sys.stdout.write( 'Input: '+kbInput)
f = open("output.txt", "w")
f.write(kbInput)
f.close()
print
Asked by Mazen
(33 rep)
Mar 16, 2017, 11:16 PM
Last activity: Mar 26, 2017, 12:00 PM
Last activity: Mar 26, 2017, 12:00 PM