Overview

Introduction

Welcome to the Working with Scripts Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

Learning Outcomes

In this module, you will complete the following exercises:

  • Exercise 1 - Work with Variables
  • Exercise 2 - Work with Loops
  • Exercise 3 - Use Error Handling and Arrays

After completing this lab, you will be able to:

  • Use Local and Global Variables
  • Write Bash Functions
  • Use the Set Command
  • Use For Loop
  • Use If…Else Statements
  • Use While loop
  • Use Error Handling
  • Use Arrays

Exam Objectives

The following exam objective is covered in this lab:

  • PT0-001: 4.4 Given a scenario, analyze a basic script (limited to Bash, Python, Ruby, and PowerShell)

Lab Duration

It will take approximately 1 hour to complete this lab.

Exercise 1- Work with Variables

There will be several tasks that you need to perform repeatedly in penetration testing. Either you can keep doing them manually, or you can automate them using scripts. There is nothing wrong with doing things manually, except that you are spending more time in doing them. You are also likely to make more errors when you do them manually. On the other hand, if you use a script to perform a task, you are likely to get the same result without any error.

Scripts can be created in different languages, such as

  • Bash: It is mostly used in Linux and Unix environments. Any operating system, which uses Linux as the base shell, can use Bash-based shell scripts. A bash script, or shell script, use the extension .sh.
  • PowerShell: It is mostly used in the Windows environment. However, since it is an open-source tool, you can also use it on Linux and Mac operating systems. A PowerShell script has the .ps1 extension.
  • Ruby: It is an interpreted language that is not limited to the operating system commands. You need to write a script and run it. There is no need to compile the script or code as you would need to do in C language. A Ruby script has the .rb extension.
  • Python: Just like Ruby, Python is also an interpreted language. Python is used heavily in penetration testing because of its robustness. A Python script has the .py extension.

Depending upon the requirement and your expertise, you can use any of them in penetration testing.

Scripts are run in the shell environment in any operating system. When writing a script, you will use variables, which are mainly used for storing a type of data in memory and then use it later. Variables can store various types of information, such as:

  • Integers
  • Character strings
  • Boolean
  • Date and time

In this exercise, you will learn to work with variables.

Learning Outcomes

After completing this exercise, you will be able to:

  • Use Local and Global Variables
  • Write Bash Functions
  • Use the Set Command

Exercise 2 - Work with Loops

The Bash-based shell script files are stored with an extension of .sh. Each script contains a script interpreter that appears as a commented line in the script. In this task, you will create and execute simple scripts to implement loops.

When writing shell scripts, you would need to build conditional statements. There are different conditional statements that are written with the help of different types of loops. You will also learn how to execute the loops without writing shell scripts.

In this exercise, you will learn about working with loops.

Learning Outcomes

After completing this exercise, you will be able to:

  • Use the For loop
  • Use If…Else statements
  • Use the While Loop

Exercise 3 - Use Error Handling and Arrays

One of the common methods is to insert and unexpected input that can generate an error condition. Therefore, to avoid such a situation, developers should use the error-handling methods. Bash provides an alternate method instead of try…catch clause.

In this exercise, you will learn about error handling and arrays.

Learning Outcomes

After completing this exercise, you will be able to:

  • Use Error Handling
  • Use Arrays

Comprehensive Learning

See the full benefits of our immersive learning experience with interactive courses and guided career paths.