Skip to content

Commit

Permalink
add scan writable files and directories
Browse files Browse the repository at this point in the history
added option -p to set spesifict location
  • Loading branch information
DyanGalih committed Dec 22, 2023
1 parent 55e81e7 commit d17ed60
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions exclude_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*-log-*
*.log
log-*
*.log.*
4 changes: 4 additions & 0 deletions exclude_paths.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./cache/*
./upload/*
*.hg/*
*.git/*
45 changes: 36 additions & 9 deletions scan.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
find $path -type f -perm /u=w,g=w,o=w $exclude_paths $exclude_files

0 comments on commit d17ed60

Please sign in to comment.