[script] IMEI changer

Hi :wave:

I decided to write this script to help with anonymity and bypass ISP restrictions

Copyright:
You are free to use/edit/share script, but always put link to this thread and/or GitHub page

GitHub page

Here

Scripts

Not to overflood thread hidden under spoiler:

V1
#!/bin/bash

echo "Choose an option: 1) Set auto-update of IMEI on boot 2) Change IMEI once 3) Remove automatic change of IMEI"
read -p "Enter your choice (1, 2, or 3): " user_choice

case $user_choice in
    1)
        echo "Setting auto-update script..."
        cat << EOF > /etc/init.d/auto_update_imei.sh
#!/bin/bash

luhn_checksum() {
    local num=\$1
    local sum=0
    local num_length=\${#num}
    for ((i=num_length-1;i>=0;i--)); do
        local digit=\${num:i:1}
        if ((i % 2 == 0)); then
            ((digit *= 2))
            if ((digit > 9)); then
                ((digit -= 9))
            fi
        fi
        ((sum += digit))
    done
    local check_digit=\$((10 - (sum % 10)))
    if ((check_digit == 10)); then
        check_digit=0
    fi
    printf "%d" "\$check_digit"
}

generate_valid_imei() {
    local prefix="\${imei_prefix[\$RANDOM % \${#imei_prefix[@]}]}"
    local suffix=\$(printf "%08d" \$((RANDOM % 10000000)))
    local full_imei="\${prefix}\${suffix}"
    local check_digit=\$(luhn_checksum "\${full_imei}")
    printf "%s%s" "\${full_imei}" "\$check_digit"
}

declare -a imei_prefix=("35674108" "35290611" "35397710" "35323210" "35384110"
                        "35982748" "35672011" "35759049" "35266891" "35407115"
                        "35538025" "35480910" "35324590" "35901183" "35139729"
                        "35479164")

SET_IMEI() {
    local imei="\$1"
    if [[ \${#imei} -eq 15 ]]; then
        gl_modem AT AT+EGMR=1,7,"\${imei}"
    fi
}

start() {
    local imei=\$(generate_valid_imei)
    SET_IMEI "\$imei"
}

stop() {
    :
}
EOF
        chmod +x /etc/init.d/auto_update_imei.sh
        /etc/init.d/auto_update_imei.sh enable
        ;;
    2)
        read -p "Change IMEI automatically or provide a custom one? (auto/custom): " imei_option
        case $imei_option in
            auto)
                imei=$(generate_valid_imei)
                echo "New IMEI: $imei"
                ;;
            custom)
                read -p "Are you sure you want to set a custom IMEI? (y/n): " confirm_custom
                if [[ "$confirm_custom" == "y" ]]; then
                    read -p "Enter your custom IMEI: " custom_imei
                    echo "New IMEI: $custom_imei"
                else
                    imei=$(generate_valid_imei)
                    echo "New IMEI: $imei"
                fi
                ;;
            *)
                echo "Invalid option."
                exit 1
                ;;
        esac
        ;;
    3)
        echo "Removing auto-update of IMEI..."
        rm /etc/init.d/auto_update_imei.sh
        ;;
    *)
        echo "Invalid choice."
        exit 1
        ;;
esac

luhn_checksum() {
    local num=$1
    local sum=0
    local num_length=${#num}
    for ((i=num_length-1;i>=0;i--)); do
        local digit=${num:i:1}
        if ((i % 2 == 0)); then
            ((digit *= 2))
            if ((digit > 9)); then
                ((digit -= 9))
            fi
        fi
        ((sum += digit))
    done
    local check_digit=$((10 - (sum % 10)))
    if ((check_digit == 10)); then
        check_digit=0
    fi
    printf "%d" "$check_digit"
}

generate_valid_imei() {
    local prefix="${imei_prefix[$RANDOM % ${#imei_prefix[@]}]}"
    local suffix=$(printf "%08d" $((RANDOM % 10000000)))
    local full_imei="${prefix}${suffix}"
    local check_digit=$(luhn_checksum "${full_imei}")
    printf "%s%s" "${full_imei}" "${check_digit}"
}

declare -a imei_prefix=("35674108" "35290611" "35397710" "35323210" "35384110"
                        "35982748" "35672011" "35759049" "35266891" "35407115"
                        "35538025" "35480910" "35324590" "35901183" "35139729"
                        "35479164")
V2
#!/bin/sh /etc/rc.common

START=99
STOP=99

luhn_checksum() {
    local num=0
    local nDigits=${#1}
    local odd=$((nDigits % 2))

    for ((i=nDigits-1; i>=0; i--)); do
        local digit=${1:$i:1}
        if ((i % 2 == odd)); then
            ((digit *= 2))
            if ((digit > 9)); then
                ((digit -= 9))
            fi
        fi
        ((num += digit))
    done
    echo "$num"
}

luhn_digit() {
    local num=$(luhn_checksum "$1")
    echo $((10 - (num % 10)))
}

is_valid_luhn() {
    local num=$(luhn_checksum "$1")
    ((num % 10 == 0))
}

generate_valid_imei() {
    local prefix="${imei_prefix[$RANDOM % ${#imei_prefix[@]}]}"
    local suffix=""
    for ((i=0; i<6; i++)); do
        suffix="${suffix}${RANDOM: -1}"
    done
    local full_imei="${prefix}${suffix}"
    local check_digit=$(luhn_digit "${full_imei}")
    echo "${full_imei}${check_digit}"
}

SET_IMEI() {
    local imei="$1"
    if [[ ${#imei} -eq 15 ]]; then
        gl_modem AT AT+EGMR=1,7,"${imei}"
    else
        echo "Invalid IMEI length."
    fi
}

declare -a imei_prefix=("35674108" "35290611" "35397710" "35323210" "35384110"
                        "35982748" "35672011" "35759049" "35266891" "35407115"
                        "35538025" "35480910" "35324590" "35901183" "35139729"
                        "35479164")

start() {
    local imei=$(generate_valid_imei)
    SET_IMEI "$imei"
}

stop() {
    :
}

How to use it?

V1
Just run it :slight_smile:

V2

  1. Put it into
 /etc/init.d/
  1. Make executable
chmod +x /etc/init.d/imei_randomiser.sh
  1. Enable
/etc/init.d/imei_randomiser.sh enable
1 Like

IMEI.info: The Check Digit is a function of all other digits in the IMEI. The purpose of the Check Digit is to help guard against the possibility of incorrect entries to the CEIR and EIR equipment.

Example:
IMEI.info: IMEI: 35145120840121

  1. (5x2, 4x2, 1x2, 0x2, 4x2, 1x2, 1x2) = (10, 8, 2, 0, 8, 2, 2)
  2. (1+0+8+2+0+8+2+2) + (3+1+5+2+8+0+2 ) = 44
  3. Luhn Digit : 6

IMEI: 351451-20-840121-6

I cannot see how in your scripts you are confirming the Luhn Digit?
If you present an invalid IMEI to any equipment that correctly checks for the Luhn Digit you will be blocked and blacklisted.

1 Like

Fixed logic a little. I was testing it in virtual environment, so missed this part.

Hope now everything will work well :slight_smile:

2 Likes