#include #include #include #include #include #include #include #include #include #include #include #define MYVERSION "1.1" 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 << " mts-hashpwd [-v] [[-d did] [-m mac] | [-p password]] salt" << endl << " -V version" << endl << " -v verbose" << endl << " -d did Device ID (serial #)" << endl << " -i Read password from standard input" << endl << " -m mac Ethernet mac address" << endl << " -p password" << endl << " -u uuid UUID (base 16)" << endl << "Either password must be supplied, or Device-ID and " << endl << "either Ethernet Mac address or UUID" << endl << "salt is required." <