Analyze a Bash script that makes HTTP requests to download files. Learn how to interpret scripts for the CompTIA PenTest+ certification exam.
Table of Contents
Question
Given the following Bash code snippet:
#!/bin/bash url="http://10.10.10.1:8888" for i in {1..10}; do for link in $(curl -s "$url/documents.php?uid=$i" | grep -oP "\/documents.*?.doc); do wget -q $url/$link done done
Which of the following would be achieved?
A. User enumeration
B. Directory brute-force attack
C. Port scan
D. File download
Answer
D. File download
Explanation
Here’s a detailed explanation of what the script does:
- It sets a variable `url` to “http://10.10.10.1:8888”.
- It starts an outer `for` loop that iterates the variable `i` from 1 to 10.
- For each value of `i`, it makes a HTTP GET request to the URL “$url/documents.php?uid=$i” using `curl`. The `-s` flag makes the request silently.
- It pipes the response from `curl` to `grep`. The `-oP` flags enable Perl-compatible regular expressions and only print the matched parts.
- The regular expression `”\/documents.*?.doc”` matches and extracts links in the response that start with “/documents” and end with “.doc”.
- The extracted links are fed into the inner `for` loop which iterates over each `link`.
- Inside the inner loop, it uses `wget` to download the file at the URL “$url/$link”. The `-q` flag enables quiet mode to suppress output.
- The process repeats for each user ID from 1 to 10, downloading all the .doc files found at the “/documents.php” endpoint for each user.
In summary, the script enumerates user IDs, makes HTTP requests to extract document links, and downloads those .doc files. Therefore, the main purpose achieved is (D) File download.
It does not perform (A) User enumeration as it simply iterates through user IDs without validating if they exist. It’s not a (B) Directory brute-force attack as it’s not trying to guess directory names. And it’s not a (C) Port scan since it only makes requests to a single known port 8888.
CompTIA PT0-002 certification exam assessment practice question and answer (Q&A) dump including multiple choice questions (MCQ) and objective type questions, with detail explanation and reference available free, helpful to pass the CompTIA PT0-002 exam and earn CompTIA PT0-002 certification.