snip.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. # snip (c) copyright 2000 by plasmoid / thc <plasmoid@pimmel.com>
  3. #
  4. # snippy lil' snip script that shows accessible smb-netbios shares
  5. # in a given ip-range. - requires smbclient and nbtscan.
  6. #
  7. # $Id: snip,v 1.2 2001/04/18 19:17:59 plasmoid Exp $
  8. # set the right paths here, if smbclient and nbtscan are not within your
  9. # path.
  10. SMBCLIENT=smbclient
  11. NBTSCAN=nbtscan
  12. ECHO=echo
  13. if [ "`$ECHO -n`" != "-n" ] ; then
  14. GNUECHO=1
  15. fi
  16. $ECHO "snip (c) copyright 2000 by plasmoid / thc <plasmoid@pimmel.com>"
  17. if [ -z "$*" ] ; then
  18. $ECHO "usage: snip <scan_range>"
  19. $ECHO "<scan_range> what to scan. can either be single IP like "
  20. $ECHO " xxx.xxx.xxx.xxx or range of addresses in one "
  21. $ECHO " of two forms xxx.xxx.xxx.xxx/xx or "
  22. $ECHO " xxx.xxx.xxx.xxx-xxx."
  23. exit
  24. fi
  25. if [ "x$GNUECHO" = "x1" ] ; then
  26. $ECHO -n " - snipping $1: "
  27. else
  28. $ECHO " - snipping $1: \c"
  29. fi
  30. servers=`$NBTSCAN -s : $1 | grep \<server\> | \
  31. sed s/" "/"%"/g | cut -d : -sf 1,2,4`
  32. $ECHO "done."
  33. if [ "x$GNUECHO" = "x1" ] ; then
  34. $ECHO -n " - searching shares: "
  35. else
  36. $ECHO " - searching shares: \c"
  37. fi
  38. for i in $servers ; do
  39. i=`$ECHO $i | sed s/"%"/" "/g`
  40. ip=`$ECHO $i | cut -d : -sf 1`
  41. host=`$ECHO $i | cut -d : -sf 2 | awk '{ print $1 }'`
  42. user=`$ECHO $i | cut -d : -sf 3`
  43. if [ "x$user" = "x<unknown>" ] ; then
  44. smbarg="-I $ip -L $host -N"
  45. else
  46. smbarg="-I $ip -L $host -N -U $user"
  47. fi
  48. output=`$SMBCLIENT $smbarg | grep Disk | awk '{ print $1 }'`
  49. for j in $output ; do
  50. if [ "x$user" = "x<unknown>" ] ; then
  51. result="$result\n$SMBCLIENT //$host/$j -I $ip -N"
  52. else
  53. result="$result\n$SMBCLIENT //$host/$j -I $ip -N -U $user"
  54. fi
  55. done
  56. if [ "x$GNUECHO" = "x1" ] ; then
  57. $ECHO -n "."
  58. else
  59. $ECHO ".\c"
  60. fi
  61. done
  62. $ECHO " done."
  63. $ECHO " - results: "
  64. $ECHO "$result"