Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learning Python Web Penetration Testing
Learning Python Web Penetration Testing

Learning Python Web Penetration Testing: Automate web penetration testing activities using Python

eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Learning Python Web Penetration Testing

Interacting with Web Applications

In the previous chapter, we learned about the web application security process and why it is important to test application security. In this chapter, we'll take a look at the following topics:

  • HTTP protocol basics
  • Anatomy of an HTTP request
  • Interacting with a web app using the requests library
  • Analyzing HTTP responses

HTTP protocol basics

In this section, we'll learn about the HTTP protocol, how it works, and the security aspects of it and which methods are supported when performing a request.

This will provide you with the basic knowledge of HTTP, which is important to understand how to build tools and test for security issues in web applications.

What is HTTP and how it works?

HTTP was designed to enable communication between clients and servers.

HTTP is a TCP/IP-based communication protocol operating in the application layer. Normally, we use a web browser to interact with web applications but in this training, we will leave the browser behind and use Python to talk with web applications. This protocol is media independent.

This...

Anatomy of an HTTP request

In this section, we'll take a look at the structure of a URL, the request and response headers, and an example of GET requests using Telnet to understand how it works at a low level.

I bet you have seen thousands of URLs by now. It's now time to stop and think about the URL structure. Let's see what each part means:

The first part is the protocol in web applications. The two protocols used are HTTP and HTTPS. When using HTTP, the port that will be used is 80, and when using HTTPS, the port will be 443.

The next part is the host we want to contact. Next, we can see the resource or the file location in that server. In this example, the directory is content and the resource is section. Then, we have the question mark symbol that indicates what's to come is the query string. These are the parameters that will be passed to the section...

Interacting with a web app using the requests library

In this section, we'll start to write Python code to perform HTTP requests using the requests library.

Requests library

Requests is an Apache 2 licensed HTTP library written in Python. It was created to reduce the complexity and work needed when using urllib2 and other HTTP libraries available at the moment.

This is an example of the code needed to perform a request to api.github.com using authentication when using the urllib2 library:

import urllib2

gh_url = 'https://api.github.com'

req = urllib2.Request(gh_url)

password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, gh_url, 'user', 'pass')

auth_manager...

Analyzing HTTP responses

In this section, we will learn about the different HTTP response status codes and different classes of HTTP response codes.

Then, we'll write examples to see successful responses or errors, and finally, we'll see a redirection example.

HTTP codes

The HTTP protocol defines five classes of response codes to indicate the status of a request:

  • 1XX-Informational: The 100 range codes are used for informational purposes. It is only present in HTTP/1.1.
  • 2XX-Success: The 200 range of codes are used to indicate that the action requested by the client was received, understood, accepted, and processed. The most common is 200 OK.
  • 3XX-Redirection: The 300 range indicates the client that must take additional...

Summary

In this chapter, we had a brief introduction to HTTP, and we saw a basic GET request example. We also saw the different HTTP methods available that we can use to interact with web applications.

We also learned about HTTP requests. We learned how to interact with a web application using Python and the requests library. We further learned about the HTTP request anatomy and the different HTTP methods and response code.

In Chapter 3, Web Crawling with Scrapy - Mapping the Application, we'll learn how to write a Web Crawler, use Spider using Python, and how to use the Scrappy library.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Understand the web application penetration testing methodology and toolkit using Python
  • • Write a web crawler/spider with the Scrapy library
  • • Detect and exploit SQL injection vulnerabilities by creating a script all by yourself

Description

Web penetration testing is the use of tools and code to attack a website or web app in order to assess its vulnerability to external threats. While there are an increasing number of sophisticated, ready-made tools to scan systems for vulnerabilities, the use of Python allows you to write system-specific scripts, or alter and extend existing testing tools to find, exploit, and record as many security weaknesses as possible. Learning Python Web Penetration Testing will walk you through the web application penetration testing methodology, showing you how to write your own tools with Python for each activity throughout the process. The book begins by emphasizing the importance of knowing how to write your own tools with Python for web application penetration testing. You will then learn to interact with a web application using Python, understand the anatomy of an HTTP request, URL, headers and message body, and later create a script to perform a request, and interpret the response and its headers. As you make your way through the book, you will write a web crawler using Python and the Scrappy library. The book will also help you to develop a tool to perform brute force attacks in different parts of the web application. You will then discover more on detecting and exploiting SQL injection vulnerabilities. By the end of this book, you will have successfully created an HTTP proxy based on the mitmproxy tool.

Who is this book for?

Learning Python Web Penetration Testing is for web developers who want to step into the world of web application security testing. Basic knowledge of Python is necessary.

What you will learn

  • Interact with a web application using the Python and Requests libraries
  • Create a basic web application crawler and make it recursive
  • Develop a brute force tool to discover and enumerate resources such as files and directories
  • Explore different authentication methods commonly used in web applications
  • Enumerate table names from a database using SQL injection
  • Understand the web application penetration testing methodology and toolkit

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 27, 2018
Length: 138 pages
Edition : 1st
Language : English
ISBN-13 : 9781789539677
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jun 27, 2018
Length: 138 pages
Edition : 1st
Language : English
ISBN-13 : 9781789539677
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 82.97
Learning Python Web Penetration Testing
€24.99
Python Penetration Testing Essentials
€24.99
Practical Web Penetration Testing
€32.99
Total 82.97 Stars icon

Table of Contents

8 Chapters
Introduction to Web Application Penetration Testing Chevron down icon Chevron up icon
Interacting with Web Applications Chevron down icon Chevron up icon
Web Crawling with Scrapy – Mapping the Application Chevron down icon Chevron up icon
Resources Discovery Chevron down icon Chevron up icon
Password Testing Chevron down icon Chevron up icon
Detecting and Exploiting SQL Injection Vulnerabilities Chevron down icon Chevron up icon
Intercepting HTTP Requests Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(33 Ratings)
5 star 54.5%
4 star 36.4%
3 star 0%
2 star 6.1%
1 star 3%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Jan 04, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book! Great way to learn python and application development. My only suggestion would be to use pyenv as opposed to virtualenv as stated in the book.
Amazon Verified review Amazon
Pradyumna Muppirala Jun 16, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Udemy Verified review Udemy
Shandor Yoav Losonci May 23, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Udemy Verified review Udemy
Elena Tosheva Jul 09, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Udemy Verified review Udemy
Yves Mervin Apr 16, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Udemy Verified review Udemy
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.