#!/bin/bash # BlueScan - Escáner de dispositivos Bluetooth # Versión 1.0.6 # by ~aKira~ # akira[ARROBA]debianizado[PUNTO]net # http://debianizado.net/ # PGP Key ID 385E02A5 declare -a Dev Scan Dispositivos Nombre Tiempo BDs Aliases Momentos BOLD="\033[1m" NOBOLD="\033[0m" trap 'Fin' SIGINT ### Funciones ### Inicio () { # Comprobamos las herramientas HCICONFIG="/usr/sbin/hciconfig" if [ -x $HCICONFIG ] then Dev=($($HCICONFIG)) DEV=$(echo ${Dev[0]} | cut -f1 -d ":") else HCICONFIG="/usr/local/sbin/hciconfig" if [ -x $HCICONFIG ] then Dev=($($HCICONFIG)) DEV=$(echo ${Dev[0]} | cut -f1 -d ":") else echo -e Es necesario el paquete "$BOLD"bluez-utils$NOBOLD sleep 2 exit fi fi # Comprobamos si hay adaptador de Bluetooth if [ -z $DEV ] then echo No se ha encontrado un adaptador de Bluetooth en el equipo sleep 2 exit else ADAP=${Dev[5]} # Capturamos la BT_ADDR local fi # Banner clear if [ $(tput cols) -gt 47 ] # Comprobamos el ancho de la ventana then ((COLUMNA=$(tput cols)/2-24)) FILA=1 else echo -e "$BOLD"La ventana es demasiado pequeña$NOBOLD echo -e "$BOLD"BlueScan no se visualizará correctamente$NOBOLD FILA=3 fi tput civis tput cup $FILA $COLUMNA tput setf 3 echo -e "$BOLD"øøøøø BlueScan - Wardriver para Bluetooth øøøøø$NOBOLD ((FILA++)) tput cup $FILA $COLUMNA echo " c0ded by ~aKira~" tput sgr0 echo echo echo -e Usando BD Address $BOLD$ADAP$NOBOLD echo Dispositivos detectados [Ctrl+c para terminar]: echo Timestamp # Inicializamos el contador T_INI=$TIMESTAMP } Hora () { if [ $(date | cut -f4 -d " " | wc -m) != 9 ] then TIME=$(date | cut -f5 -d " ") else TIME=$(date | cut -f4 -d " ") fi } Timestamp () { Hora for ((COUNT=1,UNIDAD=0;COUNT<4;COUNT++,UNIDAD++)) do # Si dejamos que tome valor "0x" no hará bien las operaciones. Si el valor está entre 01-09 tomamos sólo el segundo dígito. if [ $(echo $TIME | cut -f$COUNT -d ":" | cut -b 1) == 0 ] then Tiempo[$UNIDAD]=$(echo $TIME | cut -f$COUNT -d ":" | cut -b 2) else Tiempo[$UNIDAD]=$(echo $TIME | cut -f$COUNT -d ":") fi done # Tiempo[0]==Horas; Tiempo[1]==Minutos; Tiempo[2]==Segundos ((TIMESTAMP=${Tiempo[0]}*3600+${Tiempo[1]}*60+${Tiempo[2]})) } # Discrimina los dispositivos NUM_DISP=0 Discrimina () { FLAG=0 for DISPOS in ${Dispositivos[@]} do if [ "$1" = "$DISPOS" ] then FLAG=1 break fi done if (( !$FLAG )) then Dispositivos[$NUM_DISP]=$1 ((NUM_DISP++)) fi } Imprime () { case $1 in -a) echo echo -en "$BOLD"Dispositivo: $NOBOLD tput setf 3 echo $2;; -b) echo -en "$BOLD"Nombre:$NOBOLD tput setf 3 until [ -z $2 ] do echo -n "$2 " shift done echo;; -c) if [ -z $2 ] # Si no se ha detectado fabricante comprobamos si están activos los servicios de Nokia then NOKIA=$(grep Nokia /tmp/.bs) if [ -z "$NOKIA" ] then FAB="" else FAB="Nokia" fi fi echo -en "$BOLD"Fabricante: $NOBOLD tput setf 3 if [ -z $FAB ] then echo $2 else echo $FAB fi FAB="";; -d) echo -en "$BOLD"Servicios activos: $NOBOLD tput setf 3 until [ -z $2 ] do echo -n "$2 " shift done echo;; -e) echo -en "$BOLD"Canales activos: $NOBOLD tput setf 3 while [ $2 ] do echo -n "$2 " shift done echo;; -f) echo -en "$BOLD"Hora: $NOBOLD tput setf 3 echo $2;; esac tput sgr0 } LOG=0 Log () { ARCHIVO=$HOME/bslog.txt if (( $NUM_DISP )) then echo echo 1. Imprimir log en pantalla echo 2. Exportar log a archivo echo 3. Salir echo echo -n '> ' read OPCION case $OPCION in 1) for ((I=0;I<$LOG;I++)) do echo echo Dispositivo: ${BDs[$I]} echo Nombre:${Aliases[$I]} echo Hora: ${Momentos[$I]} done;; 2) if [ -f $ARCHIVO ] then Timestamp ARCHIVO=$HOME/bslog.$TIMESTAMP.txt fi for ((I=0;I<$LOG;I++)) do echo ------------------------------ >> $ARCHIVO echo Dispositivo: ${BDs[$I]} >> $ARCHIVO echo Nombre:${Aliases[$I]} >> $ARCHIVO echo Hora: ${Momentos[$I]} >> $ARCHIVO echo ------------------------------ >> $ARCHIVO done echo Log exportado a $ARCHIVO sleep 2;; 3) return;; *) Log;; esac fi } # Scanner Scanner () { RETARDO=5 # Retardo que frena el bucle ante un dispositivo permanentemente presente (número de segundos) ((TS2=86400+$RETARDO)) # El valor máximo que puede alcanzar TS1 es 86399+$RETARDO (23:59:59) LOG=0 while [ 1 ] do Timestamp ((TS1=$TIMESTAMP+$RETARDO)) if [ $TS1 -gt $TS2 ] # Si ha pasado menos que RETARDO, esperamos then sleep $RETARDO fi Scan=($(hcitool -i $1 scan)) # $1 es la interfaz hci pasada como Scanner $DEV INI=2 FIN=${#Scan[@]} if [ $FIN -gt $INI ] # Si se detecta algún dispositivo then Timestamp TS2=$TIMESTAMP while [ $INI -lt $FIN ] do BT_ADDR=${Scan[$INI]} Imprime -a $BT_ADDR Discrimina $BT_ADDR BDs[$LOG]=$BT_ADDR ((INI++)) # Si el siguiente elemento del array tiene 18 caracteres, es un dispositivo. # Si no, el nombre es compuesto y se imprime en la misma línea LONG=0 Nombre="" until (( $LONG == 18 || $INI >= $FIN )) do ((SIG=$INI+1)) LONG=$(echo ${Scan[$SIG]} | wc -m) Nombre="${Nombre[@]} ${Scan[$INI]}" if (($LONG == 18 || $SIG == $FIN)) then Imprime -b ${Nombre[@]} Aliases[$LOG]=${Nombre[@]} NOMBRE=${Scan[$INI]} fi ((INI++)) done if [ "$NOMBRE" = "n/a" ] then echo No se han podido detectar datos adicionales else sdptool browse $BT_ADDR > /tmp/.bs Imprime -c $(grep Provider /tmp/.bs | cut -f2 -d ":") Imprime -d $(grep Name /tmp/.bs | cut -f2 -d ":") Imprime -e $(grep Channel /tmp/.bs | cut -f2 -d ":" | sort -n) rm /tmp/.bs fi Hora Imprime -f $TIME Momentos[$LOG]=$TIME ((LOG++)) done fi done } # Conjunto de comandos que se ejecuta al captar la señal SIGINT (ctrl+c) Fin () { Timestamp # Momento en que termina la ejecución del programa ((TIEMPO=$TIMESTAMP-$T_INI)) ((HORAS=$TIEMPO/3600)) ((MIN=($TIEMPO-$HORAS*3600)/60)) ((SEG=($TIEMPO-$HORAS*3600)-$MIN*60)) echo case $NUM_DISP in 0) echo No se han detectado dispositivos;; 1) echo Se ha detectado un dispositivo durante el rastreo;; *) echo -e Se han detectado $BOLD$NUM_DISP$NOBOLD dispositivos durante el rastreo;; esac echo Duración de la sesión: "$HORAS"h "$MIN"m "$SEG"s Log tput cnorm echo exit 0 } Inicio Scanner $DEV # Copyright (C) 2006-2007 ~aKira~ # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # http://www.gnu.org/licenses/