PROJET AUTOBLOG ~ Streisand Effect


BohwaZ

Site original : BohwaZ

⇐ retour index

Remove DRM from Kindle AZW files

Friday 20 February 2015 à 23:58

When you buy a book for your Kindle on Amazon, it comes with a special surprise: DRM. Yes we are in 2015, every book ever published is already available everywhere to download for free, but you still get this stupid thing that basically pisses everybody and forbids to just use the stuff you paid for. Unbelievable. They will never learn.

So, what do you do when you accidentally bought a DRM e-book? First you swear you'll never do the same mistake again, and next time you'll just download the book from The Pirate Bay, it will be faster, easier and you will be able to read the book without wondering why the hell did you pay for a file that you can't read. When that is done, you will actually get rid of the DRM following this simple procedure:

  1. Power up your Kindle, switch back to the Kindle UI (if you have installed Duokan, which I advise you to do strongly, it's great!), go to the system settings and note your Kindle Serial Number.
  2. Download the file from Amazon ("Manage Your Content", click on the button with three dots next to the book and click "Download and transfer from USB")
  3. Download the DeDRM plugin for Calibre here.
  4. $ unzip DeDRM_plugin.zip
  5. $ python k4mobidedrm.py -s YOUR_KINDLE_SERIAL_NUMBER Stupid_encrypted_DRM_book.azw ./

That's it. A new file called Stupid_encrypted_DRM_book_nodrm.mobi will be in the directory. Delete the old one.

What was this DRM thingy for?

HOWTO: Using a removable USB key or SD card as an encryption key with EncFS

Saturday 24 January 2015 à 04:13

For this HOWTO you will need the encfs package installed (Debian and Ubuntu).

Create an empty partition on the disk

We still want to be able to use the key to store some documents, and that way it will just look like an ordinary USB key. So we have to create an empty filesystem on the removable USB key:

# USB_KEY=/dev/sdX
# fdisk $USB_KEY

Command (m for help): o
Building a new DOS disklabel with disk identifier 0xXXXXXX.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-1974271, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1974271, default 1974271): 1974270

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)

Make sure that the last sector of the partition is minus one the last one of the disk. Here the last sector of the disk is 1974271, so (1974271-1) = 1974270.

Now write the partition table:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

Now format the new partition:

# mkfs.vfat -F 32 -n Documents ${USB_KEY}1

Random "hidden" passphrase

Now comes the part of the crypto stuff. Create a random passphrase:

# dd if=/dev/urandom bs=1 count=256 > passphrase.bin

Write it to the end of the USB key:

# USB_SEEK=$(($(blockdev --getsize64 $USB_KEY)-256))
# dd if=passphrase.bin of=$USB_KEY bs=1 seek=$USB_SEEK

This way the passphrase won't be stored in a filesystem but directly on the disk, where overwriting it by mistake will be a bit more difficult. It's also a bit harder for an attacker to know that the disk actually contains an encryption passphrase (but just a bit).

You can check that the passphrase was correctly written to the disk with:

# sha1sum passphrase.bin; dd if=/dev/sdg bs=1 skip=$USB_SEEK count=256 2> /dev/null | sha1sum

The two SHA1 sums should match.

At this step I advise you to backup your passphrase, maybe by encoding it using Bubble Babble, printing it and hiding it somewhere. Or just put it in a wallet manager like KeePassX. As you wish.

Encrypted directory creation

If you already have an encrypted EncFS directory, you can skip to the next step. If you don't have an encrypted EncFS directory already here is how you can create one:

$ encfs ~/encrypted ~/decrypted
Creating new encrypted volume.
Please choose from one of the following options:
 enter "x" for expert configuration mode,
 enter "p" for pre-configured paranoia mode,
 anything else, or an empty line will select standard mode.
?>

Press p and Enter.

Paranoia configuration selected.

Configuration finished.  The filesystem to be created has
the following properties:
Filesystem cipher: "ssl/aes", version 3:0:2
Filename encoding: "nameio/block", version 3:0:1
Key Size: 256 bits
Block Size: 1024 bytes, including 8 byte MAC header
Each file contains 8 byte header with unique IV data.
Filenames encoded using IV chaining mode.
File data IV is chained to filename IV.
File holes passed through to ciphertext.

-------------------------- WARNING --------------------------
The external initialization-vector chaining option has been
enabled.  This option disables the use of hard links on the
filesystem. Without hard links, some programs may not work.
The programs 'mutt' and 'procmail' are known to fail.  For
more information, please see the encfs mailing list.
If you would like to choose another configuration setting,
please press CTRL-C now to abort and start over.

Now you will need to enter a password for your filesystem.
You will need to remember this password, as there is absolutely
no recovery mechanism.  However, the password can be changed
later using encfsctl.

New Encfs Password: 

Enter (twice) a temporary password as we are about to change it. So enter something like abcd or stuff.

Changing the EncFS password

Now we will to change the current password of the encrypted directory to the passphrase we generated and wrote to the USB key before.

$ echo -n "Enter current password: " && read -s PASSWORD && (echo $PASSWORD && base64 -w 0 passphrase.bin) | encfsctl autopasswd ~/decrypted

Type in your current password (the temporary one if you just created the encrypted directory at the previous step), hit Enter, and then EncFS will change the password to the one contained in the file passphrase.bin, encoded with Base64. This encoding is useful as EncFS expects a one-line password and

Now unmount the encrypted directory so that we can try if mounting it with our key works:

$ fusermount -u ~/decrypted

Let's try if we can mount our encrypted directory with our key:

$ base64 -w 0 passphrase.bin | encfs -S ~/encrypted ~/decrypted

And it should work.

Real-word test: mount script

And finally we are ready to mount our encrypted directory using our USB key and this simple script:

#!/bin/sh

if [ "$1" = "" -o "$2" = "" ]
then
	echo "Usage: $0 rootDir mountPoint"
	exit 0
fi

mountpoint -q "$2" && echo "$1 is already mounted" && exit 1

echo "Trying to get the key from USB keychain ..." >&2

for SFS in /sys/block/sd*; do
	DEV=`basename $SFS`
	if [ 0`cat $SFS/removable` -eq 1 -a 0`cat $SFS/size` -gt 1 ]
	then
		SKIP=$((512*$(cat /sys/block/${DEV}/size)-256))
		KEY=`dd if=/dev/${DEV} bs=1 skip=$SKIP 2> /dev/null`

		echo "> Trying device: $DEV ..." >&2
		echo -n "${KEY}" | base64 -w 0 | encfs -S "$1" "$2" \
			&& echo "Encrypted directory mounted from keyfile" && exit 0
	fi
done

echo "FAILED to find suitable USB keychain ..."
exit 1

The script is simply trying to use all the removable devices as decryption key for encfs. To use it you just have to run:

$ mount_encfs_usb.sh ~/encrypted ~/decrypted
Trying to get the key from USB keychain ...
> Trying device: sdg ...
Encrypted directory mounted from keyfile

And that's the end of this HOWTO :)

This was inspired by this StackOverflow thread and How to setup passwordless disk encryption.

Bubble Babble CLI encoder / decoder

Saturday 24 January 2015 à 03:16

At my own surprise there is no CLI tool to encode or decode a string to and from the Bubble Babble binary encoding. That's a shame as this encoding would be much more useful than Base64 for exchanging binary data orally or on paper.

So here is one quick PHP script based on my own PHP5 BubbleBabble library to do that: bubblebabble.php

Usage is pretty simple:

$ bubblebabble.php hello.txt
xifok-mirid-bodik-nemyg-temyl-dipyd-cedyx

$ bubblebabble.php -d - <<< xifok-mirid-bodik-nemyg-temyl-dipyd-cedyx
Oh, Hi Mark!

$ fortune | bubblebabble - > encoded.txt

$ bubblebabble -d encoded.txt 
Big book, big bore.
		-- Callimachus

Undocumented PHP/SQLite3 features: openBlob, readOnly, enableExceptions

Friday 23 January 2015 à 01:34

The SQLite3 module of PHP has some undocumented features that you may discover when you are reading the source code (yes that's what I do when I get bored, nothing is more fascinating than reading source code, really, you should try it).

Sqlite3Stmt::readOnly(void)

Available from PHP 5.3.5.

This method returns true if a statement doesn't change the database. This is useful sometimes, like to make sure that a template engine is only reading data and not altering the databse. Another use would be providing a way for the user to make queries on the database to select any data he wants (yes you wouldn't want this to be available to any user).

One example to check if there is no injection:

$_GET['id'] = 42;
$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = '.$_GET['id'].';');
var_dump($statement->readOnly());
// bool(true)

And if there was an injection:

$_GET['id'] = 'NULL; DROP TABLE nuclear_warheads_locations;';
$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = '.$_GET['id'].';');
var_dump($statement->readOnly());
// bool(false)

Of course you NEVER should insert any PHP variables straight in a SQL query. Instead you should use bindValue:

$statement = $db->prepare('SELECT * FROM cooking_recipes WHERE id = :id;');
$statement->bindValue(':id', $_GET['id']);

SQLite3::openBlob(string table, string column, int rowid [, string dbname])

Another undocumented feature of the PHP SQLite3 object, available since 2009, is openBlob. Basically it's a function that will return a stream pointer to a blob value in a table. Very very useful when you are dealing with files stored in a SQLite3 database.

Source code says:

proto resource SQLite3::openBlob(string table, string column, int rowid [, string dbname])
Open a blob as a stream which we can read / write to.

But despite that it's not possible to write to the blob, only reading is implemented. The blob are always opened as read-only by SQLite, so if you try to write to the stream, nothing will be saved to the database.

One example of use:

$db = new SQLite3('files.sqlite');
$db->exec('CREATE TABLE files (id INTEGER PRIMARY KEY, filename TEXT, content BLOB);');

$statement = $db->prepare('INSERT INTO files (filename, content) VALUES (?, ?);');
$statement->bindValue('filename', 'Archive.zip');
$statement->bindValue('content', file_get_contents('Archive.zip'));
$statement->execute();

$fp = $db->openBlob('files', 'content', $id);

while (!feof($fp))
{
    echo fgets($fp);
}

fclose($fp);

You can also seek in the stream. This is pretty useful for saving large files from the database too, this way you can use stream_copy_to_stream, it will be faster and more memory-efficient than dumping the file in memory before writing it to the disk.

Please note that openBlob() won't work on VIRTUAL FTS4 compressed tables (but no problem with non-compressed virtual tables).

SQLite3::enableExceptions([bool enableExceptions = false])

Available since 2009 (PHP version ??).

If set to true, then errors will be returned as exceptions instead of errors.

Ceci n'est pas une suite – Ginger Snaps Unleashed

Wednesday 21 January 2015 à 00:37

Il ne faut pas se méprendre en se limitant à la jaquette DVD de l'édition française qui repompe Underworld et qui change le titre du film de "Ginger Snaps Unleashed" à "Ginger Snaps Resurrection", cette suite n'en est pas réellement une car en restant dans le thème et avec Brigitte du premier opus, le ton est complètement différent. Il ne faut donc pas s'attendre à voir la même chose que Ginger Snaps mais en plus fort, plus vite, plus mieux, c'est simplement un film différent.

On retrouve ici la talentueuse Emily Perkins et l'excellente Tatiana Maslany qui livrent une prestation extraordinaire dans des registres très différents. Le scénario prend un tournant inattendu avec le rapport entre lycanthropie et addiction aux stupéfiants et envoie le personnage principal dans un hôpital étrange et surréaliste, à moitié abandonné, rempli d'infirmiers corrompus, où elle rencontrera Ghost (Tatiana Maslany), une gamine totalement déjantée.

L'ambiance est campée et nous emmène dans un film d'épouvante relativement dérangeant et bien ficelé, de la musique à la réalisation en passant par les effets spéciaux « old school » (pas de CGI) jusqu'à une fin complètement tarée.