From d17ed60b893557b6fa106fc3956a05497f34f35d Mon Sep 17 00:00:00 2001 From: Dyan Galih Date: Fri, 22 Dec 2023 17:10:23 +0700 Subject: [PATCH] add scan writable files and directories added option -p to set spesifict location --- README.md | 7 +++++-- exclude_files.txt | 4 ++++ exclude_paths.txt | 4 ++++ scan.sh | 45 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 exclude_files.txt create mode 100644 exclude_paths.txt diff --git a/README.md b/README.md index 266cb52..63fd5a2 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,13 @@ This bash script reads a list of search strings from a file, searches for these ## Usage -To use this script, you need to call it with the path to the directory you want to search as an argument. For example: +To use this tools, +1. Clone this project or download our last relase +2. call scan.sh with the path option (-p) to the directory you want to search as an argument. +For example: ```bash -bash scan.sh /var/www/html +bash scan.sh -p /var/www/html ``` In this example, the script will search for the strings in the `/var/www/html` directory and its subdirectories. diff --git a/exclude_files.txt b/exclude_files.txt new file mode 100644 index 0000000..af7be79 --- /dev/null +++ b/exclude_files.txt @@ -0,0 +1,4 @@ +*-log-* +*.log +log-* +*.log.* \ No newline at end of file diff --git a/exclude_paths.txt b/exclude_paths.txt new file mode 100644 index 0000000..cbc4131 --- /dev/null +++ b/exclude_paths.txt @@ -0,0 +1,4 @@ +./cache/* +./upload/* +*.hg/* +*.git/* \ No newline at end of file diff --git a/scan.sh b/scan.sh index 5a14711..4309d36 100644 --- a/scan.sh +++ b/scan.sh @@ -1,13 +1,28 @@ #!/bin/bash # Check if an argument was provided -if [ "$#" -ne 1 ]; then - echo "Usage: $0 path" - exit 1 -fi - -# Store the argument into a variable -path=$1 +exclude_paths=() + +while (( "$#" )); do + case "$1" in + -p|--path) + path="$2" + shift 2 + ;; + -e|--exclude-path) + exclude_paths+=("$2") + shift 2 + ;; + --) + shift + break + ;; + *) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done # Read the file list.txt and store each line into the array search_strings readarray -t search_strings < list.txt @@ -65,12 +80,24 @@ if [ ${#unique_grep_results[@]} -ne 0 ]; then done fi +while IFS= read -r line +do + # Adds each path to the exclude variable + exclude_paths="$exclude_paths -not -path '$line/*'" +done < exclude_paths.txt + +while IFS= read -r line +do + # Adds each path to the exclude variable + exclude_files="$exclude_files -not -name '$line/*'" +done < exclude_files.txt + echo "===================================================================================================" echo "writeable folder list:" -find $path -type d -perm /u=w,g=w,o=w +find $path -type d -perm /u=w,g=w,o=w $exclude_paths echo "===================================================================================================" echo "writeable file list:" -find $path -type f -perm /u=w,g=w,o=w \ No newline at end of file +find $path -type f -perm /u=w,g=w,o=w $exclude_paths $exclude_files \ No newline at end of file