Es muy simple, pero me ha llevado mucho (muchisimo) tiempo hacerlo, pues no soy muy amigo de la programación y este ha sido mi primer script

El funcionamiento es muy simple: Cuando abramos el chamac , detectará todas nuestras interfaces, y les cambiará la MAC por una aleatoria. Después relanzará el cliente DHCP (o daemon) para volver a tener conexión a Internet (en el caso de que estuviésemos conectados)
#################################
# Link Oficial del Proyecto #
#################################
Aquí el script: (ultima modificación: 09-10-2013)
Código:
#!/bin/bash
########## Modo DEBUG ##########
## ##
CHAMAC_DEBUG=0
## ##
################################
########## 08-09-2013 Chamac 0.1
##
## #Fecha de Salida
##
########## 10-09-2013 Chamac 0.2
##
## #Detección de clientes DHCP
## #Optimización del código
## #Detección de deaemons de red
## #Aviso de macchanger desactualizado
## #Comprobar permisos root
##
########## 11-09-2013 Chamac 0.3
##
## #Añadido menu de ayuda
## #Posibilidad de ejecutar script con el sistema
## #Eliminada dependencia macchanger, puede funcionar sin el
## #Añadidda posibilidad de usar macchanger si se quisiese
##
########## 12-09-2013 Chamac 0.4
##
## #Corregido bug cuando wicd esta off (gracias a @USUARIONUEVO)
## #Corregido fallo de colores cuando se pedia ser root
## #Añadido menu para restaurar las MAC
## #Añadido menu para ver las MAC actuales
## #Fixedo el archivo que se genera para --autoboot
## #Pequeñas mejoras en el codigo
##
########## 16-09-2013 Chamac 0.5
##
## Reducido información del script ( mas minimalista)
## Modificado representacion de las interfaces
## Añadidas varias rutas alternativas para MAC Permanente
## Corregido codigo de peticion de permisos Root
## Pequeños cambios en el codigo
##
########## 19-09-2013 Chamac 0.6
##
## Arreglado problema de cambios de MAC fallidos
## Añadido comprobador de ruta de chamac
## Optimizado deteccion de daemon
## Agregada salida DEBUG en consola
## Pequeñas optimizaciones en el codigo
## Bug interno de rutas en la opcion -r para autoejecutarse
##
########## 21-09-2013 Chamac 0.7
##
## Eliminadas rutas de /run/udev/data/nX para extraer la MAC Original
## Mejorada función --autostart para sistemas con SUDO
## Añadida opcion para MAC personalizada
## Optimizados mensajes informativos
##
########## 26-09-2013 Chamac 0.8
##
## Corregido bug que no eliminaba la entrada de /etc/sudoers
## Añadido OUI para mostrar el Vendor
## Añadida funcion --update para actualizar la base de deatos OUI
## Añadida database de OUI
## Optimizados mensajes informativos
## Estructurado codigo fuente para mejor comprension
##
########## 03-10-2013 Chamac 0.9
##
## Corregido bug "-i used with no filenames on the command line, reading from STDIN" (@USUARIONUEVO y @alister)
## Mejorado el parseo de datos
## Reducida información que se muestra sobre los Vendor (mas dinamica)
## Añadida opcion --list para mostrar todos los Vendor
## Añadida opcion --ending para mantener los bytes del Fabricante
## Añadida opcion --another para elegir otro Fabricante Aleatorio
## Reducida cantidad de repeticiones para el cambio de MAC de 6 a 3 (parece estable...)
##
########## 09-10-2013 Chamac 0.9-5
##
## Arreglado bug de duplicidad del comando -a
## Arreglado bug de variables en el parametro --another
##
##########
########## Agradecimientos
##
## Me gustaría dar las gracias al equipo de www.seguridadwireless.net por el maravilloso trabajo que estan haciendo.
## En especial, quiero dar las gracias a @USUARIONUEVO por sus inmediatos informes sorbre los bugs del script y consejos
## para el proyecto, a @warcry por el consejo de adaptar el script a mas distros linux, a @geminis_demon por sus ayudas con
## el bash y por ultimo a @alister, por mostrarme datos muy tecnicos de Linux (y necesarios) para desarrollar mi script y
## darme muy buenas ideas para que pueda seguir innovando
##
##########
ruta=$(which $0)
if [ $CHAMAC_DEBUG = 1 ]; then
## set to /dev/stdout when in developer/debugger mode
export chamac_output_device=/dev/stdout
else
## set to /dev/null when in production mode
export chamac_output_device=/dev/null
fi
function conditional_clear() {
if [[ "$chamac_output_device" != "/dev/stdout" ]]; then clear; fi
}
#Detectar interfaces
readarray -t interfaces < <(ip link | grep "<" | cut -d " " -f 2 | cut -d ":" -f 1 | grep -v lo)
#Comprobar estado del autoboot
anothermode=0
endingmode=0
macchangermode=0
custommacmode=0
if [ -f /etc/xdg/autostart/autochamac.desktop ]; then
autoboot=1
else
autoboot=0
fi
#Dar colores al estado del autobbot
if [ $autoboot = 1 ]; then
autobootstatus='\e[1;32mOn\e[0m'
else
autobootstatus='\e[1;31mOff\e[0m'
fi
#Detectar base de datos actual
if [ -f /usr/share/chamac/manuf ]; then
OUIruta="/usr/share/chamac/manuf"
dbMAC=$(cat /usr/share/chamac/manuf |grep ^[0-9A-F] | wc -l)
elif [ -f /etc/manuf ]; then
OUIruta="/etc/manuf"
dbMAC=$(cat /etc/manuf |grep ^[0-9A-F] | wc -l)
elif [ -f /usr/share/wireshark/manuf ]; then
OUIruta="/usr/share/wireshark/manuf"
dbMAC=$(cat /usr/share/wireshark/manuf |grep ^[0-9A-F] | wc -l)
else
OUIruta="N/A"
dbMAC="N/A"
fi
#Menu de ayuda
if [ "$1" = "-v" -o "$1" = "--version" ]; then
echo 0.9-5
exit
elif [ "$1" = "-m" -o "$1" = "--macchanger" ]; then
macchangermode=1
elif [ "$1" = "-e" -o "$1" = "--ending" ]; then
endingmode=1
elif [ "$1" = "-A" -o "$1" = "--another" ]; then
anothermode=1
elif [ "$1" = "-l" -o "$1" = "--list" ]; then
if [ ! $OUIruta = "N/A" ]; then
cat $OUIruta | awk '{ gsub("-", "", $1); gsub(":", "", $1); gsub("/[00-99]+$","",$1 ); gsub(/^ */,"- ", $2); print}' | sed -r 's/\s\S+\s#//' | grep ^[0-9A-F] |grep -n ""| awk '{ gsub(":", " - ", $1); print }'| perl -lane '$F[2] =~ s/(..)(?!$)/$1:/g; print qq|@F|'
else
echo -ne "Chamac Database---> "
echo -e "\e[1;33mNot installed\e[0m (use \e[1;31mchamac --update\e[0m)"
fi
exit
elif [ "$1" = "-u" -o "$1" = "--update" ]; then
if [ $(/usr/bin/id -u) != 0 ]; then
echo -e "Privileges \e[0;31mroot\e[0m---> \e[1;31mError\e[0m"
exit
fi
conditional_clear
echo -ne "Check Internet Connection---> "
if ping -c4 google.es&>$chamac_output_device; then
echo -e "\e[1;32mOK!\e[0m"
sleep 3
if [ ! -d /usr/share/chamac/manuf ]; then
mkdir /usr/share/chamac/ &>${chamac_output_device}
conditional_clear
else
rm -f /usr/share/chamac/manuf &>${chamac_output_device}
fi
wget -O /usr/share/chamac/manuf anonsvn.wireshark.org/wireshark/trunk/manuf |& grep "%"
conditional_clear
$0 -h
else
echo -e "\e[1;31mError\e[0m"
fi
exit
elif [ "$1" = "-s" -o "$1" = "--show" ]; then
conditional_clear
for INTERFACE in ${interfaces[@]}; do
rutasecundaria=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
if [ $rutasecundaria ]; then
MAC_ORIGINAL=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
else
if [ -e /sys/class/net/$INTERFACE/phy80211/addresses ]; then
MAC_ORIGINAL=$(cat /sys/class/net/$INTERFACE/phy80211/addresses)
else
rutaultima=$(ethtool -P $INTERFACE | grep Permanent)
if [ "ethtool -P $INTERFACE | grep Permanent" ]; then
MAC_ORIGINAL=$(ethtool -P $INTERFACE | grep Permanent | awk '{print $3}')
else
MAC_ORIGINAL="??:??:??:??:??:??"
fi
fi
fi
MAC_ACTUAL="$(cat /sys/class/net/$INTERFACE/address)"
if [ ! $OUIruta = "N/A" ]; then
MAC_O="$(echo $MAC_ORIGINAL| tr -d : | tr '[:lower:]' '[:upper:]')"
MAC_A="$(echo $MAC_ACTUAL| tr -d : | tr '[:lower:]' '[:upper:]')"
MAClist=$(cat $OUIruta | awk '$3 == "#"{ gsub("-", "", $1); gsub(":", "", $1); gsub("/[00-99]+$","",$1 ); gsub(/^ */,"", $1); {t=$1; $1=$2=$3=""; sub(/^[[:space:]]+/, ""); $0=t" "$0}; print}')
i=6
while [ $i -le 12 ]; do
SEARCHING_RESULT_o=$(echo "$MAClist" |grep ^${MAC_O:0:i})
SEARCHING_EXITCODE_o=$?
lineas_o=$(echo "$SEARCHING_RESULT_o" | wc -l)
if [ "$lineas_o" = 1 ]; then
if [ "$SEARCHING_EXITCODE_o" = 0 ]; then
FABRICANTE_MAC_ORIGINAL=$(echo "$SEARCHING_RESULT_o"|cut -d " " -f 2-22)
fi
fi
SEARCHING_RESULT=$(echo "$MAClist" |grep ^${MAC_A:0:i})
SEARCHING_EXITCODE=$?
lineas=$(echo "$SEARCHING_RESULT" | wc -l)
if [ "$lineas" = 1 ]; then
if [ "$SEARCHING_EXITCODE" = 0 ]; then
FABRICANTE_MAC_FALSA="(\e[1;34m$(echo "$SEARCHING_RESULT"|cut -d " " -f 2-22)\e[0m)"
fi
break
fi
let i=i+1
done
else
FABRICANTE_MAC_ORIGINAL="\e[1;31mN/A\e[0m"
FABRICANTE_MAC_ORIGINAL="\e[1;31mN/A\e[0m"
fi
if [ -z "$FABRICANTE_MAC_ORIGINAL" ]; then
FABRICANTE_MAC_ORIGINAL="unknown"
fi
if [ "$FABRICANTE_MAC_FALSA" = "($FABRICANTE_MAC_ORIGINAL)" ]; then
FABRICANTE_MAC_FALSA=""
fi
echo "======================================================\\"
echo -e " INTERFACE:\e[1;35m $INTERFACE \e[0m"
echo -e " FABRICANTE: \e[1;34m$FABRICANTE_MAC_ORIGINAL\e[0m"
echo -e "MAC ORIGINAL: $MAC_ORIGINAL "
echo -e " MAC ACTUAL: \e[1;31m$MAC_ACTUAL\e[0m $FABRICANTE_MAC_FALSA"
echo "======================================================/"
done
exit
elif [ "$1" = "-r" -o "$1" = "--restore" ]; then
if [ $(/usr/bin/id -u) != 0 ]; then
echo -e "Privileges \e[0;31mroot\e[0m---> \e[1;31mError\e[0m"
exit
fi
conditional_clear
#Definir clientes DHCP
if ps -A | grep dhcpcd &>${chamac_output_device}; then
dhcpclientrestore=dhcpcd
fi
if ps -A | grep dhclient &>${chamac_output_device}; then
dhcpclientrestore=dhclient
fi
if ps -A | grep pump &>${chamac_output_device}; then
dhcpclientrestore=pump
fi
#Comprobar el daemon del sistema
readarray -t listadedaemons < <(echo "/etc/rc.d/rc.inet1
/etc/rc.d/wicd
/etc/rc.d/rc.wicd
/etc/rc.d/network-manager
/etc/rc.d/rc.network-manager
/etc/init.d/wicd
/etc/init.d/network-manager")
for comprobandodaemon in ${listadedaemons[@]}; do
if [ -e "$comprobandodaemon" ]; then
chamac_detected_daemon="$comprobandodaemon"
break
fi
done
if [[ "${chamac_detected_daemon}" != "" ]]; then
"$chamac_detected_daemon" stop &>${chamac_output_device}
else
killall -9 wpa_supplicant &>$chamac_output_device
killall -9 $dhcpclient &>$chamac_output_device
fi
#Comprobar las MAC
for INTERFACE in ${interfaces[@]}; do
rutasecundaria=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
if [ $rutasecundaria ]; then
MAC_ORIGINAL=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
else
if [ -e /sys/class/net/$INTERFACE/phy80211/addresses ]; then
MAC_ORIGINAL=$(cat /sys/class/net/$INTERFACE/phy80211/addresses)
else
rutaultima=$(ethtool -P $INTERFACE | grep Permanent)
if [ "ethtool -P $INTERFACE | grep Permanent" ]; then
MAC_ORIGINAL=$(ethtool -P $INTERFACE | grep Permanent | awk '{print $3}')
else
MAC_ORIGINAL="??:??:??:??:??:??"
fi
fi
fi
while [ "$MAC_ORIGINAL" != "$MAC_ACTUAL" ]; do
ifconfig $INTERFACE down &>${chamac_output_device}
ip link set $INTERFACE address $MAC_ORIGINAL &>${chamac_output_device}
ifconfig $INTERFACE up &>${chamac_output_device}
break && $0 -r
conditional_clear
done
done
#Reiniciar las daemons
if [ "$chamac_detected_daemon" != "" ]; then
"$chamac_detected_daemon" start &>${chamac_output_device}
else
#Reiniciar posible servicio DHCP
if [ "$chamac_detected_daemon" == "" ]; then
if [ $dhcpclient ]; then
sleep 2
$dhcpclient &>${chamac_output_device}
fi
fi
fi
$0 -s
exit
elif [ "$1" = "-a" -o "$1" = "--autostart" ]; then
conditional_clear
echo -ne "Privileges \e[0;31mroot\e[0m---> "
if [ $(/usr/bin/id -u) = 0 ]; then
echo -e "\e[1;32mOK!\e[0m"
else
echo -e "\e[1;31mError\e[0m"
exit
fi
echo -ne "Chamac \e[0;31minstalldir\e[0m---> "
if [ $ruta = /usr/bin/chamac ]; then
echo -e "\e[1;32mOK!\e[0m"
else
echo -e "\e[1;31mError\e[0m"
echo
echo -e "Use \e[1;33mcp chamac /usr/bin/\e[0m"
exit
fi
echo -ne "Does \e[0;31mSUDO\e[0m system exist? ---> "
if [ $autoboot = 1 ]; then
rm -f /etc/xdg/autostart/autochamac.desktop
sed -i '/\/usr\/bin\/chamac/d' /etc/sudoers
if [ -f /etc/sudoers ]; then
echo -e "\e[1;32mYes\e[0m"
else
echo -e "\e[1;31mNo\e[0m"
fi
elif [ $autoboot = 0 ]; then
echo "[Desktop Entry]
Exec=/usr/bin/chamac
StartupNotify=true
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true"> /etc/xdg/autostart/autochamac.desktop
if [ -f /etc/sudoers ]; then
echo -e "\e[1;32mYes\e[0m"
echo "$(logname) ALL=(root) NOPASSWD: /usr/bin/chamac" >>/etc/sudoers
perl -pi -e 's/\/usr\/bin\/chamac/sudo \/usr\/bin\/chamac/g' /etc/xdg/autostart/autochamac.desktop
else
echo -e "\e[1;31mNo\e[0m"
fi
fi
echo
$0 -h
echo
echo -e "Ten en cuenta que tendras que dar los permisos necesarios para que el script se ejecute como \e[1;31mroot\e[0m junto con el sistema, sino, no tendra efecto"
exit
elif [ "$1" = "-M" -o "$1" = "--MAC" ]; then
echo -ne "Privileges \e[0;31mroot\e[0m---> "
if [ $(/usr/bin/id -u) = 0 ]; then
echo -e "\e[1;32mOK!\e[0m"
else
echo -e "\e[1;31mError\e[0m"
exit
fi
custommac="$(echo $2 | grep -oiE '([0-9A-F]{2}:){5}[0-9A-F]{2}$')"
if [ $custommac ]; then
custommacmode=1
elif [ -z $2 ]; then
echo -e "No se ha especificado ninguna \e[1;31mMAC\e[0m"
exit
else
echo -e "La MAC \e[1;31m$2\e[0m no es una \e[1;31mMAC\e[0m valida"
exit
fi
elif [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "Chamac v0.9-5 (Change all MAC)"
echo "Uso: chamac [options]"
echo
echo " -a, --autostart Inicia el script con el sistema"
echo -e " Estado actual: $autobootstatus"
echo " -u, --update Actualiza la Base de Datos MAC"
echo -e " Base Actual: \e[1;31m$dbMAC\e[0m"
echo " -m, --macchanger Usar macchanger para generar MAC"
echo " -M, --MAC XX:XX:XX:XX:XX:XX Usa la MAC XX:XX:XX:XX:XX:XX"
echo " -e, --ending Mantener bytes del fabricante"
echo " -A, --another Usar MAC de otro fabricante"
echo " -r, --restore Restaura las MAC Original"
echo " -s, --show Muestra todas las MAC"
echo " -l, --list Muestra todos los Fabricantes"
echo
echo " -h, --help Muestra la pantalla de ayuda"
echo " -v, --version Muestra la version de la herramienta"
echo
echo "Reporta los fallos a vk18496@gmail.com"
exit
fi
let totalmode=$anothermode+$endingmode+$macchangermode+$custommacmode
conditional_clear
echo -e "=========================================="
echo -e "| \e[1;34mChaMAC\e[0m 0.9-5 by vk496 |"
echo -e "| |"
echo -e "| netenti.blogspot.com |"
echo -e "| |"
echo -e "| Pequeño script para cambiar todas |"
echo -e "| las direcciones MAC de tu PC por unas |"
echo -e "| aleatorias. Usa \e[1;32mchamac --help\e[0m para |"
echo -e "| mas info. |"
echo -e "| |"
echo -e "| Para \e[1;31mwww.seguridadwireless.net\e[0m |"
echo -e "=========================================="
echo -e
echo
# Comprobar que macchanger esta actulizado
# 53 lineas = vieja
# 52 lineas = version Ubuntu
# 219 lineas =version 2013
echo -ne "Privileges \e[0;31mroot\e[0m---> "
if [ $(/usr/bin/id -u) = 0 ]; then
echo -e "\e[1;32mOK!\e[0m"
else
echo -e "\e[1;31mError\e[0m"
exit
fi
echo -ne "Chamac \e[0;31minstalldir\e[0m---> "
if [ $ruta = /usr/bin/chamac ]; then
echo -e "\e[1;32mOK!\e[0m"
else
echo -e "\e[1;31mError\e[0m"
echo
echo -e "Use \e[1;33mcp chamac /usr/bin/\e[0m"
exit
fi
echo -ne "Autoboot Status---> "
if [ $autoboot = 1 ]; then
echo -e "$autobootstatus"
elif [ $autoboot = 0 ]; then
echo -e "$autobootstatus"
fi
echo -ne "Chamac Database---> "
if [ $dbMAC = "N/A" ]; then
echo -e "\e[1;33mNot installed\e[0m (use \e[1;31mchamac --update\e[0m)"
else
echo -e "\e[1;32mOK!\e[0m"
echo -e " Database: \e[1;31m$dbMAC\e[0m"
fi
echo -ne "Chamac Mode-------> "
if [ $macchangermode = 1 ]; then
echo -e "\e[1;32mMacchanger\e[0m"
if type macchanger &>${chamac_output_device}; then
echo -ne "\e[0;31mmacchanger\e[0m Status-> "
if [ $(cat $(which macchanger) | wc -l) = 53 ]; then
echo -e "\e[1;33mObsoleted\e[0m"
macchangerviejo=1
else
echo -e "\e[1;32mOK!\e[0m"
macchangerviejo=0
fi
else
echo -e "\e[1;31mNot installed!\e[0m"
exit
fi
elif [ $custommacmode = 1 ]; then
echo -e "\e[1;32mCustom\e[0m"
elif [ $endingmode = 1 ]; then
echo -e "\e[1;32mEnding\e[0m"
elif [ $anothermode = 1 ]; then
echo -e "\e[1;32mAnother\e[0m"
if [ "$OUIruta" = "N/A" ]; then
echo
echo -e "\e[1;31mDatabase not installed!\e[0m"
exit
fi
elif [ $totalmode = 0 ]; then
echo -e "\e[1;32mNormal\e[0m"
fi
#Buscar posibles clientes DHCP
clientesdhcp() {
if ps -A | grep dhcpcd &>${chamac_output_device}; then
dhcpclient=dhcpcd
fi
if ps -A | grep dhclient &>${chamac_output_device}; then
dhcpclient=dhclient
fi
if ps -A | grep pump &>${chamac_output_device}; then
dhcpclient=pump
fi
}
#Comprobar el daemon del sistema
clientedaemon() {
readarray -t listadedaemons < <(echo "/etc/rc.d/rc.inet1
/etc/rc.d/wicd
/etc/rc.d/rc.wicd
/etc/rc.d/network-manager
/etc/rc.d/rc.network-manager
/etc/init.d/wicd
/etc/init.d/network-manager")
for comprobandodaemon in ${listadedaemons[@]}; do
if [ -e "$comprobandodaemon" ]; then
chamac_detected_daemon="$comprobandodaemon"
break
fi
done
if [[ "${chamac_detected_daemon}" != "" ]]; then
"$chamac_detected_daemon" stop &>${chamac_output_device}
else
killall -9 wpa_supplicant &>$chamac_output_device
killall -9 $dhcpclient &>$chamac_output_device
fi
detectarmac
}
detectarmac() {
lista=$(echo ${interfaces[@]} | wc -w)
echo
echo -e "Network inteface/s: \e[0;31m$lista\e[0m "
echo
echo -e "\e[1;31m${interfaces[@]}\e[0m"
echo
echo
sleep 3
cambiarmac
}
cambiarmac() {
mac() {
#Cambiar MAC con ifconfig
viaifconfig() {
for (( c=1; c<=3; c++ ))
do
for INTERFACE in ${interfaces[@]}; do
MAC_ACTUAL="$(cat /sys/class/net/$INTERFACE/address)"
until [ -N $MAC_ACTUAL ]; do
ifconfig $INTERFACE down &>${chamac_output_device}
ip link set $INTERFACE down &>${chamac_output_device}
if [ $endingmode = 1 ]; then
rutasecundaria=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
if [ $rutasecundaria ]; then
MAC_ORIGINAL=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
else
if [ -e /sys/class/net/$INTERFACE/phy80211/addresses ]; then
MAC_ORIGINAL=$(cat /sys/class/net/$INTERFACE/phy80211/addresses)
else
rutaultima=$(ethtool -P $INTERFACE | grep Permanent)
if [ "ethtool -P $INTERFACE | grep Permanent" ]; then
MAC_ORIGINAL=$(ethtool -P $INTERFACE | grep Permanent | awk '{print $3}')
else
MAC_ORIGINAL="??:??:??:??:??:??"
fi
fi
fi
ip link set dev $INTERFACE address $(echo "$(echo $MAC_ORIGINAL| tr -d : |cut -c 1-6)$(openssl rand -hex 3)"| sed 's/\(..\)/\1:/g; s/.$//') &>${chamac_output_device}
fi
if [ $custommacmode = 1 ]; then
ip link set dev $INTERFACE address $custommac &>${chamac_output_device}
echo $custommac &>${chamac_output_device}
fi
if [ $anothermode = 1 ]; then
listado=$(cat $OUIruta | awk '{ gsub("-", "", $1); gsub(":", "", $1); gsub("/[00-99]+$","",$1 ); print $1}' | grep ^[0-9A-F] | grep -v ^FFFFFFFFFFFF | shuf -n 1)
let anotherMACrandom=12-$(echo $listado | wc -L)
ip link set dev $INTERFACE address $(echo "$(echo $listado)$(echo $(< /dev/urandom tr -dc A-F0-9 | head -c$anotherMACrandom))"| sed 's/\(..\)/\1:/g; s/.$//') &>${chamac_output_device}
fi
if [ $totalmode = 0 ]; then
ip link set dev $INTERFACE address $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//') &>${chamac_output_device}
fi
break
conditional_clear
done
done
done
}
#Cmabar MAC con macchanger
viamacchanger() {
for interfaz in "${interfaces[@]}"; do
ifconfig $interfaz down &>${chamac_output_device}
ip link set $interfaz down &>${chamac_output_device}
macchanger -r $interfaz &>${chamac_output_device}
done
}
if [ $macchangermode = 0 ]; then
viaifconfig
elif [ $macchangermode = 1 ]; then
viamacchanger
fi
conditional_clear
interfacesup
}
interfacesup() {
#Levantar interfaces
for curInterfaceup in "${interfaces[@]}"; do
ifconfig $curInterfaceup up &>${chamac_output_device}
ip link set $curInterfaceup up &>${chamac_output_device}
done
listo
}
mac
}
listo() {
for INTERFACE in ${interfaces[@]}; do
rutasecundaria=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
if [ $rutasecundaria ]; then
MAC_ORIGINAL=$(cat /etc/udev/rules.d/70-persistent-net.rules | grep $INTERFACE | awk '{print $4}' | grep -o -P '(?<=").*(?=")')
else
if [ -e /sys/class/net/$INTERFACE/phy80211/addresses ]; then
MAC_ORIGINAL=$(cat /sys/class/net/$INTERFACE/phy80211/addresses)
else
rutaultima=$(ethtool -P $INTERFACE | grep Permanent)
if [ "ethtool -P $INTERFACE | grep Permanent" ]; then
MAC_ORIGINAL=$(ethtool -P $INTERFACE | grep Permanent | awk '{print $3}')
else
MAC_ORIGINAL="??:??:??:??:??:??"
fi
fi
fi
MAC_ACTUAL="$(cat /sys/class/net/$INTERFACE/address)"
if [ ! $OUIruta = "N/A" ]; then
MAC_O="$(echo $MAC_ORIGINAL| tr -d : | tr '[:lower:]' '[:upper:]')"
MAC_A="$(echo $MAC_ACTUAL| tr -d : | tr '[:lower:]' '[:upper:]')"
MAClist=$(cat $OUIruta | awk '$3 == "#"{ gsub("-", "", $1); gsub(":", "", $1); gsub("/[00-99]+$","",$1 ); gsub(/^ */,"", $1); {t=$1; $1=$2=$3=""; sub(/^[[:space:]]+/, ""); $0=t" "$0}; print}')
i=6
while [ $i -le 12 ]; do
SEARCHING_RESULT_o=$(echo "$MAClist" |grep ^${MAC_O:0:i})
SEARCHING_EXITCODE_o=$?
lineas_o=$(echo "$SEARCHING_RESULT_o" | wc -l)
if [ "$lineas_o" = 1 ]; then
if [ "$SEARCHING_EXITCODE_o" = 0 ]; then
FABRICANTE_MAC_ORIGINAL=$(echo "$SEARCHING_RESULT_o"|cut -d " " -f 2-22)
fi
fi
SEARCHING_RESULT=$(echo "$MAClist" |grep ^${MAC_A:0:i})
SEARCHING_EXITCODE=$?
lineas=$(echo "$SEARCHING_RESULT" | wc -l)
if [ "$lineas" = 1 ]; then
if [ "$SEARCHING_EXITCODE" = 0 ]; then
FABRICANTE_MAC_FALSA="(\e[1;34m$(echo "$SEARCHING_RESULT"|cut -d " " -f 2-22)\e[0m)"
fi
break
fi
let i=i+1
done
else
FABRICANTE_MAC_ORIGINAL="\e[1;31mN/A\e[0m"
FABRICANTE_MAC_ORIGINAL="\e[1;31mN/A\e[0m"
fi
if [ -z "$FABRICANTE_MAC_ORIGINAL" ]; then
FABRICANTE_MAC_ORIGINAL="unknown"
fi
if [ "$FABRICANTE_MAC_FALSA" = "($FABRICANTE_MAC_ORIGINAL)" ]; then
FABRICANTE_MAC_FALSA=""
fi
echo "======================================================\\"
echo -e " INTERFACE:\e[1;35m $INTERFACE \e[0m"
echo -e " FABRICANTE: \e[1;34m$FABRICANTE_MAC_ORIGINAL\e[0m"
echo -e "MAC ORIGINAL: $MAC_ORIGINAL "
echo -e " MAC ACTUAL: \e[1;31m$MAC_ACTUAL\e[0m $FABRICANTE_MAC_FALSA"
echo "======================================================/"
done
echo
if [ $custommacmode = 1 ]; then
echo -e "Nota: Hay direcciones \e[1;31mMAC\e[0m que \e[1;31mNO\e[0m se pueden usar (si eso pasa, prueba con otra \e[1;31mMAC\e[0m)"
fi
echo
echo -e "\e[1;36mReiniciando interfaces y DHCP\e[0m ... "
sleep 3
echo -e "Mediante \e[1;33mifconfig\e[0m podras comprobar que la mac realmente ha cambiado."
if [ "$chamac_detected_daemon" != "" ]; then
echo -e "Iniciando servcio \e[1;31m${chamac_detected_daemon}\e[0m"
"$chamac_detected_daemon" start &>${chamac_output_device}
else
#Reiniciar posible servicio DHCP
if [ "$chamac_detected_daemon" == "" ]; then
if [ $dhcpclient ]; then
sleep 2
$dhcpclient &>${chamac_output_device}
echo -e "Cliente \e[1;31m$dhcpclient\e[0m reiniciado"
fi
fi
fi
echo
echo -e "Recuerda revisar las demas opciones con \e[1;32mchamac --help\e[0m"
echo
echo -e "Tareas realizadas ... Hasta pronto :)"
exit
}
clientesdhcp && clientedaemon
Para instalarlo, tenemos que crear un archivo con el nombre chamac.
Después, darle permisos de ejecución:
Código:
chmod +x chamac
Y por ultimo, copiar el script a /usr/bin con:
Código:
cp chamac /usr/bin/
Espero que puedan apreciar la obra maestra de un novato


Salu2