Hey, I made two python programs, in two different computers, that uses sockets to communicate between the two computers.
Then, I wanted to execute a terminal command at the client program and the command it self will be sent from the remote controller program, then the client will send the result back to the second program.
This is what I've tried:
The controller side:
The Controlled side:
Those programs kinda work, it only worked for a few simple commands, for example: ls, pwd, cat, shutdown now. But when I tried more complex commands like: cd, rmdir, firefox. The program at the controlling side stopped working and I could not insert any input to send it to the controlled machine, it first executed those commands but afterwards, it was paused.
Does somebody know a different method that allows me to execute those commands or at least what's causing this problem?
Thanks in advance.
Then, I wanted to execute a terminal command at the client program and the command it self will be sent from the remote controller program, then the client will send the result back to the second program.
This is what I've tried:
The controller side:
Code:
import socket
s = socket.socket()
s.connect(('kali', 6655))
getInput = lambda: raw_input("client> ")
cmd = getInput()
while cmd != "###STOP###":
s.send(cmd)
reply = s.recv(1024)
print("Output:\n\n{0}".format(reply))
cmd = getInput()
s.send("###STOP###")
The Controlled side:
Code:
import socket
import os
s = socket.socket()
s.bind(('', 6655))
s.listen(1)
c, addr = s.accept()
print 'connected to: {0}'.format(addr)
cmd = ""
result = ""
getInput = lambda: c.recv(1024)
execute = lambda cmd: os.popen(cmd).read()
cmd = getInput()
while cmd != '###STOP###':
result = execute(cmd)
c.send(result)
cmd = getInput()
Those programs kinda work, it only worked for a few simple commands, for example: ls, pwd, cat, shutdown now. But when I tried more complex commands like: cd, rmdir, firefox. The program at the controlling side stopped working and I could not insert any input to send it to the controlled machine, it first executed those commands but afterwards, it was paused.
Does somebody know a different method that allows me to execute those commands or at least what's causing this problem?
Thanks in advance.
Last edited: