Skip to content

Instantly share code, notes, and snippets.

@Briansbum
Created December 13, 2022 11:17
Show Gist options
  • Save Briansbum/3ddde1d2cca4f794951e3c1c4daa62f3 to your computer and use it in GitHub Desktop.
Save Briansbum/3ddde1d2cca4f794951e3c1c4daa62f3 to your computer and use it in GitHub Desktop.
ChatGPT's Bash Chroot Ramdrive Root Nuke Extravaganza
#!/bin/bash
# Create a ram drive
mkdir /mnt/ramdrive
mount -t tmpfs -o size=1024m tmpfs /mnt/ramdrive
# Create a chroot in the ram drive
mkdir /mnt/ramdrive/chroot
# Copy the /bin directory from the root file system into the chroot environment
cp -a /bin /mnt/ramdrive/chroot/
# Mount the root file system into the chroot environment at /mnt/ramdrive/chroot/root
mkdir /mnt/ramdrive/chroot/root
mount --bind / /mnt/ramdrive/chroot/root
# Create a new chroot user
useradd -m -d /home/newuser -s /bin/bash newuser
# Give the new user write access to / on the host
chmod 775 /
# Enter the chroot as the new user
chroot /mnt/ramdrive/chroot
su - newuser
# Use the rm -rf command to recursively delete the /mnt/ramdrive/chroot/root directory
/bin/rm -rf /root
# Reboot immediatley after deleting the root dir
/bin/shutdown -r now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment