Skip to content

Instantly share code, notes, and snippets.

@christianarielli
Last active July 7, 2023 10:46
Show Gist options
  • Save christianarielli/afa8be6407a3f1c90f4940cad80a35a5 to your computer and use it in GitHub Desktop.
Save christianarielli/afa8be6407a3f1c90f4940cad80a35a5 to your computer and use it in GitHub Desktop.
This script can be used to create simple chroot environment.
#!/bin/bash
# This script can be used to create simple chroot environment
# Written by LinuxConfig.org
# (c) 2020 LinuxConfig under GNU GPL v3.0+
#!/bin/bash
CHROOT='/var/chroot'
mkdir -p $CHROOT
for i in $( ldd $* | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq )
do
cp --parents $i $CHROOT
done
# ARCH amd64
if [ -f /lib64/ld-linux-x86-64.so.2 ]; then
cp --parents /lib64/ld-linux-x86-64.so.2 /$CHROOT
fi
# ARCH i386
if [ -f /lib/ld-linux.so.2 ]; then
cp --parents /lib/ld-linux.so.2 /$CHROOT
fi
echo "Chroot jail is ready. To access it execute: chroot $CHROOT"
@christianarielli
Copy link
Author

Using that script, let’s enable some of these commands:

./chroot.sh /bin/{ls,cat,echo,rm,vi,date,mkdir}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment