int main( int argc, char const * const argv[] ) { if( 2 <= argc ) { for( int arg = 1 ; arg < argc ; arg++ ) { char const *fileName = argv[arg]; if( '@' == fileName[0] ) { fileName++ ; memFile_t fIn( fileName ); if( fIn.worked() ) { md5_t md5 ; getMD5( fIn.getData(), fIn.getLength(), md5 ); for( unsigned dig = 0 ; dig < sizeof( md5.md5bytes_ ); dig++ ) printf( "%02x", md5.md5bytes_[ dig ] ); printf( "\n" ); } else perror( fileName ); } // read entire file else if( '+' == fileName[0] ) { fileName++ ; md5_t md5 ; if( md5Cramfs( fileName, md5 ) ) { printf( "md5cramfs(%s) == ", fileName ); for( unsigned dig = 0 ; dig < sizeof( md5.md5bytes_ ); dig++ ) printf( "%02x", md5.md5bytes_[ dig ] ); printf( "\n" ); } else perror( fileName ); } else { md5_t md5 ; if( getMD5( fileName, md5 ) ) { printf( "md5(%s) == ", fileName ); for( unsigned dig = 0 ; dig < sizeof( md5.md5bytes_ ); dig++ ) printf( "%02x", md5.md5bytes_[ dig ] ); printf( "\n" ); } else perror( fileName ); } } } else fprintf( stderr, "Usage: %s [@]fileName [[+]fileName...]\n" " '@' indicates read entire file before md5\n" " '+' indicates read cramfs image (ignoring pad)\n", argv[0] ); return 0 ; }
void generateDedupDump(char* source,// IN: Source file FILE* op) // IN: File pointer for destination file { FILE *ip; unsigned long len; unsigned long offset; char buf[1024 * 4]; char hashStr[MD5_HASH_LEN * 2 + 1]; // Each byte represented by 2 hex values. // String terminated by a null char '\0' offset = 0; if(!isDedupCandidate(source)){ printf("Source file %s is not valid\n",source); return; } ip = fopen(source, "rb"); if(ip == NULL){ printf("Failed to open file %s \n", source); return; } while((len = fread(buf, RDLEN, 1, ip)) != 0){ getMD5(buf, len, hashStr); fprintf(op, "%s,%s,%lu,%lu\n", source, hashStr, offset, len); offset += len; } if(fclose(ip) != 0){ printf("Error closing file %s\n", source); return; } return; }
void newDownloadDialog::ok() { try { boost::shared_ptr<Hash> hash(HashManager::fromString(text->toPlainText().toStdString())); if (hash->getInfo().valid) { std::string stdPass = edit->text().toStdString(); if (hash->getInfo().accessPasswd.length() == 32) { stdPass = getMD5((unsigned char*)stdPass.c_str()); } if(stdPass.compare(hash->getInfo().accessPasswd) == 0) { fileName = QString::fromStdString(hash->getInfo().fileName); accept(); } else QMessageBox::about(this, tr("Błąd"),tr("Hasło nieprawidłowe! ")); } else QMessageBox::about(this, tr("Błąd"),tr("Źle skopiowany lub niepoprawny hashcode!")); } catch (std::exception& e) { QMessageBox::about(this, tr("Błąd"),tr("Nieobsługiwany hashcode!")); } }
void generate(char* source, char* destination){ FILE *ip,*op; printf("File to work on : %s\n",source); ip = FOPEN(source,"rb"); op = FOPEN(destination,"ab"); unsigned long len; unsigned long offset=0; char *buf = NULL, *buf_orig = NULL, *buf_read=NULL; // Opening input and output file char header[MAX_FILE_NAME]; if(verbose){ strcpy(header,"String, File Name, md5, offset, size \n"); FWRITE(header, "header", op); } if((buf = (char*)malloc(4*1024)) == NULL){ printf("Error in allocating memory"); } buf_orig=buf; buf_read = buf; while((len=fread(buf,1,RDLEN,ip))!=0){ // Generate MD5 here char out[MD5_DIGEST_LENGTH*2+1]; getMD5(buf,out,len); if(verbose){ FWRITE(buf_read, "buf",op); FWRITE(",",",",op); } if(fileNameRequired){ FWRITE(source, "fileName",op); FWRITE(",",",",op); } FWRITE(out,"md5value",op); FWRITE(",",",",op); char offset_str[MAX_BUF_LEN]; sprintf(offset_str, "%lu",offset); FWRITE(offset_str,"offset",op); FWRITE(",",",",op); char size_str[MAX_BUF_LEN]; sprintf(size_str, "%lu",len); FWRITE(size_str,"size",op); FWRITE("\n","New Line",op); offset += len; } free(buf); FCLOSE(op); FCLOSE(ip); }
list_node *is_samefile_inlist(list *lst, list_node *newfile) { list_node *nd = lst->head; while (1) { if (lst->filesize > MIN_BLOCK_COMPARE_SIZE) { if (compare_file_blocks(nd, newfile) == 0) { debug_msg("MD5 Checking"); if (nd->md5 == NULL) { nd->md5 = getMD5(nd->filepath); } newfile->md5 = getMD5(newfile->filepath); if (memcmp(newfile->md5, newfile->md5, MD5_DIGEST_LENGTH) == 0) { return nd; } } } else { if (compare_file_blocks(nd, newfile) == 0) { return nd; } } debug_msg("Checking next item.."); if (nd->next == NULL) { break; } else { nd = nd->next; } } debug_msg("No same file found."); return NULL; }
bool MISC::callProtocol(std::string input_str, std::string &result, const bool async_method, const unsigned int unique_id) { // Protocol std::string command; std::string data; const std::string::size_type found = input_str.find(":"); if (found==std::string::npos) // Check Invalid Format { command = input_str; } else { command = input_str.substr(0,found); data = input_str.substr(found+1); } if (command == "TIME") { getDateTime(data, result); } else if (command == "BEGUID") { getBEGUID(data, result); } else if (command == "CRC32") { getCrc32(data, result); } else if (command == "MD4") { getMD4(data, result); } else if (command == "MD5") { getMD5(data, result); } else if (command == "RANDOM_UNIQUE_STRING") { getRandomString(data, result); } else if (command == "TEST") { result = data; } else { result = "[0,\"Error Invalid Format\"]"; extension_ptr->logger->warn("extDB2: Misc Invalid Command: {0}", command); } return true; }
void combine(){ FILE *ip= FOPEN("/tmp/file1", "rb"); FILE *op= FOPEN("/tmp/nextLevel","w"); char *line; char str[MAX_COMBINED_HASH_LEN]; size_t maxLen=MAX_COMBINED_HASH_LEN; char md5str[MD5_DIGEST_LENGTH*2+1]; while(getline(&line,&maxLen,ip)!=-1){ char *token = strtok(line, ","); getMD5(token,md5str,strlen(token)); token = strtok(NULL,","); sprintf(str,"%s,%s",md5str,token); FWRITE(str, "Entry row", op); } return; }
static JSBool jsMD5File( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { *rval = JSVAL_FALSE ; if( ( 1 == argc ) && JSVAL_IS_STRING( argv[0] ) ) { JSString *sArg = JSVAL_TO_STRING( argv[0] ); md5_t md5 ; if( getMD5( JS_GetStringBytes( sArg ), md5 ) ) *rval = md5ToRval( cx, md5 ); } else JS_ReportError( cx, "Usage: md5( string );" ); return JS_TRUE; }
bool Process::operator==(const Process &other) const { if(this==&other) return true; if( getPath()!=other.getPath() ) return false; if( getName()!=other.getName() ) return false; if( !Base::ViaPointer::equal( getMD5(), other.getMD5() ) ) return false; if( !Base::ViaPointer::equal( getPID(), other.getPID() ) ) return false; if( !Base::ViaPointer::equal( getUID(), other.getUID() ) ) return false; if( getUsername()!=other.getUsername() ) return false; if( !Base::ViaPointer::equal( getParameters(), other.getParameters() ) ) return false; if( !Base::ViaPointer::equal( getReferenceURL().get(), other.getReferenceURL().get() ) ) return false; // if all fields are identical, Processes are identical too. return true; }
void *thread_func(void *new_socket_ref) { int new_socket = *(int*)new_socket_ref; //int* index = (int *) param; do{ //printf("--------------\nHebra %i\n",*index); result = recv(new_socket,buffer,80,0); if(result==-1){ perror("Servidor:Recv"); exit(1); } /* if(strcmp(buffer,"EOT")==0){ printf("Se ha recibido EOT\n"); EOT=1; }else if(strcmp(buffer,"EOT")!=0){ printf("El mensaje recibido fue:\n%s\n",buffer);*/ printf("%s\n",buffer); split_request(buffer,&req); switch(req.req_type){ case GET_STATE: printf("GET_STATE %s\n",req.req[0]); //printf("Buscamos usuario...\n"); user_ptr = getUser(req.req[0],user_list); if(user_ptr!=NULL){ sprintf(buffer,"%i %s %i", STATE,user_ptr->name,user_ptr->state); //printf("Encontrado\n Respuesta a enviar: %s\n",buffer); }else{ printf("El usuario no existe\n"); sprintf(buffer,"%i",ERROR); } if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } break; case POST_NAME_LOCATION_STATE: printf("POST_NAME_LOCATION_STATE %s %s %i\n", req.req[0],req.req[1],atoi(req.req[2])); strcpy(user.name,req.req[0]); strcpy(user.location,req.req[1]); user.state = atoi(req.req[2]); user_list = addUser(&user,user_list); showUsers(user_list); sprintf(buffer,"%i",OK); if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } break; case AUTH: printf("AUTH %s\n",req.req[0]); //Comprobamos si existe el usuario user_ptr = getUser(req.req[0],user_list); if(user_ptr!=NULL){//Si Existe mandamos reto challenge = random(); sprintf(buffer,"%i %i",CHALLENGE,challenge); printf("Enviado reto: %s\n",buffer); if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } result = recv(new_socket,buffer,80,0); if(result==-1){ perror("Servidor:Recv"); exit(1); } split_request(buffer,&req); //printf("Recibimos %s\n",buffer); strcpy(location,req.req[1]); state = atoi(req.req[2]); //Esperamos md5 name:reto:secreto result = recv(new_socket,out,16,0); for (i=0; i<16; i++) { printf("%02x", out[i]); } printf("\n"); //Comparamos md5 recibido con nuestro md5 sprintf(buffer,"%s%i%s",user_ptr->name,challenge,user_ptr->secret); printf("OUR MD5 %s : ",buffer); getMD5(buffer,strlen(buffer),md5); for (i=0; i<16; i++) { printf("%02x", md5[i]); } printf("\n"); if(memcmp(md5,out,16)==0){ printf("MATCH MD5\n"); strcpy(user_ptr->location,location); user_ptr->state = state; sprintf(buffer,"%i",OK); if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } }else{ printf("MD5 incorrecto.\n"); sprintf(buffer,"%i",ERROR); if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } } }else{//Si no existe mandamos error printf("No existe el usuario.\n"); sprintf(buffer,"%i",ERROR); if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } } break; case GET_LOCATION: printf("GET_LOCATION %s\n",req.req[0]); user_ptr = getUser(req.req[0],user_list); if(user_ptr!=NULL){ sprintf(buffer,"%i %s %s", LOCATION,user_ptr->name,user_ptr->location); }else{ sprintf(buffer,"%i",ERROR); } if(send(new_socket,buffer,80,0)==-1){ printf("Servidor:Send\n"); exit(1); } break; case EXIT: printf("EXIT\n"); printf("Fin de la conexion\n"); EOT=1; } freeRequest(&req); //} //printf("-----\n"); }while(!EOT); // the function must return something - NULL will do return NULL; }
string LoginSocket::vkReq(string &data) { string viewer_id = getParam(data, "viewer_id"); string api_id = getParam(data, "api_id"); string auth_key = getParam(data, "auth_key"); string user_id = getParam(data, "user_id"); string referrer = getParam(data, "referrer"); string api_url = getParam(data, "api_url"); string secret = getParam(data, "secret"); string sid = getParam(data, "sid"); string lc_name = getParam(data, "lc_name"); string api_result = getParam(data, "api_result"); api_result = UrlDecodeString(api_result); string first_name = getJsonParamStr(api_result, "first_name"); string last_name = getJsonParamStr(api_result, "last_name"); string nickname = getJsonParamStr(api_result, "nickname"); int sex = atoi(getJsonParamInt(api_result, "sex").c_str()); string photo_medium = getJsonParamStr(api_result, "photo_medium"); if (viewer_id.empty() || api_id.empty() || _social_net[SocialNetDesc::VK].app_id != api_id) { traceerr("%s, trace req. data: %s", "Error wrong req parameters, Warning!Possible hacking attempt!", data.c_str()); return ""; } char hash[(MD5_DIGEST_LENGTH+2)*2] = {"\0"}; getMD5((char*)(api_id + string("_") + viewer_id + string("_") + _social_net[SocialNetDesc::VK].app_secret).c_str(), hash); string hash_str = string(hash); if (auth_key != hash_str) { traceerr("%s, trace req. auth_key: %s; local_hash: %s", "Error auth_key fail, Warning!Possible hacking attempt!", auth_key.c_str(), hash_str.c_str()); return ""; } uint32 vid = atoi(viewer_id.c_str()); shared_ptr<User> user = iStorage->getLocalUser(vid, SocialNetDesc::VK); if (user == shared_ptr<User>()) { traceerr("Error! Requested user not found!"); return ""; } user->set("first_name", Value(first_name, true)); user->set("last_name", Value(last_name, true)); user->set("nickname", Value(nickname, true)); user->set("avatar", Value(photo_medium, true)); user->set("sex", Value(sex, true)); //GENERATE NEADED FLASHVARS string iframe = _social_net[SocialNetDesc::VK].iframe; char flashvars[1024] = {'\0'}; snprintf(flashvars, 1024, "api_id: \"%s\",viewer_id: \"%s\",user_id: \"%s\", referrer: \"%s\", api_url: \"%s\", secret: \"%s\", sid: \"%s\", lc_name:\ \"%s\"", api_id.c_str(), viewer_id.c_str(), user_id.c_str(), referrer.c_str(), api_url.c_str(), secret.c_str(), sid.c_str(), lc_name.c_str()); string::size_type pos = iframe.find("var flashvars = {"); if (pos == string::npos) { traceerr("%s", "Error: wrong VK template!"); return ""; } iframe.insert(pos+17, flashvars); return iframe; }
/** * CPU Function that takes in a simple dictionary of plaintext * and returns a better dictionary for stronger password cracking. * * @params * orig_words pointer to original array of words * orig_num_words number of words in the original array * new_dict pointer to the new dictionary. must be freed * at end of program **/ unsigned int mutateAndCheck(password *newdict, password *olddict, unsigned int numwords){ printf("Starting with dictionary manipulation.\n"); unsigned int i, found=0; int z; word16 md5Hash; /* Loop until all mutations are done. Last mutation will break out */ for (z=-1;z<252 && !found;z++){ //printf("Iteration: %d\n",z); /* Copy over original dictionary */ memcpy(newdict,olddict,numwords*sizeof(password)); if(z != -1){ /* Go through each word in the dictionary */ for (i=0;i<numwords;i++){ if (z==0){ /* First letter uppercase */ if (newdict[i].word[0] >= 'a' && newdict[i].word[0] <= 'z') newdict[i].word[0] +='A'-'a'; } if (z==1){ /* Last letter uppercase */ size_t len = newdict[i].length; if (newdict[i].word[len-1] >= 'a' && newdict[i].word[len-1] <= 'z') newdict[i].word[len-1] += 'A'-'a'; } if (z>=2 && z<=11){ /* Add one digit to end * iterator: z-2 */ size_t len = newdict[i].length; newdict[i].word[len] = '0' + z-2; newdict[i].length += 1; } /* Add sequence of numbers at end; e.g. 1234, 84, 1999 */ if (z>=12 && z<=111){ // 0 to 99 // iterator: z-12 size_t len = newdict[i].length; newdict[i].word[len] = '0' + ((z-12)/10)%10; newdict[i].word[len+1] = '0' + (z-12)%10; newdict[i].length += 2; } if (z>=112 && z<=231){ // 1900 to 2020 // iterator: z + (1900-112) size_t len = newdict[i].length; newdict[i].word[len] = '0' + ((z+1900-112)/1000)%10; newdict[i].word[len+1] = '0' + ((z+1900-112)/100)%10; newdict[i].word[len+2] = '0' + ((z+1900-112)/10)%10; newdict[i].word[len+3] = '0' + (z+1900-112)%10; newdict[i].length += 4; } if (z>=232 && z<=251){ // Other common sequences // iterator: z-232 //sprintf(&temp,"%s",sequences[z-252]); size_t len = newdict[i].length; memcpy(&(newdict[i].word[len]),seq[z-232].word,seq[z-232].length); newdict[i].length = len + seq[z-232].length; } /* Terminate loop when number 50 is substituted * Right now, this is when z=252*/ /* TODO Call Gaurav's MD5 padding, generation, and checking here */ } } found = getMD5(newdict, &md5Hash, numwords); } return found; }
void enterpass(SSL *ssl){ //char *prompt="Password [displayed to screen]: "; char *motd="<< Welcome >>\n"; char buffer[64]={0x00}; //write(s,banner,strlen(banner)); //write(s,prompt,strlen(prompt)); //read(s,buffer,sizeof(buffer)); SSL_read(ssl,buffer,sizeof(buffer)-1); /*Hash password*/ char trans[SALT_LENGTH+33] = {'\0'}; char tmp[3]={'\0'},buf[33]={'\0'},hash[33]={'\0'}; int i; for(i=0;i<strlen(buffer);i++){ if(buffer[i]==0x00){ break; } } if(i>2) i--; #ifdef DEBUG sprintf(tmp, "%d",i); SSL_write(ssl,tmp,1); SSL_write(ssl,"->i\n",4); #endif getMD5(buffer,i,buf); #ifdef DEBUG SSL_write(ssl,buf,strlen(buf)); SSL_write(ssl,"->buf\n",6); #endif strncpy(trans,_SALT_,SALT_LENGTH); for(i=0;i<32;i++){ trans[SALT_LENGTH+i]=buf[i]; } #ifdef DEBUG SSL_write(ssl,trans,strlen(trans)); SSL_write(ssl,"->trans\n",8); #endif getMD5(trans,SALT_LENGTH+32,hash); #ifdef DEBUG sprintf(tmp, "%d",strlen(buf)); SSL_write(ssl,tmp,2); SSL_write(ssl,"->buflen\n",9); SSL_write(ssl,hash,strlen(hash)); SSL_write(ssl,"->hash\n",7); #endif /*End Hash Password*/ if(!strncmp(hash, _RPASSWORD_, strlen(_RPASSWORD_))) { SSL_write(ssl,motd,strlen(motd)); }else { //write(s,"Wrong!\n", 7); //close(s); #ifdef DEBUG SSL_write(ssl,"Wrong!\n", 7); #endif _exit(0); } }