(https://www.arg-wireless.com.ar/proxy.php?request=http%3A%2F%2F1.bp.blogspot.com%2F-XsoWJJjF5Js%2FUkSL2ariHrI%2FAAAAAAAAA5k%2F7bQTxrBGjfU%2Fs400%2Fchange-mac-address.jpg&hash=b0196db1cf7eea815409bd734ff1f67ae29e5e2e)
Antes de explicar nada, vamos a definir lo que es la MAC:
La dirección MAC (siglas en inglés de media access control; en español "control de acceso al medio") es un identificador de 48 bits (6 bloques hexadecimales) que corresponde de forma única a una tarjeta o dispositivo de red. Se conoce también como dirección física, y es
ÚNICA para cada dispositivo.
Las direcciones MAC son únicas a nivel mundial, puesto que son escritas directamente, en forma binaria, en el hardware en su momento de fabricación.
A pesar de eso, el sistema (en Linux, concretamente el kernel) es el que se encarga de gestionarla, por tanto, se puede cambiar muy fácilmente con el comando ifconfig.
Hace más de una vez que he usado macchanger (herramienta casi "universal en linux) para cambiar la MAC, y lo que más me incomodaba era tener que hacer ifconfig down, usar macchanger y por último ifconfig up sobre cualquier interfaz que quisiese, lo que me venía a la cabeza: ¿Que será del pobre que tenga que hacer eso para 4 o 5 tarjetas de red?
Por eso, con un poco de tiempo libre, decidí adentrarme en el mundo del bash y crear mi propio script que detectase todos las interfaces para cambiarles la MAC por una aleatoria.
(https://www.arg-wireless.com.ar/proxy.php?request=http%3A%2F%2F2.bp.blogspot.com%2F-sRa_3e0gFuQ%2FUkSOBmokSZI%2FAAAAAAAAA5w%2FH7dDEXjh0ZI%2Fs400%2Fchamac1.png&hash=67fead8441830ce2ad370f9f91a3b2f1f3207bc1)
El funcionamiento del script es muy simple, solo tenéis que bajar el código que hay a continuación y ponerlo dentro de la ruta
/usr/bin/ con el nombre de
chamac y con los permisos necesarios:
chmod +x chamac
cp chamac /usr/bin/Actualización 03-10-2013 v0.9
Le he hecho mas ajustes al chamac, añadiéndole opciones mas interesantes y arreglado algunas cosillas para que vaya mas rapido.
(https://www.arg-wireless.com.ar/proxy.php?request=http%3A%2F%2F1.bp.blogspot.com%2F-kiZBaSl8UlU%2FUk2obUOgScI%2FAAAAAAAAA6A%2FQgFmzZ7Jdh4%2Fs400%2Fchamac2.png&hash=d7db025355019efaf6705bd90d98aa26734d5319)
Changelog:########## 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...)
##
##########Código Fuente:#!/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
##
##########
########## 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
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 -v ^[#] | wc -l)
elif [ -f /etc/manuf ]; then
OUIruta="/etc/manuf"
dbMAC=$(cat /etc/manuf | grep -v ^[#] | wc -l)
elif [ -f /usr/share/wireshark/manuf ]; then
OUIruta="/usr/share/wireshark/manuf"
dbMAC=$(cat /usr/share/wireshark/manuf | grep -v ^[#] | wc -l)
else
OUIruta="N/A"
dbMAC="N/A"
fi
#Menu de ayuda
if [ "$1" = "-v" -o "$1" = "--version" ]; then
echo 0.8
exit
elif [ "$1" = "-m" -o "$1" = "--macchanger" ]; then
macchangermode=1
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_A="$(echo $MAC_ACTUAL| tr -d :)"
MAC_O="$(echo $MAC_ORIGINAL| tr -d :)"
MAClist=$(cat $OUIruta | sed 's/\t/ /g' | awk '{ gsub("-", "", $1); gsub(":", "", $1); gsub("/44", "", $1); gsub("/40", "", $1); gsub("/36", "", $1); gsub("/32", "", $1); gsub("/25", "", $1); gsub("/24", "", $1); gsub("/16", "", $1); gsub(/[ ]+/," "); print }')
i=6
while [ $i -le 12 ]; do
SEARCHING_RESULT_o=$(echo "$MAClist" |grep -i ^${MAC_O:0:i}|perl -pi -e 's/#/\e[0m\e[1;31m-\e[0m\e[1;34m/g')
SEARCHING_EXITCODE_o=$?
lineas_o=$(echo "$SEARCHING_RESULT_o" | grep -c "")
if [ "$lineas_o" = 1 ]; then
if [ "$SEARCHING_EXITCODE_o" = 0 ]; then
FABRICANTE_MAC_ORIGINAL="(\e[1;34m$(echo "$SEARCHING_RESULT_o"|cut -d " " -f 2-22)\e[0m)"
fi
fi
SEARCHING_RESULT=$(echo "$MAClist" |grep -i ^${MAC_A:0:i}|perl -pi -e 's/#/-/g')
SEARCHING_EXITCODE=$?
lineas=$(echo "$SEARCHING_RESULT" | grep -c "")
if [ "$lineas" = 1 ]; then
if [ "$SEARCHING_EXITCODE" = 0 ]; then
FABRICANTE_MAC_FALSA=$(echo "$SEARCHING_RESULT"|cut -d " " -f 2-22)
fi
break
fi
if [ $i -eq 12 ]; then
echo unknown
fi
let i=i+1
done
else
FABRICANTE_MAC_FALSA="\e[1;31mN/A\e[0m"
FABRICANTE_MAC_ORIGINAL="(\e[1;31mN/A\e[0m)"
fi
if [ -z "$FABRICANTE_MAC_FALSA" ]; then
FABRICANTE_MAC_FALSA="unknown"
fi
echo "=================================================\\"
echo -e " INTERFACE:\e[1;35m $INTERFACE \e[0m "
echo -e "MAC ORIGINAL: $MAC_ORIGINAL $FABRICANTE_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.8 (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 " -r, --restore Restaura las MAC Original"
echo " -s, --show Muestra todas las MAC"
echo " -h, --help Muestra la pantalla de ayuda"
echo " -v, --version Muestra la version de la herramienta"
echo " -M, --MAC XX:XX:XX:XX:XX:XX Usa la MAC XX:XX:XX:XX:XX:XX"
echo
echo "Reporta los fallos a vk18496@gmail.com"
exit
fi
conditional_clear
echo -e "=========================================="
echo -e "| \e[1;34mChaMAC\e[0m 0.8 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 [ $macchangermode = 0 ]; then
if [ $custommacmode = 1 ]; then
echo -e "\e[1;32mCustom\e[0m"
else
echo -e "\e[1;32mNormal\e[0m"
fi
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<=6; 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 [ $custommacmode = 0 ]; then
ip link set dev $INTERFACE address $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//') &>${chamac_output_device}
elif [ $custommacmode = 1 ]; then
ip link set dev $INTERFACE address $custommac &>${chamac_output_device}
echo $custommac &>${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_A="$(echo $MAC_ACTUAL| tr -d :)"
MAC_O="$(echo $MAC_ORIGINAL| tr -d :)"
MAClist=$(cat $OUIruta | sed 's/\t/ /g' | awk '{ gsub("-", "", $1); gsub(":", "", $1); gsub("/44", "", $1); gsub("/40", "", $1); gsub("/36", "", $1); gsub("/32", "", $1); gsub("/25", "", $1); gsub("/24", "", $1); gsub("/16", "", $1); gsub(/[ ]+/," "); print }')
i=6
while [ $i -le 12 ]; do
SEARCHING_RESULT_o=$(echo "$MAClist" |grep -i ^${MAC_O:0:i}|perl -pi -e 's/#/\e[0m\e[1;31m-\e[0m\e[1;34m/g')
SEARCHING_EXITCODE_o=$?
lineas_o=$(echo "$SEARCHING_RESULT_o" | grep -c "")
if [ "$lineas_o" = 1 ]; then
if [ "$SEARCHING_EXITCODE_o" = 0 ]; then
FABRICANTE_MAC_ORIGINAL="(\e[1;34m$(echo "$SEARCHING_RESULT_o"|cut -d " " -f 2-22)\e[0m)"
fi
fi
SEARCHING_RESULT=$(echo "$MAClist" |grep -i ^${MAC_A:0:i}|perl -pi -e 's/#/-/g')
SEARCHING_EXITCODE=$?
lineas=$(echo "$SEARCHING_RESULT" | grep -c "")
if [ "$lineas" = 1 ]; then
if [ "$SEARCHING_EXITCODE" = 0 ]; then
FABRICANTE_MAC_FALSA=$(echo "$SEARCHING_RESULT"|cut -d " " -f 2-22)
fi
break
fi
if [ $i -eq 12 ]; then
echo unknown
fi
let i=i+1
done
else
FABRICANTE_MAC_FALSA="\e[1;31mN/A\e[0m"
FABRICANTE_MAC_ORIGINAL="(\e[1;31mN/A\e[0m)"
fi
if [ -z "$FABRICANTE_MAC_FALSA" ]; then
FABRICANTE_MAC_FALSA="unknown"
fi
echo "=================================================\\"
echo -e " INTERFACE:\e[1;35m $INTERFACE \e[0m "
echo -e "MAC ORIGINAL: $MAC_ORIGINAL $FABRICANTE_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 && clientedaemonDescargar ChaMAC 0.8https://mega.co.nz/#!6IlyUTKb!C58m12YlY6DoUlcbyZ1FxBbW7tQqokqRuJr80Pwh_WI
Descargar ChaMAC 0.9https://sites.google.com/site/blognetenti/chamac