Cyber Ops Quick Reference
Cyber Ops Quick Reference
-c Count matching lines -exec Execute specified command -f Read list from specified file
-E Enable extended regex for each file found -k List all type matches
-i Ignore case -name Search by filename -z Look inside compressed files
-P Enable Perl regex -size Search by file size
-R Recursively search -type Search by file type cut
Paul Troncone & Carl Albing, Ph.D. Command Quick Reference https://www.rapidcyberops.com
Cybersecurity Ops with bash
Attack, Defend, and Analyze from the Command Line
Output Variables While Loop
Writing to the screen Declaring a Variable i=0
while (( i < 1000 ))
echo 'Hello World' MYVAR='Hello' do
echo $i
printf 'Hello World\n' let i++
Referencing a Variable done
Format Strings echo $MYVAR
Format strings for printf
For Loop
echo "$MYVAR World" Numerical looping
%s String
%d Decimal Assigning Shell Output for ((i=0; i < 1000; i++))
%f Floating point do
%x Hexadecimal CMDOUT=$(pwd) echo $i
\n Newline done
\r Carriage return
\t Horizontal tab
If Statements
Iterating over a list
Command conditional (cmd will
Positional Parameters return 0 if success) for VAL in 20 3 dog 7
Script parameters do
if cmd echo $VAL
$# Number of parameters then done
$0 Name of the script some cmds
$1 else
First parameter
other cmds Case Statement
$2 Second parameter …
fi case $MYVAR in
Default parameters "carl")
File and numeric conditionals echo 'Hi Carl!'
MYVAR=${1:-Cake} ;;
if [[ -e $FILENAME ]] "paul")
then echo 'Hi Paul!'
Note: If parameter 1 is unset, the ;;
echo $FILENAME exists
value of MYVAR will default to Cake fi *) # default
echo 'Goodbye'
User Input exit
;;
Read from stdin File Test Use esac
read MYVAR -d Directory exists
-e File exists Functions
Prompting -r File is readable Declaring a function
-w File is writable
read –p 'Name: ' USRNAME
-x File is executable function myfun ()
{
Reading a File # function body
while IFS="" read MYLINE echo 'This is myfun()'
do Numeric Test Use }
echo "$MYLINE" -eq Equal
done < "somefile.txt" Invoking a function
-gt Greater than
Note: IFS="" preserves whitespace -lt Less than myfun param1 param2
Paul Troncone & Carl Albing, Ph.D. bash Quick Reference https://www.rapidcyberops.com