Proj 1: HTTP with Python and "Requests" (10 pts.)

What You Need

A computer, real or virtual, with Python 2.7. One easy way to proceed is to use a Kali virtual machine.

Purpose

Learn how to use Python to perform HTTP requests.

1. Introduction to Python and Requests

Installing Requests

In a Terminal or Command Prompt, execute this command:
pip install requests
When I did that on Kali 2017.3, it was already installed, as shown below.

Performing a GET

In Kali Linux, in a Terminal window, execute this command:
python
The Python interactive shell opens, as shown below.

At the Python >>> prompt, execute these commands to fetch my Web page.

import requests
r = requests.get("https://samsclass.info")
print r.headers
print r.status_code
The "requests.get" method sends a GET to the server, and the reply is placed into the object named "r".

The headers and status_code are attributes of "r", and are printed, as shown below.

Viewing the Response Body

To see the HTML source code of my page, at the Python >>> prompt, execute this command :
print r.text
The entire HTML code for my page scrolls by, ending as shown below.

Listing the Methods and Attributes of "r"

To see all the methods and attributes available for the "r" object, execute this command:
print dir(r)
The entire HTML code for my page scrolls by, ending as shown below.

Viewing a Login in Chrome

In Chrome, go to:

https://games.samsclass.info/cookielogin/

From the Chrome menu bar, click View, Developer, "Developer Tools". In the Developer Tools pane, click the Network tab.

In the Cookie Login Page, enter a username of foo and a password of bar and click the Submit button, as shown below.

In the Developer Tools pane, a request appears, showing a relative URL of cookelogin.php?n=foo&p=bar, as shown below.

In the Developer Tools pane, click cookeligin.php?n=foo&p=bar.

A "Headers" pane appears, showing the URL and Request Method, as shown below.

Logging in from Python with GET

To attempt a log in, at the Python >>> prompt, execute these command :
r = requests.get("https://games.samsclass.info/cookielogin/cookielogin.php?n=foo&p=bar")
print r.text
The login is rejected, as shown below.

Repeat the GET request, changing the username to root and the password to toor to see a "Welcome >b<Linux Root User!" message, as shown below.


2. Challenge A: Logging in from Python with POST

Examine the login form below in Chrome Developer Tools.

This is a simple login form. Test it with any username and password you like.

Username:      

Password:      

Note the Method, URL, and parameters, as shown below.

Log in with Python, as shown below.


3. Loop Examples

Here are examples of looping in Python. Note the colon and the indentation required for lines inside the loop.

Looping Through String Values

Looping Through Numerical Values

Here's an example using loops to log in to the form above:

4. Challenge B: Brute Forcing a Login Form

Write a script in Python to try all possible credentials and get into the form below.

The user name is one of these:

The PIN is a two-digit number, like this:

Username:      

PIN:      

Write a script that finds the correct credentials and logs in.

When you find it, save an image showing the correct user name and PIN, and also the secret word the server sends, as shown below:

Challenge C: Four Accounts

Break into each of the four accounts below. Save an image of the successful login screen for each one.

Save the whole-desktop images as "Proj 2xb", "Proj 2xc", "Proj 2xd", and "Proj 2xe".

Username:            PIN:    

Credits

CEO: Sarah Bellum
Staff: Pete Moss, Sandy Beach
(Stolen from A Prairie Home Companion)

Hint

Sources

Requests: HTTP for Humans


Last revised: 3-6-18