Chap 12 - Scripting for Penetration Testing Flashcards
Which of the following operating systems support PowerShell interpreters?
A. Linux
B. Mac
C. Windows
D. All of the above
All of the above
PowerShell interpreters are available on all major platforms, including Windows, macOS, and many popular Linux variants.
Examine the following line of code. In what programming language might it be written?
print(“The system contains several serious vulnerabilities.”);
A. Ruby
B. PowerShell
C. Bash
D. Perl
Perl
As you prepare for the exam, you should be able to identify the programming language used in code snippets. The print command is used to generate output in Python and Perl. Of these, only Perl is listed as a possible answer choice.
Examine the following line of code. In what programming language is it written?
Write-Host “The system contains several serious vulnerabilities.”
A. Perl
B. PowerShell
C. JavaScript
D. Python
PowerShell
As you prepare for the exam, you should be able to identify the programming language used in code snippets. The Write-Host command is used to generate output in PowerShell.
Which one of the following statements does not correctly describe the Ruby programming language?
A. It is a general‐purpose programming language.
B. It is an interpreted language.
C. It uses scripts.
D. It is a compiled language.
It is a compiled language.
Ruby is a general‐purpose programming language. It is an interpreted language that uses scripts, rather than a compiled language that uses source code to generate executable files.
Which one of the following commands will allow the file owner to execute a Bash script?
A. chmod o+e script.sh
B. chmod o+x script.sh
C. chmod u+e script.sh
D. chmod u+x script.sh
chmod u+x script.sh
You must set the user (owner) bit to execute (x) to allow the execution of a Bash script. The chmod u+x command performs this task.
Which one of the following PowerShell execution policies allows the execution of any PowerShell script that you write on the local machine but requires that scripts downloaded from the Internet be signed by a trusted publisher?
A. Bypass
B. Unrestricted
C. RemoteSigned
D. AllSigned
RemoteSigned
The RemoteSigned policy allows the execution of any PowerShell script that you write on the local machine but requires that scripts downloaded from the Internet be signed by a trusted publisher.
Which one of the following lines of code would create an array in a PowerShell script?
A. $ports = 22, 25, 80, 443
B. ports = (22,25,80,443)
C. ports = [22,25,80,443]
D. $ports = [22,25,80,443]
$ports = 22, 25, 80, 443
PowerShell requires the use of the $ before an array name in an assignment operation. The elements of the array are then provided as a comma‐separated list. Option B would work in Bash, and option C would work in Ruby or Python.
What comparison operator tests for equality in Ruby?
A. -eq
B. -ne
C. ==
D. !=
==
The == operator tests for equality in Ruby, Python, JavaScript, and for numeric comparisons in Perl. The != operator tests for inequality in those languages. The -eq operator tests for equality in Bash and PowerShell, and the -ne operator tests for inequality in those languages.
What value would be used to encode a space in a URL string?
A. %20
B. %21
C. %22
D. %23
%20
The %20 value is used to URL encode spaces using the percent encoding scheme.
Examine this code snippet. In what language is this code written?
begin
system ‘nmap ‘ + ip
rescue
puts ‘An error occurred.’
end
A. Python
B. PowerShell
C. Ruby
D. Bash
Ruby
Among other characteristics, the rescue keyword for error handling is unique to Ruby.
Which of the following pairs of languages allow the direct concatenation of a string and an integer?
A. Python and Bash
B. Bash and PowerShell
C. Python and Ruby
D. Ruby and PowerShell
Bash and PowerShell
Bash and PowerShell allow the direct concatenation of strings and numeric values. Ruby and Python require the explicit conversion of numeric values to strings prior to concatenation.
What is the limit to the number of elsif clauses in a Ruby script?
A. 1
B. 2
C. 10
D. No limit
No limit
There is no limit to the number of elsif clauses that may be included in a Ruby script.
Analyze the following segment of code:
Do {
$test=’mike’ + $i
$cracked = Test-Password $test
$i++
}
While($cracked -eq 0)
In what language is this code written?
A. Ruby
B. PowerShell
C. Python
D. Bash
PowerShell
Use the flowchart in Figure 12.6 to answer this question. The code contains a Do statement, so it is written in PowerShell.
Analyze the following segment of code:
if [ $weekday==1 ]
then
/usr/local/bin/nmap 192.168.1.1
elif [ $weekday==3 ]
then
/usr/local/bin/nmap 192.168.1.2
else
/usr/local/bin/nmap 192.168.1.0/24
fi
In what language is this code written?
A. Ruby
B. PowerShell
C. Python
D. Bash
Bash
Use the flowchart in Figure 12.4 to answer this question. The code contains an fi statement, so it is written in Bash.
Analyze the following segment of code:
for hst in range(0,256):
ip= net + str(hst)
print(ip, ‘: ‘, socket.gethostbyaddr(ip), ‘\n’)
In what language is this code written?
A. Ruby
B. PowerShell
C. Python
D. Bash
Python
Use the flowchart in Figure 12.5 shown below to answer this question. The code contains colons, so it is written in Python.