PenTest+ Module 11 - Modifying Scripts

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/46

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:17 AM on 6/21/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

47 Terms

1
New cards

Bash

A command-line scripting language used for the command shell inside Unix-like systems (Linux and MacOS)

Bash is NOT object oriented

All bash scripts should start with #!/bin/bash

2
New cards

Bash Variables

Define a variable with varName = <value>

To use the variable, use $. $varName for example

3
New cards

Bash Variable Declaring

declare option VarName=<value>

Ex: declare -i PhoneNumber=1111111 (treat as integer)

Ex: declare -r Pi=3.14 (read only)

4
New cards

Bash Arrays

tempArray=[value1, value2, value3]

Index with $tempArray[index] (remember that in bash you reference variables with $)

5
New cards

Bash Named and Associative Arrays

declare -A PhoneBook (declare it first)

PhoneBook[name]=”Jason”

PhoneBook[number]=”111-1111”

${PhoneBook[name]} to get the name (named arrays use curly brackets

${PhoneBook[number]} to get the number

6
New cards

Bash Arithmetic Comparison

is a equal to bif [ “$a” -eq “$b” ]

is a not equal to bif [ “$a” -ne “$b” ]

greater than-gt

greater than or equal to-ge

less than-lt

less than or equal tole

You can use < and > but you have to use double parenthesis around the operation

((“$a” < “$b”)) for example

7
New cards

Bash String Comparison

if [ “$a” = “$b” ] or if [ “$a” == “$b” ] for is equal to

if [ “$a” != “$b” ] for not equal to

You can compare words with < and >. This will order based on ASCII ordering

if [ “$a” \< “$b” ] for is less than (in alphabetical order)

if [[ “$a” < “$b” ]] for is less than (remember double wrapped if using raw < and >

8
New cards

Bash Logical Comparison

if [condition]
  then
    # do some command
elif [condition]
  then
    # do something
else
    # do something
fi

9
New cards

Bash For Loop Done

for var in <list>
do
    # commands
done

Ex:

for value in {1..5}
do
    echo $value
done

echo "All done"

10
New cards

Bash While Do Done

while [some test]
do 
    # commands
done

Ex:

counter=1
while [$counter -lt 10]
do
    echo $counter
    ((counter++))
done

echo "All done"

11
New cards

Bash Until Do Done

Perform a set of commands until a test is true

until [some test]
do
    # commands
done

Ex:

counter = 1
until [$counter -gt 5]
do
    echo $counter
    ((counter++))
done

echo "All done"

12
New cards

Bash String Operations

The commands used to manipulate data in string format

13
New cards

Bash Substrings

testString = "Test String"
echo ${testString:2:4}

> st S

First number is start index, second number is how many characters from that position (including the position itself)

14
New cards

Bash Inputting and Outputting Data

Output with echo

Input with read

Read input into a variable: read UserName

15
New cards

Bash Getting Input From File

TempFile = $(<test.txt)
echo "$TempFile"

TempFile contains the contents of test.txt

16
New cards

Bash Outputting to a File

> overwrites what is in the file

» appends to a file

echo "hi" > hi.txt
echo "amongus" >> hi.txt

17
New cards

Bash Command Line Args

$1 is the first argument passed into the script

$0 is the name of the script itself

18
New cards

PowerShell Comments

Uses #

<# a bunch of stuff #> also works to make large multi-line comments

19
New cards

PowerShell Variables

All variable creation begins with $

$varName = <value>

$CustomerName = Jason

Access variables by also using the $ notation

Also allows typing

[int]$AnswerNumber = 42

[string]$AnswerString = “The life, the universe, and everything”

Constants (set the variable to read only)

Set-Variable <VarName> -Option ReadOnly -Value <value>

20
New cards

PowerShell Arrays

$tempArray = @() # Blank array

$TempArray = @('Jason', 'Sahra', 'Eduardo', 'Linda')

Arrays are denoted with @

Access with $tempArray[index]

21
New cards

PowerShell Named and Associative Arrays

$PhoneBook = @{}
$PhoneBook.name = 'Jason'
$PhoneBook.number = '321-1234'

#Reference
$PhoneBook.name

# All in one
$PhoneBook = @{'name' = 'Jason', 'number' = '321-1234'}

22
New cards

PowerShell Comparisons

Same as Bash, also uses -eq, -le, -ge, -lt, -gt, etc

23
New cards

PowerShell Conditional Statements

if (condition) {
    # Then do some command
}
if (condition) {
    # Code here
}

elseif (condition) {
    # Code here
}

else {
    # Code here
}

24
New cards

PowerShell For Loop

for (<Init> ; <Condition> ; <Repeat>) {

    <Statement list>
}
for ($i = 1; $1 -lt 5; $i++) {
    Write-Host $i
}

Write-Host "All done"

25
New cards

PowerShell Do While

Do {
    # Commands
}
While ($this -eq $that)
$i = 1
Do {
    Write-Host $i
    $i++
}
While ($i -lt 10)

Write-Host "All Done"

26
New cards

PowerShell Until Do

Do {
    # commands
}
Until ($this -eq $that)
$i = 1
Do {
    Write-Host $i
    $i++
}
Until ($i -gt 5)

Write-Host "All Done"

27
New cards

PowerShell String Operations

Print with Write-Host

Concatenation: Write-Host $testString + “2””Test String2”

28
New cards

PowerShell Substrings

$testString = "Test String"
$testString.substring(2, 4)

> st S

First number is starting index, second number is amount of characters to include (including the starting index itself

29
New cards

PowerShell Get Input

Read-Host $VarName

30
New cards

PowerShell Read File

$TempFile = Get-Content - Path C:\Test.txt
Write-Host $TempFile

31
New cards

PowerShell Write to File

> overwrites

» Appends

Write-Host "Hello" > hello.txt
Write-Host "Hi" >> hello.txt

32
New cards

PowerShell Dead Giveaway

The cmdlets are dead giveaways that a script is PowerShell

33
New cards

Python Comments

Uses #

34
New cards

Python Variables

varName = <value>

35
New cards

Python Type Casting / Setting

Price = int(42) # Variable will always be an int
Price = float(42.00) # Variable will always be a float
Price = str("The life, the universe, and everything")

No need to do anything special to reference variables, just use the name

36
New cards

Python Constants

Use all caps to denote

PI = 3.14159

37
New cards

Python Arrays

tempArray = []
tempArray = [value1, value2, value3]

nameArray = ["Jason", "Mary", "Joe"] 

nameArray[0] => Jason

38
New cards

Python Dictionary

PhoneBook = {}
PhoneBook = {'name' = 'Jason', 'number' = "321-1234"}

PhoneBook["name"] => Jason

39
New cards

Python Comparisons

equal to → ==

not equal to → != or <>

greater than, less than, gte, lte → >, <, >=, <=

40
New cards

Python Conditional Statements

if condition:
    # code
if a == b:
    print(a)
if (condition):
    # code
elif (condition):
    # more stuff
else:
    # stuff

41
New cards

Python For Loop

for x in list:
    # Stuff

42
New cards

Python While Loop

i = 1
while i < 6:
    print(i)
    i++

print("All done")

43
New cards

Python Until Loop

Don’t really exist in Python. You do it by reversing the conditional check of a while loop

44
New cards

Python String Operations

String Concatenation → print(testString, “ in Python” + “ today”)

45
New cards

Python Substrings

MyName = "Jason Dion"

MyName[0] -> 'J'

MyName[0:4] -> 'Jaso'

MyName[6:8] -> 'Di' 

MyName[-2] -> 'o'

MyName[6:-2] -> 'Di'

MyName[-4:-2] -> 'Di'

Python substring, first number is the start index, second number is end index non-inclusive

Allows negative indexing. -1 is the very last character

46
New cards

Python Input and Output

Input with var = input(“Please enter your name:”)

Output with print

47
New cards

Python Files

Write to file

tempFile = open('test.txt', 'w') # write will overwrite 

tempFile = open('test.txt', 'a') # append will append, no overwrite

Read from file

tempFile = open('test.txt', 'r')

print(tempFile.read())

print(tempFile.read(50)) # prints first 50 characters

print(tempFile.readline(-5)) # Prints last 5 lines of file