void numappatk(dictionary_t *uhashes, dictionary_t *wordhash, dictionary_t *solved, std::string *salt) { std::string suffix; std::string year; std::string md5hex; std::string md5hexy; int i,j; for (auto it = wordhash->begin(); it != wordhash->end(); ++it) { /*if the hash isn't already solved*/ if (solved->find(it->first) == solved->end()) /*if the unmodified hash isn't in the hash:user map * aka if simple dictattack fails */ if (uhashes->find(it->first) == uhashes->end()) /*for (char i='0'; i<='9'; ++i) for (char j='0'; j<='9'; ++j)*/ for (i=0,j=1940; i<=99; ++i,++j) { suffix = std::to_string(i); year = std::to_string(j); /*simple 0-99 suffix*/ md5hex = md5hash(it->second + suffix + *salt); /*a lot of people like to use a significant year*/ md5hexy = md5hash(it->second + year + *salt); if (uhashes->find(md5hex) != uhashes->end()) { std::cout<<"[+] Cracked " <<uhashes->at(md5hex)<<':' <<it->second + suffix <<std::endl; (*solved)[md5hex] = it->second + suffix; } if (uhashes->find(md5hexy) != uhashes->end()) { std::cout<<"[+] Cracked " <<uhashes->at(md5hexy)<<':' <<it->second + year <<std::endl; (*solved)[md5hexy] = it->second + year; } gl.pwgens += 2; suffix.clear(); } else { std::cout << "[+] Cracked " << uhashes->at(it->first) << ':' << it->second << std::endl; (*solved)[it->first] = wordhash->at(it->first); } } }
static int prepare_fromnet(void) { static char contentmd5[33] = { '\0', }; sendreturn_t *sres; sendresult_t sendstat; char *fdata, *fhash; sres = newsendreturnbuf(1, NULL); sendstat = sendmessage("config hosts.cfg", NULL, XYMON_TIMEOUT, sres); if (sendstat != XYMONSEND_OK) { freesendreturnbuf(sres); errprintf("Cannot load hosts.cfg from xymond, code %d\n", sendstat); return -1; } fdata = getsendreturnstr(sres, 1); freesendreturnbuf(sres); fhash = md5hash(fdata); if (strcmp(contentmd5, fhash) == 0) { /* No changes */ xfree(fdata); return 1; } if (contentbuffer) freestrbuffer(contentbuffer); contentbuffer = convertstrbuffer(fdata, 0); strcpy(contentmd5, fhash); return 0; }
QByteArray ImapPrivate::hmacMd5 (const QString& username, const QString& password, const QString& serverResponse) { QByteArray passwordBytes = password.toLatin1(); QByteArray ipad(64, 0); QByteArray opad(64, 0); for (int i = 0; i < 64; ++i) { if (i < passwordBytes.size()) { ipad[i] = (quint8)(0x36 ^ passwordBytes[i]); opad[i] = (quint8)(0x5c ^ passwordBytes[i]); } else { ipad[i] = 0x36; opad[i] = 0x5c; } } QByteArray serverResponseBytes = serverResponse.toLatin1(); while (serverResponseBytes[0] == '+' || serverResponseBytes[0] == ' ') serverResponseBytes.remove(0, 1); QCryptographicHash md5hash(QCryptographicHash::Md5); md5hash.addData(ipad); md5hash.addData(serverResponseBytes); QByteArray resultIpad = md5hash.result(); md5hash.reset(); md5hash.addData(opad); md5hash.addData(resultIpad); QByteArray resultOpad = md5hash.result(); QByteArray response = username.toLatin1() + ' ' + resultOpad.toHex(); return(response.toBase64()); }
S32 JCLSLBridge::bridge_channel(LLUUID user) { if(l2c == 0 || l2c_inuse == false) { std::string tmps = md5hash(user.asString(),1); int i = (int)strtol((tmps.substr(0, 7) + "\n").c_str(),(char **)NULL,16); return (S32)i; }else return l2c; }
//*********************************************************** //* Process any type of data node //*********************************************************** void ImportEnex::processData(QString nodeName, Data &data) { nodeName.toLower(); QString x = textValue(); QByteArray ba; ba.append(x); QByteArray bin = QByteArray::fromBase64(ba); data.body.clear(); data.body = bin; data.size = bin.length(); QCryptographicHash md5hash(QCryptographicHash::Md5); QByteArray hash = md5hash.hash(bin, QCryptographicHash::Md5); data.bodyHash = hash; }
int generate_vkey(pnode *mac_node) { int i; hash_key vkey; unsigned char id[1023], tmp[15]; sprintf(id, "%u", mac_node->id); for(i = 0; i < vns; i++) { sprintf(tmp, "%u", i); strcat(id, tmp); vkey = md5hash((void *)id); mac_node->vkey[i] = vkey; } return 0; }
char *NNPHMangle(char *vserv, char *node, char *cryptpw) { char buffer[256], md5buf[34]; static char res[256]; /* This string is arbitrary, as long as it is the same for any given node, you're ok */ snprintf(buffer, sizeof(buffer), "%s/%d/%s/%s", node, (int)time(NULL) / 3600, vserv, cryptpw); /* Safety: in the event we cant md5, then leave some useful data in md5buf */ snprintf(md5buf, sizeof(md5buf), "%s", node); md5hashstr(md5hash(buffer), md5buf); /* Clip the string. 8 digits is enough */ md5buf[8] = '\0'; snprintf(res, sizeof(res), "%s.%s", md5buf, vserv); return(res); }
//*********************************************************** //* Process any type of data node //*********************************************************** void ImportData::processData(QString nodeName, Data &data) { QLOG_DEBUG() << "Processing Data Node"; nodeName.toLower(); bool atEnd = false; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); // if (name == "size") { // data.size = intValue(); // data.__isset.size = true; // } if (name == "body") { QString x = textValue(); QByteArray bin = QByteArray::fromHex(x.toLocal8Bit()); data.body.clear(); data.body = bin; QCryptographicHash md5hash(QCryptographicHash::Md5); QByteArray hash = md5hash.hash(bin, QCryptographicHash::Md5); QLOG_DEBUG() << "Actual:" << hash.toHex(); data.bodyHash.clear(); data.bodyHash = hash; data.size = bin.size(); } // if (name == "bodyhash") { // QByteArray hexData = textValue().toLocal8Bit(); // QLOG_DEBUG() << hexData; // //QByteArray hexData; // //hexData.append(textValue()); // QByteArray binData = QByteArray::fromHex(hexData); // QLOG_DEBUG() << QByteArray::fromHex(hexData); // data.bodyHash.clear(); // data.bodyHash.append(binData.data(), binData.size()); // data.__isset.bodyHash = true; // } } reader->readNext(); QString nName = reader->name().toString().toLower(); if (nName == nodeName.toLower() && reader->isEndElement()) atEnd = true; } }
static void verify_package(struct pkginfo *pkg) { struct fsys_namenode_list *file; struct varbuf filename = VARBUF_INIT; ensure_packagefiles_available(pkg); parse_filehash(pkg, &pkg->installed); pkg_conffiles_mark_old(pkg); for (file = pkg->files; file; file = file->next) { struct verify_checks checks; struct fsys_namenode *fnn; char hash[MD5HASHLEN + 1]; int failures = 0; fnn = namenodetouse(file->namenode, pkg, &pkg->installed); if (strcmp(fnn->newhash, EMPTYHASHFLAG) == 0) { if (fnn->oldhash == NULL) continue; else fnn->newhash = fnn->oldhash; } varbuf_reset(&filename); varbuf_add_str(&filename, instdir); varbuf_add_str(&filename, fnn->name); varbuf_end_str(&filename); memset(&checks, 0, sizeof(checks)); md5hash(pkg, hash, filename.buf); if (strcmp(hash, fnn->newhash) != 0) { checks.md5sum = VERIFY_FAIL; failures++; } if (failures) verify_output(fnn, &checks); } varbuf_destroy(&filename); }
static void verify_package(struct pkginfo *pkg) { struct fileinlist *file; ensure_packagefiles_available(pkg); parse_filehash(pkg, &pkg->installed); pkg_conffiles_mark_old(pkg); for (file = pkg->clientdata->files; file; file = file->next) { struct verify_checks checks; struct filenamenode *fnn; char hash[MD5HASHLEN + 1]; int failures = 0; fnn = namenodetouse(file->namenode, pkg, &pkg->installed); if (strcmp(fnn->newhash, EMPTYHASHFLAG) == 0) { if (fnn->oldhash == NULL) continue; else fnn->newhash = fnn->oldhash; } memset(&checks, 0, sizeof(checks)); md5hash(pkg, hash, fnn->name); if (strcmp(hash, fnn->newhash) != 0) { checks.md5sum = VERIFY_FAIL; failures++; } if (failures) verify_output(fnn, &checks); } }
int main(int argc, const char * argv[]) { if (argc == 2) { if (strcmp(argv[1], "-v") == 0) { printf("%s\n",version); } else if (strcmp(argv[1], "-s") == 0) { printf("MD5 (\"\") = %s\n", md5hash("")); } else if (strcmp(argv[1], "-f") == 0){ printf("%s\n", illegal_option); printf("%s\n", usage); } else if (strcmp(argv[1], "-?") == 0){ printf("%s\n", usage); } else if (strcmp(argv[1], "-cf") == 0){ printf("%s\n", usage_check); } else if (strcmp(argv[1], "-cs") == 0){ printf("%s\n", usage_check); } else{ printf("%s %s\n", illegal_option, argv[1]); printf("%s\n",usage); } } else if (argc == 3){ if (strcmp(argv[1], "-s") == 0) { printf("MD5 (\"%s\") = %s\n", argv[2], md5hash(argv[2])); } else if (strcmp(argv[1], "-f") == 0){ clock_t start,end; start = clock(); printf("MD5 (%s) = %s\n", argv[2], hash_file(argv[2])); end = clock(); printf("Hash in %f sec\n",(float)(end-start)/CLOCKS_PER_SEC); } else if (strcmp(argv[1], "-cf") == 0){ printf("%s\n", usage_check); } else if (strcmp(argv[1], "-cs") == 0){ printf("%s\n", usage_check); } else{ printf("%s (\"%s\")", illegal_string, argv[2]); printf("%s\n", usage); } } else if (argc == 4){ if (strcmp(argv[1], "-cf") == 0 ) { if (strcmp(hash_file(argv[2]), argv[3]) == 0) { printf("It seems to be all right\n"); } else printf("File Dismatch\n"); } else if (strcmp(argv[1], "-cs") == 0 ) { if (strcmp(md5hash(argv[2]), argv[3]) == 0) { printf("It seems to be all right\n"); } else printf("String Dismatch\n"); } } else{ printf("%s\n", illegal_option); printf("%s\n", usage); } return 0; }
TInt TMD5Checker::CheckFile(class RFs& aFs, const TDesC& aFile, const char* aHash) { TPtrC8 md5hash(reinterpret_cast<const TUint8*>(aHash)); md5hash.Set(reinterpret_cast<const TUint8*>(aHash), strlen(aHash)); return CheckFile(aFs, aFile, md5hash); }
int DiClusterMulticonfigRead(FILE* fp, MultiSlaterDet* MSD) { *MSD = DiClusterMulticonfig; DiClusterMulticonfigInternals* internals = malloc(sizeof(DiClusterMulticonfigInternals)); SlaterDet Qa, Qb; char fnamea[255], fnameb[255]; char md5hasha[255], md5hashb[255]; double d; int na, nb; char anga[15], angb[15]; int npia, npib; int Na, Nb; char buf[BUFSIZE]; fgets(buf, BUFSIZE, fp); sscanf(buf, "<DiClusterMulticonfig d=%lf na=%d anga=%s npia=%d Na=%d nb=%d angb=%s npib=%d Nb=%d>", &d, &na, anga, &npia, &Na, &nb, angb, &npib, &Nb); internals->d = d; internals->na = na; internals->npia = npia; internals->Na = Na; internals->nb = nb; internals->npib = npib; internals->Nb = Nb; // decode angular projection parameters initangles(anga, &internals->nanga, &internals->alphaa, &internals->betaa, &internals->gammaa, &internals->weighta); initangles(angb, &internals->nangb, &internals->alphab, &internals->betab, &internals->gammab, &internals->weightb); { int i; fprintf(stderr, "Angles Cluster A:\n"); for (i=0; i<internals->nanga; i++) fprintf(stderr, "(alpha, beta, gamma): weight = (%8.3f, %8.3f, %8.3f): %8.5f\n", internals->alphaa[i], internals->betaa[i], internals->gammaa[i], internals->weighta[i]); fprintf(stderr, "Angles Cluster B:\n"); for (i=0; i<internals->nangb; i++) fprintf(stderr, "(alpha, beta, gamma): weight = (%8.3f, %8.3f, %8.3f): %8.5f\n", internals->alphab[i], internals->betab[i], internals->gammab[i], internals->weightb[i]); } // Slater dets for Cluster a internals->Qa = malloc(na*sizeof(SlaterDet)); int ia; for (ia=0; ia<na; ia++) { fgets(buf, BUFSIZE, fp); sscanf(buf, "<Cluster %s %s>", fnamea, md5hasha); if (strncmp(md5hasha, md5hash(fnamea), 32)) { fprintf(stderr, "... SlaterDetFile does not match with existing hash\n"); return -1; } if (readSlaterDetfromFile(&Qa, fnamea)) { fprintf(stderr, "... couldn't open %s for reading\n", fnamea); return -1; } cloneSlaterDet(&Qa, &internals->Qa[ia]); } internals->Ja = malloc(Na*sizeof(int)); internals->Ma = malloc(Na*sizeof(int)); internals->Pia = malloc(Na*sizeof(int)); internals->wa = malloc(Na*CLMAX*(JMAX+1)*sizeof(complex double)); int Ja; int Ma; int Pia; char ca[BUFSIZE]; int Ia; for (Ia=0; Ia<Na; Ia++) { fgets(buf, BUFSIZE, fp); sscanf(buf, "<Projection %d %d %d %[() ,.0-9eE+-]>", &Ja, &Ma, &Pia, ca); // fprintf(stderr, "Ja: %d, Ma: %d, Pia: %d, coefficients: %s\n", // Ja, Ma, Pia, ca); internals->Ja[Ia] = Ja; internals->Ma[Ia] = Ma; internals->Pia[Ia] = Pia; sreadcvec(ca, na*(Ja+1), internals->wa[Ia]); } // Slater dets for Cluster b internals->Qb = malloc(nb*sizeof(SlaterDet)); int ib; for (ib=0; ib<nb; ib++) { fgets(buf, BUFSIZE, fp); sscanf(buf, "<Cluster %s %s>", fnameb, md5hashb); if (strncmp(md5hashb, md5hash(fnameb), 32)) { fprintf(stderr, "... SlaterDetFile does not match with existing hash\n"); return -1; } if (readSlaterDetfromFile(&Qb, fnameb)) { fprintf(stderr, "... couldn't open %s for reading\n", fnameb); return -1; } cloneSlaterDet(&Qb, &internals->Qb[ib]); } internals->Jb = malloc(Nb*sizeof(int)); internals->Mb = malloc(Nb*sizeof(int)); internals->Pib = malloc(Nb*sizeof(int)); internals->wb = malloc(Nb*CLMAX*(JMAX+1)*sizeof(complex double)); int Jb; int Mb; int Pib; char cb[BUFSIZE]; int Ib; for (Ib=0; Ib<Nb; Ib++) { fgets(buf, BUFSIZE, fp); sscanf(buf, "<Projection %d %d %d %[() ,.0-9eE+-]>", &Jb, &Mb, &Pib, cb); internals->Jb[Ib] = Jb; internals->Mb[Ib] = Mb; internals->Pib[Ib] = Pib; sreadcvec(cb, nb*(Jb+1), internals->wb[Ib]); } MSD->A = internals->Qa[0].A + internals->Qb[0].A; MSD->N = Na*Nb; MSD->n = na*npia*internals->nanga*nb*npib*internals->nangb; MSD->internals = internals; fprintf(stderr, "N: %d, n: %d\n", MSD->N, MSD->n); return 0; }
bool isFileCorrect (const QString &fileName, const QString &md5) { return md5hash (fileName) == md5; }
void FileWatcher::saveFile(QString file) { QFileInfo fileInfo(file); // If we have a dbi import file QLOG_DEBUG() << fileInfo.dir().absolutePath() + QDir::separator(); QLOG_DEBUG() << global.fileManager.getDbiDirPath(); if ((fileInfo.dir().absolutePath() + QDir::separator()) == global.fileManager.getDbiDirPath()) { BatchImport importer; importer.import(file); emit(nnexImported()); QFile f(file); f.remove(); return; } // If we have a user-import file QFile f(file); f.open(QIODevice::ReadOnly); QByteArray data = f.readAll(); f.close(); if (f.size() == 0) return; Note newNote; NoteTable ntable(global.db); ConfigStore cs(global.db); qint32 lid = cs.incrementLidCounter(); QCryptographicHash md5hash(QCryptographicHash::Md5); QByteArray hash = md5hash.hash(data, QCryptographicHash::Md5); // * Start setting up the new note newNote.guid = QString::number(lid); newNote.title = file; NotebookTable bookTable(global.db); QString notebook; bookTable.getGuid(notebook, notebookLid); newNote.notebookGuid = notebook; QString newNoteBody = QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")+ QString("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">")+ QString("<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\">"); MimeReference mimeRef; QString mime = mimeRef.getMimeFromFileName(file); QString enMedia =QString("<en-media hash=\"") +hash.toHex() +QString("\" border=\"0\"") +QString(" type=\"" +mime +"\" ") +QString("/>"); newNoteBody.append(enMedia + QString("</en-note>")); newNote.content = newNoteBody; newNote.active = true; newNote.created = QDateTime::currentMSecsSinceEpoch();; newNote.updated = newNote.created; newNote.updateSequenceNum = 0; NoteAttributes na; na.sourceURL = "file://" + file; newNote.attributes = na; qint32 noteLid = lid; ntable.add(lid, newNote, true); QString noteGuid = ntable.getGuid(lid); lid = cs.incrementLidCounter(); // Start creating the new resource Resource newRes; Data d; d.body = data; d.bodyHash = hash; d.size = data.size(); newRes.data = d; newRes.mime = mime; ResourceAttributes ra; ra.fileName = file; if (mime.startsWith("image", Qt::CaseInsensitive) || mime.endsWith("pdf", Qt::CaseInsensitive)) ra.attachment = false; else ra.attachment = true; newRes.active = true; newRes.guid = QString::number(lid); newRes.noteGuid = noteGuid; newRes.updateSequenceNum = 0; ResourceTable restable(global.db); restable.add(lid, newRes, true, noteLid); emit(fileImported(noteLid, lid)); if (scanType == FileWatcher::ImportDelete) { QLOG_DEBUG() << f.remove(); } }