Created
April 5, 2020 12:41
-
-
Save timb-machine/16f236aa53158b7303f100d19b6080ca to your computer and use it in GitHub Desktop.
socky.sh
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/sh | |
| # Not to be confused with https://labs.portcullis.co.uk/tools/unix-socket-scanner/ which does more detailed enumeration but doesn't do permission checks | |
| netstat -an | grep stream | awk '{print $9}' | sort | uniq | egrep -v "vms\/|^$" | while read socketname | |
| do | |
| if [ -n "$(printf "${socketname}" | grep "^/")" ] | |
| then | |
| printf "==\n" | |
| ls -la "${socketname}" | |
| if [ -n "$(ls -la "${socketname}" | grep "s.......w. ")" ] | |
| then | |
| printf "E: ${socketname} is world writable\n" | |
| printf "\n" | |
| printf "QUIT\n" | socat "UNIX:${socketname}" STDIO | |
| else | |
| if [ -n "$(ls -la "${socketname}" | grep "s......r.. ")" ] | |
| then | |
| printf "E: ${socketname} is world readable\n" | |
| printf "\n" | |
| printf "QUIT\n" | socat "UNIX:${socketname}" STDIO | |
| fi | |
| fi | |
| printf "\n" | |
| else | |
| sudo find / -name "${socketname}" -type s 2>/dev/null | while read socketpath | |
| do | |
| printf "==\n" | |
| ls -la "${socketpath}" | |
| if [ -n "$(ls -la "${socketpath}" | grep "s.......w. ")" ] | |
| then | |
| printf "E: ${socketpath} is world writable\n" | |
| printf "\n" | |
| printf "QUIT\n" | socat "UNIX:${socketpath}" STDIO | |
| else | |
| if [ -n "$(ls -la "${socketpath}" | grep "s......r.. ")" ] | |
| then | |
| printf "E: ${socketpath} is world readable\n" | |
| printf "\n" | |
| printf "QUIT\n" | socat "UNIX:${socketpath}" STDIO | |
| fi | |
| fi | |
| printf "\n" | |
| done | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment