Chap 12 - Scripting for Penetration Testing Flashcards

1
Q

Which of the following operating systems support PowerShell interpreters?

A. Linux
B. Mac
C. Windows
D. All of the above

A

All of the above

PowerShell interpreters are available on all major platforms, including Windows, macOS, and many popular Linux variants.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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]

A

$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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What comparison operator tests for equality in Ruby?

A. -eq
B. -ne
C. ==
D. !=

A

==

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What value would be used to encode a space in a URL string?

A. %20
B. %21
C. %22
D. %23

A

%20

The %20 value is used to URL encode spaces using the percent encoding scheme.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

Ruby

Among other characteristics, the rescue keyword for error handling is unique to Ruby.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the limit to the number of elsif clauses in a Ruby script?

A. 1
B. 2
C. 10
D. No limit

A

No limit

There is no limit to the number of elsif clauses that may be included in a Ruby script.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

PowerShell

Use the flowchart in Figure 12.6 to answer this question. The code contains a Do statement, so it is written in PowerShell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

Bash

Use the flowchart in Figure 12.4 to answer this question. The code contains an fi statement, so it is written in Bash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

Python

Use the flowchart in Figure 12.5 shown below to answer this question. The code contains colons, so it is written in Python.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What Unix command can you use to listen for input on a network port?

A. grep
B. sed
C. awk
D. nc

A

nc

The nc command allows you to open a network port for listening and then direct the input received on that port to a file or executable.

17
Q

Which one of the following programming languages does not offer a built‐in robust error‐handling capability?

A. PowerShell
B. Python
C. Ruby
D. Bash

A

Bash

PowerShell, Python, and Ruby all support variants of the try..catch clause. Bash does not provide a built‐in error‐handling capability.

18
Q

What value would be used to encode an ampersand in a URL string?

A. %24
B. %25
C. %26
D. %27

A

%26

The %26 value is used to URL‐encode ampersands using the percent encoding scheme.

19
Q

What comparison operator tests to see if one number is greater than or equal to another number in Bash?

A. -gt
B. -ge
C. ˃
D. ˃=

A

-ge

The -ge operator tests whether one value is greater than or equal to another value in Bash and PowerShell, whereas the -gt operator tests whether one value is strictly greater than the other. The ˃= and ˃ operators are used in Ruby, Perl, and Python for the same purposes.