top of page
book of spells.webp

Start your journey towards mastering the CLI with our FREE Command Line Book of Spells.

By entering your email address you agree to receive emails from Command Line Wizardry. We'll respect your privacy and you can unsubscribe at any time.

Writer's pictureCybersecurity Ops with bash

Cybersecurity Ops with bash - Chapter 20 Solutions

Updated: May 10, 2019

Below are selected solutions for the Chapter 20 workshop questions from Cybersecurity Ops with bash. Note - These are just examples, many possible solutions exist.


Question 2


Try expanding and customizing the features of softinv.sh by adding the following

functionality:


Modify the script to add, for Linux distros only, an ls of the /bin and /usr/bin

directories.


Answer


The ls command that we want to run on the Linux systems is something like this:

ls -b /bin /usr/bin


You might want to add other options to the ls command. We used the -b option to show any non-printing characters in the filenames. You might also consider adding /sbin and /usr/sbin as other directories to be listed; these are the directories used by the root (privileged) user.


1. We set a variable (LNONLY) to hold the string that is that command:

Later on, for the case statement for windows systems we unset the variable so that the variable is no longer defined.


2. At the bottom of the script, we can execute the command:

The shell will replace the values of LNONLY and OUTFN and then execute the resulting command line. On a Linux system the ls command will be run. The redirects on this command throw out any errors and append all the regular output to the $OUTFN file (defined earlier in the script). In the case of an Windows OS we have unset the variable LNONLY, so the variable reference is replaced by nothing, by emptiness (not a null string, but by no thing). All that is left to execute are some harmless redirects.


540 views0 comments

Kommentare


bottom of page