QuestionQ74

Reconnaissance and Enumeration

A penetration tester obtains initial access to a system and prepares to conduct further reconnaissance. The tester cannot use Nmap on the system used to obtain initial access. The tester creates the following script to scan a network range:

Question Image

The tester needs to modify the existing script to scan multiple ports. The tester enters a comma-separated port list in the port variable. Which of the following should the tester do next to achieve the required functionality?

  • A Duplicate the $socket code block and modify $port for each new port variable.
  • B Add a new Foreach loop directly beneath the other Foreach loop and enclose with {...}.
  • C Add $p in $port to the initial Foreach loop directly following the $range variable.
  • D Add $(Each ($p in $port) on the line before $socket and enclose with {....}.
Explanation

A comma-separated PowerShell value can be iterated as a collection. A nested Foreach loop is required so that, for each IP address in the network range, the script attempts a connection to every specified port. The socket constructor should use the current port-loop value.

Community Discussion

No comments yet. Be the first to start the discussion!