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
|
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import socket
import threading
#configuration AES
key = "AAAAAAAAAAAAAAAA"
cipher = AES.new(key)
def pad (s):
return s + ((16-len(s)%16)*'{')
def encrypt(plaintext):
global cipher
return cipher.encrypt(pad(plaintext)).encode('utf-8')
class ClientThread(threading.Thread):
def __init__(self, ip, port, clientsocket):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
self.clientsocket = clientsocket
print("[+] Nouveau thread pour %s %s" % (self.ip, self.port, ))
def run(self):
print("Connection de %s %s" % (self.ip, self.port, ))
r = '/Users/macbookpro15/Desktop/test.conf'
fichier = open(r, 'r')
f = fichier.read()
data = encrypt(f)
fichier.close()
self.clientsocket.send(data)
print("Client déconnecté...")
self.clientsocket.close()
tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpsock.bind(("192.168.1.2",1111))
while True:
tcpsock.listen(10)
print( "En écoute...")
(clientsocket, (ip, port)) = tcpsock.accept()
newthread = ClientThread(ip, port, clientsocket)
newthread.start() |
Partager