Created
October 3, 2020 23:59
-
-
Save 3lpsy/0cf7967aaaea1fe2e76f77689ebcf5c2 to your computer and use it in GitHub Desktop.
Parse smbmap.py Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# I've writte a lot of bad bash scripts in my day. This may be the worst one. | |
# smbmap.py's output must not have colores (overwrite 'colored' function to return first arg) | |
# and the 'Working on it' message must also not exist. There's a fork on GH that adds --no-color and --no-update | |
IP="" | |
SHARE="" | |
PERMS="" | |
FOUND=0 | |
data="$(cat $1)" | |
while read p; do | |
if [[ ${#p} -gt 5 && $(echo -n "$p" | grep -v '\-\-\-\-\-\-') && $(echo -n "$p" | grep -v 'Working on it') && $(echo -n "$p" | grep -v "Permissions") ]]; then | |
if [[ $(echo -n "$p" | grep 'Name: ') ]]; then | |
IP=$(echo -n "$p" | awk '$1=$1' | cut -d ' ' -f3 | cut -d ':' -f1); | |
NAME=$(echo -n "$p" | awk '$1=$1' | cut -d ' ' -f5); | |
FOUND=1 | |
elif [ $FOUND -eq 1 ]; then | |
SHARE=$(echo -n "$p" | awk '$1=$1' | sed -E 's#READ.*$##' | sed -E 's#WRITE.*$##' | sed 's#NO ACCESS#NOACCESS#g' | sed -E 's#NOACCESS.*$##' | awk '$1=$1' | cut -d ' ' -f1-) | |
#echo "Share: $SHARE"; | |
PERMS_COM=$(echo -n "$p" | awk '$1=$1' | sed "s#${SHARE}##" | sed 's#READ ONLY#READ_ONLY#g' | sed 's#NO ACCESS#NO_ACCESS#g' | sed 's#READ, WRITE#READ_WRITE#g' | cut -d ' ' -f2) | |
#echo "Perms: $PERMS_COM" | |
echo "${IP}:${NAME}:${SHARE}:${PERMS_COM}" | |
fi | |
fi | |
done <$1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment