Remote Exploit Forums

Go Back   Remote Exploit Forums > Archives > BackTrack v2.0 Final > Tutorials & Guides


Tutorials & Guides Contributions welcome! Please check the rules & guidelines for posting

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-07-2008, 09:22 PM
Junior Member
 
Join Date: Jan 2008
Posts: 7
Default BT3 on USB with persistent changes, using Linux.

Before I start, I would like to thank Pureh@te for his video tutorial that covers this. GREAT JOB

When I could not find a written Tutorial that included the persistent changes, and was done from start to finish on a Linux box, I decided to write my own so here it is.
On a side note, this is the first Tutorial I have ever written, so any feedback would be appreciated


For this Tutorial I will be installing BT3 on a 2 GB Flash Drive. Feel free to use a drive with more capacity, I recommend that you have at least 2 GB's.

Now lets get started.

Download the BT3B USB version.

Open a terminal and wget it.
Code:
wget http://www.remote-exploit.org/cgi-bin/fileget?version=bt3b-usb
I can't post links so you'll have to correct it

Once you have downloaded the file. place it in a directory of your likings and forget about it for the time being.

We will need to split our 2GB drive into 2 separate partitions. One partition will be 1.10 GB's on a FAT32 file system, and the second will be the remainder of the free space as an Ext 3 filesystem.

I will be using "fdisk, mkfs, & fsck" to setup the partitions.

Insert your drive into the nearest USB port and lets-

Create the Partitions

Open a terminal and type the following command:
Code:
fdisk /dev/sdb
You will need ROOT Privs. for most of the commands I use

This is the fdisk prompt:
Code:
Command (m for help):
To list the existing partitions type "p" and enter
Code:
Command (m for help): p

Disk /dev/sdb: 1998 MB, 1998585344 bytes
255 heads, 63 sectors/track, 242 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa62da6ab

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1  *            1         132     1060258+  b  W95 FAT32
/dev/sdb2             133         242      883575  83  Linux
We need to delete these partitions so type "d" and enter
You will then be asked for the partition number that you want to delete.
Code:
Command (m for help): d
Partition number (1-4):
Type the number "1" and hit enter, now repeat the process for the remaining partitions.

Once there are no partitions, the output of "p" will be:
Code:
Command (m for help): p

Disk /dev/sdb: 1998 MB, 1998585344 bytes
255 heads, 63 sectors/track, 242 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa62da6ab

   Device Boot      Start         End      Blocks   Id  System
To create a new partition type "n" and enter. This will prompt us for some details:
Code:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)  
p
Partition number (1-4): 1
First cylinder (1-242, default 1):  
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-242, default 242): +1080M
Lets create the second partition
I know the first partition should be FAT32 and is clearly Linux, don't worry we are getting to that

Again type "n" and answer the questions.
Code:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-242, default 133):
Using default value 133
Last cylinder or +size or +sizeM or +sizeK (133-242, default 242):
Using default value 242
Lets look at our partition layout now. Type "p" and enter.
Code:
Command (m for help): p

Disk /dev/sdb: 1998 MB, 1998585344 bytes
255 heads, 63 sectors/track, 242 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa62da6ab

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  83  Linux
/dev/sdb2             133         242      883575   83  Linux
Its time to change the ID of partition 1 to correspond with the Fat 32 Filesystem type that we will be using.

Type "t" and enter, then answer the questions:
Code:
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)
We only need to change partition 1 because 2 is already set for Ext 3.

Now we will make the first partition bootable.

Type "a" and enter the partition number that you want bootable. in this instance it will be 1.
Code:
Command (m for help): a
Partition number (1-4): 1
One last look at our partitions before we move on, so type "p" and enter:
Code:
Command (m for help): p

Disk /dev/sdb: 1998 MB, 1998585344 bytes
255 heads, 63 sectors/track, 242 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa62da6ab

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         132     1060258+   b  W95 FAT32
/dev/sdb2             133         242      883575   83  Linux
Everything looks good so lets write these changes to the drive.
Type "w" and enter

Writing the Filesystems

For this task we will be using "mkfs"

At the terminal type:
Code:
user@laptop:~$ mkfs -t vfat /dev/sdb1
Should output
Code:
mkfs.vfat 2.11 (12 Mar 2005)
Then for the second partition type:
Code:
mkfs -t ext2 /dev/sdb2
Should output
Code:
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
56896 inodes, 226918 blocks
11345 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=234881024
7 block groups
32768 blocks per group, 32768 fragments per group
8128 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
Its time to use "fsck" to -

Check The Filesystems

At the Terminal type:
Code:
fsck -y /dev/sdb1
Should Output:
Code:
fsck 1.40.8 (13-Mar-2008)
dosfsck 2.11, 12 Mar 2005, FAT32, LFN
/dev/sdb1: 0 files, 1/264543 clusters
Then:
Code:
fsck -y /dev/sdb2
Should Output:
Code:
fsck 1.40.8 (13-Mar-2008)
e2fsck 1.40.8 (13-Mar-2008)
/dev/sdb2: clean, 11/55328 files, 6071/220893 blocks
Thats it, the partitions are created, filesystems written, and then checked. We are ready to start installing!!!

"cd" to the directory where you have the downloaded BT3 rar file, and run unrar.
Code:
unrar x bt3b141207.rar
If you experience issues on your Distro unpacking the .rar, be sure you have unrar installed.

Once the unpacking is completed OK we need to start copying files to our drive. "cd" into the unpacked directory and copy "boot" and "BT3" directories to the first partition of your flash drive.

So type:
Code:
cp -r boot /media/disk
Then:
Code:
cp -r BT3 /media/disk
I'm using ubuntu and the flash drive is mounted in /media you will need to change this to where your drive is mounted

We need to "cd" to the first partition of the flash drive.

So type:
Code:
cd /media/disk
"cd" into the boot directory and then into the syslinux directory.
Code:
cd boot/syslinux
Here we need to change a few permissions.

In the terminal type:
Code:
chmod 777 lilo
then:
Code:
chmod 777 syslinux
Using your favorite text editor we need to modify the syslinux.cfg file. Here I will use nano.
Code:
nano syslinux.cfg
Change this line:
Code:
LABEL pchanges
MENU LABEL BT3 Graphics mode with Persistent Changes
KERNEL /boot/vmlinuz
APPEND vga=0x317 initrd=/boot/initrd.gz ramdisk_size=6666 root=/dev/ram0 rw changes=/slax/slaxsave.dat autoexec=xconf;kdm
To:
Code:
LABEL pchanges
MENU LABEL BT3 Graphics mode with Persistent Changes
KERNEL /boot/vmlinuz
APPEND vga=0x317 initrd=/boot/initrd.gz ramdisk_size=6666 root=/dev/ram0 rw changes=/dev/sdb2 autoexec=xconf;kdm
You can add this line to any of the boot choices, as it is you will need to boot to "BT3 Graphics mode with Persistent Changes" for the changes to be saved

We need to go back up one directory to run the bootinst.sh script
So:
Code:
cd ..
An "ls" should show:
Code:
bootinst.bat  bootlilo.sh  dos        isolinux  mt86p     vesamenu.c32
bootinst.sh   chain.c32    initrd.gz  modules   syslinux  vmlinuz
Run the bootinst.sh script:
Code:
./bootinst.sh
This begins the Slax boot installer:
Code:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                        Welcome to Slax boot installer
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This installer will setup disk /dev/sdb1 to boot only Slax.

Warning! Master boot record (MBR) of /dev/sdb will be overwritten.
If you use /dev/sdb to boot any existing operating system, it will not work
anymore. Only Slax will boot from this device. Be careful!

Press any key to continue, or Ctrl+C to abort...
Hit any key and:
Code:
Flushing filesystem buffers, this may take a while...
Setting up MBR on /dev/sdb...
The Master Boot Record of  /dev/sdb  has been updated.
Activating partition /dev/sdb1...
No partition table modifications are needed.
Updating MBR on /dev/sdb...
Setting up boot record for /dev/sdb1...
Disk /dev/sdb1 should be bootable now. Installation finished.

Read the information above and then press any key to exit...
The install worked perfectly!!!!

Reboot your machine and test out the stick

If anyone has any questions or are not clear on any part of this Tutorial I will answer any of your questions to the best of my ablility.

Last edited by pureh@te; 06-08-2008 at 08:29 AM.
Reply With Quote
  #2 (permalink)  
Old 06-08-2008, 04:52 AM
Munkey106's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Lafayette, Louisiana
Posts: 165
Send a message via AIM to Munkey106
Default

Nice tutorial, thanks!
Reply With Quote
  #3 (permalink)  
Old 06-08-2008, 08:31 AM
pureh@te's Avatar
Jenkem Addict
 
Join Date: Mar 2007
Location: /dev/null
Posts: 5,549
Default

Excellent tutorial. Very clear and well documented. Two thumbs up

Fixed your link for you to.
Reply With Quote
  #4 (permalink)  
Old 06-08-2008, 09:45 AM
Senior Member
 
Join Date: May 2007
Posts: 207
Default

Awesome tutorial, thanks.

I'll be trying this when I get to work on Monday
Reply With Quote
  #5 (permalink)  
Old 06-08-2008, 12:49 PM
Junior Member
 
Join Date: Jan 2008
Posts: 7
Default

Quote:
Originally Posted by pureh@te View Post
Excellent tutorial. Very clear and well documented. Two thumbs up

Fixed your link for you to.
Thanks!!

And Thanks for fixing the link
Reply With Quote
  #6 (permalink)  
Old 06-22-2008, 05:36 PM
New Member
 
Join Date: Jun 2008
Posts: 2
Default

Quote:
Originally Posted by umattu View Post
We need to go back up one directory to run the bootinst.sh script
So:
Code:
cd ..
An "ls" should show:
Code:
bootinst.bat  bootlilo.sh  dos        isolinux  mt86p     vesamenu.c32
bootinst.sh   chain.c32    initrd.gz  modules   syslinux  vmlinuz
Run the bootinst.sh script:
Code:
./bootinst.sh
This begins the Slax boot installer:
But it doesn't, for me.

System:
Ubuntu v8.04 (essentially fresh/vanilla)
Backtrack v3 final
[Excluding hardware information]

Input:
Code:
./bootinst.sh
Output:
Code:
bash: ./bootinst.sh: Permission denied
root@(Your ad here):/media/disk/boot#
. . .

Code:
root@(Your ad here):/media/disk/boot# chmod +x bootinst.sh
root@(Your ad here):/media/disk/boot# ./bootinst.sh
Can't find device to install to.
Make sure you run this script from a mounted device.
Here's the text of bootinst.sh. I seriously hope it's standard, as my browser *thinks* it was downloaded from [remote exploit website], and had matching md5/sha1 checksums.

Code:
#!/bin/bash

set -e
TARGET=""
MBR=""

# Find out which partition or disk are we using
MYMNT=$(cd -P $(dirname $0) ; pwd)
while [ "$MYMNT" != "" -a "$MYMNT" != "." -a "$MYMNT" != "/" ]; do
   TARGET=$(egrep "[^[:space:]]+[[:space:]]+$MYMNT[[:space:]]+" /proc/mounts | cut -d " " -f 1)
   if [ "$TARGET" != "" ]; then break; fi
   MYMNT=$(dirname "$MYMNT")
done

if [ "$TARGET" = "" ]; then
   echo "Can't find device to install to."
   echo "Make sure you run this script from a mounted device."
   exit 1
fi
Searching around, a lot of users have had this problem, and have for the most part blamed it on OSX or SD cards. I'm using a 2gb usb flash drive. I got a little different information from fdisk regarding cylinders and whatnot. It could be my hardware, but I was kind of hoping there would be something else to this.
Reply With Quote
  #7 (permalink)  
Old 06-22-2008, 08:36 PM
Senior Member
 
Join Date: Jan 2007
Posts: 270
Default

I've had problems with the bootinst.sh when running it from distros other than BT. You should try to boot off a BT cd and run the script. When I ran the script from my slackware 12.1 system I got a "bad interpretor" error message. Same on gentoo. In both cases running it while booted off a bt cd succeeded.

I noticed you have your disk mounted in media. Does ubuntu automount(hal) external drives? If it does, this might possibly be the cause of your problem. You should "cat /proc/mounts" and see if your drive is listed. The "mount" command with no arguements will show you the same info. Possibly it is mounted with the noexec flag. I don't use ubuntu, or an auto-mounter of any kind. If it writes an entry in /etc/fstab it might shed a little light on your problem. Plugging in your drive then running "dmesg" might also be helpful.

Maybe you could shutdown the auto-mounter and mount your drive manually.

Or you could just boot off a bt cd and run the script.

Good Luck
Reply With Quote
  #8 (permalink)  
Old 06-23-2008, 01:01 PM
New Member
 
Join Date: Jun 2008
Posts: 2
Default Interesting . . .

fdisk returns:
Code:
Disk /dev/sdb: 1998 MB, 1998585856 bytes
16 heads, 32 sectors/track, 7624 cylinders
Units = cylinders of 512 * 512 = 262144 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        4121     1054960    b  W95 FAT32
/dev/sdb2            4122        7624      896768   83  Linux
mount returns:
Code:
. . . .
/dev/sdb1 on /media/disk-1 type vfat (rw,nosuid,nodev,uhelper=hal,shortname=mixed,uid=1001,utf8,umask=077,flush)
"/media/disk" isn't part of my usb stick, but the tutorial (if followed to the letter) has me install the core files on it. Newbie mistake on my part, I'm sure. "sdb2" doesn't auto-mount/mount at all, and can't be detected for some reason:
Code:
root@(Your ad here):/media# mount /dev/sdb2
mount: can't find /dev/sdb2 in /etc/fstab or /etc/mtab
root@(Your ad here):/media# umount /dev/sdb1
umount: /dev/sdb1: not mounted
I'm going to play around with fdisk's file systems for a bit. I have a feeling that Ubuntu doesn't have built in support for "id 83 (Linux)" file systems. That's silly. I thought anything with "Linux" in the title would automatically work together ;-)
Reply With Quote
  #9 (permalink)  
Old 06-23-2008, 05:22 PM
Junior Member
 
Join Date: Jan 2008
Posts: 7
Default

Quote:
Originally Posted by Starglider View Post
I'm going to play around with fdisk's file systems for a bit. I have a feeling that Ubuntu doesn't have built in support for "id 83 (Linux)" file systems. That's silly. I thought anything with "Linux" in the title would automatically work together ;-)
Ubuntu does support "id 83" I did all of this on an ubuntu system.

Here is my bootinst.sh:

Code:
#!/bin/bash

set -e
TARGET=""
MBR=""

# Find out which partition or disk are we using
MYMNT=$(cd -P $(dirname $0) ; pwd)
while [ "$MYMNT" != "" -a "$MYMNT" != "." -a "$MYMNT" != "/" ]; do
   TARGET=$(egrep "[^[:space:]]+[[:space:]]+$MYMNT[[:space:]]+" /proc/mounts | cut -d " " -f 1)
   if [ "$TARGET" != "" ]; then break; fi
   MYMNT=$(dirname "$MYMNT")
done

if [ "$TARGET" = "" ]; then
   echo "Can't find device to install to."
   echo "Make sure you run this script from a mounted device."
   exit 1
fi

MBR=$(echo "$TARGET" | sed -r "s/[0-9]+\$//g")
NUM=${TARGET:${#MBR}}
cd "$MYMNT"

clear
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "                        Welcome to Slax boot installer                         "
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo
echo "This installer will setup disk $TARGET to boot only Slax."
if [ "$MBR" != "$TARGET" ]; then
   echo
   echo "Warning! Master boot record (MBR) of $MBR will be overwritten."
   echo "If you use $MBR to boot any existing operating system, it will not work"
   echo "anymore. Only Slax will boot from this device. Be careful!"
fi
echo
echo "Press any key to continue, or Ctrl+C to abort..."
read junk
clear

echo "Flushing filesystem buffers, this may take a while..."
sync

# setup MBR if the device is not in superfloppy format
if [ "$MBR" != "$TARGET" ]; then
   echo "Setting up MBR on $MBR..."
   ./boot/syslinux/lilo -S /dev/null -M $MBR ext # this must be here to support -A for extended partitions
   echo "Activating partition $TARGET..."
   ./boot/syslinux/lilo -S /dev/null -A $MBR $NUM
   echo "Updating MBR on $MBR..." # this must be here because LILO mbr is bad. mbr.bin is from syslinux
   cat ./boot/syslinux/mbr.bin > $MBR
fi

echo "Setting up boot record for $TARGET..."
./boot/syslinux/syslinux -d boot/syslinux $TARGET

echo "Disk $TARGET should be bootable now. Installation finished."

echo
echo "Read the information above and then press any key to exit..."
read junk
Quote:
Originally Posted by Starglider View Post
"/media/disk" isn't part of my usb stick, but the tutorial (if followed to the letter) has me install the core files on it.
/media/disk is NOT part of your drive, ubuntu auto mounts the USB stick and other drives in the /media directory. So /dev/sdb1 should be mounted as /media/disk and /dev/sdb2 should be mounted in /media/disk-1.

If you were to try and copy the files to /dev/sdb1, stdout would tell you that it is not a directory
Code:
bash: cd: /dev/sdb1: Not a directory
Try to
Code:
user@lappie:~$cd /media/disk/boot
Then
Code:
user@lappie:/media/disk/boot$sudo ./bootinst.sh
Let me know what happens.
Reply With Quote
  #10 (permalink)  
Old 06-26-2008, 12:12 PM
Senior Member
 
Join Date: Apr 2006
Posts: 166
Question

Got problems....if I use /sdb2 it doesn't save....
So i've booted without saving and noticed that sda2 is the linux partition and sda1 is the vfat.... so i've tryed to use /sda2 but the boot process hangs with the message:

mount: mounting aufs on union failed
Fatal error occoured - can't setup union (aufs)
Please reboot....

Any idea?

-----------------------edit------------------------------------------------------

Just manually create in ext2 partition the "changes" folder...

---------------------------------------------------------------------------------

Please add the trick in the main thread!

Last edited by michelinok; 06-26-2008 at 12:26 PM.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:38 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2