Tags: python3 web automation scripting requests 

Rating: 4.0

# web/finger-warmup @ DamCTF Oct. 2020

* challenge author: **babayet2**
* solves: **405**
* points: **160**

## Description

>A finger warmup to prepare for the rest of the CTF, good luck!
>
>You may find [this](https://realpython.com/python-requests/) or [this](https://programminghistorian.org/en/lessons/intro-to-beautiful-soup) to be helpful.

## Analysis

We are presented with a website whose sole content is a link.
Clicking on that link brings redirects us to the same site, with
another link. From the description and the title, the intent is
clear. We are going to have to automate the process of following the
links until we get the flag.

### Solving

Since we were told to use requests/beautifulsoup, I chose to look into those
and implement a solution with them.

My solution looks like this:

```python
#!/usr/bin/env python3

import requests
from bs4 import BeautifulSoup
from pwn import log

BASE_URL = "https://finger-warmup.chals.damctf.xyz/"

redirect = ""
while True:
log.info(f"Sending request to.. {BASE_URL}{redirect}")
response = requests.get(f"{BASE_URL}{redirect}")
log.info(f"Received data: {response.text}")
soup = BeautifulSoup(response.text, "html.parser")

try:
# find the next link
redirect = soup.find_all("a")[0].get("href")
except Exception:
# if we can't find a link, the flag has probably been found
log.info("Done!")
exit(0)

```

Once the script is done, we see the following:

![solve.py](https://i.imgur.com/eQ6YzaF.png)

Original writeup (https://medium.com/@igotinfected/web-finger-warmup-damctf-oct-2020-63d69d73648).