various scripts for various tasks.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3KB

  1. #!/bin/bash
  2. # script used to chroot/pivot a live system on tmpfs in order to wipe it
  3. # only tested with Debian 7.11
  4. #
  5. # first copy and execute it:
  6. # scp pivotroot.sh root@<remote_host>:/tmp/
  7. # ssh root@<remote_host> bash /tmp/pivotroot.sh
  8. #
  9. # you will then be able to connect again to it on port 666 (change it if you like) and do what you want
  10. #
  11. # note: bash is the default shell under debian so there will be bashisms (don't run it with Bourne shell)
  12. #
  13. apt-get install -y dropbear screen tmux
  14. CHROOTDIR='/tmp/tmproot'
  15. CHROOTPORT=666
  16. mkdir ${CHROOTDIR}
  17. mount -t tmpfs none ${CHROOTDIR}
  18. mkdir ${CHROOTDIR}/{bin,sbin,proc,sys,dev,run,usr,var,tmp,etc,root,oldroot}
  19. mkdir -p ${CHROOTDIR}/usr/bin
  20. mkdir -p ${CHROOTDIR}/lib/x86_64-linux-gnu ${CHROOTDIR}/lib64 ${CHROOTDIR}/usr/share ${CHROOTDIR}/usr/lib/x86_64-linux-gnu ${CHROOTDIR}/var/run/screen
  21. mount -t proc proc ${CHROOTDIR}/proc
  22. mount --bind /dev ${CHROOTDIR}/dev
  23. mount --bind /dev/pts ${CHROOTDIR}/dev/pts
  24. mount --make-rprivate / # necessary for pivot_root to work
  25. cp -vrp /usr/share/terminfo ${CHROOTDIR}/usr/share/
  26. cp -vrp /usr/lib/x86_64-linux-gnu/libevent* ${CHROOTDIR}/usr/lib/x86_64-linux-gnu/
  27. cp -vrp /lib/x86_64-linux-gnu/* ${CHROOTDIR}/lib/x86_64-linux-gnu/
  28. cp -vrp /lib64/ld-linux-x86-64.so.2 ${CHROOTDIR}/lib64/
  29. cp -vrp /sbin/* ${CHROOTDIR}/sbin/
  30. cp -vrp /bin/* ${CHROOTDIR}/bin/
  31. cp -vrp /usr/bin/id /usr/bin/shred /usr/bin/ldd /usr/bin/screen /usr/bin/tmux ${CHROOTDIR}/usr/bin/
  32. cp -vrp /usr/sbin/dropbear ${CHROOTDIR}/sbin/
  33. #cp -vrp /etc/passwd* /etc/shadow* /etc/group* /etc/shells ${CHROOTDIR}/etc/
  34. #cp -vrp /etc/dropbear ${CHROOTDIR}/etc/
  35. cp -vrp /etc/* ${CHROOTDIR}/etc/
  36. chmod g+w ${CHROOTDIR}/run
  37. echo "" > ${CHROOTDIR}/root/.bash_history
  38. echo "TERM=xterm-16color" >>${CHROOTDIR}/root/.profile #necessary for tmux/screen to work
  39. echo "alias halt=\"echo 'o' > /proc/sysrq-trigger\"" >>${CHROOTDIR}/root/.profile
  40. echo "alias reboot=\"echo 'b' > /proc/sysrq-trigger\"" >>${CHROOTDIR}/root/.profile
  41. pivot_root ${CHROOTDIR} ${CHROOTDIR}/oldroot
  42. /sbin/dropbear -p ${CHROOTPORT}
  43. echo
  44. echo "system pivot-rooted."
  45. echo "you can now connect with ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${CHROOTPORT} root@`hostname`, launch screen/tmux and shred"
  46. echo "and finaly use reboot or halt commands (warning: they are not the real thing...)"
  47. echo
  48. echo "happy wiping!"
  49. echo