Hold Tight...

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    ::0
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Gambas
PHP
Delphi
Bash
  • Cybersecurity
  • Generative AI
  • Cloud & Automation
  • Cryptocurrency

Simplify Linux ID Generation for Fast, Unique IDs

23/10/2024

Enhance Anonymity with the Ultimate Bash ID Generator

Maintaining privacy and security in today’s digital landscape is essential, especially for cybersecurity enthusiasts and professionals. Unique identifiers (IDs) play a pivotal role in ensuring anonymity while facilitating secure operations. Recognizing the challenges associated with generating and managing IDs in Linux environments, I developed the Ultimate Bash ID Generator—a simple yet powerful script to streamline the process.

What is the Ultimate Bash ID Generator?

The Ultimate Bash ID Generator is a versatile script designed to generate secure, unique IDs tailored for cybersecurity applications. Whether you’re working on a privacy-focused operating system like Linux Kodachi or any other Linux distribution, this script simplifies ID generation, enabling users to enhance their anonymity without technical hurdles.

Key Features of the Script

  • UUID and Fake ID Generation: Generate standard UUIDs and customizable Fake IDs.
  • Multiple Hashing Algorithms: Hash IDs with MD5, SHA-256, and SHA-384 for enhanced security.
  • Base64 Encoding: Encode IDs in Base64 for seamless integration into various systems.
  • Customizable Parameters: Define the number of IDs and the length of Fake IDs to suit your needs.
  • Flexible Output Formats: Export IDs in plain text or JSON for easy usage and automation.
  • Dependency Management: Automatically checks for and installs required dependencies.
  • Comprehensive Logging: Logs all operations and errors for auditing and troubleshooting.

How It Works

  1. Generate IDs:
  • Use the script to generate UUIDs and Fake IDs.
  • Apply advanced hashing and encoding for added security.
  1. Customize Output:
  • Choose between plain text or JSON format.
  • Define the number and length of IDs based on your requirements.
  1. Ensure Logging:
  • Record all actions and potential errors for review and debugging.

Quick Start

  1. Download the Script:
    Save the script as id-generator.sh and make it executable.
  2. Run the Script:
    Use the following commands based on your needs:
   # Generate a single ID
   ./id-generator.sh

   # Generate five IDs
   ./id-generator.sh -n 5

   # Generate three IDs with JSON output
   ./id-generator.sh -n 3 -o json

   # Specify Fake ID length
   ./id-generator.sh -n 2 -f 128
  1. Explore Outputs:
  • Check the generated IDs in your specified output format.
  • Review the log file for a detailed record of actions.

Benefits

  • Ease of Use: Simplifies ID generation with a user-friendly interface.
  • Enhanced Security: Combines hashing and encoding for robust privacy measures.
  • Automation-Friendly: Integrates seamlessly with existing workflows.
  • Customizable Outputs: Offers flexibility to meet diverse use cases.

Conclusion

The Ultimate Bash ID Generator bridges the gap between complex cybersecurity needs and usability. It empowers both beginners and seasoned professionals to maintain anonymity and enhance security effortlessly. By leveraging this script, you can focus on your core tasks while enjoying streamlined, secure ID generation.

Download the script today and take a step towards a more secure digital environment.

ShellScript
#!/bin/bash

# =========================================
# Ultimate Bash ID Generator
# =========================================
#
# Version: 2.4
# Script written by Warith Al Maawali
#
# Discord channel: https://discord.gg/KEFErEx
# Twitter: http://twitter.com/warith2020
# Linkedin: http://www.linkedin.com/in/warith1977
# Website: https://www.digi77.com
# (c) 2024
#
# Description:
# This script generates UUIDs and Fake IDs, hashes them using multiple algorithms,
# encodes them in Base64, and outputs the results in either JSON or plain text.
# It supports generating multiple IDs, customizable Fake ID lengths, logging, and
# robust error handling.
#
# Usage: ./id-generator.sh [options]
#
# Usage Examples:
#   Generate a single ID:
#     ./id-generator.sh
#   Generate five IDs:
#     ./id-generator.sh -n 5
#   Generate three IDs with JSON output:
#     ./id-generator.sh -n 3 -o json
#   Specify Fake ID length:
#     ./id-generator.sh -n 2 -f 128
#   Display Help:
#     ./id-generator.sh -h
# =========================================

# Constants
DEFAULT_NUM_IDS=1
DEFAULT_OUTPUT_FORMAT="text"
DEFAULT_FAKE_ID_LENGTH=128
DEFAULT_LOG_FILE="id_generator.log"
OUTPUT_FILE=""
JSON_OUTPUT=()

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Dependencies
REQUIRED_COMMANDS=("uuidgen" "md5sum" "sha256sum" "sha384sum" "base64" "jq" "tr" "head" "awk")

# Functions

# Display usage instructions
usage() {
    cat <<EOF
Usage: $0 [options]

Options:
  -n NUM           Number of UUIDs and Fake IDs to generate (default: 1)
  -o FORMAT        Output format: text (default) or json
  -f LENGTH        Length of the Fake ID (default: 128)
  -l LOGFILE       Log file path (default: ./id_generator.log)
  -h, --help       Display this help message

Examples:
  Generate a single ID:
    $0
  Generate five IDs:
    $0 -n 5
  Generate three IDs with JSON output:
    $0 -n 3 -o json
  Specify Fake ID length:
    $0 -n 2 -f 128
  Specify a custom log file:
    $0 -l /var/log/id_generator.log
EOF
    exit 1
}

# Log messages with timestamp
log() {
    local message="$1"
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a "$LOG_FILE"
}

# Check and install dependencies
check_dependencies() {
    for cmd in "${REQUIRED_COMMANDS[@]}"; do
        if ! command -v "$cmd" &>/dev/null; then
            log "Dependency '$cmd' not found. Attempting to install..."
            case "$cmd" in
                uuidgen)
                    sudo apt-get update && sudo apt-get install -y uuid-runtime || { log "Failed to install uuidgen."; exit 1; }
                    ;;
                jq)
                    sudo apt-get update && sudo apt-get install -y jq || { log "Failed to install jq."; exit 1; }
                    ;;
                *)
                    sudo apt-get update && sudo apt-get install -y "$cmd" || { log "Failed to install $cmd."; exit 1; }
                    ;;
            esac
            log "Installed '$cmd' successfully."
        fi
    done
}

# Function to hash using different algorithms
hash_id() {
    local id="$1"
    local algorithm="$2"
    case "$algorithm" in
        md5)
            echo -n "$id" | md5sum | awk '{print $1}'
            ;;
        sha256)
            echo -n "$id" | sha256sum | awk '{print $1}'
            ;;
        sha384)
            echo -n "$id" | sha384sum | awk '{print $1}'
            ;;
        *)
            echo "Unsupported hash algorithm: $algorithm" >&2
            return 1
            ;;
    esac
}

# Generate a single UUID and Fake ID, returning JSON data
generate_single_id() {
    local fake_id_length="$1"
    local uuid
    uuid=$(uuidgen)
    if [ -z "$uuid" ]; then
        log "Failed to generate UUID."
        return 1
    fi

    local fake_id
    fake_id=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | tr -d '\n' | head -c "$fake_id_length")
    if [ ${#fake_id} -ne "$fake_id_length" ]; then
        log "Failed to generate Fake ID of specified length."
        return 1
    fi

    local uuid_md5 uuid_sha256 uuid_sha384 uuid_base64
    uuid_md5=$(hash_id "$uuid" "md5")
    uuid_sha256=$(hash_id "$uuid" "sha256")
    uuid_sha384=$(hash_id "$uuid" "sha384")
    uuid_base64=$(echo -n "$uuid" | base64)

    local fake_id_md5 fake_id_sha256 fake_id_sha384 fake_id_base64
    fake_id_md5=$(hash_id "$fake_id" "md5")
    fake_id_sha256=$(hash_id "$fake_id" "sha256")
    fake_id_sha384=$(hash_id "$fake_id" "sha384")
    fake_id_base64=$(echo -n "$fake_id" | base64)

    # Generate JSON object for this ID
    jq -n \
        --arg uuid "$uuid" \
        --arg uuid_md5 "$uuid_md5" \
        --arg uuid_sha256 "$uuid_sha256" \
        --arg uuid_sha384 "$uuid_sha384" \
        --arg uuid_base64 "$uuid_base64" \
        --arg fake_id "$fake_id" \
        --arg fake_id_md5 "$fake_id_md5" \
        --arg fake_id_sha256 "$fake_id_sha256" \
        --arg fake_id_sha384 "$fake_id_sha384" \
        --arg fake_id_base64 "$fake_id_base64" \
        '{
            uuid: {
                original: $uuid,
                md5: $uuid_md5,
                sha256: $uuid_sha256,
                sha384: $uuid_sha384,
                base64: $uuid_base64
            },
            fake_id: {
                original: $fake_id,
                md5: $fake_id_md5,
                sha256: $fake_id_sha256,
                sha384: $fake_id_sha384,
                base64: $fake_id_base64
            }
        }'
}

# Generate multiple IDs
generateIDs() {
    local count="$1"
    local fake_id_length="$2"
    local i=1
    local json_array=()
    local text_output=""

    log "Starting generation of $count ID(s)."

    while [ "$i" -le "$count" ]; do
        log "Generating ID $i..."
        local id_json
        id_json=$(generate_single_id "$fake_id_length")
        if [ $? -eq 0 ]; then
            json_array+=("$id_json")
            log "Successfully generated ID $i."

            # Parse JSON to extract fields for terminal output
            local uuid original_uuid uuid_md5 uuid_sha256 uuid_sha384 uuid_base64
            local fake_id original_fake_id fake_id_md5 fake_id_sha256 fake_id_sha384 fake_id_base64

            original_uuid=$(echo "$id_json" | jq -r '.uuid.original')
            uuid_md5=$(echo "$id_json" | jq -r '.uuid.md5')
            uuid_sha256=$(echo "$id_json" | jq -r '.uuid.sha256')
            uuid_sha384=$(echo "$id_json" | jq -r '.uuid.sha384')
            uuid_base64=$(echo "$id_json" | jq -r '.uuid.base64')

            original_fake_id=$(echo "$id_json" | jq -r '.fake_id.original')
            fake_id_md5=$(echo "$id_json" | jq -r '.fake_id.md5')
            fake_id_sha256=$(echo "$id_json" | jq -r '.fake_id.sha256')
            fake_id_sha384=$(echo "$id_json" | jq -r '.fake_id.sha384')
            fake_id_base64=$(echo "$id_json" | jq -r '.fake_id.base64')

            # Terminal Output
            echo -e "${BLUE}UUID Generation:${NC}"
            echo -e "  ${GREEN}Original UUID:${NC} $original_uuid"
            echo -e "  ${GREEN}UUID MD5:${NC} $uuid_md5"
            echo -e "  ${GREEN}UUID SHA-256:${NC} $uuid_sha256"
            echo -e "  ${GREEN}UUID SHA-384:${NC} $uuid_sha384"
            echo -e "  ${GREEN}UUID Base64:${NC} $uuid_base64"
            echo ""
            echo -e "${YELLOW}Fake ID Generation:${NC}"
            echo -e "  ${GREEN}Original Fake ID:${NC} $original_fake_id"
            echo -e "  ${GREEN}Fake ID MD5:${NC} $fake_id_md5"
            echo -e "  ${GREEN}Fake ID SHA-256:${NC} $fake_id_sha256"
            echo -e "  ${GREEN}Fake ID SHA-384:${NC} $fake_id_sha384"
            echo -e "  ${GREEN}Fake ID Base64:${NC} $fake_id_base64"
            echo -e "${NC}----------------------------------------${NC}"

            # Append to text_output for file output
            text_output+="UUID Generation:\n"
            text_output+="  Original UUID: $original_uuid\n"
            text_output+="  UUID MD5: $uuid_md5\n"
            text_output+="  UUID SHA-256: $uuid_sha256\n"
            text_output+="  UUID SHA-384: $uuid_sha384\n"
            text_output+="  UUID Base64: $uuid_base64\n\n"
            text_output+="Fake ID Generation:\n"
            text_output+="  Original Fake ID: $original_fake_id\n"
            text_output+="  Fake ID MD5: $fake_id_md5\n"
            text_output+="  Fake ID SHA-256: $fake_id_sha256\n"
            text_output+="  Fake ID SHA-384: $fake_id_sha384\n"
            text_output+="  Fake ID Base64: $fake_id_base64\n"
            text_output+="----------------------------------------\n\n"

        else
            echo -e "${RED}ID $i: FAILED${NC}"
            log "Failed to generate ID $i."
        fi
        i=$((i + 1))
    done

    # Handle file output
    if [ "$OUTPUT_FORMAT" == "json" ]; then
        # Combine all JSON objects into a JSON array
        printf '%s\n' "${json_array[@]}" | jq -s '.' > "$OUTPUT_FILE"
        echo -e "\n${BLUE}JSON results saved to $OUTPUT_FILE${NC}"
        log "JSON results saved to $OUTPUT_FILE."
    elif [ "$OUTPUT_FORMAT" == "text" ]; then
        # Write text output to file
        echo -e "$text_output" > "$OUTPUT_FILE"
        echo -e "\n${BLUE}Text results saved to $OUTPUT_FILE${NC}"
        log "Text results saved to $OUTPUT_FILE."
    fi
}

# Parse command-line arguments
parse_args() {
    while [[ $# -gt 0 ]]; do
        key="$1"
        case $key in
            -n)
                NUM_IDS="$2"
                if ! [[ "$NUM_IDS" =~ ^[0-9]+$ ]]; then
                    echo -e "${RED}ERROR: -n requires a numeric argument.${NC}"
                    usage
                fi
                shift # past argument
                shift # past value
                ;;
            -o)
                OUTPUT_FORMAT="$2"
                if [[ "$OUTPUT_FORMAT" != "text" && "$OUTPUT_FORMAT" != "json" ]]; then
                    echo -e "${RED}ERROR: -o accepts 'text' or 'json' only.${NC}"
                    usage
                fi
                OUTPUT_FILE="output.$OUTPUT_FORMAT"
                shift
                shift
                ;;
            -f)
                FAKE_ID_LENGTH="$2"
                if ! [[ "$FAKE_ID_LENGTH" =~ ^[0-9]+$ ]]; then
                    echo -e "${RED}ERROR: -f requires a numeric argument.${NC}"
                    usage
                fi
                shift
                shift
                ;;
            -l)
                LOG_FILE="$2"
                shift
                shift
                ;;
            -h|--help)
                usage
                ;;
            *)
                echo -e "${RED}ERROR: Unknown option: $1${NC}"
                usage
                ;;
        esac
    done

    # Set default values if not set
    NUM_IDS=${NUM_IDS:-$DEFAULT_NUM_IDS}
    OUTPUT_FORMAT=${OUTPUT_FORMAT:-$DEFAULT_OUTPUT_FORMAT}
    FAKE_ID_LENGTH=${FAKE_ID_LENGTH:-$DEFAULT_FAKE_ID_LENGTH}
    LOG_FILE=${LOG_FILE:-$DEFAULT_LOG_FILE}

    # Set default output file if not specified
    if [ -z "$OUTPUT_FILE" ]; then
        OUTPUT_FILE="output.$OUTPUT_FORMAT"
    fi
}

# Main Execution

# Initialize default values
NUM_IDS=$DEFAULT_NUM_IDS
OUTPUT_FORMAT=$DEFAULT_OUTPUT_FORMAT
FAKE_ID_LENGTH=$DEFAULT_FAKE_ID_LENGTH
LOG_FILE=$DEFAULT_LOG_FILE

# Parse arguments
parse_args "$@"

# Check dependencies
check_dependencies

# Generate IDs and capture output
generateIDs "$NUM_IDS" "$FAKE_ID_LENGTH"

# Save results to file is handled within generateIDs

log "ID generation process completed."

exit 0
ShellScript

Posted in Tech BlogTags:
© 2024 Warith AL Maawali. All Rights Reserved.
Stay Secure, Stay Assured.