IDEs will also allow you to use integration with version control libraries that you can source from third parties, which means that you can pull up codes that are created by others and then mix and match them with your own code to get the results that you want. You can get your preferred IDE from a third-party source, such as educational sites for programming languages, or from the developers of the language themselves.
The IDLE tool that comes with your installation package serves as a platform where you can efficiently key in your codes and interact with Python. You can easily pull up IDLE by clicking on its icon on your desktop, the Start Menu or locating it on the install folder.
IDLE allows you to use these features: The Python shell window which allows you to make use of color-coded code input and output and get error messages if you input a wrong statement. A debugger that comes with stepping, local and global namespace viewing, and persistent breakpoints Browsers and configuration A text editor that allows you to use multiple windows, colorizing for Python, auto- completion, undo, and other features Using IDLE will allow you to use two windows the Shell and the Editor which you can use simultaneously.
You can also have output windows that have a different context menu and title. The menus that you can use in IDLE will change depending on the window that you have selected. The options that belong to each menu are straightforward, which means that you will not have a hard time understanding what each of them do even if you are new to programming.
Here are the menus and the window that they are associated with. File for Editor and Shell windows This menu contains the following options: 1. New 2. Open 3. Recent Files 4. Class Browser 6. Path Browser 7. Save 8. Save As 9. Save Copy As Print Window Close Exit Edit for Editor and Shell This menu contains the following options: 1.
Undo 2. Redo 3. Cut 4. Copy 5. Paste 6. Select All 7. Find 8. Find Again 9. Find Selection Find in Files Replace Go to Line Show Completions Expand Word Show Call Tip Indent Region 2. Comment Out Region 4.
Uncomment Region 5. Tabify Region 6. Untabify Region 7. Toggle Tabs 8. New Indent Width 9. Format Paragraph Strip Trailing Whitespace Run Editor window 1. Python Shell 2. Check Module 3. Debugger 3. Stack Viewer 4. Configure IDLE 2. Code Context available only in Editor Windows 1. Zoom Height Help 1. IDLE Help 3. Python Docs 4. There is no real guideline in choosing where you should type out and save your codes — as long as the editor that you are using helps you code comfortably and comes with syntax highlighting which will help you visualize your code, then you will be able to achieve your hacking goals and create the code that you want to use in the future.
Here are other editors and their features that you might want to check out: PyCharm Educational Edition If you want to focus on learning Python instead of concentrating on how you should be navigating your windows, then this is the editor for you. You can pull up existing codes in the editor to learn how certain programs are written, or learn using the tutorial that comes with it. You can download this free editor from www. Sublime Text Sublime Text allows you to use a package manager, which essentially works for any person that is used to typing in word processors.
It also comes with features such as code folding, which hides lines of codes that you are not working on. Take note that this is not a free software, but it does come with a trial period that does not have a time limit. VIM This free software will allow you to do lots of customizing, which is great if you are an experienced programmer that wants to work using settings that you are most comfortable with.
Another plus factor to this software is that it has an extended history of usage, which means that you have a community of users that you can easily tap when you need some help. If you are new to programming, this might feel like a daunting text editor to use, but the steep learning curve will pay off in the end. By learning how to code through hacking right away, you will be able to get a good grasp of Python as you experience it using different tools that were already made by other hackers.
If you are gunning to develop a web app for your hacks, then this is probably the IDE that will work best for you. Chapter 2: Python Basics Your goal, of course, is to make Python go beyond printing a text. To do that, you will need to learn other concepts that are essential in a Python script. You will also want to create a script that is easy for you to understand and review in the future, just in any case you want to improve it and turn it into a working tool for your hacks. In order to take inputs and manipulate them in order to get certain results, you will first need to learn how variables and constants work in this programming language.
Comments These are statements that come after the symbol. These pieces of texts allow you to: Explain the problems that you are aiming to overcome or solve in your program Take note of the important assumptions, details, and decisions that you want to perform in the code Making notes in your code does not only remind you what you want to achieve in your code, but also help readers that will be using your program understand what lines of code are supposed to do.
Literal Constants Literal constants are named as such because you take these pieces of text for their literal value. These constants can be: Numbers They can be integers plain whole numbers or floats numbers that have decimal points Strings These are sequences of characters, which you can specify using single quote, double quotes, or triple quotes.
Take note that single and double quotes function similarly in Python, and that you can express them freely inside triple quotes. Here is an example: Strings are also immutable, which means that you cannot change a string once you have created it.
How to Format Strings There are instances in which you will want to construct strings from a different piece of information. To do this, you will need to use the method. Just like what the name means, variables have varying values, such as real numbers, strings, Booleans, dictionaries, or lists, which you can access through certain methods. Take a look at this sample code: In this example, you are able to define the variable named port, which is going to be used to store the integer 21, and the variable named banner, which is going to hold a string.
In order to combine these variables together as a single string, you will need to use the variable port through the use of the str function. Since you need to quickly access the data you stored, you need to assign names to variables. This is where identifiers come to play. Identifiers work like code names that you use to point out to something that you have used in your code or program. Here are some rules that you need to follow when assigning them: The initial character should be a letter of the alphabet or an underscore.
The remaining characters should consist of underscores, letters, or digits They are case-sensitive, which means that mycode and myCode do not call out the same value and not interchangeable when you assign them as an identifier. Objects Things that are referred to as anything in the code that exists in Python are called objects.
If you are migrating to Python from another programming language, you need to take note that everything in Python, including string, numbers, and functions, is classified as an object. Lists Python allows you to make use of a list data structure which is extremely useful when it comes to storing collections of objects.
As a programmer, you can create lists that contain different types of data. At the same time, you can also make use of several built-in techniques in Python that will allow you to insert, index, count, sort, append, remove, pop, and even reverse items in a list.
Take a look at this example: Using the above code, you were able to create a list through the method append , print all the specified items, and then manage to sort the items before you asked the program to print them again. Dictionaries are extremely helpful in creating hacking scripts. For example, you can create a scanner that is designed to exploit vulnerabilities of a particular system, such as open TCP ports.
If you have a dictionary that will display service names for corresponding ports that you want to exploit. For example, you can create a dictionary that will allow you to look up the ftp key, and then provide you an output of 21, which corresponds to a port that you may want to test. You can also use dictionaries to perform brute force attacks to crack an encrypted password. What makes Python even better is that you can code your own dictionaries and use them in other scripts that you may want to develop in the future.
When you create a dictionary, keys should be separated from their corresponding value with a colon, and the items should be separated using commas. In the following example, you will be able to use the.
Take a look at this example: Now that you know the basic concepts that make Python scripts perform tasks, you are now ready to start using them in your own script. In the next chapter, you will learn how a readable Python script should look like. In this chapter, you will learn how to use some of the most basic concepts to run simple commands and format your Python codes in such a way that it will be easier for you to understand and document them later.
That entire line is considered a statement because it indicated that something should be done, which is connecting the said variable to a numerical value. Afterwards, you printed out the value of i by using the print command. Afterwards, you added 1 to the given value that you stored in the variable i, and then you saved it. When you use the print statement again, you get the value of 6. At the same time, you also assigned a literal string to the variable s and then proceeded to use the print statement.
Physical and Logical Lines What you see when you type out a program is called a physical line. What Python gets when you type a statement is called the logical line. With this said, this programming language assumes that every physical line that you see corresponds to a given logical line. While you can use more than one logical line on a physical line by using the semicolon ; symbol, Python encourages that programmers like you input a single statement in order to make your codes more readable.
This way, you will be able to see lines that you are working on and avoid possible confusion when you are working on two different logical lines and get lost on what you are supposed to work on.
Indentation Python is one of the programming languages out there where white space, especially the space at the beginning of each line of code is important. By using indentation, you can group together blocks, or statements that belong together.
As a rule of thumb, see to it that you are using the same indentation when you are working on similar statements. Also remember that using the wrong indentation can make your code prone to error. Take a look at this example: When you run this code, you will get this result: Python recommend that you use four spaces for your indentations.
Typical good text editors will do this for you. As long as you are consistent with the spaces that you are using, you will be able to avoid unexpected results in your code. Now that you know the basics, you can now start learning the more interesting stuff!
Chapter 5: Operators and Expressions Most of the statements also called logical lines that you will be writing in your code will include expressions. Expressions are divided into operands and operators. Operators are essentially functions that do something in your code, which are represented by symbols or keywords.
They usually require pieces on information that they can work on, which are called operands. Python Operators Take a look at how expressions look like in an interpreter prompt: When you evaluate expressions in an interpreter prompt and you used the right syntax, you will be able to see the result that you are expecting right after the logical line. Since you will be producing codes for your own hacking tools, you will need to memorize how operators are used in a code.
Also take note that Python uses the operators according to precedence. That means that when you ask your code to perform certain operations that have higher precedence. For example, Python will always perform operations that require it to divide or multiply variables over operations that require it to add or subtract. If two operators have the same value of precedence, then Python will evaluate them from left to right. Here is a list of the operators that are available in Python.
In case that the first operand in the equation is absent, Python assumes that it is zero. For example: will give you a negative number, and 80 — 40 gives you Multiply 8 Multiplies to numbers or repeats a string a certain number of times. Take a look at this example: Save this as expression. Now that you are aware of how you can use the building blocks of a programming language, you can now ready to learn how you can use them in a code! Chapter 6: Functions and Modules Writing a code for hacking can be tedious when you are limited to using operations — just imagine having to write an operation and then repeat that over and over again throughout your script in order for your code to do something.
It is a good thing that Python allows you to make use of functions and modules that will allow you to repeat certain actions within your code and in other scripts that you will be building in the future. In this chapter, you will learn how to create and make use of functions and modules.
You will also learn how to iterate commands that you have issued in your script in order to repeat certain actions for different elements, and handle errors that you may encounter in your script.
Functions In Python, a function allows you to create a block of code that will be able to do an action. They are also reusable, which means that you can provide a name to that statement block and then run this block using the name that you assigned it anywhere in the program that you are building without any limit. Functions are probably the most important component of a programming language.
In Python, they are usually defined using the keyword def, followed by an identifier name for the function that you want to use. Take a look at this example: Save this as function1.
Parameters are indicated in functions in order to include an input that you can use to pass different values to the function and get a specific result that you have in mind. Also notice that you have managed to call the function two times in this exercise, which means that you did not have to write the entire code again for Python to repeat a particular action. Function Parameters Functions are able to take in values that they will be able to use, which are called parameters.
Parameters act similarly to variables, except that you are defining their values whenever you call the function and that you have already assigned values to them once you run the function. Parameters are specified within a pair of parentheses when you are defining the function and are separated using commas. If you need to call the function in your code, you will need to supply the values in the same way.
Also take note that when you are supplying value to your function while you are naming it, these values are called parameters; but when you are supplying values as you call the function, these values are called arguments.
You should get this output: Keyword Arguments There will be instances as you code wherein you have too many parameters in your function — if you want to specify some of them, then you can use keyword arguments in order to give values for some of the parameters. You should get the following output: The return Statement If you want to break out of the function, or if you want to return a value from the function, then this statement will prove to be helpful.
You should get the following output: DocStrings Python comes with a cool feature called docstrings, which is a tool that you can use to document the code that you are creating and make it easier to understand. You can also get a docstring from a function while the code is already running.
You should get the following output: What happened here is that you are able to view the docstring for the function that you have used, which is the first string on the initial logical line. Take note that docstrings can also be used in classes and modules. Iteration There are some instances wherein you may find it to redundant to write the same code multiple times to do a similar function, such as checking different IP addresses or analyze different ports.
For this reason, you may want to use a for-loop instead to iterate the same code for different elements. For example, if you wish to iterate a code for the subnet of IP addresses from For example, when you divide anything by zero, you are likely to experience a runtime error because Python knows that it is impossible to do so.
Using the example above, you can use the try or except statement in order to make use of the exception handling so that when the error happens, the exception handling feature will catch the error and then print the message on the screen.
The simplest way to make modules is to create a file that contains all the variables and functions that you may need to use in a future program and then save it as a.
Alternatively, you can also create your modules in a language in which the Python interpreter is written, such as the C language. You can also have a module imported by another program and use all the functionality saved in there, which is the same as you use the standard libraries that you use in Python.
You should get this output: What happened here is that you first imported the sys module. By using the import statement, you are able to tell python that you want to use a module that contains the functionality that is related to the Python environment. When this programming language executes the statement, it will then look for the.
Since this is a built-in module, Python knows the location where it can be found. In any case you are trying to import a module written in Python, the interpreter will then search all directories that are listed in the variable sys.
Once it is found, the statements found in that module will be run, making it available for you to use. This initialization process only takes place the first time you import a module. Called the sys module, this module includes command line arguments, maximum size of integers that can be used, flags, path hooks, as well as other available modules. Being able to interact with the sys module will allow you to create different scripts that you can use for different hacking purposes.
For example, you may want to analyze different command line arguments during runtime. If you are going to build a scanner to discover system vulnerabilities, you may want to pass a filename as a command line argument, which can be done by using the list sys.
Take a look at this sample code to see how this module is used: When you run this piece of code, you will see that the command line argument has been analyzed and then Python prints out the results on the screen.
Using this module, you can allow the programming language to interact on its own with the file-system, permissions, user database, and different OS environment. Using the previous example, you, the user, submitted a text file as a command line argument.
However, it will also be of value if you can check if the file that you have passed exists and the current user of the machine you are targeting have the necessary permissions to read that file. To determine this, you can create a code that will display an error message if either one of the condition is not met.
You can use this code to do that: To check your code, you can attempt to read a file that is not available in the system, which will cause the script you just typed in to display the error.
Afterwards, you can enter a filename that will be successfully read. This extensive collection contains several built-in modules that allow you to access different functionalities in the system.
This means that you are able to deal away with platforms when it comes to creating your codes. If you are running Python from a Windows machine, you are likely to have the entire standard library included in your installation. If you are operating using UNIX or any similar operating system, you may need to use the packaging tools available in your operating system if you want to get some of the optional components. At this point, you already know the essentials in Python.
As you create your own codes for hacking or import modules from libraries, you will be able to discover more functionalities and learn what they are for.
Since you are learning how to code in order to hack, the best way for you to pick up your pace is to learn as you create tools that you can use for hacking. This means that it is time for you to do the exciting stuff! Chapter 7: Setting Up for Hacking At this point, you have a basic idea of how Python works and how programs were created using this programming language. Now, you are ready to learn how you can use Python scripts to compromise websites, networks, and more.
Learning how to hack entails being able to setup the right environment that you can work in in order to develop your own exploitation tools. Since you have already installed Python and the standard library that comes with it, you are pretty much set up for hacking. All you need to do now is to install other tools and libraries that you can use for the exploits that will be detailed in this book.
Installing Third Party Libraries Third party libraries are essentially libraries that do not come native with your installation of Python. All you need to do to get them is to download them from a targeted source, perform uncompressing on the package that you just downloaded, and then change into the target directory. As you might have already guessed, third party libraries are extremely useful when it comes to developing your own tools out of the resources that are already created by someone else.
Since Python is a highly collaborative programming language, you can use libraries that you may find from website sources such as GitHub or the Python website and incorporate them into your code.
There Once you are inside the directory, you can install the downloaded package using the command python setup. Tip: If you want to establish your development environment faster, you may want to get a copy of the BackTrack Linux Penetration Distribuion, which essentially allows you to get access to tools that are used for forensics, network analysis, penetration testing, and wireless attacks.
This Python program will not only teach you how you can crack passwords, but also help you learn how to embed a library in your code and get results that you want.
To write this password cracker, you will need to have a crypt algorithm that will allow you to hash passwords that are in the UNIX format.
When you launch the Python interpreter, you will actually see that the crypt library that you need for this code is already right in the standard library.
Now, to compute for an encrypted hash of a UNIX password, all you need to do is to call the function crypt. The code should return with a string that contains the hashed password. This is how the output should look like: When that happens, you can simply write a program that uses iteration throughout an entire dictionary, which will try against each word that will be possibly yield the word used for the password.
Now, you will need to create two functions that you can use in the program that you are going to write, which are testPass and main.
The main function will pull up the file that contains the encrypted password, which is password. After that, the main function will call the testPass function to test the hashed passwords against the dictionary.
The testPass function will take the password that is still encrypted as a parameter and then will return after exhausting the words available in the dictionary or when it has successfully decrypted the password.
At this point, you are now able to set up an ideal hacking environment for Python and learn how to make use of available resources from other hackers. In this chapter, you will learn how to attack a network using some third-party tools and codes that you can write using Python. At the same time, you will also gain better awareness on how hackers gain information about their target and perform attacks based on the vulnerabilities that they were able to discover.
Reconaissance: The Opening Salvo to Your Attack Hacking a system begins with reconnaissance, which is the discovery of strategic vulnerabilities in network before launching any cyber-attack. Whenever you connect to the internet and send data over the web, you are leaving behind footprints that hackers can trace back to you.
When that happens, it is possible that hackers will want to study your activities over your network and discover vulnerabilities in your system that will make it easier for them to infiltrate and steal data that can be of value to them. In order to interact with this open ports, you will also need to create TCP sockets. Python is one of the modern programming languages that allows you to gain access to BSD socket interfaces.
If you are new to this concept, BSD sockets give you an interface that will allow you to write applications so that you can do communications with a network right in between hosts.
If you are able to know the IP address and the TCP ports that are associated with the service that you want to target, then you can better plan your attack. Most of the time, this information is available to system administrators in an organization and this data is also something that admins need to hide from any attacker. Before you can launch any attack on any network, you will need to gain this information first. Well, if you are searching for an ebook to learn about penetration testing and ethical hacking, then The Basics of Hacking and Penetration Testing might be the best pick for you.
The eBook can help you to learn about the importance of digital lives, privacy, and security. So, Hacking Revealed is another best Hacking book that you can read right now. The book contains lots of valuable information that could help you understand dozens of things related to ethical hacking. Ethical Hacking for Beginners is for those searching for an introductory book to learn about the practices of ethical hacking.
The book has lots of guides that could help you understand how Linux works and utilizes terminal directions. For beginners, the book also offers step-by-step techniques and tips for the simple hacking process. Well, if you are searching for a book to get valuable information on various forms of security like IT Security, Data Security, Network Security, Internet Security, etc. The book throws lights on tools and methods used by ethical hackers to hack or crack securities.
If you are searching for a powerful guide to staying updated with the latest web attacks and defense, you need to read the Web Hacking book.
The book briefly explains the web and what hackers go after. Along with that, the book also has a detailed analysis of various hacking techniques as well. The book can help you learn and write your own exploits, buffer overflow, malware analysis, etc.
0コメント