Topic: mysql 口令算法 |
Print this page |
1.mysql 口令算法 | Copy to clipboard |
Posted by: 阿熊 Posted on: 2012-08-21 23:22 mysql口令的加密分两种。一种是古董级别的mysql323加密,另一种是蒙骗了大众的的mysql sha1加密。 虽然现在遇到这样的加密可以用cain来破解,按说我不用在这里多此一举,但本文不是为了破解而写,只是科普一下,让大家更清楚的了解mysql口令的加密方法到底是怎样的。 先说mysql4.1.x版本以后的: mysql> select password('kyo327'); +-------------------------------------------+ | password('kyo327') | +-------------------------------------------+ | *B19CB640DF626A73397BFBBB8111D11E2BEC11F1 | +-------------------------------------------+ 1 row in set (0.02 sec) mysql> select sha1('kyo327'); +------------------------------------------+ | sha1('kyo327') | +------------------------------------------+ | d81e2a1a72f5a4f570b0f05baaa0cffc5d2d6820 | +------------------------------------------+ 1 row in set (0.03 sec) 很明显不是标准的sha1加密。然而这个问题像是皇帝的新装一样,好像没有哪个人指出来,那我就在这里当一次无知的小孩吧。 再看下面 mysql> select sha1(0xd81e2a1a72f5a4f570b0f05baaa0cffc5d2d6820); +--------------------------------------------------+ | sha1(0xd81e2a1a72f5a4f570b0f05baaa0cffc5d2d6820) | +--------------------------------------------------+ | b19cb640df626a73397bfbbb8111d11e2bec11f1 | +--------------------------------------------------+ 1 row in set (0.00 sec) 我想无需用过多言语,大家应该都很清楚mysql4.1.x以后版本的加密方式了吧。 接下来说一说mysql323加密。 这个我是直接从mysql源代码里抠出来的。代码如下: #include "stdio.h" #include <string.h> void hash_password(long *result, const char *password, int password_len) { register long nr=1345345333L, add=7, nr2=0x12345671L; long tmp; const char *password_end= password + password_len; for (; password < password_end; password++) { if (*password == ' ' || *password == '\t') continue; /* skip space in password */ tmp= (long) (char) *password; nr^= (((nr & 63)+add)*tmp)+ (nr << 8); nr2+=(nr2 << 8) ^ nr; add+=tmp; } result[0]=nr & (((long) 1L << 31) -1L); /* Don't use sign bit (str2int) */; result[1]=nr2 & (((long) 1L << 31) -1L); } int main(int argc, char* argv[]) { const char *password="kyo"; long hash_res[2]; hash_password(hash_res, password, (int) strlen(password)); printf("%08lx%08lx\n", hash_res[0], hash_res[1]); return 0; } 运行后 7901b47128d1045d ----------------------------------------------------------------------------------- mysql> select old_password('kyo'); +---------------------+ | old_password('kyo') | +---------------------+ | 7901b47128d1045d | +---------------------+ 1 row in set (0.00 sec) ----------------------------------------------------------------------------------- over。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |