Results 1 to 4 of 4

Thread: shell script to write kali with persistence

  1. #1
    Join Date
    2016-Dec
    Location
    California
    Posts
    33

    shell script to write kali with persistence

    I wrote a linux shell script to write an iso with persistence to a USB drive.
    Please post comments.

    Code:
    #!/bin/bash
    # vi:nowrap
    # write iso with persistence
    # kali-persistence.sh {iso}
    
    # *** IMPORTANT *** edit DEVICE as needed ***
    
    DEVICE=/dev/sdb
    
    # .......1.........2.........3.........4.........5.........6....
    if [ ! -e $DEVICE ] # device exists ?
    then
      echo;echo "device $DEVICE ?";echo;exit 10
    fi
    
    ISO=${1}
    if [ ! -e "$ISO" ] # iso exists ?
    then
      echo;echo ".iso $ISO ?";echo;exit 10
    fi
    
    # .......1.........2.........3.........4.........5.........6....
    # writing the iso creates 2 partitions
      echo;echo "Write $ISO to $DEVICE"
      sudo dd bs=1M if=$ISO of=$DEVICE oflag=direct status=progress && sync
    
      PERSIS=3 # write persistence to partition 3
      START=$(du -B1000000 $ISO | cut -f1)
      END=$(lsblk --noheadings --nodeps --bytes --output SIZE $DEVICE)
      END=$(($END / 1000000))
      echo;echo "Persistence on $DEVICE$PERSIS from $START to $END"
      sudo parted $DEVICE mkpart primary $START $END &&
      sleep 1
      sudo mkfs.ext3 -L persistence $DEVICE$PERSIS &&
      sudo mkdir -p /mnt/kaliUSB &&
      sudo mount $DEVICE$PERSIS /mnt/kaliUSB &&
      sudo sh -c "echo '/ union' > /mnt/kaliUSB/persistence.conf" &&
      sudo umount $DEVICE$PERSIS &&
      sudo rm -fr /mnt/kaliUSB/
      sudo fdisk -l $DEVICE
    # .......1.........2.........3.........4.........5.........6....

  2. #2
    Join Date
    2016-Dec
    Location
    Canada
    Posts
    326
    Looks nice how do i use it. Plug in a usb with a iso? Please!

  3. #3
    Join Date
    2016-Dec
    Location
    California
    Posts
    33
    @bigbiz
    Looks nice how do i use it. Plug in a usb with a iso? Please!
    Code:
    Instructions to write an iso with persistence USING a Linux script.
    
    # .......1.........2.........3.........4.........5.........6....
    Download a kali iso from:
      https://www.kali.org/downloads/
    Verify the SHA256Sum checksum
    Copy the script to a file
    Name the file 'kali-persistence.sh'
    Put the iso AND the script in the SAME folder
    Open terminal to the folder
    Make 'kali-persistence.sh' executable:
      chmod u+x kali-persistence.sh
    Run script:
      ./kali-persistence.sh {nameofiso}.iso
    Enter a password if prompted
    Progress is displayed while writing the iso
    If a previous label is detected
    Type 'y' at the prompt to proceed
    Progress is NOT displayed while partitioning the USB drive
    When finished, Disk and Device info displayed
    
    To use the live USB drive:
    Reboot
    Use WHATEVER! key is need to boot from the USB drive
    SOME boot menu keys by manufacturer
    Acer      F12, F9, Esc
    Asus      F8, Esc
    Dell      F12
    Fujitsu   F12, Esc
    HP        F9, Esc
    Lenovo    F12,F8, F10, Novo
    Samsung   F12, F2, Esc
    Sony      F11, F10, Esc
    Toshiba   F12
    others    F12, Esc
    Apple     Option
    
    Choose: 'Live USB Persistence'
    Login: root
    Password: toor
    
    # .......1.........2.........3.........4.........5.........6....
    Writing the iso should look something like the following.
    I am writing 'kali-linux-light-2019.1a-i386.iso'
    To a 4gb USB drive, leaving about 3gb persistence.
    For a NON-light kali iso, use an 8gb or larger USB drive.
    
    # .......1.........2.........3.........4.........5.........6....
    root@kali:~/Downloads/kali# ls -la
    total 1049596
    drwxr-xr-x 2 root root       4096 Apr 10 08:57 .
    drwxr-xr-x 3 root root       4096 Apr 10 08:57 ..
    -rw-r--r-- 1 root root 1074769920 Mar 21 15:22 kali-linux-light-2019.1a-i386.iso
    -rw-r--r-- 1 root root       1865 Apr  9 08:46 kali-persistence.sh
    
    root@kali:~/Downloads/kali# chmod u+x kali-persistence.sh
    
    root@kali:~/Downloads/kali# ls -la
    total 1049596
    drwxr-xr-x 2 root root       4096 Apr 10 08:57 .
    drwxr-xr-x 3 root root       4096 Apr 10 08:57 ..
    -rw-r--r-- 1 root root 1074769920 Mar 21 15:22 kali-linux-light-2019.1a-i386.iso
    -rwxr--r-- 1 root root       1865 Apr  9 08:46 kali-persistence.sh
    
    root@kali:~/Downloads/kali# ./kali-persistence.sh kali-linux-light-2019.1a-i386.iso
    
    Write kali-linux-light-2019.1a-i386.iso to /dev/sdb
    1069547520 bytes (1.1 GB, 1020 MiB) copied, 92 s, 11.6 MB/s
    1024+1 records in
    1024+1 records out
    1074769920 bytes (1.1 GB, 1.0 GiB) copied, 92.516 s, 11.6 MB/s
    
    Persistence on /dev/sdb3 from 1075 to 4016
    Information: You may need to update /etc/fstab.
    
    mke2fs 1.44.5 (15-Dec-2018)
    /dev/sdb3 contains a ext3 file system labelled 'persistence'
    	last mounted on /mnt/kaliUSB on Wed Apr 10 08:24:02 2019
    Proceed anyway? (y,N) y
    Creating filesystem with 718080 4k blocks and 179520 inodes
    Filesystem UUID: f34264ea-4ca9-4952-8813-959535b2a9fe
    Superblock backups stored on blocks:
    	32768, 98304, 163840, 229376, 294912
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    Disk /dev/sdb: 3.8 GiB, 4016046080 bytes, 7843840 sectors
    Disk model: Transcend 4GB
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x4e1a8e59
    
    Device     Boot   Start     End Sectors  Size Id Type
    /dev/sdb1  *         64 2097151 2097088 1024M 17 Hidden HPFS/NTFS
    /dev/sdb2       2097152 2098559    1408  704K  1 FAT12
    /dev/sdb3       2099200 7843839 5744640  2.8G 83 Linux
    
    # .......1.........2.........3.........4.........5.........6....

  4. #4
    Join Date
    2016-Dec
    Location
    Canada
    Posts
    326
    Thnx. Much clear now

Similar Threads

  1. shell script to run airodump-ng for 10 seconds
    By debaser in forum General Archive
    Replies: 0
    Last Post: 2021-01-19, 21:54
  2. Help Creating a Shell Script
    By jrustad24 in forum General Archive
    Replies: 0
    Last Post: 2020-11-22, 10:32
  3. Open a new Kali shell in Nethunter Terminal in a script
    By CeEe4 in forum NetHunter General Questions
    Replies: 0
    Last Post: 2016-11-19, 08:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •