File size: 8,752 Bytes
433dc73 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | #!/usr/bin/env python3
"""
==============================================================================
VYRON OS — Phase 7 RootFS Direct Ext4 Injection Engine
Injects users, hardened sudoers, autologin, SSH, and provisioning service
directly into the Debian 12 ARM64 root filesystem image via debugfs.
==============================================================================
"""
import os
import sys
import subprocess
import shutil
DEBUGFS = "/opt/homebrew/opt/e2fsprogs/sbin/debugfs"
ROOT_DIR = "/Users/sujayv/Downloads/VyronOS"
RELEASE_DIR = os.path.join(ROOT_DIR, "release_phase7")
ROOTFS_IMG = os.path.join(RELEASE_DIR, "rootfs.img")
STAGE_DIR = os.path.join(RELEASE_DIR, "injected_files")
def run_debugfs(cmds):
cmd_str = "\n".join(cmds) + "\n"
p = subprocess.run([DEBUGFS, "-w", ROOTFS_IMG], input=cmd_str, capture_output=True, text=True)
if p.returncode != 0:
print(f"debugfs error: {p.stderr}")
return p
def main():
print("==========================================================================")
print(" VYRON OS — Phase 7 Direct RootFS Ext4 Injection Engine")
print("==========================================================================")
os.makedirs(STAGE_DIR, exist_ok=True)
# 1. Prepare Shadow file with password 'vyron' ($1$vyron123$9LpmFEejDn7J7LMjTaNyu.)
# Crypt hash for 'vyron'
HASH = "$1$vyron123$9LpmFEejDn7J7LMjTaNyu."
# Dump current files
run_debugfs([f"dump etc/passwd {STAGE_DIR}/passwd", f"dump etc/shadow {STAGE_DIR}/shadow", f"dump etc/group {STAGE_DIR}/group"])
# Update passwd
with open(f"{STAGE_DIR}/passwd", "r") as f:
passwd_content = f.read()
if "vyron:x:1000:" not in passwd_content:
passwd_content += "vyron:x:1000:1000:Vyron User:/home/vyron:/bin/bash\n"
with open(f"{STAGE_DIR}/passwd", "w") as f:
f.write(passwd_content)
print(" Added user 'vyron' (UID 1000, GID 1000) to /etc/passwd")
# Update shadow
with open(f"{STAGE_DIR}/shadow", "r") as f:
lines = f.readlines()
new_shadow = []
has_vyron = False
for line in lines:
if line.startswith("root:"):
new_shadow.append(f"root:{HASH}:20774:0:99999:7:::\n")
elif line.startswith("vyron:"):
new_shadow.append(f"vyron:{HASH}:20774:0:99999:7:::\n")
has_vyron = True
else:
new_shadow.append(line)
if not has_vyron:
new_shadow.append(f"vyron:{HASH}:20774:0:99999:7:::\n")
with open(f"{STAGE_DIR}/shadow", "w") as f:
f.writelines(new_shadow)
print(" Set authenticated password 'vyron' for root and vyron in /etc/shadow")
# Update group
with open(f"{STAGE_DIR}/group", "r") as f:
group_lines = f.readlines()
new_group = []
has_vyron_group = False
for line in group_lines:
parts = line.strip().split(":")
gname = parts[0]
if gname in ["sudo", "audio", "video", "users"]:
members = parts[3].split(",") if len(parts) > 3 and parts[3] else []
if "vyron" not in members:
members.append("vyron")
parts[3] = ",".join(members)
new_group.append(":".join(parts) + "\n")
elif gname == "vyron":
has_vyron_group = True
new_group.append(line)
else:
new_group.append(line)
if not has_vyron_group:
new_group.append("vyron:x:1000:\n")
with open(f"{STAGE_DIR}/group", "w") as f:
f.writelines(new_group)
print(" Configured groups (sudo, audio, video) for vyron in /etc/group")
# Sudoers hardening
with open(f"{STAGE_DIR}/vyron_sudoers", "w") as f:
f.write("vyron ALL=(ALL:ALL) ALL\n")
# SSH configuration
with open(f"{STAGE_DIR}/sshd_vyron.conf", "w") as f:
f.write("PermitRootLogin yes\nPasswordAuthentication yes\n")
# Autologin configuration for tty1
os.makedirs(f"{STAGE_DIR}/autologin.d", exist_ok=True)
with open(f"{STAGE_DIR}/autologin.d/autologin.conf", "w") as f:
f.write("[Service]\nExecStart=\nExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin vyron %I $TERM\n")
# Provisioning script
with open(f"{STAGE_DIR}/vyron-provision.sh", "w") as f:
f.write("""#!/bin/bash
set -x
echo "=== VYRON OS PROVISIONING STARTED ===" > /var/log/vyron-provision.log
export DEBIAN_FRONTEND=noninteractive
# 1. Repositories
cat << 'SOURCES' > /etc/apt/sources.list
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
SOURCES
apt-get update >> /var/log/vyron-provision.log 2>&1
# 2. Install Desktop, Audio, Package Management & Security Packages
apt-get install -y --no-install-recommends \
xfce4 xfce4-goodies lightdm lightdm-gtk-greeter \
aptitude aptitude-common pipewire pipewire-pulse wireplumber \
alsa-utils pciutils tree polkitd dbus sudo curl htop >> /var/log/vyron-provision.log 2>&1
# 3. Mount assets from CIDATA if present
mkdir -p /mnt/cidata
mount /dev/sr0 /mnt/cidata 2>/dev/null || mount /dev/cdrom /mnt/cidata 2>/dev/null || true
if [ -f /mnt/cidata/vyron_assets.tar.gz ]; then
mkdir -p /tmp/payload
tar -xzf /mnt/cidata/vyron_assets.tar.gz -C /tmp/payload/
cp -r /tmp/payload/themes/* /usr/share/themes/ 2>/dev/null || true
cp -r /tmp/payload/icons /usr/share/icons/Vyron-Icons 2>/dev/null || true
mkdir -p /usr/share/backgrounds/vyron
cp -r /tmp/payload/wallpapers/* /usr/share/backgrounds/vyron/ 2>/dev/null || true
cp /tmp/payload/bin/* /usr/local/bin/ 2>/dev/null || true
chmod +x /usr/local/bin/*.py 2>/dev/null || true
fi
# 4. Sudo Hardening
chmod 0440 /etc/sudoers.d/vyron
chown root:root /etc/sudoers.d/vyron
# 5. Enable LightDM Autologin
sed -i 's/^#autologin-user=.*/autologin-user=vyron/' /etc/lightdm/lightdm.conf 2>/dev/null || true
sed -i 's/^#autologin-user-timeout=.*/autologin-user-timeout=0/' /etc/lightdm/lightdm.conf 2>/dev/null || true
systemctl enable lightdm 2>/dev/null || true
# Disable provisioning service
systemctl disable vyron-provision.service 2>/dev/null || true
echo "=== VYRON OS PROVISIONING COMPLETE ===" >> /var/log/vyron-provision.log
systemctl start lightdm 2>/dev/null || true
""")
# Provisioning service unit
with open(f"{STAGE_DIR}/vyron-provision.service", "w") as f:
f.write("""[Unit]
Description=VyronOS Release First-Boot Provisioning
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/bash /usr/local/bin/vyron-provision.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
""")
print("\n>>> Injecting files into rootfs.img via debugfs...")
debugfs_cmds = [
# Passwd, Shadow, Group
f"rm etc/passwd", f"write {STAGE_DIR}/passwd etc/passwd", "sif etc/passwd mode 0100644",
f"rm etc/shadow", f"write {STAGE_DIR}/shadow etc/shadow", "sif etc/shadow mode 0100640", "sif etc/shadow gid 42",
f"rm etc/group", f"write {STAGE_DIR}/group etc/group", "sif etc/group mode 0100644",
# Home directory
"mkdir home/vyron", "sif home/vyron mode 040755", "sif home/vyron uid 1000", "sif home/vyron gid 1000",
# Sudoers
"mkdir etc/sudoers.d",
f"rm etc/sudoers.d/vyron", f"write {STAGE_DIR}/vyron_sudoers etc/sudoers.d/vyron",
"sif etc/sudoers.d/vyron mode 0100440", "sif etc/sudoers.d/vyron uid 0", "sif etc/sudoers.d/vyron gid 0",
# SSH config
"mkdir etc/ssh/sshd_config.d",
f"rm etc/ssh/sshd_config.d/vyron.conf", f"write {STAGE_DIR}/sshd_vyron.conf etc/ssh/sshd_config.d/vyron.conf",
# Provisioning script
f"rm usr/local/bin/vyron-provision.sh", f"write {STAGE_DIR}/vyron-provision.sh usr/local/bin/vyron-provision.sh",
"sif usr/local/bin/vyron-provision.sh mode 0100755", "sif usr/local/bin/vyron-provision.sh uid 0",
# Provisioning service
f"rm etc/systemd/system/vyron-provision.service", f"write {STAGE_DIR}/vyron-provision.service etc/systemd/system/vyron-provision.service",
"sif etc/systemd/system/vyron-provision.service mode 0100644",
# Enable service symlink
"mkdir etc/systemd/system/multi-user.target.wants",
"ln etc/systemd/system/vyron-provision.service etc/systemd/system/multi-user.target.wants/vyron-provision.service"
]
p = run_debugfs(debugfs_cmds)
print(" RootFS direct injection completed successfully.")
return 0
if __name__ == "__main__":
sys.exit(main())
|