Create executable, automountable filesystem in a file, with password!

dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it. USAGE: SEE SAMPLE OUTPUT The file is composed of three parts: a) The legible script (about 242 bytes) b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242) c) The actual filesystem Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option. PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :) It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file. The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables.
Sample Output
Use at your own risk.

# dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');  echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm    T)>>F
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.127043 s, 82.5 MB/s
T is not a block special device.
Proceed anyway? (y,n) y
1+0 records in
1+0 records out
9104 bytes (9.1 kB) copied, 0.000116352 s, 78.2 MB/s

(before executing next, make sure /mnt is empty and has nothing mounted, otherwise you can lose files)

# bash F
9191
(I entered 9191, is the password, can be modified in the script)

# l /mnt/
drwx------ 2 root root 12K Jan 31 02:33 lost+found/

# df -h
Filesystem        Size  Used Avail Use% Mounted on
...
/dev/loop0        9.7M  1.1M  8.1M  12% /mnt

# mount
...
/root/F on /mnt type ext3 (rw,relatime,data=ordered)

# umount /mnt 

# head -1 F
E=$(echo cmVhZCBPO21vdW50IC1vIGxvb3Asb2Zmc2V0PSRPIEYgL21udDsK|base64 -d);eval $E;exit;

# E=$(echo cmVhZCBPO21vdW50IC1vIGxvb3Asb2Zmc2V0PSRPIEYgL21udDsK|base64 -d);echo $E
(changed eval x echo)
read O;mount -o loop,offset=$O F /mnt;

What Others Think

doesnt seem to work on ubunbu, bash F just hangs
chrismccoy · 513 weeks and 6 days ago
Chrismccoy: It's probably not hanging, but asking you for the offset. If not, just follow the procedure (sample output) to confirm it generated the executable base64 encoder header correctly. I'ts really simple...
rodolfoap · 513 weeks and 6 days ago
(executable base64 encodeD header)
rodolfoap · 513 weeks and 6 days ago
head -1 F shows the exact same as yours, then the next part root@sorry:/home/chris# read O;mount -o loop,offset=$O F /mnt; mount: invalid offset '' specified
chrismccoy · 513 weeks and 5 days ago
nm got it working ;)
chrismccoy · 513 weeks and 5 days ago
OG WhatsApp APK is an updated version of the official WhatsApp app that has been enhanced with new features and rendered more OGWhatsApp APK Download
alenaofficial · 36 weeks and 6 days ago
I have tried the code you have shared here and it worked well. legal cbd products You have shared comments with each line will be helpful to get a clear idea about the code without much difficulty. Thanks for your effort.
TwanGrey · 35 weeks and 2 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas Amazing! This blog looks just like my old one! It's on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!
rahimhh21 · 14 weeks and 6 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 5 weeks and 6 days ago
More than 11,000 years ago, humans started passing through the region, as shown by some dordle of the park's estimated 1,850 archeological sites.
emotionplague · 1 week ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: