Transcript for:

so now that you have an interest in cyber security what comes next is usually the question of what kind of programming do i need to know so in this video what we're going to cover is the python that i think you need to know as you're entering into a cyber security this is an introductory course into python for the purpose of cyber security i have tried to keep it as streamlined as possible to keep you away from having to watch a six hour course on python for cyber security that is just full of stuff that i think you're not really going to need in the future so this is a beginner course and if you have any questions as you're going through it please leave some questions down in the comments or you want to cover something more in depth please let me know because i don't know exactly what it is that you guys want to know and what you want to learn and so be curious and then let me know so i can try to help you out so i'm regularly seeing videos on youtube that says python for hackers or python for penetration testing and in these videos they don't actually teach you anything so my goal in this course in this video is for you to come out with some understanding of python be able to write your own for loops be able to understand variables lists strings and functions and for you to come out with the ability to write maybe your own recon tool it will take some practice and maybe you're going to have to watch this video several times in order to fully grasp these concepts but my hope is that when you finish this that you will be able to come out with a knowledge of python modify exploits that you find online and maybe even write your own tools all right before we dive into this course i want to take a second and ask you to please subscribe to my channel i have said this before i don't get anything from doing these videos i don't get anything from putting out these courses for you my channel is not big enough and so the one thing that really keeps me encouraged in making these videos is when you guys comment and when you guys subscribe to my channel so please subscribe and with that let's go ahead and jump into the course i decided to go ahead and show you guys how to install pycharm on your linux vm if you have a mac or windows it's really straightforward you just go to the jetbrains you download pycharm i'll have this link in the description and you'll click windows mac or linux and then you'll just hit download and it will automatically start to download unless you're on linux so i have had to do this for several virtual machines that i have had it won't download and so what you have to do is right click the direct link and you'll copy link then you will you will go to your terminal and you'll run a wget wherever you want this file to be saved so if you want its own pycharm folder put it in its own pycharm folder for me it is in my downloads and you can save it wherever you want you'll hit enter this might take a little bit depending on your speed that you your internet speed and then you're going to unzip it wherever you downloaded it with this command right here and then it will unzip a bunch of files will come out and then you will be able to cd in to the folder so for me i will cd into my downloads because that's where it is and then i'll go into pycharm and then i'll ls inside here and i'll go into my bin and then this is the executable i want to launch in order to launch pycharm so i will type in bash and then i will type in pycharm.sh and it will automatically launch pycharm for me so this is how you get pycharm on linux if you are wanting it on your linux i usually write everything on my mac and then if i need to run the code over on linux i will pull it over to my linux machine and run it over here so with that we will get started in the next section all right we are ready to start our python course so we're going to start out very simply with a string a string is a sentence that is a data type so we're going to have several different data types coming up but a string looks very simple it is what i think of as a sentence in english so you just have hello world a string is always going to be stored inside of quotations so if we were to print this it would print right here hello world for us and if we change it it's going to change along with us so this is really simply this is a string and we can store strings inside variables which is going to be coming up in the next section but first before we go on you will see sometimes that you need a string on a new line especially if you're going to export something into a csv file you're going to want things on new lines and at the end of your string you can type something like this and then say hello world number two and then we can print this and we have hello world and hello world number two and if i wanted to get rid of that space i would do it this way so we have hello world and hello world number two another way to go about printing this would be like this so print and then we put our quotations and we say hello and then we can add this like this hello world just like that and now if we were to print it we have hello world hello world number two and then hello world you see how there's no space right here this is something that i run into regularly and i just had happen the other day there's two different ways you can put a space right here and i'm going to show you the easiest way first is just add space right there rerun it and now you have a space but i think it's helpful to know more than one way to do this so you can add another quotation and put a space in there and add another plus sign so you can run it this way and you still have that space and it's really important to know this right here because sometimes you'll be running a for loop and everything is just smashed together and you want to space in there and you can add spaces simply just by doing this so what i'm showing you right now you may be thinking this is not ever going to be helpful and it i wouldn't be showing it to you if this wasn't helpful and it's something you're going to run into in the future so this is a very streamlined course and i'm showing you just what you need to know in the world of cyber security now we're going to be covering something called a variable and a variable holds the place of some kind of data that we're going to want to use later so we'll go ahead and comment this out and on a mac it is command and then question mark and so comment that out so now if we run our program there's no output and we're going to look at a variable so a variable can be something like this name and then the name jim this name is going to hold whatever is right here so this is our variable which is going to represent the name gem so if we come down here and we print and then we type in name and then we run this it's going to print what is stored inside this variable when we look at variables one of the things you're going to want to be able to do especially in the world of cyber security if you ever want to write your own tool is you're going to be saving variables only they're going to be input variables so if we were to go like this and we say name equals input and then we type what is your name and then we'll want a space right here so when we type in the prompt it has a space we'll comment this out and then we'll print name so we're going to print the variable whatever the user inputs here so now we can say what is your name and we can say tom and when we hit enter it prints tom and there's something else that's really cool that i use all the time it's called an f-string and what you do is you add an f at the beginning of your string but you can print variables inside your strings so we'll go ahead and put name inside here and so we can say hello and then the name so we'll say run this what is your name tim and it puts out hello tim so this is an f string this is something you're going to want to know this is something i use all the time and in the next coming of videos we're going to look at data types and how we can pull information out of a specific string and this comes becomes really useful whenever you run a script on a victim machine or on your target machine or your target server you'll you may get a lot of output that you don't really need and this is a good way to start extracting data so we'll start that here in just a moment okay it is time to draw out some information from our string so what we can do here is we can save a variable and we'll call this variable name and we can put inside of our name tommy so we have tommy here and let's say we want to grab just this m right here what we can do with this is we can say print we want to print our name and then we add some square brackets just like this and when you're running python it always starts at zero so it goes zero one two and so that first m is going to be two just like this and so if we run this it's gonna print that in for us and just to show you if we want to print the t we would enter a 0 here and this is one of the most basic ways to draw out information and it's going to get a lot more complex as we go but this is what the square brackets do when you see them and when we start to tackle lists and arrays these square brackets become a really useful tool to remember so as we continue to go through this i want to pause right here and i want you to go ahead and play around in your own text editor and print some make some print statements make them on new lines add in some spaces make some inputs and actually practice gathering information and maybe have two or three inputs and have it print things back and forth and you have a little conversation with your text editor so i want to go ahead and give you this challenge for you to go ahead and play around with the things you've learned so far and try and really ingrain this information into your mind these are the foundations of python programming and you need to know and understand how they work you're going to notice is you can name variables whatever you want and i name my variables really poorly mostly because programs i write i write for myself and i am not working with a team of developers but maybe you will someday and when you name your variables you can name them whatever you want and you'll want to make them names so other people can understand what is going on so if you look at some of the code i've written in past videos i do this right here i name everything like this and it is not really the best way to go about naming these so i'll name one guy one and i'll go guy two and he'll equal bob and then i'll come down here and i'll print uh guy to and then i run this and then i have tim and bob you can you can name variables whatever you want literally you can go whatever i want and you can make this a variable and then you can come down here and you can print whatever you want right there and you can name variables whatever you want so i would recommend getting in a good habit of making your variables something that you can recognize and it's a very bad habit that i have because i make my variables so that people cannot read what i have done so this is something i'm trying to get better at but i probably won't because this is a bad habit that has formed over many years but i want you to have a good habit of naming your variables something that you can understand and other people's can understand so as you go through and work through your challenge try to name your variables different things that you will be able to understand in six months after you have written a program and you need to go back and edit it okay i have created this a little challenge here for you if you want you can go ahead and pause the video and open up your text editor and see if you can create this little program right here so we want to one create an input with a greeting so just say hello what is your favorite food let them put it in and then take another input and say what is your favorite hobby and store that also in a variable and then we're gonna print with an f string their favorite food and their hobby so if you want to give this a go you can go ahead and give it a try if not we will start it now so we're gonna start out with create an input with a greeting so we'll just say print hello and then we're going to take an input but we've got to save it as a variable so we'll save this as food and it's going to equal and input and ins where inside the input we're going to have the question what is your favorite food question mark space i see that we have a typo here on all three and then that's gonna be saved as their food then we're gonna say input and this is going to be we'll just save this as hobby and we're going to take an input and we're going to say what is your favorite hobby question mark space and then we're going to print with an f string all of this together and we'll say print your favorite food is and then if you remember we need our f string here and we should grab our curly braces and say food and your favorite hobby is curly braces hobby now when we run this if we did everything right it should print for us this final statement after we give these inputs so we say run and it says hello what is your favorite food and we'll just say chips what is your favorite hobby running and it says your favorite food is chips and your favorite hobby is running so this is a simple input form and it's going to print out with our variables that we have stored and this is a good practice because when you write a program for a tool maybe that you develop in the future you're gonna want to know how to do inputs so that way you can take the input save it in a variable and then later do something with it so later on in the course i'm going to give you a practical example of taking input and then running it in a program that is really helpful and i will cover that when we are ready for it all right so we have covered the string so far this integer is a whole number so if we say int we have a number of seven floats we're not really going to use these a whole lot in the world of cyber security they have a point within the number so 3.14 would be an example of a float to date i cannot remember a single time i have used a float in cyber security usually that's more towards a data science or something of that nature a boolean is true false you will want to remember boolean we'll cover these a bit in the future when we do our while loops we'll be using the true false so these are some of the different data types and just to get an idea of what these look like if we save a variable and we make it a float and we say like one two three and then we print this it will tell us what we have so we can come down here and we can say print and then we can put type and then we can put in our variable and when we run this it will tell us that we have a float and if we put in an integer it will tell us that we have an integer and then so on and so forth we can do this with an a and then we can also do this with a string and we can hit run and it tells us we have a string sometimes we will do something like this and then we have this saved as a string here and then when we go to add this to something else we can get an error and it's because we have a string and we'll be trying to add together a string and a integer and it won't work so we'll go variable 2 equals 3 and then when we say variable three equals variable one plus variable two we're going to get an error and it's gonna tell us that you can you can't add these together so this is one version of how these matter another version of this is let's say we want to print and we say we have an integer right here and we want to add it to a string and we can go like this and we say 70 what do you think is going to happen it tells us we can't add these together but if we take this and we turn this into an integer what will happen now now it works so this is the difference so this is an integer this is a string unless we declare it to be an integer and you can do the same thing with floats so i'm not going to cover those and then what happens if we do this right here what do you think the output will be and the answer is 70 70. so this is the difference between integers and strings and how they work with numbers and data so if we wanted to we can turn both of these into integers and this is the last example i promise i don't want to bore you with adding these together and then we say enter and we're back to 140. so this is a little bit of strings integers and booleans and we'll kind of skip floats because i don't think we'll really need them but it's worth mentioning so you know they're here and with that we will continue on with our next challenge okay so we have these numbers here number one two three four five saved as num1 and then num2 and then num3 what i want you to do is to write this to your console or write this to your text editor and then i want you to add this variable plus this variable and see what the output is and then i want you to take the second number in num1 so it would be this 2 right here and i want you to add it to the second number in num3 which is this seven so your output should be nine i want to see if you can figure that out and then the third challenge is to take num2 uh and change it change num2 into a float and print the type to the console so that way the console tells us that it is a float so if you'd like to go ahead and pause and give this a try you can do that now or we will go ahead and tackle this right now together so what we are going to do just first is we're just going to print and we're going to say we're going to turn this into an integer and we're going to go and write in num1 and then we'll add this as an integer and then we will say num2 and this needs to be closed off or we are we will get an error and this should print it for us so it tells us here is the total if we add those together and then the second challenge is to add the second number so we'll just take this just a heads up copy and paste and programming is always a bad idea because if i have a bug here i just now copied and pasted it and i have two of them but what we're going to do is we're going to take this and we're going to put in our square brackets and if you remember it says zero one so we're gonna say one and then we're gonna say one i guess i didn't really need this and then we'll print this and our output is nine so now we've grabbed the second numbers and then our third challenge is to change number two into a float so that it prints float so what we want to do here is just say print and then we're going to tell it we want a type and we want to print out the type of num2 and then above that we're going to just type in num2 you can do this two different ways i'm gonna do it this way i'm gonna say num2 equals num2 and we'll just go like this and we'll type float and we'll close this off and now if we print this it tells us it is a float and we will continue on with our python course in the next section okay we are going to do a walkthrough of if alif and else statements so this is the instructions for the the little program i'm gonna write but when i finish this program i'm gonna give you a challenge to do something similar on your own so i'm only going to give one example you're and you're going to need to pay attention and maybe watch this walk through twice and then go on and try the challenge so the first thing we're going to do is if you are under five you are a kid so our if statement is going to first need an input from the user that is going to tell us what is their age so we'll just say we have a variable and we want it to be an integer and integer and we want an input and we're going to ask them what is your age question mark space and we have to have that space otherwise it's really ugly in the terminal and then we're going to start our if statement so we're going to say if a u this person's their input which is their variable is less than the age of 5 then we want it to print that they are a kid so print you are a kid now one thing we want to do is if they hit the age of 5 we'll need an equal sign here otherwise i'll just show you if we say we'll need an else statement so this doesn't error out actually we'll just let it air out we'll say what is your age and they say 5 and we get no output because they this doesn't include five remembering that the computer starts at zero and then it's going to stop at four so if we want to include five in as you're as a kid we'll need that the variable is less than or equal to a five now if we put the five in here it will print for us you are a kid so what we we need to do next is we're going to type in elif because we're going to make an lift statement and we're going to say the variable is less than 15 and the reason we don't have to worry about anything under 5 is because it will catch this if statement and then this whole program we write after this will stop and the computer will actually skip it so we don't need to worry about adding anything else in here and we can say actually if you are less than or equal to 15 then we are going to print you are a big kid and then for the final alif alif we will say the variable and we will say if it is greater than or equal to 21 and that's ugly and we will say print and we're gonna print you are a bigger kid and now we're going to put in an else statement and in our else statement we're going to print anything that's over 21 we're just gonna print you are old so now if we run this and we rerun the program we run it and we say how old are you and we say three we get your kid if we say 13 we get your big kid if we say 18 we see you're a bigger kid and if we say you are 44 we get you are old now because we're going to be using this as a tool for us to be able to write tools and modify tools i'm not going to cover this because i think that it's not really necessary for cyber security but if somebody were to run this and they put in the letter a the letter a it's going to crash our program because the letter a that is not a number it's not an integer so what we'd have to do is we would have to make this so that if they if they put this in and it was an a it would print enter a number and then rerun but we're not going to do that because it's not really necessary for cyber security it's just something to be aware about now what's coming up is your challenge let me delete all this and i will write up your challenge for you in the next section your challenge here is to take the temperature from the user and then tell them if it is less than 20 degrees you need boots and this is from the us so i'm running in fahrenheit not celsius and if it's less than 30 you will need a coat if it's less than 70 you will need a jacket if it's over 70 it is nice outside so take this input or take this information and make a program with if elif and else statements okay so here is how i would go about doing this i would take an input and it will say what is the temp outside and this is this will need to be an integer because we're going to be comparing this as a number so we'll say if var is less than 20 then we're going to print you need boots and we'll say l if bar is less than 30. print you need a coat and then we're going to use one more alif here l if var is less than 70 print you need a jacket and then finally we'll do else and it's above 70 then it's nice out and we don't actually need to put anything in there because this is an else statement so everything that's above 70 will automatically print it is nice outside so when we run this if we put 12 we need boots if it's 22 we need a coat and if it is 65 we need a jacket and if it's 85 in my opinion it's perfect outside so this is the if and elif and the else statements we're going to be moving into for loops and later we're going to look at nested if statements and they'll look something like this if it's less than 20 and then we can say if it is if var is less than we'll say it's actually it's greater than 25 and then we can print you need boots and then we'll print something like gloves so nested if statements look something like this and you can have nested if statements just so you're aware of it so if we say it's 26 it it will oh because we're hitting this one we'll hit we'll say this is 15. so if we say that the temperature is 16 we hit you need gloves and you will need boots so this is a nested if statement uh we'll cover these a little more in the future i don't know how much you will need these nested if statements i use them every now and then so it's nice to know that you can run nested if statements but for now we're going to move on to our for loops before we get into for loops too far i want to show you why for loops are important and i also want to show you why lists are important which we're going to be going over here in just a minute after we get the basic understanding of a for loop so this is a program i've shown it before it don't worry about what it looks like it looks kind of complicated but it's really not what happens is you put in a repo that you would like to target on github to go and search for all of the usernames passwords and files that just shouldn't be made to the public so in this case it's looking for pass for passwords on github but what we have done here is a for loop so this for loop right here we have an empty list which we're going to cover in a second and it goes out to github right here and it will go through all these links everything you can click on and it's going to narrow it all the way down to the repositories and it will click this link and then it will click to it'll click the file and then we'll click the raw then it copies this entire thing and it puts it into a text it puts it into a csv file and then checks for the word password so that's the program itself but what's important to remember is what happens is it goes out and it pulls all the links and puts them in a list then it goes through this for loop and it puts takes all of these and it says for every one of these items that is inside of the links which is actually this variable that i have up top it's going to do something so for loops are very important you can see i have another one right here so for loops we are going to need them lists you are going to need them as well and i just wanted to show you this because sometimes what happens is you'll be going through trying to learn something and i'm showing you something very elementary and you are like why why do i need to know a program that tells me to put on a jacket this is all building up to something that is going to be able to help you build tools and more specifically if you're new just be able to read through exploits and be able to edit them because you're going to need to know how to read python and edit exploits as you grow in the world of cyber security so here is a very basic for loop and i'm going to show you it in a string because we've already covered strings and what this all this does is we have our variable string right here that is holding hello world and so the way the for loop works is it says for i in string so this i right here is going to be another variable that holds one letter each time the for loop runs this i is going to represent one letter and in a list it's going to represent each item in the list so this will run i'm going to run it so you can see what this looks like the way it runs is it goes for i in string so it's going to grab the first letter which is going to be the h and then it prints it but the for loop is not over so it runs the loop again and it'll grab the e and it'll print just the e on a new line and then it goes through and it runs every single time until it is out of things to run and then it closes the loop so this is how for loops work i'd like for you to go ahead and write out your own for loop and maybe put something different in here and try to get an understanding of how it works and if we wanted this to print all of this together you would have to store this into a new variable and then print it outside the for loop down here like this and this is where we would print our new variable and we're going to cover this in list because this is something that you will need to do in the future so go ahead play around with the for loop right one get an understanding of how it works if this doesn't make sense rewatch it and hopefully it makes sense i know after teaching for loops to several different students that for loops sometimes can be hard to understand but they are really useful and something you need to learn so we're going to be covering lists in the next section we're going to be looking at lists and a list is something that is going to be useful because we're going to be appending two lists all the time within our for loops so a list can look like this my list equals square bracket and lists always go inside of square brackets and we can say item 1 and then comma item two and then we can do and item three so we have our list here and if we want to run a for loop through this list we will say for i in my list print i and now if we run this it will run item 1 item 2 item 3. so this is a list we will be using these in the coming lessons and they will be helpful for you in the future as you've seen in this program i have two lists right here and they are used regularly to append to so lis is something you will need to know so go ahead make your own list and see if you can loop through your list and maybe try and just print something like this later just print the item to so you'll have item one two three and then print number two and see if you can remember how to do that if you have forgotten it would look something like this print and then we can say my list and then we can put this in square brackets and we'd say zero one and then we have a one and now we could print this and we have one two three two so that is gonna be it for the list we're gonna move on and we're gonna start using this in a more comprehensive manner so we're going to try a while loop now and the way we're gonna do a while loop is by using a boolean i like to set a variable and then set it to true and then at the end of the while loop i will set it to false so the way this works is make a variable and we'll just say variable actually we'll name it on that's a good way to name the variable and we'll say on equals true and then we'll say while on and we'll make a variable and we'll just call it variable because i don't know what to name it and we will take an input and we will say continue running while loop and then we will put y we'll put a y or a no so d would you like the while loop to continue yes or no and then we can say that we can go do something like this and then we can set a variable up here and say i equals zero just so you can see how many times this is running and then we'll say i plus equals one and then this should just continue to run and then we'll put an if statement say if the variable equals equals in then we'll say that on equals false and this will kill our for loop so now if we run this it'll say would you continue continue running the while loop and we will say yes yes yes and then when we say no it'll kill the while loop i forgot to print i forgot to print our i so that we could see this so now we can say would you like to continue yes yes and you can see our variable every time the i the for loop runs our i gets added to one so our for loop has run now it says seven times eight times nine ten and then when we're done we can say no and we can end it okay we are going to be starting functions and just to be clear i have not pre-written any of the code we are about to go over or mostly anything we've gone through in this course that's why you've seen me make mistakes and so as we start functions i'm going to try and make this a little more realistic for us so that when we are [Music] thinking through functions and writing code in the realm of cyber in the realm of cyber security you can start to get an idea of how this can be used so we're going to start with functions and a function just calls something very specific that we want to happen so we can just say we'll call it my function and then the way your function is going to start is with a def my function and then we close it off like this and then down here we want our function to do something very specific so we can say print and then we can say it worked and the way a function gets called is usually somewhere further down inside the code something happens and it triggers this function back up above it for it to actually do something so what would happen in order to call this is we would just say my function now when we run this when the computer reaches this right here this closing bracket right here i usually like to think of this as the call sign for the function so if we run this it's going to print it worked and this will become more clear as we write more of these but this is the basic concept of functions and one thing we can do with functions is we can pass through variables so we can say something along the lines of i and then we can say i or we'll make it a different variable we'll say variable equals i plus three and then we can say print and then we can say we want to print our variable and so in our function we can pass information through like this so when we say my function we can now say input and then we can say what would you like to add and because this is a string we're going to need to make this into an integer i guess we can go and make it an integer right here and we can say int and then we can close this off now when we run this it's going to ask us what would we like to add and we can say 3 enter and it will say 3 plus 3 equals 6. so this is a very basic function so we take some kind of input right here this is where we call our function so now this function is being triggered but we want to pass something into our function some kind of variable or some kind of information that we've grabbed somewhere else and what happens is it can now use this inside the function this you may be thinking like in what case would i possibly ever need to use this and so i'm going to just show you my github dumpster diving tool once again that i've used multiple times on this channel this right here where it's grabbed a repo i call this function and it's going to loop through to see every single file inside of the repo is it a python file is it a javascript file is it an xml file and what happens is when i pass this repo through it now is able to use this variable that has come from somewhere else inside this function and then i do the same thing up here i pass through a variable inside of a function so this is really important to know and you will use it and we're going to go ahead and give another example and actually before we give another example i want you to try and write your own function and see if you can get it to take an input so let's take the input and make it the first letter of your name so i'll write out the instructions you want the we'll say first letter of your name and you want to take this as an input so we'll say input and then you want to call a function that adds your first letter to the rest of your name so here's your instructions you're going to make a function and then you're it's going to take a variable and that variable is going to be the first letter of your name and then you're going to add that to the rest of your name so i hope this makes sense and i'll go ahead and walk you through what this would look like so we'll go def my function and then we're going to call this function we're going to pass through let's use i as our variable so that stops giving us whenever this is giving us an error and i can't stand looking at it i type in pass and that will not give us the error and we'll come back and delete that in a second and we're gonna call my function and we're gonna take another input and we're going to say what is the first letter of your name question mark now we can delete this and we're going to come back up here and we're going to use this and we're going to say that my function and we're going to take this input and it's going to be it passed through as i and so down here we're just going to say my first name is ryan so we will say i will call the variable equals i plus and then we can put the rest of this inside of a string and we can say something like this and then we can print our variable so when we run this if i put an r in here it'll print out my name so i hope you're able to figure this out maybe try to come up with another way to write a function and practice writing functions and see if you can get the hang of it and in the next section i'm we're gonna go over something that will show you how this can be really helpful in building your own tool okay i hope you have played around with functions and you are now ready to try and become a little more advanced and we're going to try and gear it towards cyber security now and i hope you're familiar with maybe the nmap scan and some other tools so we'll just use an nmap scan right now and we'll just say like we're going to call function and we'll call it in map and this is going to take a variable and we'll actually call it the ip because we're going to take an ip address and the way i like to run my nmap scans is with the they'll look something like this in map dash a like this and then we're gonna pass in the ip address and then i like it to be verbose now in order to get this to run we would have to import a module called os but we're not ready for that so this is just to show you how the functions will work and so i will wrap this entire thing inside of curly braces um i got dashes in here that shouldn't be there i don't know why i did that and then we'll wrap this inside curly braces this is not supposed to be inside curly braces that is supposed to be inside of quotes and we'll make this an f string and we'll say our variable equals instead this would be an os command if we were actually going to run this in our linux machine or windows whatever you choose to use as your hacking vm and now what we'd do is we'd come down here and we would say um something like nmap to call our function and then we're going to take an input and we're going to say what ip would you like to scan and then right here we are going to print running in map scan against and then we will put in the ip address and this will need to be an f string so the way this or sorry that will not be the ip that will be against the variable so it will tell us that it is running the nmap scan right here okay so when we run this we can say what's who would we like to scan against and we'd say 192.168 point something point something else then we run this it'll print running in map scan against and then it gives us the output right here so this would be a way that if you were trying to write your own tool to automate your recon this would be one of those ways you would use a function in order to automate your recon and there's a lot more you can do with this ip address and you could pass it into multiple different tools and then you have written your own tool so this is how we can use functions in cyber security that are really helpful for us and whenever you're going for a certification it'll be really helpful for you to be able to read through functions and maybe modify them especially in exploits because vulnerabilities and exploits change over time and you will need to be able to change and modify different ex different exploits that you come across on google in order to gain access to a machine before we end this course i want to give you a little bit of an introduction into making your own tools and then i want to challenge you to add to this recon tool that i'm about to show you and you can start to build your own tool for [Music] recon and it'll help you remember the python code that we've gone over so far in this course so i've gone ahead and connected it to hack the box and launched the box devel and so i want to just show you what os system does so we'll import os system you've seen this before and this is just our operating system it just means we're going to be able to tell our linux machine to carry out commands the exact same way you would inside of a terminal so we're going to make a function and we're going to call it recon and we're going to pass through an ip address really if you remember this is just a variable that we're going to be passing through into the function and then we're going to call our function down here and we'll just call it recon and then we're going to ask for an input and then we're going to say what i p would you like to scan and then we'll put a question mark and a space there so that way it's not all smashed together and now inside of here what we can do to make this program run our recon and automate it for us is we can type os system and then we can put in here we're gonna make this an f string what we want to do so we're gonna run an in-map scan and we're gonna run it on all port or we're going to want all outputs we're going to run it on all ports and just in case it is blocking the ping we'll put the p and you don't have to put this in here it's optional and then we are going to put in the ip address that we run through and i really like to run everything as verbose so this when we run this you'll be able to see it'll say what ip would you like to scan and i'll put in the ip address and it will now start the scan for us so this is what the same thing we would see inside the terminal we're going to see port 80 421 is open and at the end of the scan it will tell us everything that has happened on this scan now you can add to this we'll stop this you can add to this same scan when it gets done running the nmap scan you can come down here and maybe you want to look for different directories and so you could go os dot system and we're going to make an f string and we can add in maybe we want it to run durb and we want it to run on the same ip address that we've already passed in and it will now launch this right here as soon as it gets done with nmap and the cool thing about this is if you have your own recon tool set up you can go ahead and run the program send over the ip address and then you can leave and it will automatically run your recon or maybe while your recon tool is running you can do other more manual enumeration maybe it has port 80 open and you see that real quick with the nmap scan and you want to start looking at what's on port 80 and it will run your in-map scan it will run your door buster for you and maybe you want to run w fuzz or maybe you want to run a sub-lister i want you to go ahead and start off with what i have given you right here and you can add to this tool with the information that you have learned so far