当我通过套接字发送命令“ sudo”时,程序将执行它。但是,弹出式sudo会出现在终端上,并且不会通过套接字发送,因此我无法编写密码。
所以,我的问题是是否有办法通过我的套接字发送“ [sudo] marmeus的密码:” ,所以我将能够发送密码或解决这个问题。
#!/usr/bin/env python
import socket
import subprocess
import os
TCP_IP = '127.0.0.1'
TCP_PORT = 5555
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
print("Conectado!")
while 1:
#Checking if there is data received through the socket
data = s.recv(1024)
if not data:
break
print(data)
#Execute the commands received
out = os.popen(data)
output = output.read()
if not output:
s.sendall(" ")
#Send the output of a command executed
print(output)
s.sendall(output)
print("he salido")
s.close()