5.1.1 Tools & code analysis: Analyzing Scripts in Bash Flashcards

1
Q

What kind of questions to expect in the exam related to script analysis?

A

▪ Identify vulnerability
▪ Identify function

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

Coding in Bash: what is Bash? Is it an object-oriented programming language?

A

▪ A command-line scripting language used for the command shell inside Unix-like systems
▪ Bash is not an object-oriented programming language

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

Coding in Bash: how a bash line start?

A

!/bin/bash

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

Coding in Bash: how comment are being written in bash?

A

▪ # This is the first line of my script
▪ # This script is used to do backups of my systems

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

Coding in Bash: how to spot a variable in bash?

A

In bash, variables are typically written using the following syntax: variable_name=value
They can be spotted because they start like $name

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

Coding in Bash: how to spot an array in bash?

A

In bash, arrays can be declared and initialized using the following syntax: array_name=(value1 value2 value3). For exemple: fruits=(“apple” “banana” “orange”)
To access individual elements in the array, you can use the following syntax: echo ${fruits[0]} # This will output the first element “apple”

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

Coding in Bash: what is Named Arrays in Bash?

A
  • A named array is a collection of elements indexed by a key or name, rather than by a numerical index. This allows you to access the elements of the array using a specific name associated with each element. It can be created like this:
    # Declare named array
    declare -A fruits
    # Assign values to named elements
    fruits[apple]=”red”
    fruits[banana]=”yellow”
    # Access named elements
    echo “The color of the apple is ${fruits[apple]}”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Coding in Bash: what is Associative Arrays in Bash?

A

An associative array in Bash is a specific type of named array where the keys can be strings instead of just numerical indices. This allows for more flexible and descriptive indexing of the array elements. An associative array in Bash can be created and accessed like this:
# Declare associative array
declare -A capitals
# Assign values to associative elements
capitals[France]=”Paris”
capitals[Germany]=”Berlin”
# Access associative elements
echo “The capital of France is ${capitals[France]}”

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

Coding in Bash: provide the basic writing for arithmetic in Bash (=, !=,<,> etc) (7)

A

In the following statement $a and $b are variables:
● is equal to: if [ “$a” -eq “$b” ]
● is not equal to: if [ “$a” -ne “$b” ]
● is greater than: if [ “$a” -gt “$b” ]
● is greater than or equal to: if [ “$a” -ge “$b” ]
● is less than: if [ “$a” -lt “$b” ]
● is less than or equal to: if [ “$a” -le “$b” ]
● is less than (within double parentheses): ((“$a” < “$b”))

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

Coding in Bash: provide the basic writing for string comparison in Bash (4)

A

In the following statement $a and $b are variables:
● is equal to:
if [ “$a” = “$b” ]
if [ “$a” == “$b” ]
● is not equal to: if [ “$a” != “$b” ]
● is less than (in ASCII alphabetical order):
if [ “$a” < “$b” ]
if [[ “$a” < “$b” ]]
● is greater than (in ASCII alphabetical order):
if [ “$a” > “$b” ]
if [[ “$a” > “$b” ]]

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

Coding in Bash: list and explain the conditional statement in Bash (2)

A

▪ if [condition]
then # do some command
fi
▪ if [<condition>]
then # code here
elif [<condition>]
then # code here
else # code here
fi</condition></condition>

For exemple if the code is
if [ “$a” -gt 10 ]; then
echo “a is greater than 10”
elif [ “$a” -eq 10 ]; then
echo “a is equal to 10”
else
echo “a is less than 10”
fi

The script first checks if the value of a is greater than 10. If it is, the corresponding action is taken. If not, it then checks if the value of a is equal to 10, and executes the relevant code block. If neither condition is true, the code block associated with else is executed.

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

Coding in Bash: explain how loop are created in Bash (3)

A

▪ For Do Done: Performs a set of commands for each item in a list:
for $variable in <list>
do <commands>
done
▪ While Do Done: Performs a set of commands while a test is true:
while [ <some> ]
do <commands>
done
▪ Until Do Done: Performs a set of commands until a test is true:
until [ <some> ]
do <commands>
done</commands></some></commands></some></commands></list>

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