#!/bin/bash # AUTO ACCOUNT CREATION FOR ALL USERS # Membuat akun FTP/SSH untuk semua user reguler di sistem # FOR EDUCATIONAL/AUTHORIZED SECURITY TESTING ONLY # Warna untuk output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # Konfigurasi PASSWORD_LENGTH=16 QUOTA_GB=5 EXPIRY_DAYS=30 OUTPUT_FILE="accounts_created_$(date +%F_%H%M%S).txt" LOG_FILE="system_users_$(date +%F_%H%M%S).log" # Fungsi untuk menampilkan banner show_banner() { echo -e "${BLUE}" cat << "EOF" ╔══════════════════════════════════════════════════════════╗ ║ AUTO ACCOUNT CREATION FOR ALL SYSTEM USERS ║ ║ Create FTP/SSH accounts for all regular users ║ ║ FOR AUTHORIZED TESTING ONLY ║ ╚══════════════════════════════════════════════════════════╝ EOF echo -e "${NC}" } # Fungsi untuk memeriksa privilege check_privilege() { if [ "$(id -u)" -ne 0 ]; then echo -e "${RED}[!] Error: This script must be run as root${NC}" exit 1 fi } # Fungsi untuk mendeteksi distribusi Linux detect_distro() { if [ -f /etc/os-release ]; then . /etc/os-release DISTRO=$ID elif [ -f /etc/redhat-release ]; then DISTRO="rhel" else DISTRO="unknown" fi echo -e "${YELLOW}[*] Detected distribution: $DISTRO${NC}" } # Fungsi untuk menginstal dependensi install_dependencies() { echo -e "${YELLOW}[*] Installing dependencies...${NC}" case $DISTRO in ubuntu|debian) apt update -qq apt install -y -qq vsftpd openssh-server quota pwgen ;; centos|rhel|fedora) yum update -y -q yum install -y -q vsftpd openssh-server quota pwgen ;; arch) pacman -Syu --noconfirm vsftpd openssh quota-tools pwgen ;; *) echo -e "${RED}[!] Unsupported distribution: $DISTRO${NC}" exit 1 ;; esac echo -e "${GREEN}[+] Dependencies installed successfully${NC}" } # Fungsi untuk menghasilkan password acak generate_password() { pwgen -s -1 $PASSWORD_LENGTH } # Fungsi untuk mendapatkan semua user reguler get_regular_users() { echo -e "${YELLOW}[*] Getting all regular users...${NC}" # Filter user reguler (UID >= 1000 dan bukan nobody) awk -F: '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd | sort > /tmp/regular_users.txt # Tambahkan user dengan UID antara 500-999 (untuk beberapa sistem) awk -F: '$3 >= 500 && $3 < 1000 && $1 != "nfsnobody" {print $1}' /etc/passwd | sort >> /tmp/regular_users.txt # Hapus duplikat sort -u /tmp/regular_users.txt -o /tmp/regular_users.txt USER_COUNT=$(wc -l < /tmp/regular_users.txt) echo -e "${GREEN}[+] Found $USER_COUNT regular users${NC}" # Tampilkan user yang akan diproses echo -e "${BLUE}[*] Users to process:${NC}" cat /tmp/regular_users.txt | nl -bn } # Fungsi untuk membuat akun FTP untuk satu user create_ftp_account() { local username=$1 local password=$2 echo -e "${YELLOW}[*] Creating FTP account for: $username${NC}" # Buat direktori FTP jika belum ada mkdir -p /home/ftp/$username # Set ownership chown $username:$username /home/ftp/$username # Konfigurasi vsftpd mkdir -p /etc/vsftpd_user_conf echo "local_root=/home/ftp/$username" > /etc/vsftpd_user_conf/$username echo "write_enable=YES" >> /etc/vsftpd_user_conf/$username # Tambahkan user ke vsftpd user list echo "$username" >> /etc/vsftpd.user_list # Set password echo "$username:$password" | chpasswd # Set quota set_quota "$username" "$QUOTA_GB" # Set kadaluarsa chage -M $EXPIRY_DAYS $username echo -e "${GREEN}[+] FTP account created for $username${NC}" } # Fungsi untuk membuat akun SSH untuk satu user create_ssh_account() { local username=$1 local password=$2 echo -e "${YELLOW}[*] Creating SSH account for: $username${NC}" # Set password echo "$username:$password" | chpasswd # Set quota set_quota "$username" "$QUOTA_GB" # Set kadaluarsa chage -M $EXPIRY_DAYS $username echo -e "${GREEN}[+] SSH account created for $username${NC}" } # Fungsi untuk mengatur quota set_quota() { local username=$1 local quota_gb=$2 # Aktifkan quota jika belum if ! grep -q 'usrquota' /etc/fstab; then echo -e "${YELLOW}[!] Quota not enabled. Enabling now...${NC}" # Backup fstab cp /etc/fstab /etc/fstab.bak # Tambahkan usrquota ke partisi root sed -i 's|\/[[:space:]]*ext4|\/ ext4,usrquota|g' /etc/fstab # Remount filesystem mount -o remount / # Buat quota file quotacheck -cum / quotaon -v / fi # Set quota untuk user setquota -u $username ${quota_gb}G ${quota_gb}G 0 0 / } # Fungsi untuk mengkonfigurasi vsftpd configure_vsftpd() { echo -e "${YELLOW}[*] Configuring vsftpd...${NC}" # Backup konfigurasi asli cp /etc/vsftpd.conf /etc/vsftpd.conf.bak # Buat konfigurasi baru cat > /etc/vsftpd.conf << EOF listen=YES anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES use_localtime=YES xferlog_enable=YES connect_from_port_20=YES chroot_local_user=YES allow_writeable_chroot=YES user_config_dir=/etc/vsftpd_user_conf userlist_enable=YES userlist_file=/etc/vsftpd.user_list userlist_deny=NO pam_service_name=vsftpd EOF # Restart vsftpd systemctl restart vsftpd 2>/dev/null || service vsftpd restart 2>/dev/null echo -e "${GREEN}[+] vsftpd configured successfully${NC}" } # Fungsi utama main() { show_banner check_privilege detect_distro install_dependencies get_regular_users # Inisialisasi file output echo "AUTO ACCOUNT CREATION REPORT" > "$OUTPUT_FILE" echo "Date: $(date)" >> "$OUTPUT_FILE" echo "========================================" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" # Konfigurasi vsftpd configure_vsftpd # Proses setiap user while IFS= read -r username; do # Skip jika user tidak memiliki home directory if [ ! -d "/home/$username" ]; then echo -e "${RED}[!] Skipping $username (no home directory)${NC}" continue fi # Generate password password=$(generate_password) # Buat akun FTP create_ftp_account "$username" "$password" # Buat akun SSH create_ssh_account "$username" "$password" # Simpan ke file output echo "Username: $username" >> "$OUTPUT_FILE" echo "Password: $password" >> "$OUTPUT_FILE" echo "FTP Access: ftp://$(hostname -I | awk '{print $1}')" >> "$OUTPUT_FILE" echo "SSH Access: ssh $username@$(hostname -I | awk '{print $1}')" >> "$OUTPUT_FILE" echo "Quota: $QUOTA_GB GB" >> "$OUTPUT_FILE" echo "Expires: $EXPIRY_DAYS days" >> "$OUTPUT_FILE" echo "----------------------------------------" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" echo -e "${GREEN}[+] Account created for $username${NC}" done < /tmp/regular_users.txt # Bersihkan rm -f /tmp/regular_users.txt echo -e "${GREEN}[+] All accounts created successfully!${NC}" echo -e "${BLUE}[*] Account details saved to: $OUTPUT_FILE${NC}" echo -e "${YELLOW}[!] IMPORTANT: Secure the output file immediately!${NC}" } # Jalankan program main "$@"