📄 00000002.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: reden (Offer 快快来啊 ~!), 信区: Linux <BR>标 题: Linux程式设计入门 - crypt <BR>发信站: BBS 水木清华站 (Thu Apr 1 19:56:43 1999) <BR> <BR>Linux程式设计入门 - crypt <BR> <BR> <BR> <BR> crypt是个密码加密函数,它是基於Data Encryption Standard(DES)演算法。 <BR> <BR> crypt基本上是One way encryption,因此它只适用於密码的使用,不适合於资 <BR> <BR> 料加密。 <BR> <BR> <BR> char *crypt(const char *key, const char *salt); <BR> <BR> <BR> key是使用者的密码。salt是两个字,每个字可从[a-zA-Z0-9./]中选出来,因 <BR> <BR> 此同一密码增加了4096种可能性。透过使用key中每个字的低七位元,取得 <BR> <BR> 56-bit关键字,这56-bit关键字被用来加密成一组字,这组字有13个可显示的 <BR> <BR> ASCII字,包含开头两个salt。 <BR> <BR> <BR> crypt在您有自行管理使用者的场合时使用,例如会员网站、BBS等等。 <BR> <BR> <BR> <BR> 范例一 : crypt_word.c <BR> <BR> <BR> #include <stdio.h> <BR> <BR> #include <stdlib.h> <BR> <BR> #include <unistd.h> <BR> <BR> <BR> void main(int argc,char **argv) <BR> <BR> { <BR> <BR> if (argc!=3) exit(0); <BR> <BR> printf("%s\n",crypt(argv[1],argv[2])); <BR> <BR> } <BR> <BR> <BR> 编译 <BR> <BR> <BR> gcc -o crypt_word crypt.c -lcrypt <BR> <BR> <BR> 检验 <BR> <BR> <BR> 请先看您的/etc/passwd,找一个您自己的帐号,看前面两个字,那是您自己的 <BR> <BR> salt。接下来输入: <BR> <BR> <BR> ./crypt_word your_password salt <BR> <BR> <BR> 看看它们是否相同(应该要相同,除非您加了crypt plugin或使用不同的crypt <BR> <BR> function,例如shadow、pam,这种状况下,加密字是不同的),另外检验看看 <BR> <BR> 他们是否为13个字。 <BR> <BR> <BR> 您也可以利用Apache上所附的htpasswd来产生加密字做为验证。 <BR> <BR> <BR> 范例二: verify_passwd.c <BR> <BR> <BR> 注意,这个范例读取/etc/passwd的资料,不适用於使用shadow或已经使用pam <BR> <BR> 的系统(例如slackware,RedHat及Debian在不外加crypt plugin的状况下,应 <BR> <BR> 当相同)。此范例仅供叁考,做为了解crypt函数运作的情形,真正撰写程式 <BR> <BR> 时,应该避免类似的写法。 <BR> <BR> <BR> #include <stdio.h> <BR> <BR> #include <stdlib.h> <BR> <BR> #include <unistd.h> <BR> <BR> <BR> typedef struct { <BR> <BR> char username[64]; <BR> <BR> char passwd[16]; <BR> <BR> int uid; <BR> <BR> int gid; <BR> <BR> char name[256]; <BR> <BR> char root[256]; <BR> <BR> char shell[256]; <BR> <BR> } account; <BR> <BR> <BR> /* 注意! 以下的写法,真实世界的软体开发状况下,千万不要用! */ <BR> <BR> int acc_info(char *info,account *user) <BR> <BR> { <BR> <BR> char * start = info; <BR> <BR> char * now = info; <BR> <BR> <BR> /* username */ <BR> <BR> while (*now&&*now!=':') now++; /* 这是超级大安全漏洞 */ <BR> <BR> if (!*now) return 0; <BR> <BR> *now = 0; now++; <BR> <BR> strcpy(user->username,start); /* 这会导致buffer overflow */ <BR> <BR> start = now; <BR> <BR> /* passwd */ <BR> <BR> while (*now&&*now!=':') now++; /* 这是超级大安全漏洞 */ <BR> <BR> if (!*now) return 0; <BR> <BR> *now = 0; now++; <BR> <BR> strcpy(user->passwd,start); /* 这会导致buffer overflow */ <BR> <BR> start = now; <BR> <BR> /* uid */ <BR> <BR> while (*now&&*now!=':') now++; <BR> <BR> if (!*now) return 0; <BR> <BR> *now = 0; now++; <BR> <BR> user->uid = atoi(start); <BR> <BR> start = now; <BR> <BR> /* gid */ <BR> <BR> while (*now&&*now!=':') now++; <BR> <BR> if (!*now) return 0; <BR> <BR> *now = 0; now++; <BR> <BR> user->gid = atoi(start); <BR> <BR> start = now; <BR> <BR> /* name */ <BR> <BR> while (*now&&*now!=':') now++; /* 这是超级大安全漏洞 */ <BR> <BR> if (!*now) return 0; <BR> <BR> *now = 0; now++; <BR> <BR> strcpy(user->name,start); /* 这会导致buffer overflow */ <BR> <BR> start = now; <BR> <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -