From dfca89c7e7f3b972c5f152bb0ae078ec16c11ca1 Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 21 Mar 2017 12:12:50 -0500 Subject: hashpwd.cpp in correct directory --- src/hashpwd.cpp | 277 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 src/hashpwd.cpp (limited to 'src') diff --git a/src/hashpwd.cpp b/src/hashpwd.cpp new file mode 100644 index 0000000..76e656a --- /dev/null +++ b/src/hashpwd.cpp @@ -0,0 +1,277 @@ +//============================================================================ +// Name : hashpwd.cpp +// Author : +// Version : +// Copyright : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +int v = 0; + +string magic_comp = "fc1c"; + +static const string base64_chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + +void escapeOutput(string &input, string &outstr) +{ + outstr.clear(); + int idx = 0; int lastnl = 0; + for (string::iterator it=input.begin(); it!=input.end(); ++it) { + stringstream conv; + lastnl = 0; + if (isprint(*it)) { + if (idx > 0) { + outstr += ' '; + idx++; + } + outstr += *it; + idx++; + if(idx > 74) { + outstr += '\n'; + lastnl = 1; + } + } else { + conv.str(string()); + conv << "\\x" << hex << setw(2) << ((unsigned int)*it & 0xff); + if (idx > 0) { + outstr += ' '; + idx++; + } + idx+=5; + outstr += conv.str(); + if(idx > 74) { + outstr += '\n'; + lastnl = 1; + } + } + } + if(lastnl) + if (outstr.size () > 0) outstr.resize (outstr.size () - 1); +} + +void binTo64(const unsigned char *data, unsigned int datalen, string &str, unsigned int strLen) +{ + unsigned int idx = 0; + int sex; + unsigned char incoming[3]; + int last; + + str.clear(); + (v == 1) && cout << "binTo64 datalen: " << datalen << endl; + (v == 1) && cout << "binTo64 strLen: " << strLen << endl; + for(unsigned int i=0; i= datalen) + break; + if (idx + 3 > datalen) { + memset(incoming,0,3); + memcpy(incoming,data+idx,datalen-idx); + last = datalen - idx - 1; + } else { + memcpy(incoming,data+idx,sizeof incoming); + last = 4; + } + idx += 3; + + (v == 1) && cout << hex << "in[0]: " << (int)incoming[0] << " in[1]: " << (int)incoming[1]<< " in[2] " << (int)incoming[2] << endl; + + sex = (incoming[0] >> 2); + str += base64_chars[sex]; + (v == 1) && cout << "1st, 4th inp char: " << hex << sex << " to: " << str << endl; + + sex = (incoming[1] >> 4); + (v == 1) && cout << "2nd, 5th inp char: " << hex << sex << endl; + sex += (incoming[0] << 4) & 0x30; + str += base64_chars[sex]; + (v == 1) && cout << "3rd, 6th inp char: " << hex << sex << " to: " << str << endl; + (v == 1) && cout << "last: " << last << endl; + if (last == 0) + continue; + sex = (incoming[2] >> 6); + sex += ((incoming[1] << 2) & 0x3c); + str += base64_chars[sex]; + + if(last == 1) + continue; + + sex = (incoming[2] & 0x3f); + str += base64_chars[sex]; + + (v == 1) && cout << "Converted " << idx << "chars: " << str << endl; + } + while (str.length() < strLen) + str += '='; + return; +} + +int badPassword(string &passwd) +{ + unsigned char a[3]; + int i = 0; + int lower=0, upper=0, numeric=0, special=0; + a[0] = a[1] = a[2] = 0; + for (string::iterator it=passwd.begin(); it!=passwd.end(); ++it) { + a[0] = *it; + if (i > 1) { + if ((a[0] == a[1]) && (a[1] == a[2])) + return 1; + if ((a[0] == a[1]+1) && (a[1] == a[2]+1)) + return 1; + if ((a[0] == a[1]-1) && (a[1] == a[2]-1)) + return 1; + } + a[2] = a[1]; + a[1] = a[0]; + if(islower(*it)) + lower=1; + if(isupper(*it)) + upper=1; + if(isdigit(*it)) + numeric=1; + if((*it == '/') || (*it == '+')) + special=1; + i++; + } + if (lower + upper + numeric + special < 3) + return 1; + return 0; +} + +void usage(void) +{ + cout << "usage:" << endl << + " hashpwd [-v] [[-d did] [-m mac] | [-p password]] salt" << endl << + " -v verbose" << endl << + " -d did Device ID (serial #)" << endl << + " -m mac Ethernet mac address" << endl << + " -p password" << endl << + "Either password must be supplied, or Device-ID and Ethernet Mac address" << endl << + "salt is required." <