Advertisement
opexxx

smb_check.sh

Jan 7th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. FILE=smb_endpoints
  4. OUT_FILE=smb_check_no_auth
  5. AUTH_FILE=
  6.  
  7. INFO="[ \033[1;33m=\033[0m ] "
  8. SUCCESS="[ \033[1;32m+\033[0m ] "
  9. FAIL="[ \033[1;31m!\033[0m ] "
  10.  
  11. while read p; do
  12.     if [ -z "$AUTH_FILE" ]; then
  13.         echo -e "$INFO Now testing server at $p without credentials"
  14.         COMMAND="smbclient -N -L $p 2>/dev/null"
  15.     else
  16.         echo -e "$INFO Now testing server at $p with credentials from $AUTH_FILE"
  17.         COMMAND="smbclient -L $p -A $AUTH_FILE 2>/dev/null"
  18.     fi
  19.     RESULT=$(eval $COMMAND)
  20.     if [[ $RESULT == *"NT_STATUS_ACCESS_DENIED"* ]]; then
  21.         echo -e "$FAIL Access to server at $p was denied. Continuing."
  22.     elif [[ $RESULT == *"NT_STATUS_LOGON_FAILURE"* ]]; then
  23.         echo -e "$FAIL Log on to server at $p failed. Continuing."
  24.     elif [[ $RESULT == *"NT_STATUS_IO_TIMEOUT"* ]]; then
  25.         echo -e "$FAIL Connection to server at $p timed out. Continuing."
  26.     elif [[ $RESULT == *"NT_STATUS_CONNECTION_REFUSED"* ]]; then
  27.         echo -e "$FAIL Connection to server at $p refused. Continuing."
  28.     elif [[ $RESULT == *"NT_STATUS_ACCOUNT_DISABLED"* ]]; then
  29.         echo -e "$FAIL The account was disabled for connecting to $p. Continuing."
  30.     elif [[ $RESULT == *"NT_STATUS_UNSUCCESSFUL"* ]]; then
  31.         echo -e "$FAIL The connection to $p was unsuccessful. Continuing."
  32.     elif [[ $RESULT == *"NT_STATUS_CONNECTION_DISCONNECTED"* ]]; then
  33.         echo -e "$FAIL The connection to $p was disconnected... Continuing."
  34.     elif [[ $RESULT == *"ERRDOS"* ]]; then
  35.         echo -e "$FAIL Protocol negotiation to $p failed. Continuing."
  36.     else
  37.         echo -e "$SUCCESS Access to server at $p granted!"
  38.         SHARES=$(echo "$RESULT" | awk '/Sharename/,/Server               Comment/' | egrep -v "Sharename       |---|Server               |^$" | grep -v "Anonymous login" | grep -v "NT_STATUS_RESOURCE_NAME_NOT_FOUND" | grep -v "NetBIOS over TCP" | awk '{print $1}')
  39.         while read -r line; do
  40.             if [ -z "$AUTH_FILE" ]; then
  41.                 echo -e "$INFO Testing \\\\\\\\$p\\\\$line without credentials"
  42.                 COMMAND="smbclient -N \\\\\\\\$p\\\\$line -c ls 2>/dev/null"
  43.             else
  44.                 echo -e "$INFO Testing \\\\\\\\$p\\\\$line with credentials from $AUTH_FILE"
  45.                 COMMAND="smbclient -A $AUTH_FILE \\\\\\\\$p\\\\$line -c ls 2>/dev/null"
  46.             fi
  47.             SHARE_RESULT=$(eval $COMMAND)
  48.             echo "$COMMAND" >> smbclient_responses
  49.             echo "$SHARE_RESULT" >> smbclient_responses
  50.             if [[ $SHARE_RESULT == *"NT_STATUS_ACCESS_DENIED"* ]]; then
  51.                 echo -e "$FAIL Access denied to \\\\\\\\$p\\\\$line."
  52.             elif [[ $SHARE_RESULT == *"NT_STATUS_BAD_NETWORK_NAME"* ]]; then
  53.                 echo -e "$FAIL Bad network name error returned when accessing \\\\\\\\$p\\\\$line. Continuing."
  54.             elif [[ $SHARE_RESULT == *"NT_STATUS_IO_TIMEOUT"* ]]; then
  55.                 echo -e "$FAIL Connection to \\\\\\\\$p\\\\$line timed out. Continuing."
  56.             elif [[ $SHARE_RESULT == *"NT_STATUS_WRONG_PASSWORD"* ]]; then
  57.                 echo -e "$FAIL Received wrong password error for \\\\\\\\$p\\\\$line... Weird. Continuing."
  58.             elif [[ $SHARE_RESULT == *"NT_STATUS_NO_MEDIA_IN_DEVICE"* ]]; then
  59.                 echo -e "$FAIL No media found in device at \\\\\\\\$p\\\\$line. Continuing."
  60.             elif [[ $SHARE_RESULT == *"NT_STATUS_LOGON_FAILURE"* ]]; then
  61.                 echo -e "$FAIL Logon failure thrown for \\\\\\\\$p\\\\$line. Continuing."
  62.             elif [[ $SHARE_RESULT == *"NT_STATUS_ACCESS_DENIED"* ]]; then
  63.                 echo -e "$FAIL Access denied for \\\\\\\\$p\\\\$line. Continuing."
  64.             elif [[ $SHARE_RESULT == *"NT_STATUS_NETWORK_ACCESS_DENIED"* ]]; then
  65.                 echo -e "$FAIL Network access denied for \\\\\\\\$p\\\\$line. Continuing."
  66.             elif [[ $SHARE_RESULT == *"NT_STATUS"* ]]; then
  67.                 echo -e "$FAIL Unexpected NT_STATUS error thrown for \\\\\\\\$p\\\\$line. Continuing."
  68.             else
  69.                 echo -e "$SUCCESS Access granted to \\\\\\\\$p\\\\$line!"
  70.                 echo "$p $line \\\\$p\\$line" >> $OUT_FILE
  71.             fi
  72.         done <<< "$SHARES"
  73.     fi
  74. done <$FILE
  75.  
  76. echo -e "$SUCCESS All done! Results written to file at $OUT_FILE. Exiting."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement