Advertisement
metalx1000

Create Minimal Linux File System with NMAP for Chroot

Jun 23rd, 2015
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.42 KB | None | 0 0
  1. #!/bin/bash
  2. #more info here http://www.cyberciti.biz/faq/debian-ubuntu-restricting-ssh-user-session-to-a-directory-chrooted-jail/
  3.  
  4. fs="$PWD/jail"
  5. echo "Creating ${fs}..."
  6. mkdir -p ${fs}/{etc,usr/{bin,lib},bin,lib}/
  7.  
  8. mkdir -p $fs/dev/
  9. mknod -m 666 $fs/dev/null c 1 3
  10. mknod -m 666 $fs/dev/tty c 5 0
  11. mknod -m 666 $fs/dev/zero c 1 5
  12. mknod -m 666 $fs/dev/random c 1 8
  13.  
  14. cp -v /lib/ld-linux.so.2 $fs/lib/
  15.  
  16. chown root:root $fs
  17. chmod 0755 $fs
  18.  
  19. wget "http://www.busybox.net/downloads/binaries/latest/busybox-i686" -O ${fs}/bin/busybox
  20. chmod +x ${fs}/bin/busybox
  21.  
  22. cd ${fs}/bin
  23. ./busybox  --help | \
  24. sed -e '1,/^Currently defined functions:/d' \
  25.     -e 's/[ \t]//g' -e 's/,$//' -e 's/,/\n/g' | \
  26. while read app ; do
  27.   if [ "$app" != "" ]; then
  28.     printf "linking %-12s ...\n" "$app"
  29.     ln -sf "./busybox" "$app"
  30.     ls -ld "$app"
  31.   fi
  32. done
  33.  
  34. echo "nameserver 8.8.8.8" > $fs/etc/resolv.conf
  35. echo "search 8.8.8.8" >> $fs/etc/resolv.conf
  36.  
  37. #add nmap
  38. cp -v /usr/bin/nmap $fs/usr/bin/nmap_real
  39. #create unprivileged nmap script
  40. cat << EOF > $fs/usr/bin/nmap
  41. #!/bin/sh
  42. nmap_real --unprivileged \$*
  43. EOF
  44. chmod +x $fs/usr/bin/nmap
  45.  
  46. mkdir -p $fs/{usr/share/nmap/,etc/services}
  47. #cp -vr /usr/share/nmap $fs/usr/share/nmap/
  48. ldd /usr/bin/nmap|while read line;
  49. do  
  50.   echo "$line"|\
  51.   awk '{print $3}'
  52. done|grep lib|while read line;
  53. do
  54.   cp -v "$line" $fs/usr/lib/;
  55. done
  56.  
  57. clear
  58. echo "welcome to your chroot!"
  59. chroot $fs sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement