Create an Advanced Keylogger in Python - Crash Course 2020

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys it's grant here hope all is well so with my recent activity with creating an advanced key logger in Python and then adding some features to that after some audience improvements I've decided to create a small crash course pertaining to how I built the key logger my thought process and just the overall implementation of what I did as an FYI before we get into this crash course this isn't professionally written code and I am NOT a very talented programmer slash coder but the implementations that I used for the key logger really haven't changed since the videos besides from that there is free downloadable notes that you can download these notes are a little bit different than just a complete set of notes they are a springboard they offer a springboard for you to create your own version of the keylogger before you try looking at the crash course so that you can actually go through the application portion because often times that is really important if you can apply what you're learning instead of just following a random course instructor you're really going to get a better benefit out of the the resource so there are notes in the description below that are freely downloadable I hope you guys enjoy the crash course and without further ado let's transition on to how I thought of the project and what my thinking approach was [Music] before we start this course I have a few recommendations or prerequisites that I recommend that you do and follow before getting into the crash course content the first thing is to make sure you have Python 3 installed I am using Python 3.7 but the latest version Python 3.8 will work the next thing is to make sure you have a text editor that you can write your Python code in whether that's just a default ideally that you will use I am using pycharm you can reference the downloadable notes if you need help with installations of pycharm for instructions and number three is to make sure that you have some of the Python basics down I will not be going through the very basics of Python throughout this course so for instance I am going to assume that you know what a loop is or a variable or a list for example there are tons of free resources and courses and I'll link a few in the description below for the Python basics I recommend you either look at eto Rica's crash course on YouTube about an hour and 30 minutes long which is free or there is a very cheap course Python basics which is geared towards the cybersecurity perspective by Chris Diaz at who is an information security professional he has a course on udemy that you can buy so you can you follow any type of resource but just learn make sure that you have the Python basics down as I have said before just a quick heads up I am NOT a professional coder and/or a programmer so there are always improvements to be made to code to my code of course and also in addition one of the big downsides of Python is the ease of turning your programs into workable executables Python isn't very good at this I'll leave you with the resources you need to put this keylogger into an executable but I do not directly do it on this crash course so just make sure the just a heads up that we aren't going to be putting this into an executable and in addition this is flagged by antivirus so even if you were to put this into an executable you would have to work around antivirus this is more about just developing code and functionalities within Python and the approach that I had speaking of how I approached this project really there was the way I approached this project was I wanted to create a keylogger which was a bit more advanced than the one I had created before last summer so I create a basic key logger from a Python cybersecurity course and it was a very simple and popular implementation for the key logger in Python so if you look up like Python key logger on YouTube or on Google you often will see this simple implementation of the key logger written in Python a new Python had the ability to easily integrate more features because of its extensive access to libraries or modules or whatever you want to call them so after conducting a bit of research additional features for the key logger let me look at it I looked at a few other courses out there and some suggestions like kora I decided to go ahead and use Python as the language that I would write as my implementation so what I like to do with my projects when it comes to building whether it's a small scale large scale project is perform what I like to call it I guess just a basic research phase and so I research in this time for potential libraries that I would use for my features common implementations may be like what was previously used or like you know checking github and break up my project into steps after performing this basic research so I wrote down my key logger features as well as some potential libraries that I could use on a document I then went about going creating a little outlined diagram that I would use which would be offer as a guide to help build the key logger and I broke down my features into chunks so that have clarity on what I wanted to complete for each step now I understand it's not every project where you're not going to know exactly what you're going to do or what the end goal is but having an end goal result or angle in mind and performing some basic research referred before diving into it directly is really gonna help you direct you in a way that it's gonna make it easier to break down the project into foreseeable chunks so that you don't get overwhelmed or you don't know where to start breaking it down into steps is what I love to do when it comes to approaching a project so with all of this out of the way it is time finally to develop the advanced key logger in Python alright let's get started with this key logger to start we will first open up a PI term project so we are double-clicking pycharm where and here we have this we will create a brand new project save your project to any location and wait for the project to load okay once the project has loaded and everything is loaded up we are going to be creating two new directories directly under our main folder so let's go ahead and create the first new directory which will be called python or project rather not python and the next directory will be called photography now we are going to create our first python file under ectly under the project directory so do your new python file and call it whatever you want to call it but I will call this slugger click ok and let it load now before we start typing any code we need to go ahead and add some imports or some modules or libraries or packages or third-party whatever I there are so many names for them so basically to do this to import modules there are multiple ways the first way is to use pip and we can use pip directly through our terminal in pi terms so you can use pip install and then the package name if you have pip installed on your computer you can also do this through the command prompt if you wanted to so you could use pip install and directly and still from here now pip is great and it's very easy to use but oftentimes there is permission errors and the modules that get downloaded go into certain directories and it so it's kind of hard to manage where these libraries are getting installed if they can be globally accessible throughout the computer sometimes you have a error where you can access the module on this project but let's say you were to open up a new project it says it's it's not on there but it's installed so it's kind of complicated and so to work around this and for the sakes of simplicity even though pip is widely used we will be working or directly importing each of our imports through this PyCharm project to do that all we have to do is go to file settings under project : click project interpreter you will see pip and setup tools and these are our packages right now that are in the default or the project that we created so to add our new module click the plus sign and up here we have a search bar and we can search for any of the modules that we want so I have in the guide the modules that we need to directly download through this process right here so starting with P py win32 all you have to do is press py to click the correct name and click install package once the module has been successfully installed you will see this green success bar and it is successfully installed so I'm going to go ahead and import all of these just follow the same exact process where we will type in the next module name and click install package I'm going to do this for all of these modules right here so go ahead and do that and I'm going to skip forward because it's a little bit tedious to do this once we have added all of the Python modules that were specified in the document we can go ahead and exit out of the available packages and you will see all of our imports here so these are the modules that we just imported are the third-party libraries and we'll be using these to add our features to the advanced sealer so go ahead and click OK ok so now we can go ahead and add our libraries to the keylogger project and this keylogger dot py is our main file now if you were going to be developing this in real time meaning like you're going to develop it on your own and it was going to be something where you did it all right by yourself you don't follow my guide you would probably be importing these libraries as you go as you add new features as you add new code but since we know exactly what we're doing and I've already gone through the process of doing that we are going to go ahead and import all of the libraries right now so let's go ahead and do that to start out we will go ahead and create our first comments and we'll call these libraries to make sure we have that specified and organized then we will go ahead and start importing all of our libraries so let's go ahead and do this and yeah let's just do this so our first set of libraries is some email libraries so that we can add our email features so let's go ahead and add all of these and just type them as you see on this okay so here are our first set of libraries we've imported three from our four rather from our email and the SMTP live the next one will be some default modules or libraries that we will use for collecting computer information these are our two that we will be using to collect information and now it's time to get the clipboard we will also go ahead and grab our keystrokes with the PI input library we will import some system information to track the time so this includes the time module and us module we will also for our microphone capabilities we have to import two modules sound device and the Skippy i/o dot wah file oh did I forgot to import sound advice to encrypt our files we will be using the cryptography library we will be also using the get pass information to get the username and the requests a library to get some more computer information and finally to add our screenshot functionality we will be using the multi processing freeze support to only take one screenshot at a time and from the pillow module we will be importing image grab and these are all the libraries that we will be using for the advanced key logger so each of these modules adds a certain functionality and gives us access to code which allows us to do or perform certain things now you may be wondering grant like what what grant what do you like how do you get all these libraries like what do you do even do to look these up I have no idea what any of these are what what did you do so what I did was I basically just went to google.com said how to get screenshot from Python library and the most popular one that came up was from the pillow module and a subsection what would push called image grab and so I did this for all of these libraries I just looked up like how to get clipboard information library module for Python and it came up with win32 clipboard and there's multiple modules for the same functionality and oftentimes it's just a matter of parsing through the one that works the best for your capabilities and just using that library so we have our libraries created or imported into our main project and it is finally time to get started writing some code the first segment that we will be creating is the key logger itself as you know by now a key logger logs keys in to log keys in Python we will be using the py inputs or py and put keyboard module or library there was two important imports that we imported from py n put the key and the listener the key logs the key and the listener listens for each key typed on the keyboard before we get started with logging keys let's create two default variables the first variable that we will be creating is the key log dot txt log file this is where all keys that are logged are going to be appended to so let's go and create a default variable so that we don't have to keep writing keys on your score log at txt every single time our next default variable that we will create is the file path itself this is where our key log dot txt file will be stored for now for simplicity sakes and to make it convenient on us I'm just going to be using this directory right here instead of having to figure out where all of this is all we have to do is right click the directory say copy path and we can paste it in here and there is our path and make sure to add double backslashes per each box so that is an escape sequence finally we will add one little tidbit for the file path so that we can access our key log txt file so we will add the extend which will allow us to add an extension right here and then we can access our key log txt when I created this key logger when I was in the process of creating his key logger I looked online for any tutorials that had to do with py input to see if I could find some sort of way to implement easily implement and log the keys I stumbled upon a YouTube tutorial on free code camp argh that was created by tech with Tim and he creates a basic key logger with Python using the py input module that we are using so from this tutorial and a little bit more of research and based off of some inspiration I went ahead and implemented a very simple simple and very similar implementation to with what tech with Tim shows so if you want a better explanation tech with Tim is a fantastic explainer of code you'll gain a little bit of a better understanding using this tutorial basically I do the same exact thing video input makes logging keys in Python relatively simple in order to get started with logging keys we will first create three functions and also open up the listener so that we can append each key to the log file so let's go ahead and define some constant variables sorting out with count and we will set that equal to zero we will also create a new empty list called keys where each key will be appended to the list but it's empty for now okay so now it's time to start with our first function which is on press we will be taking the parameter key so that we can log each key so type in key let's create some default global variables so that they can be accessible within the entire function so we're gonna create three keys counts actually we're doing - Wow I suck at tutorials it's all right we're in anyway we're going to be doing two global variables keys and count not three so the first thing that we're going going to want to do is if you want to output each key that is typed onto the screen of Pi charms we can simply type print key and that will print each key the next thing that we will want to do is append each key to our empty list as I said before so let's go ahead and do that and to do this we simply just type in these pend H key after we have appended this key to the keys list we are going to increase our key count by one the next function that we will be creating is the write files function which is going to write the keys to a specific file that we specified which is going to be the key underscore of log txt let's go ahead and create this new function and we were going to take the parameter ease let's go ahead and open up our file so that we can start appending some data to the file specifically the keys in this case to do this we will use the width followed by the open block our file path plus the extension plus the keys information and we want to append all new data we don't want to write it if we wrote it basically every single time that we would reopen the file everything would be deleted so we want to append each key so we will be using a za for a pend and we will call this F the file F that we are opening now the following section that I'm about to describe here is completely up to you if you want to do this but for me personally I want to make Mikey log txt file pretty readable you know so that's pretty easy to read and gather information relatively quickly so we are going to be doing a few modifications within the keys so that it looks a little bit better let's go ahead and loop through each of the keys within the keys the list that we appended so or key so for each key in the keys list we're gonna be looking for are checking specific basically instructions for modification the first thing that we want to do is replace every single single quote with nothing so that when we have for instance let's say it was H E hell so each time that py input logs a key it has those single quotes in between and we don't necessarily want this because it just makes it look a little different so we can go ahead and quickly replace each single quote with a blank line or nothing so that it will look like that so to do this we will create a new variable and first we will convert our key to a string and we will replace whoops don't do that we will replace each single quote with nothing how we're good the next thing that I wanted to do with in this process is make it each word readable on a different line reason being it's just easier to read throughout each line and it makes a little bit harder if you don't parse through the spaces so what I did was I did key find space so if there is a space or the space bar is typed and that is greater than zero we create a new line so every single time the space bar is entered a new line is created and we close the file the next function that we are going to write is on release we don't necessarily have to write this function but this function really helps us if we want to actually exit out of the key logger so let's go ahead and define on release and we will also be taking in a key parameter we're gonna be checking if a certain key value equals something so if the key equals P desk or the escape key is entered return false what this will do is it will exit our key logger finally let's open up the listener block which listens for each key and implements our three functions together do this we'll use the with listener on press and we will define this unpress so we're basically defining the value on press is equal to our function that we wrote on press and on release so the value of on release is going to be the function that we created which is on release obviously and we're gonna call this as listener listener join which joins our keys together before we run this code there is one more little thing that we must implement in order to continue to add new keys to the log file we are going to be adding in if statement so you see that we have this count variable here so if we do if counts is greater than or equal to 1 we're going to reset the counter able to zero and we're going to write the list keys to the key log dot txt log file and then we will create a new list called keys with Tina empty it'll just be an empty list so this just helps us better organize our key log XT file finally before we run the key logger we have to add another if statement within our write file function we are going to expand this if statement using Elif and we are going to be checking the value of each key and writing the key to the file and then closing in the log file now if we go ahead and click play and let's go ahead and write hello world the first thing you will see is our characters being outputted because of this line right here on line 41 and if we stop the key logger and go to our key log txt you will see hello world and I was just testing something before before this reload recording so but yeah you will see hello world here and you're good to go so we have the key basic key logger working and now it's time to move on and start adding some different features to this key logger or I guess spyware like features so let's just go ahead and get started with that the next feature that we will be adding to our key logger is email functionality so let's say we wanted to take all of these key so the key log txt file and we wanted to send this to our email so that we can access the keys we have to add some email functionality to it now when I was creating the key logger I didn't really necessarily know how to go about doing this but I found this really easy tutorial by geeks for geeks org that shows you how to not only send email but add an attachment so for instance the log file add the keys log file attachment you are email so that we can access the email we use SMTP Gmail for our service so we're using Gmail comm and yeah so let's go ahead and implement this function into our key logger alright so we are going to now create this send email function which allows us to send different emails to do this all I'm going to do is just do this a copy and let's just paste this somewhere and okay cool we're done I'm just joking we're actually not gonna do that we're gonna go through it line by line but we're gonna be using a very very similar template to what geeks for geek geeks has done here so let's go ahead and do this inish you couldn't tell that was human I'm trying to I don't know I'm trying to make this like a better tutorial but alright so let's go ahead and create the next function which is going to be the send email function we are going to be creating this function with three different parameters we will call it send email the first parameter we will use is the file name that we want to send followed by the attachment and finally for the cue address so which address we want we can assign the address where we want to send it all right so let's go ahead and create these defaults we're going to need three of them the first one is the email address that we are going to be sending from for me I'm going to be using a disposable gmail account or a trash one that doesn't isn't used for anything else I would HIGHLY advise that you do the same don't use something or a personal gmail account use something that is just create a new one if you want to so call this next is the password for this gmail address I'm exposing my password and finally we will need a to address and this can be anything this could be the same email address you're sitting from it could be a temporary email address that you want to put in here that's why I have this grambler or the sorry will here so that we can change it whenever we want to so if you wanted to create a mail manner account or a temp mail account and have some temporary email address we could do that for me I'm just gonna put the same email address in here all right our default variables are now finished and it's time to create our send email function so the first thing that we will need to do is define our from address so the sending address so that we can incorporate basically our email address parameter or so our variable that we just created so we're sending from which email address while we're sending from this email address so we're just incorporating it either within the function next thing we are going to do is start with the creation of our message using the mime or multi internet mail extensions totally did not look that up in Internet Protocol which allows us to format email messages to support character texts and email attachments videos audio images so it is a way for us to incorporate our attachments let's go ahead and create this new message and we will add our first Miami multi-part next three variables that we will be creating are are from to in subject handles so that we can have the from address to address and of course the subject so first is the from and we are going to define this using our message that we just defined and we're going to be incorporating our from address variable next is our to address and we will be using the to address parameter that we defined above and finally our subject if you wanted to you could call this subject anywhere anything you could even add an additional parameter and call it you know whatever subject here and you can have a specific subject for each email that you send but for me I just like keep it simple and we'll just give it saying log file alright so now we have to create the body of the email and to do this we have to first define a body or a string so that we can attach it to the email so this can be anything but I'm just gonna keep it simple body of the mail so every single time an email sent you will see the body of the mail in the body of the email then let's attach this body to the message to do this we will do use the message attach method followed by our multi Internet's my text there and we will attach our body and you will keep it as plain a format okay the next few variables that we will be defining here are going to be the attachment so let's go ahead and first define what we will be attaching so up above we had a file name and we are going to be calling file name equal to itself file name and we are going to be creating our attachment and we will open up the attachments wherever that is at and we will read the binary so we will read the attachment next we need to create the base I will create this as P and do mime base application/octet-stream so these are just some defaults variable or not variables default settings that we add to our mine base here this is just a very default line of code next thing that we will do is encode our message so we'll do P that set payload attachments followed by readings we will read the attachment and then we have to finish our encoding by coating it with base base64 and boom there we go okay we're almost done we have to add a header we have to attach the message and then we can start up an instance login to our gmail accounts and send the mail so let's first add our header by doing P that add header so this would be the email header I will just use it the the what geeks for geeks had our attachment has the file name let's go ahead and attach P to our message and now we can start to create the SMTP session so I will define a new variable called s and we will be using the SMTP Lib dot smtp followed by our assumed t defining our the smtp server and the port that we will use to access Gmail which will be 587 it's typically used for this type of purpose so yeah hmm next is starting up our TLS we must secure what we are trying to you know steal so we will create a TLS session and now it's time to finally log in to our gmail address with our front address and password then we need to make sure that we can convert the multi-part message into a string so that it is able to send so we will just do text message as string to convert the string and finally finally we will send our e our email by doing send mail followed by from address to address and our text and we will quit our session I didn't do a great job of explaining all of this a lot of this is very defaults you will see this when you're trying to incorporate the SMTP library as well as our email libraries or modules here so we can go ahead and test this real quick by creating or defining any instance and let's say we wanted to attach our key log text file to do this all we have to do is first define our file name followed by the where this file name or where this file is located so we have to incorporate the full extension and the to address we already have that defined and there we go we're good to go so if we click Play here and wait for one second and let's just say we stop that and if you wait a few minutes later we will have our first email that has sent to us with our key log which just has a whole bunch of stupid keys but yeah so we got this function to work and it is now time to move on to our next parts which is the getting the computer information to get computer information we are going to be using multiple libraries or modules that we have imported and using the methods to get specific information including like the processor system the Machine the hostname and the private IP address and also try and create for the public IP address as you can probably tell by now we have kind of our variables right here which act as the controls are the defaults for the entire key logger so we're gonna create yet again another default variable which is gonna create a new file for us which is going to be the system information so let's go ahead and do this create a new variable called system information - followed by whatever we want our file to be called I'm just gonna call it system info txt and let's go ahead and exit out of arson email or minimize that and append a new function between a Z key logger and the send email function for this one we are going to be calling it computer inflamation and the first thing that we are going to do is open up our system info txt file with the with open block with open file path plus extend plus system information and we are going to append to our file and we will call this F first thing that we will do is use the socket get hostname to get to the hostname so let's create a new variable and call it host name followed by socket get hostname and let's get the IP address by using the socket socket host by name and the host name we will be using the host name variable there okay now when I was first creating this key logger I did not create a wave or means of me getting my public IP address I just got the private IP address but with a few edits in suggestions from the audience there was a way that I could try to find the public IP address and to do this we will be using epified org now amplify that org only allows you to queried their service a certain amount of times and after that happens you know let's say after three times it shuts down and that will ruin the functionality of our key logger so in order to limits the the ability for us to stop or halt the keylogger we will be using a try/except block so we are going to try to get the public IP so let's go ahead and write try by followed by a public IP variable and we will simply use the get and the web URL at five org and we will convert that to text so what we're doing here is defining the public IP variable and we are using the get function to get some certain information and we're converting that into text and we will write our public IP to the log file so I'm just going to organize this by using the public address followed by appending to the public IP and we're good so if we do if we are successful in our query we can get our public IP however if we aren't successful we are going to accept any exception any any and all exception and we will write an error message saying couldn't get public IP address most likely of max so this time if the query does not is not successful and it blocks us we will accept any exception and we will write an error message to our log file all right now it's time to get some other information including the processor information the system information machine hostname and private IP address let's go ahead and get our processor information and to do a lot of this we will be using the platform module followed by some specific methods within this library or module so we are going to first write to our file the processor information now you know why even get the processor information well why not I guess if you're extracting information why not get as much information as you want but this could just give you an insight into maybe how powerful the machine is or if there's any vulnerabilities for this particular processor so that's the reason why I would get the processor information to get the processor information all we have to do is simply use the platform dot processor information and that will get our processor and information keep saying processor and let's create a new line so our next setting or yeah thing will be there that's bad grammar okay the next thing we will get is the system information including the version so like the Windows version if this is a Windows machine and we will organize this by system and we'll add platform that system and also add a blank line and the platform oops and like we did for the prior one above we will add a new line there we go oops and of course make sure to add that awesome next thing we will get is the machine information again we will be using the method dot machine from the platform library you can see how handy python really comes when it comes to you know importing different dependencies and libraries and just simply using their methods that are have already been defined so we'll use platform not machine followed by creating our in neo line and let's write our hostname which we got up here so we can just do F dot right host name followed by our host name and pen down the line and finally let's go ahead and write our private IP address which we got up here so if you were like on a university network when I was at the time of writing this key logger oftentimes the the IP address is the same so like they use this in a an order for you in order to track you so if you were let's say targeting someone on a university network this would help you and allow you to get their private IP address which then you can sign into their network and target their IP address with whatever you want to do so that's why I have this option here and there we are we have our computer information so if we go ahead and define computer information and we call this a function we will hopefully get a new file called system info dot text and Abel gain all of our information of our system we're just gonna wait a moment here let it send an email and as you can see we now have our system information followed by everything that we need here so awesome we have what we need in terms of getting our system information the next thing that we will be doing is getting our clipboard so if we let's say we're copying and pasting passwords email addresses important information we can get the clipboard information from this individual that we are targeting let's get that now okay let's go ahead and get the clipboard information we are going to insert this function between our key logger in our computer information function so let's go ahead and create a new function called copy at clipboard and we are going to take no clipboard contents or no parameters rather before we continue on with this let's go up to our controls and create a default variable for our clipboard information we can call this whatever we want but I will keep it uniform with the others and call it clipboard underscore information followed by the clipboard XT file name whatever you want to name it that is the name that I am going to give it okay so we have imported the win32 clipboard which is a sub module of P 132 so we all we have to do is work with the let's see here the the win32 clipboard to get to what we want with the clipboard so let's go ahead and first open up the file by using the width open block followed by our file path extension and clipboard information we will be appending to this file and we'll call it f just like any other file that we open okay so there's two instances for a clipboard you have texts or string which could be used to copy so you could copy this right here or you could copy like a PowerPoint file or a image or an audio clip and so because for simplicity's sake and because it's very limited in terms of what you can do we are just going to be appending strings to our little dot txt file so we are going to create a try except block first we will start with our try block and the first thing we'll do is use the dot open clipboard method to open the clipboard next thing we will want to do is type in pasted underscore data or whatever variable name we want to call it and this is where we actually get our clipboard information so we will be using the lit clipboard data method to get the contents in our clipboard then we will close our clipboard with the closed clipboard method and finally let's go ahead and write this data to our clipboard txt a log file there we go so we can get the contents if the contents are a string but let's say this is an image or the individual that we are targeting has copied an image audio file or some sort of other file that isn't a string we want to make sure that our key logger doesn't stop so to do this we will just do accept followed by F dot write and error message and whistie sake of course you alright clipboard could not be copied and we're done so now we can get the clipboard information and to quickly test this all we have to do is call our clipboard it right there and let's see if this works we should see a clipboard txt file up here and there we are we have our clipboard with a Google Docs string URL so that is the clipboard and that's pretty easy to get it was a pretty easy thing to do with the win32 clipboard and module the next thing we will do now finally is start working on getting our recording of the microphone if it's on and we will be getting a screenshot as well so that we can figure out what the person maybe is looking at whether that's maybe a Facebook account bank account or whatever it is so let's go ahead and start on the microphone to get the microphone we imported to import in modules and or libraries we have the Skippy Iowa file and the sound device we will use both of these to collect the contents of the microphone so that we can record maybe what's going on if someone you know is talking to another person on the phone or yeah whatever it is so to do this we are going to insert it between our key log here and our copy clipboard and let's go ahead and create our next function it we will call this microphone will take no parameters the first thing that we want to set is the sampling frequency and the common sampling frequency is forty four thousand one hundred Hertz so we just need to set this to a default variable named FS or whatever you want to call it for me I call it FS here next thing that we want to do is specify the amount of seconds we want to record for the microphone so you know we could do a minute we could do 10 minutes we could do 10 10 hours but it doesn't really matter so right now I'm just going to type seconds microphone underscore time and let's go ahead and define the microphone time variable in our default controls I'll just give it 10 for now okay so now let's go ahead and use the sound device module to record our microphone and to do this let's create a variable called Maier recording which will store our recording and we are going to be using the dot rec method within the sound device library so dr. rec and we must convert our seconds into our sampling frequency as well as set the sample rates equal to FS that we specified and channels equal to two then we will wait for the recording to take place and finally we are going to write this to a dot wah file hence why we imported Skippy i/o so let's go ahead and do that do write file path plus extend plus we will call this audio information the frame sampling and as well as the my recording so we can attach that let's go ahead and create our audio information right here so let's go up here call this audio information call this audio and make sure to have the dot WAV or love for our extension so if we play this we will get a recording of what is going on for hopefully ten seconds awesome as you can see I just recorded for 10 seconds and we have the audio wave file up here so we are making some good progress with our key logger next thing we will do is get the screen shot information or get a screenshot of what is going on on the screen so let's go ahead and do that okay so for the screen shot we will once again like by convention by now what we're doing is creating a function for each feature we will go ahead and create our screen shot function no parameters for this function as well this is a pretty easy little library to work with we imported the image grab functionality from the pillow module so all we have to do is define a variable followed by the image grab grab method to grab the image so I'm just gonna call this I am and use the image grab grab and there we go we have grabbed an image now we need to save this to a certain file path and we will use our practice file path plus extend plus screen spots their score information and let's go ahead and add this into our default control make sure to add the dot PNG extension so now if we were to run this and let's go ahead and disable our michael microfone before now so we not to worry about that you will see a screenshot pop up in this path and as you can tell we do now have a screenshots that just was taken awesome let's go ahead and add a timer function to our key logger so that every certain amount of iteration or time we take the steps of copying the clipboard gaining more keystrokes getting the screenshots and maybe a recording the microphone so you know we want to do this every few let's just say minutes or hours depending on how long you want to run the key logger so to do this there of course there's multiple ways to implement this but the way that I did this was by adding the time function to our to the key logger and then implements some of the features for the time function here are count we are going to go ahead and add above a few time controls so that the key logger can iterate through the features to do this we will have three default variables we'll have the number of iterations and this will be always set to zero so think of this as your base of value for your counter then we will have deterrent time which will get the current time of when the keylogger is launched and created so it will update every so often eventually as you'll see in a minute here so to get current time we just do time dot time and finally to get the stopping time we can do stopping time equals time time plus time underscore iteration so what this does is every single time that we want to let's say go through each of the features of the keylogger we can get the current time and then we add the current time plus the stopping time so let's go ahead and add our time iteration up here to our default controls so let's say we wanted to have each iteration go on or I don't know 15 seconds then we can just write 15 and we have that there the next thing that we will do is go ahead and add a while loop which will query for really the number of iterations that we want to go through so let's say we want to do 5,000 iterations of each feature at 15 seconds that's what this wild state won't we'll look for so to write a while statement we'll do while number of iterations is less than number of iterations and we will do the following things for the keylogger so highlight all of the keylogger features and press tab for pycharm to go ahead and indent that and we have a number of iterations and let's go ahead and define this up here above let's say we wanted to do this three iterations so we'll have three iterations at fifteen seconds each for each feature so 15 seconds will be allocated okay so there's a few things we have to do in our key logger to edit it so the first thing that we are going to want to do is add the current time variable into our global variable this statement right here under the on press and what we're gonna want to do is create a current time right here and get the current time at this position and time so every single time a key is pressed will have that current time being queried the next thing we will have to do is go under the define on release and we are going to be creating a new exit statement so if the current time is greater than the stopping time at this point we want to exit out of our key logger so that we can go ahead and take those keys from the log file and send it to our email so we can do return false and boom now we have stopped the key logger and finally before we are finished we are going to go ahead and do a little bit more of adding a little bit more to our timer so the next thing that we need to do is check if the current time is greater than the stopping time for the rest of the features this right here does it for the key logs itself so think of it as just the key logger right here but we need to check if the current time is greater than the stopping time so that we can do the other features as well and send out emails so we'll go ahead and write a similar statement to the one right here so if current time is greater than stopping time and we want to do a few different things the first thing that we're going to want to do is clear out the entire logs for the keys in for me the reason why we want to do this is so that we can have a new clean file for the the key log and we won't have the previous key logs that have already been logged so we will do a with open file path plus extend plus keys keys information and we will add the right block to that we want to clear the contents and we'll open that as the file name F and simply do F that right and we'll you literally just do a empty string so now we are appending a empty string to the file and clearing contents in addition we want to go ahead and start getting some of the features so the first thing that we want to do is get the screenshots so simply with our function we can do the screenshot and then we want to go ahead and email this screenshot to our email so we'll do the screenshot information as our file name the attachment is the file path so the file path where the screen information file exists and the to address can be any address you want to get next thing you want to do is go ahead and copy the clipboard contents to do that we just have to simply type copy clipboard and we want to increase the number of iterations to one so this is going to now add to the number of iterations one up here and we want to go ahead and update our time as well so let's go ahead and do time that time and stopping time equals time time plus time iteration now we will be adding some more features or ascending the rest of the files after we have encrypted so our timer function is now complete so each time that we want to have this key logger go through each feature we can have it go through each feature 15 times for five thousand iterations and I don't know how long that would take well I mean you could just do 15 times 5,000 but you get the point so yeah yet this is the timer function now let's move on to encryption okay for encryption why would we even encrypt our files in the first place well let's say we wanted to office gate our files on as a victim machine and we didn't want the victim to find out what the heck we were doing I mean if you had a log with all of your passwords and the website visited and things like that you're gonna be a little bit taken aback and you're gonna probably take some precautions to try to remove this key logger as soon as possible but if you have something that looks like it's just random strings of data the average user probably isn't gonna look around and do much for it so that's why we have encryption and really honestly we have already encrypted our information right here so or not encrypted our information but we have downloaded a imported a module which will allow us to encrypt at certain files so the first thing that we are going to want to do is actually create our list with the the the regular files and then we're going to want to create a list with the encrypted files so before we do that let's go up to our default controls and as you can see we have all of these text files right here and what we'll want to do is go ahead and create the encryption for the files to have that dot txt extension so the keys information the system information and the clipboard information are all going to be encrypted these will not be so what I did when I was creating this key logger is just add the simple e and also do the e e watch case T now if you wanted to obfuscate and make this look hidden you would name this something completely different but for demonstration purposes it doesn't really matter so we'll do this for all three of them and finally the clipboard and make sure to enter yeah of course okay let's go back down and oh actually also as a means for us to help us out with our list I guess I probably should have done this pretty early right under our file path and extend I'm gonna have a final merge which is just going to combine our file path and our extension so we don't have to keep writing file path pest extend plus the you know the file so final merge equals file path plus extend this will be easier for us now we're creating these lists alright so we're at the bottom here and we are going to create two lists files to encrypt and encrypted file names so let's go ahead and first start out with the first list files to encrypt and we are going to create empty lists here and we will query a three or have three different files that we want to encrypt obviously we want to encrypt the system information and clipboard and keys information so to do this all they have to do now is finally click file merge plus system information the regular system information file merge plus the clipboard information and finally a file merge plus he's information so those are the files that we want to encrypt now we want to have the encrypted file names into a list so that we can easily access them when we're actually encrypting them so let's go ahead and create a new list called encrypted file names and we'll do the file merge plus the system information e-file merge plus Flipboard information E and finally file merge plus the keys information ok now that we have that we have our two lists and it will make the files easily accessible when we are trying to encrypt them okay so let's go ahead and create a for loop here which is going to traverse through the files to encrypt and encrypt our files so for encrypting this is the element that we will create or the the element that we this is the element that we will create and this is a varial it's the variable name that we will assign to each position in the list and we are looking to go through our iterate through ze files to encrypt so what we're gonna want to do is open up each file and we're gonna want to read that file and then we're gonna want to add some encryption and then we are going to want to encrypt that information with the key to the new file or the e files and then we want to send the emails with the encrypted file and then we want to go ahead and do that over and over again until the three files have been encrypted so it sounds a lot complicated sounds really complicated but really it really isn't so first thing when you do open up each file and read the data do this we will use the width open block followed by what we want to open so we're looking to files to encrypt and we want to access the first position within the list here and so we're going to create a default variable called count and we're going to equal that to zero so what this will do is it will start out with the zero position which is zero index which is right here and then it will go 1 and then 2 so 3 in total and we want to write or read a binary so we want to read the information from this file and we're gonna call it F and as I said all we want to do is read the data so let's just do F dot read and we're going to assign that to the variable data now when it came to finally like you know encrypting these and I was in the process I had to simply look up how to encrypt with the key and to do this it's pretty easy all we have to do is add a little bit of our add the encrypted method to encrypt our data with a specified key the first thing we want to do is go ahead and do Fernet equals burnett and then the key here and for the key we are going to generate the key right here in our cryptography a file and that's why we have the cryptography file in the first place but let's ignore that for now what we're gonna want to do also is encrypt the data so after that encrypts data so with the fare net we are going to encrypt the data now we want to go ahead and append this encrypted data that we read from the blank unencrypted data file and we want to go ahead and append that to the new file and to do this we will do the with open encrypted files list starting at index zero but it will go up as we continue and we want to go ahead and write binary there and as F and we want to go ahead and F dot write the encrypted data so that's going to basically read encrypt and then append to a new file and finally we want to go ahead and send an email to ourselves so that we can get the encrypted files without any worry to do this all we have to do is do a cryptid file names followed by the encrypted file names counts so we're just sending the attachment so this is the file names and then we want to go ahead and add the to address and yeah so that is getting the position of the name and then it's getting the path and then the to address and we want to increase the counts by one so what we're doing here now is increasing the count by one so then we will be done with zero index and move on to the first index to end we will give each iteration so each time that the keylogger iterates through one iteration we'll let it sleep for ah two minutes let's just say so that we can send the emails and have that properly sent to us without any interruption now what we're gonna want to do is go up to our cryptography file and we're gonna want to create two new files a generate key in a decrypt file py program so the generate key is going to generate the key for us which then we will put right here and we will also create a little program which decrypt each of the files so that when we receive that the files from our email we can run our little decryption of the files this little program so that we don't have to worry about I don't know doing it I guess you couldn't do it manually but you get what I mean so alright let's go ahead and create the first one which is gonna be generate kita py under the cryptography directory and this is gonna be really easy to generate a key first thing we need to do is import our cryptography library and we will define a new variable called key which is going to generate the key so we'll do fair net generate key in which that just generates the key as it says and we will go ahead and create a new file called luscious colas encryption key that txt and we'll write to this file and then we will write the key to the file and then we will close the file so every single time you want to generate a new key all you have to do is just run this little Python program which will generate a new key for you let's go ahead and run this real quick boom so we have our encryption key which then we can copy and we can paste this into our key logger dot py so you see this little key variable here that is highlighted an underscore under with red we are going to put this up on our default controls and we will call this key equal to a string of power encryption key so let's say we want to change our encryption key we can by just doing and running this little program okay so let's go ahead and create one more little program which will decrypt each of our files to do this we will call this the decrypt file about py under the cryptography folder we are going to import the same exact library as before and we will give our key variable a blank string and then we are going to go ahead and we will want to create three files the system information Eclipse Ord information keyboard information II so that we can easily access these so let's just do that real quick okay so we are going to create yet again another list and assigned it to the variable encrypted files we are going to go ahead and make this list consists of these three files or variables right here and we all have such a default counter to 0 now we're gonna create a for loop which will decrypt each of these files so let's go ahead and assign a variable name per each position we'll call this e crypting file and encrypted files and what we're going to want to do is basically do the same exact thing as encrypting except that we will be decrypting so let's go back to our key logger so we don't want to continue to rewrite code and go down to our little encrypted files here and let's go ahead and copy all of what's inside our little for loop which encrypts the files and paste this here let's go ahead and delete the send email we don't need to worry about that and for this all we need to do is quickly change a few things so before we do anything let's go ahead and decrypt our file by just simply doing the Crypt and boom we are now decrypting our files right here we want to change the files to encrypt to encrypted files and right here to encrypted files and I changed the variable name here decrypted so we're gonna change the variable name as well your spelling and there we go so now we can add our key once again that we just generated into our program here and we can add our four I'm sorry three different files to our file path right here and we can decrypt those files so this is a nice little program that does this for us the next thing that we will do is go ahead and clean up a bit of our things add a few comments to organize our program and finish this key logger so we're almost done if we wanted to add our file path into a different location but we needed to know the username of the specific user that we are targeting we can use the get pass module to get to the username so to get the username for instance we can use username equals get pass oops get user and then we can impended this username to our file here to our file string we wanted to separate each of these by making some white space and let's just add a few comments I made some very generic comments for each section may you can make these a little bit more detailed if needed but for now and for time consumption I'm not going to go through and try to get all of these comments detailed so that's basically it for the keylogger it was pretty simple to create and obviously there is many improvements to be made but I think that this is it offers a great launch pad in a great start in terms of understanding how to implement different features with modules and libraries through Python if you want to go ahead and put this into an executable although it's very tricky and hard I recommend two solutions the first one is PI installer which is very hard oftentimes to get to work with these longer scripts but some people have had success with this particular key logger with PI installer the other one that we can use is called auto PI to exe I have it downloaded I'll have it in the description below to start Auto PXE after you've downloaded just go to your command prompt and do Auto Y to the X e to launch its and we can add our main script file and we can do some pretty cool things it's a little easy little GUI interface so that we can basically compile this into an executable this takes a few tries and for the six of this crash course although I probably should be doing X it's a crash course that's basically what you would do to make this into an executable so that is it for the crash course key logger of course there is always more improvements that you can't build I think you guys for watching this video if you have launched this video I will left you leave a like I'm just joking but just yeah I hope you guys enjoyed the video and the way that I have implemented my keylogger so until the next video have a good day
Info
Channel: Grant Collins
Views: 33,622
Rating: 4.9707794 out of 5
Keywords:
Id: 25um032xgrw
Channel Id: undefined
Length: 90min 27sec (5427 seconds)
Published: Sat Mar 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.