exam questions

Exam PT0-002 All Questions

View all questions & answers for the PT0-002 exam

Exam PT0-002 topic 1 question 303 discussion

Actual exam question from CompTIA's PT0-002
Question #: 303
Topic #: 1
[All PT0-002 Questions]

A penetration tester wrote the following Bash script to brute force a local service password:



The script is not working as expected. Which of the following changes should the penetration tester make to get the script to work?

  • A.
  • B.
  • C.
  • D.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
BurN1nGSPheRE
2 weeks, 5 days ago
Selected Answer: ง
We need to search for the correct password by testing each password continuously. If the password is incorrect, it should display the result "wrong password". But if the correct password is found, it should display "The correct Password is ..." and then stop the process using a break. In this case, option D is the most correct.
upvoted 1 times
...
BlackSkullz
1 month, 3 weeks ago
Selected Answer: D
I believe it's D. The "||" value only executes the next command if the one before it fails. In the context of this Bash script, the inability to find "Wrong Password" would result in failure of that particular command, but it also means that the password may be correct. So if grep fails to to find "Wrong Password", then the "||" would instead execute the next command, effectivly revealing the correct password
upvoted 1 times
...
FasterN8
6 months ago
Selected Answer: D
The || OR is exactly what is needed. If the "Wrong password" string is not found, (the first part fails) then execute the (echo and break) portion.
upvoted 1 times
...
Etc_Shadow28000
6 months, 1 week ago
Selected Answer: C
C. Replace & ( echo "The correct password is $p" && break ) with && ( echo "The correct password is $p" && break ) Explanation: • The & operator is used to run commands in the background, which is not suitable for this script because we need to sequentially process each password and check the response. • The && operator ensures that the following commands are only executed if the preceding command succeeds. • The || operator runs the second command only if the preceding command fails, which isn’t what we need here. Therefore, replacing the background execution operator & with the conditional execution operator && ensures that the script only proceeds to echo the correct password and break the loop if the preceding grep command did not find “Wrong Password”.
upvoted 2 times
Etc_Shadow28000
6 months, 1 week ago
Issue with Option D: The || operator is used to execute the following command only if the preceding command fails (i.e., returns a non-zero exit status). In the given script, grep "Wrong Password" will succeed (exit status 0) if “Wrong Password” is found in the output, and it will fail (non-zero exit status) if “Wrong Password” is not found. echo $p | nc -u 127.0.0.1 20000 | grep "Wrong Password" || ( echo "The correct password is $p" && break ) - If grep "Wrong Password" fails (which means the password might be correct), then echo "The correct password is $p" && break will execute. - If grep "Wrong Password" succeeds (which means the password is wrong), nothing will happen, and the loop will continue.
upvoted 2 times
...
...
MalikMak
9 months, 3 weeks ago
Selected Answer: A
The correct answer is A and not D, The grep command is looking for "Wrong Password". If "Wrong Password" is found, grep will return a zero exit status, and because of the ||, the subsequent echo and break commands will not be executed. But we want the opposite to happen: you want to detect when the password does not produce the "Wrong Password" message, which would indicate a successful password guess.
upvoted 2 times
...
Tytuss
9 months, 3 weeks ago
Answer is A based of AI. I typed the entire thing out. Here is it's response: Without knowing the exact behavior of the local service and the specific issue with the script, it’s hard to definitively say which option is correct. However, option A seems to be the most likely answer. It changes the logic so that if the “Wrong Password” message is not found (indicating a correct password), it will echo the correct password and break the loop. The other options seem to have syntax errors or incorrect logic. But please note that this is just an educated guess based on the information provided.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago