exam questions

Exam PT0-001 All Questions

View all questions & answers for the PT0-001 exam

Exam PT0-001 topic 1 question 153 discussion

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

A penetration tester is attempting to open a socket in a bash script but receives errors when running it. The current state of the relevant line in the script is as follows:

Which of the following lines of code would correct the issue upon substitution?

  • A. open 0<>/dev/tcp/${HOST}:${PORT}
  • B. exec 0</dev/tcp/${HOST}/${PORT}
  • C. exec 0</dev/tcp/$[HOST]:$[PORT]
  • D. exec 3<>/dev/tcp/${HOST}/${PORT}
  • E. open 3</dev/tcp/${HOST}/${PORT}
  • F. open 3</dev/tcp/$[HOST]/$[PORT]
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
Matherson
Highly Voted 4 years, 2 months ago
$ exec {file-descriptor}<>/dev/{protocol}/{host}/{port} should be the command to open a socket in bash. https://www.xmodulo.com/tcp-udp-socket-bash-shell.html This site breaks down and explains each part of the syntax. I found it super helpful.
upvoted 8 times
Matherson
4 years, 2 months ago
D is the answer. Only one with the correct $exec 3
upvoted 2 times
...
...
macr0sss
Highly Voted 4 years, 2 months ago
answer D. file descriptor needs to be over 2 (so 3 is ok), read/write <> and rest same everywhere.
upvoted 6 times
...
miabe
Most Recent 3 years ago
Selected Answer: D
looks good to me
upvoted 1 times
...
Moytra
3 years, 8 months ago
Fyi, definitely this is the D one. After some research everything points that we can focus in the sistaxis itself, so the File descriptor reserved in bash are the 0,1,2 Saying that we have remaining D E F, However, to open a socket is with exec. And the sistaxis correct says that is $ exec {file-descriptor}<>/dev/{protocol}/{host}/{port} Take a look in the <> D is the only one that has the correct one, this is definetely D.
upvoted 1 times
...
MonKEY69
4 years ago
I would put D. https://unix.stackexchange.com/questions/336876/simple-shell-script-to-send-socket-message
upvoted 1 times
...
Lekitchen
4 years, 2 months ago
I would think that the correct answer would be D. The syntax for C includes $[HOST]:$[PORT], doesn't match the syntax found on https://www.xmodulo.com/tcp-udp-socket-bash-shell.html. My reasoning for D being correct is that in order to use the shell as an exploit, you would want it to be both readable and writable. So you would need a <> to be present.
upvoted 1 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 ...