📄 wkeygen.c
字号:
/* * wkeygen.c * WEP Key Generators * * This program generates WEP keys using de facto standard key * generators for 40 and 128 bit keys. * * Link against OpenSSL's libcrypto.a * * I place this code in the public domain. * May 2001, Tim Newsham * May 2006, Fernando Tarin */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <openssl/md5.h>#include "config.h"#define WEPKEYSIZE 5#define WEPSTRONGKEYSIZE 13#define WEPKEYS 4#define WEPKEYSTORE (WEPKEYSIZE * WEPKEYS)#define WEPSTRONGKEYSTORE (WEPSTRONGKEYSIZE * WEPKEYS)#define TAM_LINE 25#define ERROR 0#define OK 1/* * gets a line from file stream if TAM_LINE is exceeded an error is raised */int get_line (char * line, FILE * stream){ int i=0; while (i < (TAM_LINE-1) && (line[i] = fgetc(stream)) != '\n') i++; line[i] = '\0'; if (i == (TAM_LINE-1)) return ERROR; else return OK;}/* * generate four subkeys from a seed using the defacto standard */voidwep_seedkeygen(int val, u_char *keys){ int i; for(i = 0; i < WEPKEYSTORE; i++) { val *= 0x343fd; val += 0x269ec3; keys[i] = val >> 16; } return;}/* * generate one key from a string using the de facto standard * * resultant key is stored in * one 128 bit key: keys[0-15] * * (NOTE: I'm not sure why, but it seems that only values 0-12 are used, * resulting in 104 bits of keying, not 128) */voidwep_keygen128(char *str, u_char *keys){ MD5_CTX ctx; u_char buf[64]; int i, j; /* repeat str until buf is full */ j = 0; for(i = 0; i < 64; i++) { if(str[j] == 0) j = 0; buf[i] = str[j++]; } MD5_Init(&ctx); MD5_Update(&ctx, buf, sizeof buf); MD5_Final(buf, &ctx); memcpy(keys, buf, WEPSTRONGKEYSTORE); for(i = 0; i < WEPSTRONGKEYSIZE; i++) { keys[i] = buf[i]; } //for(; i < WEPSTRONGKEYSTORE; i++) { // keys[i] = 0; //} return;}/* * generate four subkeys from a string using the defacto standard * * resultant keys are stored in * four 40 bit keys: keys[0-4], keys[5-9], keys[10-14] and keys[15-20] */voidwep_keygen40(char *str, u_char *keys) { int val, i, shift; /* * seed is generated by xor'ing in the keystring bytes * into the four bytes of the seed, starting at the little end */ val = 0; for(i = 0; str[i]; i++) { shift = i & 0x3; val ^= (str[i] << (shift * 8)); } wep_seedkeygen(val, keys); return;}voidwep_keyprint40(u_char *keys){ int i; char sepchar; for(i = 0; i < WEPKEYSTORE; i++) { sepchar = (i % WEPKEYSIZE == WEPKEYSIZE - 1) ? '\n' : ':'; printf("%02x%c", keys[i], sepchar); } return;}voidwep_keyprint128(u_char *keys){ int i; char sepchar; for(i = 0; i < WEPSTRONGKEYSIZE; i++) { sepchar = (i % WEPSTRONGKEYSIZE == WEPSTRONGKEYSIZE - 1) ? '\n' : ':'; printf("%02x%c", keys[i], sepchar); } return;}voidusage(char *prog){ printf("Usage: %s -i [-s] | [-s] keystring\n", prog); printf("\t -i reads keystring from stdin\n"); printf("\t -s generates a 128 wepkey default is 64 wepkey\n"); printf("\nThis tool is part from Wepdecrypt project - Version %s\n", VERSION); printf("http://wepdecrypt.sourceforge.net/\n"); exit(1);}intmain(int argc, char **argv) { u_char keys[WEPKEYSTORE]; u_char strongkeys[WEPSTRONGKEYSTORE]; char *prog, *genstr, keystr[TAM_LINE]; int strong, ch, readstdin; prog = argv[0]; strong = readstdin = 0; if (argc == 1) usage(prog); while((ch = getopt(argc, argv, "is")) != EOF) { switch(ch) { case 's': if (argc == 2) usage(prog); strong ++; break; case 'i': if (strong || (argc > 2 && (strncmp(argv[2],"-s",2) != 0)) || argc > 3 || ((strncmp(argv[1],"-i",2) != 0) && (strncmp(argv[1],"-s",2) != 0))) usage(prog); readstdin++; break; default: usage(prog); } } if (readstdin) { //while (fscanf(stdin, "%s", keystr) != EOF){ while (1){ get_line(keystr, stdin); if (keystr[0] == EOF) break; genstr = keystr; if(strong) { wep_keygen128(genstr, strongkeys); wep_keyprint128(strongkeys); } else { wep_keygen40(genstr, keys); wep_keyprint40(keys); } } } else{ if(strong) { genstr = argv[2]; wep_keygen128(genstr, strongkeys); wep_keyprint128(strongkeys); } else { genstr = argv[1]; wep_keygen40(genstr, keys); wep_keyprint40(keys); } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -