Professional Documents
Culture Documents
#include <ctype.h>
#include <libgen.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <curl/curl.h>
#include "include/strings.c"
/*===========================================================================*/
static bool downloadoui(char *ouiname)
{
static size_t bread;
static CURLcode ret;
static CURL *hnd;
static FILE *fhoui;
static FILE *fhouitmp;
static char ouibuff[OUIBUFFER_MAX];
while (len) {
if (*ptr != '\r') break;
*ptr-- = 0;
len--;
}
return len;
}
/*---------------------------------------------------------------------------*/
static int fgetline(FILE *inputstream, size_t size, char *buffer)
{
if (feof(inputstream)) return -1;
char *buffptr = fgets (buffer, size, inputstream);
return len;
}
/*===========================================================================*/
static void getessidinfo(char *essidname)
{
static int l, p;
static uint8_t essidbuffer[66];
l = strlen(essidname);
if((l < 2) || (l > 64))
{
fprintf(stderr, "not a valid ESSID hex string\n");
return;
}
if((l %2) != 0)
{
fprintf(stderr, "not a valid hex string\n");
return;
}
for(p = 0; p < l; p++)
{
if(!isxdigit((unsigned char)essidname[p]))
{
fprintf(stderr, "not a valid hex string\n");
return;
}
}
memset(&essidbuffer, 0, 66);
if(hex2bin(essidname, essidbuffer, l /2) == false)
{
fprintf(stderr, "not a valid ESSID hex string\n");
return;
}
fprintf(stdout, "%s\n", essidbuffer);
return;
}
/*===========================================================================*/
static void gethexessidinfo(char *hexessidname)
{
static int l, p;
l = strlen(hexessidname);
for(p = 0; p < l; p++)
{
fprintf(stdout, "%02x", hexessidname[p]);
}
fprintf(stdout, "\n");
return;
}
/*===========================================================================*/
static void get16800info(char *ouiname, char *hash16800line)
{
static int len;
static int l, l1;
static FILE* fhoui;
static char *vendorptr;
static char *essidptr;
static char *passwdptr;
fclose(fhoui);
return;
}
/*===========================================================================*/
static void get2500info(char *ouiname, char *hash2500line)
{
static int len;
static int l, l1;
static FILE* fhoui;
static char *vendorptr;
static char *essidptr;
static char *passwdptr;
fclose(fhoui);
return;
}
/*===========================================================================*/
static void getoui(char *ouiname, unsigned long long int oui)
{
static int len;
static FILE* fhoui;
static char *vendorptr;
static unsigned long long int vendoroui;
static char linein[LINEBUFFER_MAX];
static char vendorapname[256];
#ifdef BIG_ENDIAN_HOST
int lsb = oui & 0xf;
#else
int lsb = (oui >> 16) & 0xf;
#endif
if ((fhoui = fopen(ouiname, "r")) == NULL)
{
fprintf(stderr, "unable to open database %s\n", ouiname);
exit (EXIT_FAILURE);
}
fclose(fhoui);
return;
}
/*===========================================================================*/
static void getvendor(char *ouiname, char *vendorstring)
{
static int len;
char linein[LINEBUFFER_MAX];
case 'm':
l= strlen(optarg);
if((l > 17) || (l < 6))
{
fprintf(stderr, "error wrong oui size %s (need eg.
11:22:33:44:55:aa or 112233)\n", optarg);
exit(EXIT_FAILURE);
}
p2 = 0;
for(p1 = 0; p1 < l; p1++)
{
if(isxdigit((unsigned char)optarg[p1]))
{
optarg[p2] = optarg[p1];
p2++;
}
}
optarg[6] = 0;
for(p1 = 0; p1 < 6; p1++)
{
if(!isxdigit((unsigned char)optarg[p1]))
{
fprintf(stderr, "error wrong oui %s (need eg.
11:22:33:44:55:aa or 112233)\n", optarg);
exit(EXIT_FAILURE);
}
}
oui = strtoull(optarg, NULL, 16);
mode = 'm';
break;
case 'p':
hash16800line = optarg;
l = strlen(hash16800line);
if(l < 61)
{
fprintf(stderr, "error hashline too short %s\n", optarg);
exit(EXIT_FAILURE);
}
if(memcmp(&pmkidtype, hash16800line, 7) == 0)
{
hash16800line += 7;
l -=7;
if(memcmp(&pmkidtypeend, &hash16800line[l -3], 3) == 0)
hash16800line[l -3] = 0;
}
if(memcmp(&eapoltype, hash16800line, 7) == 0)
{
hash16800line += 7;
hashlineend = strchr(&hash16800line[59], '*');
if(hashlineend != NULL) hashlineend[0] = 0;
}
if(((hash16800line[32] != ':') && (hash16800line[45] != ':') &&
(hash16800line[58] != ':')) && ((hash16800line[32] != '*') && (hash16800line[45] !=
'*') && (hash16800line[58] != '*')))
{
fprintf(stderr, "error hashline wrong format %s\n", optarg);
exit(EXIT_FAILURE);
}
mode = 'p';
break;
case 'P':
hash2500line = optarg;
l = strlen(hash2500line);
if(l < 61)
{
fprintf(stderr, "error hashline too short %s\n", optarg);
exit(EXIT_FAILURE);
}
if((hash2500line[32] != ':') && (hash2500line[45] != ':') &&
(hash2500line[58] != ':'))
{
fprintf(stderr, "error hashline wrong format %s\n", optarg);
exit(EXIT_FAILURE);
}
mode = 'P';
break;
case 'v':
vendorname = optarg;
mode = 'v';
break;
case 'e':
hexessidname = optarg;
mode = 'e';
break;
case 'x':
essidname = optarg;
mode = 'x';
break;
default:
usage(basename(argv[0]));
}
}
if(argc > 3)
{
fprintf(stderr, "only one argument allowed\n");
exit(EXIT_FAILURE);
}
uid = getuid();
pwd = getpwuid(uid);
if(pwd == NULL)
{
fprintf(stderr, "failed to get home dir\n");
exit(EXIT_FAILURE);
}
ret = chdir(pwd->pw_dir);
if(ret == -1)
{
fprintf(stderr, "failed to change dir\n");
}
if(stat(confdirname, &statinfo) == -1)
{
if(mkdir(confdirname,0755) == -1)
{
fprintf(stderr, "failed to create conf dir\n");
exit(EXIT_FAILURE);
}
}
if(mode == 'd')
{
downloadoui(ouinameuser);
return EXIT_SUCCESS;
}
if(stat(ouinamesystemwide, &statinfo) == 0)
{
ouiname = ouinamesystemwide;
}
if(stat(ouinameuser, &statinfo) == 0)
{
ouiname = ouinameuser;
}
if(ouiname == NULL)
{
fprintf(stderr, "failed read oui.txt\n"
"use download option -d to download it\n"
"or download file https://standards-oui.ieee.org/oui/oui.txt\n"
"and save it to ~/.hcxtools/oui.txt\n");
exit(EXIT_FAILURE);
}
if(stat(ouiname, &statinfo) < 0)
{
fprintf(stderr, "failed read oui.txt\n"
"use download option -d to download it\n"
"or download file https://standards-oui.ieee.org/oui/oui.txt\n"
"and save it to ~/.hcxtools/oui.txt\n");
exit(EXIT_FAILURE);
}
if(mode == 'm')
{
getoui(ouiname, oui);
}
else if(mode == 'p')
{
get16800info(ouiname, hash16800line);
}
else if(mode == 'P')
{
get2500info(ouiname, hash2500line);
}
else
{
usage(basename(argv[0]));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}