miércoles, mayo 30, 2007

copy2usb

Me entro la curosidad de como hacer de linux un virus... y cree este script copy2usb que corriendo desde una maquina con Damn Small Linux arrancada desde una USB es capaz de clonarce en otra usb, es posible poner el comando en algun script de inicializacion para comenzar una reproduccion automatica, pero la idea era una prueba de concepto y no un virus que reemplace todos los archivos por una distribucion de linux, si quieren mas info me avisan.

Por alguna curiosa razon es casi imposible publicar este util script dentro de las paginas de DSL haaa y para mi este script es dominio publico.


#!/bin/bash
# usbfathdd.sh - cbagger01's slightly modified version of
# the original pendrive_usbhdd.sh / pendrive_usbzip.sh by
# (c) Robert Shingledecker 2005
# added usb storage log check
# Usb2Usb by John Edgar Congote Calle 2007

. /etc/init.d/dsl-functions

export PATH="$PATH:."

clear
echo
echo "${RED}DSL ${WHITE}pendrive BIOS boot FAT USB_HDD ${BLUE}install/update.${NORMAL}"
echo
echo "1. Your BIOS must support USB-HDD booting."
echo "2. A single FAT partition will be made."
echo "3. Backup/Restore will be pre setup."
echo "4. Do not have your pendrive mounted."
echo  
echo "${YELLOW}No responsibility for data loss or hardware damage!${NORMAL}"
echo

# Check to help the user avoid accidentally installing to the wrong devicename
echo -n "${CYAN}Display your USB storage device information log? ${YELLOW}(Y/n): ${NORMAL}" 
read ANSWER
if [ "$ANSWER" != "n" ] && [ "$ANSWER" != "N" ] ; then
  SEPARATOR="--------------------------------------------------------"
  SEDGREEN=" \[1;32m"
  SEDNORMAL=" \[0;39m"
  dmesg | grep -A 4 "SCSI emulation" | sed "s/--/$SEPARATOR/g;/scsi.* disk/ s/disk/disk$SEDGREEN/g;s/ at /$SEDNORMAL at /g"
fi    
ANSWER=

echo -n "${CYAN}Enter the origin device name of pendrive.${WHITE}(EXAMPLE: ${YELLOW}sda): ${NORMAL}" 
read DEVICEORG
if [ -z "$DEVICEORG" ] ; then
  echo "No device chosen. The script will be terminated."
  echo -n "Press Enter key to continue."; read gagme
  exit 1
fi    
ORIGIN="$DEVICEORG"1

echo -n "${CYAN}Enter the target device name of pendrive.${WHITE}(EXAMPLE: ${YELLOW}sdb): ${NORMAL}" 
read DEVICETAR
if [ -z "$DEVICETAR" ] ; then
  echo "No device chosen. The script will be terminated."
  echo -n "Press Enter key to continue."; read gagme
  exit 1
fi    
TARGET="$DEVICETAR"1

mkdir /mnt/origin
mount -t vfat /dev/$ORIGIN /mnt/origin

echo -n "${RED}Ready to proceed.${NORMAL} (y/..)? "
read answer
if [ "$answer" != "y" ]; then
  echo "Aborted by user."
  echo "Press Enter key to continue: "; read gagme
  exit 1
fi

echo
echo -n "${BLUE}Writing zero's to beginning of ${MAGENTA}/dev/$DEVICETAR${NORMAL} "
dd if=/dev/zero of=/dev/$DEVICETAR bs=1k count=1 >/dev/null 2>&1 &
rotdash $!
echo " Done."
sync
echo "${BLUE}Partitioning ${MAGENTA}/dev/$DEVICETAR${NORMAL}"
fdisk /dev/$DEVICETAR << EOF >/dev/null 2>&1
n
p
1


a
1
t
6
w
EOF
sync
hdparm -z /dev/$DEVICETAR
echo "${BLUE}Formatting ${MAGENTA}/dev/$TARGET${NORMAL}"
mkdosfs /dev/$TARGET >/dev/null 2>&1
sync
dd if=/bin/mbr.bin of=/dev/$DEVICE
sync

echo "${BLUE}Applying syslinux to pendrive partition.${NORMAL}"
syslinux /dev/$TARGET

echo -n "${BLUE}Setting up system image on ${MAGENTA}/mnt/$TARGET${NORMAL}..."
mkdir /mnt/pendrive
mount -t vfat /dev/$TARGET /mnt/pendrive
if [ $? != 0 ]; then
   echo "Error mounting usb device"
   echo -n "Press Enter key to continue."; read gagme
   exit 1
fi
cp -r /mnt/origin/* /mnt/pendrive
rotdash $!
sync
echo " Done."
umount /mnt/pendrive
umount /mnt/origin
echo "${GREEN}USB installation has completed${NORMAL}"
echo -n "Press Enter key to continue."; read gagme

1 comentario:

Andrés dijo...

Muy buena la idea.