Hello and welcome back to a brand new section in Dark Web and cybersecurity
course. In this section we will talk about dark web automation,
which is based on Python.
So on the first video we will start a fast introduction about, uh,
Python. Uh, keep in mind, uh, this course doesn't focus on Python,
so you will learn Python a bit faster. Uh,
it's better if you have the knowledge of Python before,
but I will explain the, uh,
the useful stuff and the beginner stuff in Python as like a fast
walkthrough.
It's not enough to just learn, uh, learn this, uh,
in Python. Uh, you should have more knowledge about it.
But as a beginner level and a fast walkthrough, it's uh,
it's good to have these knowledge and maybe you can practice, uh,
and get some knowledge for those who don't know Python.
So let's start in introduction in Python. So what is Python?
Python is a commonly used general purpose, high level programming language.
It was founded by WeDo Roso in 1991 and then further
developed by Python Software Foundation.
This is designed with a focus on code readability as well as is syntax
allows programmers to demonstrate their ideas and lesson lines of code.
And Python has a programming language that helps you to work quickly and
integrate system more effective. So why we need Python?
Cause Python can create literally anything.
Like you can use it in AI machine learning,
you can use it in cybersecurity business, digital marketing,
uh, like create apps, creating games.
It can be used nearly in anything and especially automation.
And this is what our main concern in this course,
which is automation for the purpose of dark web investigation.
So we can like create hacking tools, automated system administration.
It can be used to also create web apps and it can be linked to databases
and can be used in data science like AI and machine learning as we said before.
And what's nice about uh, Python,
it's a high level programming language and it's designed
to do many tasks.
And Python is an interpreter language.
So basically it uh, runs line by line.
It's not like c plus plus or Java or these kind of languages. So,
uh,
basically Python is based on C and so everything what we write and Python
is being converted to c and C.
He handles the execution on the lower level of the computer
into binaries. So features of Python, easy to code,
it's like writing English words cross platform mainly on all
platforms available nowadays. Free and open source,
integrated and interpreted language as we said. And it's a high level language.
Python versus other languages. Python is easy and beginner friendly,
mostly used by junior developers.
And Java and other languages is harder for beginners.
Basically we, when when you learn Python,
you can learn it fast like in one or two hours.
If you have like a basic, uh,
programming knowledge or if you even don't have programming knowledge,
this is Python let you ease.
It can let you finish your task.
Even if you don't know a lot of programming knowledge,
unlike c plus plus and Java,
where you need to have lots of knowledge about it and it,
it's harder to uh, write uh, using these kind of languages.
So Python is the most beginner friendly and at the end it can do the task that
we want and that's what's important. So what is a variable?
The first thing we need to begin in any language is to understand
variable, especially for those who don't know. So variable is for storing data.
Data can be taxed on numbers and you must assign an operator for the
variable like the equals operator.
But we will discuss operator after the variable section cause there's a lot of
kinda, uh, operators.
So basically a variable can be a name, can be anything. It just a,
a place to store a data and use it later. For example,
like you want to say,
you want to create a variable called port and this port equals 80,
let's say, which is the http.
So what are the types of the variable we haver flow stringless topal
dictionary Integer is uh, is a number.
Float is a decimal number and string,
basically it's any word you can put words, uh,
it can be a single letter also. Uh,
it's literally everything in between double quotation or single
quotation. That would be called a string. A list example,
we have services equal
sub http, ssh and ftp.
So that's the syntax of creating a list. So basically we have a variable,
it's equal to a sub and each sub it's have its own uh, value.
And it's the same thing with, but it's,
and double parentheses instead of subs.
We'll discuss more about these later in the future slides.
And uh, finally we have the dictionary. Uh,
an example for it at services equal TTP A T SSH 23,
SMB 4 45. And here it's uh, currently bracelets.
So also we will discuss this uh, later in the future slide.
But these are the main types of variables that we mostly we will use.
So variable name can be start with a character or underscore and checking type
of variable using a method called type. For example,
we have FTP equal 21.
So we created a variable called FTP and it's equal to 21.
So that's a variable of type integer.
But if you would like to check the type of this variable simply you can use
type which is a method bypassing the variable name within the method,
like this type ftp.
So when you write this on Python, you call a function,
it's a built-in function.
So basically you write type and in between you pass through the variable that
you created before and it'll output that it's an integer
basically. So this uh, function,
it's useful for sometimes that you don't know what kind of variable is this
cause late it might get complex. So, uh, using this function is very useful.
Legal variables and illegal variables.
As you know when writing uh, or when creating a variable,
there's certain errors we might face.
There's a correct way to create a variable.
So the legal variables or the accepted variables must start with character or
underscore lowercase or uppercase. As a basic example,
as I said before, HTP equal 80.
So I created a random variable,
it's called http and I assign it 80.
It's equal to 80 illegal variables. It start with a number.
It has underscore between words like SSH, dash,
htp, equal error. So anything would uh, underscore it won't work.
It'll give you error.
Operators use to perform actions on variable using plus
operators to add together to values. And there's multiple types of operators.
We have arithmetic operators, assignment operators, comparison,
logical identity membership. But wise there's a lot of operators.
But in this course,
mostly we'll focus on the TIC comparison and the the logical
cause. Uh, that's the most ones that we will use.
Strings.
A sequence of characters starts and end with double quotes or single quotes.
Most data types used in Python as the most data type ever used
in Python. An example port 22, it's equal to ssh.
So as you can see it's a variable equal double quotes ssh,
which means this variable is a string advantages,
it's used to concatenate strings with variable or text.
So basically combining uh,
two variables with each other or just uh,
the strings writing code becomes easier.
Saves a text message in a variable like ftp,
equal FTP server accessing a specific values. This is really useful.
You will use things always three ways to create a string. A single quote,
example port 22 SSH double quote,
example port 22 ssh.
So the difference here is just single quote on double quotes, but at the,
it's the same. Nothing can change. You can use either this or that.
Triple quotes,
this is useful for to write a paragraph or to create a menu for a tool.
As you can see like in hacking tools or any tool that you see on
GitHub,
you see like those big menus and stuff that you can click here or click there.
So basically they use uh,
these kind of stuff which is the triple quotes.
And we have also multiline strings start with triple quotation and ends with a
triple quotation. And you can insert a big chunk of uh words.
An example. So you have a menu. I created a variable called menu.
And you have welcome to my tool. If you press one, it's support scanner two,
vulnerability scanner three, it's exit. Okay.
And as you can see we have at first three double quotations and the end three
double quotations. And at the end we print it.
So to output a certain string or anything you want to output,
basically you just use a function called print.
So print menu concatenations putting
two or more strings together like hack plus me,
this will output hack me.
So as you can see we have two strings but we concatenate it with a
plus. So this will output hacking.
Concatenation can be done only with strings. An example usage.
So we have a variable called IP address and
IP address or IP ad. It's taking an input.
Please enter an IP address and to do an input and to
talk with the user, you just use a uh,
function called input. So basically whatever it's input,
the data would be saved on IP ads. And we have port one with the sa,
same logic bus.
But here you will enter a port number and at the end I need to print
what the user has input.
So print scanning plus IP ad plus on
plus port.
So scanning is in double quotations cause it's not a variable plus IP
ad.
There's no double quotations here cause it's not a string but it's a variable of
a string.
So plus IP add plus on cause it's on is not a variable plus
port. So when you have a variable or you need to print a variable,
you don't put it in double quotations or single quotations.
So Python will output from this example scanning uh,
29.1 0.9 9.999 port
2019. Therefore we successfully concatenate strings with variables.
Accessing an item in a string.
Accessing a string is through is by indexing.
Assuming we have a variable course equal python programming,
an example usage would be course zero, course one.
This will output P, this will output Y.
What can we understand from in programming you must count from zero
and not from one. So Python P is zero,
Y is one, T is two and so on,
even the space between N and P, you must count it.
And programming word is not like the real word that we count in.
So course zero will output P and course one will output Y.
The logic is the same with anything in programming.
Literally you count from zero and it'll output the exact first thing.
Zero is P,
one is Y formatting a string formatting is a changing the format
of tax of how we will output it on the screen and it can be achieved using a
method called format. So format is a built-in function.
We use it to change the format of the text to make it more uh,
better on the out. So an example usage. So we have a IP address,
a variable of string and I must print it but I don't want to
concatenate it in a weird way like we saw in the previous slides.
So I did put scanning IP address and curly bracelet
where it should be put.
So basically inside this curly bracelet we will have the IP address.
So to achieve this, you just put the curly bracelets here,
which is the position of the variable that you will put in.
So in order to achieve this, when you close the double quotes,
you just type dot for IP address.
So directly the IP address. So it would be here.
So at the end it'll output scanning IP address
25 0 2 19 77.
And every time if you want like to add more curly bracelets on the same line,
keep in mind the first variable you put,
it'll be given to the first curly bracelet. And so on conditions,
conditions are statement made by the program is that determines the behavior of
the program and evaluates whether they are true or false.
This could be used to build pathways in a program that allows for consistency
and a better assessment method and conditions is needed in programming,
each condition will be shown in the exercise. So an example, uh,
chart here you have if and inside this earth there's a condition.
So if a equal true, then B, L C. And if, okay,
so this is an example chart of how conditions are.
So if a is true then we will execute B.
But if A is false it'll execute C. Okay,
I will show you how this is done in example.
But we have multiple types of conditions.
We have if else Eli or else if
and or nested if based statement.
This is the types of condition that you will use all the time.
So an example.
So there's a variable port equal 88. Okay?
So this is an integer variable we have another variable
is open equal port and
22 84, 4 3 common open ports. By the way,
everything in hashtag it's a comment vulnerability, it's a string variable.
Heart bleed is exploitable vulnerability equal
heart bleed or vulnerability equal equal sha shock.
So is exploitable equal vulnerability equal,
equal heart bleed or vulnerability equal equal sha shock.
So here we're saying if it's equal, equal that or equal equal that.
And here we'll create a condition. So as exploitable contain all of this.
So if statement, an example of if,
if is open print port is open.
So basically it's true cause we already said it is open and all
of this are open. If else statement, if it's open print,
port is open, else print is closed.
So if it's not open else it'll execute. It's closed.
If else, if else statement we have, if is open, port is open,
else if is exploitable port is closed but there is a vulnerability else
ports port is closed and not vulnerable.
So if the condition is false else,
if if the condition is false then else it will execute that.
And operator if is open and is exploitable,
if both are true,
then it'll print port is open and exploit or operator
if is open or is exploitable. If that is true,
then port is either open or exploitable, you see. So basically at first,
if it's the thing is true then it'll do that. If it's not, it'll do the that.
So nested if statement, nested if statement, basically it's an if inside, an if.
Okay,
basically nested the meaning of it is something inside something.
So nested if statement if is open and if it's exploitable,
if both is if if this is open,
if it's true and if is exploitable is true,
it'll print port is open and exploitable. But if it is open,
true and if exploitable is not true then it'll go to the else.
Okay? But if it's open is true and if exploitable is not,
it'll print port is closed. Okay, so that's it.
Pass a statement basically means don't do anything.
So if is open pass, don't do anything,
no actions needed as it'll print port is closed if the condition
is false, not true tops.
Tops are used to store multiple values in one variable.
So basically topple is kind of the same logic as list,
but as we said it's in double parenthesis, sorry,
topples are fixed and so it can be changed.
Topples are common separated and then the uses of the parenthesis is optional.
Topples elements can be duplicated.
You can access the elements in topple through indexing as I showed you before
with strings and how to access a string. Same logic with tap. So tap
AEI, o u 0, 1, 2, 3, 4, you see. So tap zero,
it'll print a one, it'll and so on so forth.
You need to count from zero in order to find an index from the number of the
element inside of top.
Use index function Index in order to delete a top used deal
followed by the top name to delete at the entire topple.
An important note about tops values cannot be changed.
It's not like list a reference between and list besides of
the presentation of either subs or parentheses
or bracelets.
The main difference between tops and list that list values can be
changed but tops cannot, cannot be changed. List. As we said,
it's mainly like topple,
but here you can change the values and also you must count
from zero dictionary.
And Python is a unsorted set of sub data values used to store data
values written in currently brackets.
Each element is accessed by any key dictionary.
RN sequence provide fast lockup and dictionary can be useful a lot
such as filter dictionary, search by keys.
So basically the logic of dictionary is key and values.
So we have the key HTP and it has a value 80,
another ftp, it's a key but it's value is 21.
So each key has its own value and uh,
key is a unique also.
So here are an example list ports
22 84, 4, 3, 3, 3, 8, 9 accessing list elements
first port.
So if I need to print the first value of the list,
which is 22,
so basically 22 is index of zero.
So first ports subzero ports zero.
So basically I did print first port double quotations,
then I concatenated with with this and I call the
variable ports sub zero and that's how will I get
22. Same thing with the second port,
but you should add the index one, not zero.
So it'll be 80 modifying list values support one it's
equal 80, 80. Now print modified port ports,
it'll print all of this but here it'll be 80, 80 topple vulnerabilities,
heart bleed, shell shock, spector accessing topple elements.
Same thing with the list. Nothing change.
But what cannot we can do is basically we can change
the value of tops dictionary host one,
IP host two, IP host three and the ip.
So let's say I need the value of the second key.
So basically uh, I say host,
host two and then it'll print IP address of host two is that.
And you can modify the dictionary values basically host host three for example
and change this IP address into 2.02 cause basically it's the same but
I'm changing one digit of it. And print modified host,
host it will print all of it with the modified value of the
third key loops.
Loops are an session concept and programming as they allow us to execute a
block of code repeatedly.
They are used to when we want to perform a certain action multiple times
or iterate over a collection of items such as a list or a dictionary.
Loops provide efficiency,
flexibility and the ability to automate repetitive task.
Generally we use two kind of loops for loop and the
Y loop for loop iterates over a sequence and while loop iterates
it repeatedly execute a block of code as long as a specified condition is true.
By utilizing loops, programs can make their code more efficient,
concise and maintainable. They plan a vital role in automating process,
iterating over collection and implementing dynamic behavior and various
programming tasks including cybersecurity related operations.
In this course we will focus on four loop and y loop and now we will see an
example of that for loop.
So we have a variable vulnerabilities contains all, all of that.
So to iterate over a list of vulnerabilities using a loop,
basically four in vulnerabilities.
So I created vulnerabilities basically this,
as you can see this variable doesn't exist but we have vulnerabilities even you
can literally say anything you can say for x and vulnerabilities for Y and
vulnerabilities for your name and your vulnerabilities.
It doesn't matter as long you are putting in.
So basically for vulnerabilities and vulnerabilities.
So basically you're telling Python for this and that,
taking it in English words. Okay,
so print scanning for vulnerability vulnerabilities.
So here you might ask why there's enough,
if you remember the dot format,
it's the same concept but different usage.
So you put F at the beginning before double quotations and
currently brackets here where you want to put it,
it doesn't matter and the name of the variable. Okay,
so the different here between this and the dot format.
In dot format you don't say you don't put the variable name inside
the double quotations you don't.
This is only the case of when you use this kind of format,
which is the F before the double quotation.
So let's say it was four x and vulnerabilities and you need to use the
same format here.
So you say scanning for curly brackets X instead of vulnerability and so on.
So now after uh, executing this,
so each time it iterates over vulnerabilities it'll print scanning for hard
bleeds, scanning for shell shocks, scanning for specter vulnerability.
So basically you are iterating over a list while loop.
So I created a condition called count and count is equal.
One attempting to crack password using a while loop for example,
while count is less than or equal five.
And remember the difference between Y and four four is iterating.
Y is based on conditions.
So while count is less than or equal five first S
count is less than or equal five. Yes it is.
So it's true as one is less than or equal five
prints attempting to attempting password count.
Okay,
so here it'll print each attempt at doing attempt
1, 2, 3 until it's reach five and it'll be terminated.
But if it was 10 it'll continue to 10. If it was hundred it'll continue to 100.
It depends on your condition that you will put.
But if it was count equals seven and you did less than or equal five,
then it won't work Count plus equal one cause
it'll add each time cause
it'll uh,
in order to terminate this count also count plus equal one one
each reach five nested loop ports equal
2 84, 4 3 we have this list and we have this list
also one is based on integers, the other is based on strings
checking open ports on multiple hosts using nested loop four host and host
four port and ports.
As you can see host and port doesn't exist Python by default.
We can create with Python a variable that doesn't exist.
And this is so famous when you do four loops and these kind of stuff.
So for host and host nested for port and ports.
So we are saying if host and the host and nested,
I mean nested port in ports scanning host,
host on port port.
So basically it'll print scanning this host on this port and so on,
so on and so on. Functions.
Functions are integral part of coding as they allow you to break down complex
problems into smaller manageable pieces of code.
A function is a block of organized reusable code that performs a specific task.
It help us improve code organization. Modularity,
reusability and maintainability functions are fundamental.
Building block and programming. They allow you to encapsulate logic,
promote code, reuse, and improve code, organization and readability.
By leveraging functions effectively, you can create more maintainable, scalable,
and efficient code. An example of functions,
first function is to check if a port is open. So death is port,
open port as you can see I create a function with a keyword
called death. Death is port open
and I open parenthesis always a function will have parenthesis,
but it doesn't matter. It might not have port,
it might have nothing and it might have uh, multiple values or variable names.
I mean.
So if port in 20 84, 43 return through as
return, false function,
call port status equal is port,
port open 22 print is port 22,
open port status and here it'll print through.
Cause already we said if port in these,
it'll return through as it'll return false. If not,
none of that it'll return false. So after run this,
it'll return through second function to perform or
vulnerability scan D,
vulnerability scan host vulnerability is equal. Heart bleed,
cell shock spectrum.
It's a list of vulnerabilities for vulnerability and vulnerability scanning.
Host for vulnerability. Vulnerability what the format. So vulnerability scan,
uh, we passed a string which represent the variable host.
So this is a passing through and now this
1 9 2 1 6 8 0 0.1 is now in host and now you
can use it inside this function.
So here it'll be for vulnerability and vulnerability scanning.
This host which is this, well what we,
we pass it here and it would be scanning for that host with
hardware shock inspector and so on. Finally,
we have function to calculate the risk score. D,
calculate risk score and it takes a vulnerability and it takes the variable
called vulnerabilities, risk score equal land. Now you'll ask me what is land?
Land means length and it'll output the length of vulnerabilities.
So lan,
it's a function that will output the length of a list or
something. So LAN and we pass through the vulnerabilities,
the variable times five, return this score.
So here I created a variable called the risk score Equal calculate risk score
vulnerabilities found. So calculate risk score the function.
And I passed through the list that I have, which is heart bleed, spectrum,
meltdown and print risk score. Risk score, basically that's it.
Obviously all of this, uh, just an example,
it's not a real scan or a real way to do this kind of stuff.
It's just a simple, uh,
logic of how to use these kind of functions or the syntax and python
just to get familiar in this kind of stuff in order to use it in a real life of
operation that we will use in your daily life as a cyber analyst,
cyber consultant, and especially in this course when it comes to dark web.
Lastly, we have models. Model is a library contains functions.
Model is a useful to be used in your code model is simply a
python file with an extension pi,
a basic usage of uh, models. Basically
import and model name, for example,
import UN map or input OS or input request
and accessing a specific model function example OS system.
You can open CMD to install a model or shell
you open and type PIP install. And the name of the library,
which is in this case, uh, there's an,
I gave an example about unap PIP install unap. And as we can see in this figure,
the example is to installing unap model, collecting, downloading,
and now it's ready to be used. Thank you for watching this video.
I hope it was useful.
I know it's not the full course of Python or uh,
it's not the full walkthrough, but what I gave you,
it's more than enough to get start or understand at least the next videos.
But I highly suggest for you is to exercise some python,
get to know more Python.
Cause the example in the next videos are a bit advanced,
but just follow along and you'll enjoy it.
So I will see you in the next video where we'll discuss onion links automation
using Python, which will be the first dark web automation and discourse.
See you on the next video.