GPEN practice question 14 of 35
You run the following bash script in Linux: for i in 'cat hostlist.txt' ;do nc -q 2 -v $i 80 < request.txt done where, hostlist.txt file contains the list of IP addresses and request.txt is the output file. Which of the following tasks do you want to perform by running this script?
Full set: 385 questionsThe script iterates through a list of IP addresses stored in hostlist.txt. For each IP address ($i), it uses Netcat (nc) to establish a connection to port 80. The < request.txt part redirects the content of request.txt (presumably a valid HTTP request like GET / HTTP/1.0) to the server. The -v (verbose) flag ensures that the response from the server is printed to standard output. This response from a web server on port 80 includes HTTP headers containing version and server type information, a process known as banner grabbing. The -q 2 option ensures the connection closes 2 seconds after the request is sent.
A. This is not a port scan because the script only connects to a single, predefined port (80) for each host.
B. The script sends the contents of request.txt to the remote hosts, not the hostlist.txt file itself.
D. The script uses Netcat (nc), not nmap, and it is actively connecting to hosts, not listening for incoming connections.
1. OpenBSD. (n.d.). nc(1) - arbitrary TCP and UDP connections and listens. OpenBSD manual pages. Retrieved from https://man.openbsd.org/nc.1. This manual describes the fundamental operation of Netcat (nc) as a client to connect to a specified host and port, reading from standard input and sending the data to the remote host. The script uses this exact client functionality.
2. Shields, C. (2015). Lecture 3: Scanning. EN.600.412/612 Hacking and the Art of Exploitation, Johns Hopkins University, Department of Computer Science. Slide 23, "Banner Grabbing," demonstrates using Netcat for this purpose with the command echo "HEAD / HTTP/1.0\r\n\r\n" | nc -v -w 1 80. This directly parallels the technique used in the question's script, confirming its use for banner grabbing in an academic context.
3. GNU. (n.d.). GNU Netcat: The TCP/IP Swiss Army Knife. GNU Netcat Manual. Section 2.1, "Basic Usage," outlines the client mode syntax netcat [options] host port, which is the mode used in the script to connect to the target hosts. The manual confirms that data from standard input is sent over the established connection.
Keep practicing
Take the free GPEN practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other GPEN practice questions
- Question 1You want to connect to your friend's computer and run a Trojan on it. Which of the follow…
- Question 2Which protocol would need to be available on a target in order for Nmap to identify servi…
- Question 3Which of the following vulnerability scanner scans from CGI, IDA, Unicode, and Nimda vuln…
- Question 4Which of the following Web attacks is performed by manipulating codes of programming lang…
- Question 5You work as a Web developer in the IBM Inc. Your area of proficiency is PHP. Since you ha…
- Question 6You work as a Network Penetration tester in the Secure Inc. Your company takes the projec…
