ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 76 - PT0-003 discussion

Report
Export

A penetration tester creates a list of target domains that require further enumeration. The tester writes the following script to perform vulnerability scanning across the domains:

line 1: #!/usr/bin/bash

line 2: DOMAINS_LIST = '/path/to/list.txt'

line 3: while read -r i; do

line 4: nikto -h $i -o scan-$i.txt &

line 5: done

The script does not work as intended. Which of the following should the tester do to fix the script?

A.
Change line 2 to {'domain1', 'domain2', 'domain3', }.
Answers
A.
Change line 2 to {'domain1', 'domain2', 'domain3', }.
B.
Change line 3 to while true; read -r i; do.
Answers
B.
Change line 3 to while true; read -r i; do.
C.
Change line 4 to nikto $i | tee scan-$i.txt.
Answers
C.
Change line 4 to nikto $i | tee scan-$i.txt.
D.
Change line 5 to done < '$DOMAINS_LIST'.
Answers
D.
Change line 5 to done < '$DOMAINS_LIST'.
Suggested answer: D

Explanation:

The issue with the script lies in how the while loop reads the file containing the list of domains. The current script doesn't correctly redirect the file's content to the loop. Changing line 5 to done < '$DOMAINS_LIST' correctly directs the loop to read from the file.

Step-by-Step Explanation

Original Script:

DOMAINS_LIST='/path/to/list.txt'

while read -r i; do

nikto -h $i -o scan-$i.txt &

done

Identified Problem:

The while read -r i; do loop needs to know which file to read lines from. Without redirecting the input file to the loop, it doesn't process any input.

Solution:

Add done < '$DOMAINS_LIST' to the end of the loop to specify the input source.

Corrected script:

DOMAINS_LIST='/path/to/list.txt'

while read -r i; do

nikto -h $i -o scan-$i.txt &

done < '$DOMAINS_LIST'

done < '$DOMAINS_LIST' ensures that the while loop reads each line from DOMAINS_LIST.

This fix makes the loop iterate over each domain in the list and run nikto against each.

Reference from Pentesting Literature:

Scripting a

asked 02/10/2024
Salvatore Andrisani
40 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first