Skip to content

Instantly share code, notes, and snippets.

@do-aki
Created April 17, 2013 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save do-aki/5402830 to your computer and use it in GitHub Desktop.
Save do-aki/5402830 to your computer and use it in GitHub Desktop.
MySQL Casual Talks Vol.4 LT 「セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor」 http://www.slideshare.net/do_aki/mysql-config-editor を参照。 Crypt::ECB と Crypt::OpenSSL::AES が必要です。
######################################
# usage
# mylogin_dumper.pl ~/.mylogin.conf
######################################
use strict;
use warnings;
use Crypt::ECB;
#use Crypt::OpenSSL::AES;
my $my_login_file = shift;
my $my_key;
open(my $my_login, '<:bytes', $my_login_file);
seek($my_login, 4, 0); # Reserved for future use.
read($my_login, $my_key, 20); # LOGIN_KEY_LEN
my $crypt = new Crypt::ECB;
$crypt->cipher('Crypt::OpenSSL::AES');
$crypt->key(aes_create_key($my_key));
my $store_size;
while(read($my_login, $store_size, 4)) {
my $encrypted_block;
last unless (read($my_login, $encrypted_block, unpack('l', $store_size)));
print $crypt->decrypt($encrypted_block);
}
close($my_login);
# emulate my_aes_create_key at mysys_ssl/my_aes.cc
sub aes_create_key {
my $key = shift;
my @key = unpack('C20', $key);
my @rkey = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
for (my $i=0; $i < 20; ++$i) {
$rkey[$i % 16] ^= $key[$i];
}
pack('C16', @rkey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment