int agent_alloc(struct agent **agp, struct reicec *cli, const struct trice_conf *conf) { struct agent *ag; int err = 0; ag = mem_zalloc(sizeof(*ag), destructor); if (!ag) return ENOMEM; ag->cli = cli; ag->client = cli->client; rand_str(ag->lufrag, sizeof(ag->lufrag)); rand_str(ag->lpwd, sizeof(ag->lpwd)); err = trice_alloc(&ag->icem, conf, cli->client, ag->lufrag, ag->lpwd); if (err) goto out; err = stun_alloc(&ag->stun, NULL, NULL, NULL); if (err) goto out; out: if (err) mem_deref(ag); else *agp = ag; return err; }
int main() { int size; mydisk_init("diskfile", MAX_BLOCKS, 0); init_cache(CACHED_BLOCKS); /* Test case 1: read/write block */ size = BLOCK_SIZE; memset(buffer, 0, size); strcpy(buffer, "hello world\n"); mydisk_write_block(0, buffer); memset(buffer2, 0, size); mydisk_read_block(0, buffer2); check_test(memcmp(buffer2, "hello world\n", 13)); /* Test case 2: basic read/write */ memset(buffer, 0, size); mydisk_read(0, 13, buffer); check_test(memcmp(buffer, "hello world\n", 13)); /* Test case 3: read in the middle */ memset(buffer, 0, BLOCK_SIZE); mydisk_read(8, 5, buffer); check_test(memcmp(buffer, "rld\n", 5)); /* Test case 4: read/write across blocks */ size = BLOCK_SIZE; rand_str(buffer, size); mydisk_write(144, size, buffer); memset(buffer2, 0, size); mydisk_read(144, size, buffer2); check_test(memcmp(buffer, buffer2, size)); /* Test case 5: large read/write */ size = BLOCK_SIZE * (MAX_BLOCKS - 1); rand_str(buffer, size); mydisk_write(276, size, buffer); mydisk_read(276, size, buffer2); check_test(memcmp(buffer, buffer2, size)); /* Test case 6~9: read/write exception */ check_test(!mydisk_read(-1, 0, buffer)); check_test(!mydisk_read(0, -10, buffer)); check_test(!mydisk_read(100, BLOCK_SIZE * MAX_BLOCKS, buffer)); check_test(mydisk_write(0, 0, buffer)); check_test(stress_test()); check_test(stress_test2()); close_cache(); mydisk_close(); return 0; }
long test_row_put(HbCli myhbcli, std::string table, int klen, int vlen) { long ms = 0; char key[klen+1]; char value[vlen+1]; for (int i=0; i<COUNT; i++) { rand_str(key, klen); rand_str(value, vlen); gettimeofday(&tvpre, NULL); myhbcli.putRow(table, key, "entry:m", value); gettimeofday(&tvafter, NULL); ms += gen_ms(tvpre, tvafter); } return ms; }
DictionaryType* new_DictionaryType() { DictionaryType* pObj = NULL; /* Allocating memory */ pObj = (DictionaryType*)malloc(sizeof(DictionaryType)); if (pObj == NULL) { return NULL; } memset(&pObj->generated_KMF_ID[0], 0, sizeof(pObj->generated_KMF_ID)); rand_str(pObj->generated_KMF_ID, 8); pObj->attributes = NULL; pObj->eContainer = NULL; pObj->path = NULL; pObj->AddAttributes = DictionaryType_AddAttributes; pObj->RemoveAttributes = DictionaryType_RemoveAttributes; pObj->FindAttributesByID = DictionaryType_FindAttributesByID; pObj->internalGetKey = DictionaryType_internalGetKey; pObj->metaClassName = DictionaryType_metaClassName; pObj->Delete = delete_DictionaryType; pObj->VisitAttributes = DictionaryType_VisitAttributes; pObj->VisitPathAttributes = DictionaryType_VisitPathAttributes; pObj->VisitReferences = DictionaryType_VisitReferences; pObj->VisitPathReferences = DictionaryType_VisitPathReferences; pObj->FindByPath = DictionaryType_FindByPath; return pObj; }
static void device_connect(struct device *device, struct device *peer_device) { struct peer *peer; ASSERT_TRUE(device != NULL); ASSERT_TRUE(peer_device != NULL); #if 0 re_printf("@@@ connect %s ----> %s\n", device->name, peer_device->name); #endif peer = device_find_peer(device, peer_device); if (peer) { re_printf("device %s already connected to %s\n", device->name, peer_device->name); } ASSERT_TRUE(peer == NULL); peer = (struct peer *)mem_zalloc(sizeof(*peer), peer_destructor); ASSERT_TRUE(peer != NULL); peer->device = peer_device; rand_str(peer->sid, sizeof(peer->sid)); list_append(&device->peerl, &peer->le, peer); }
void test(size_t N, size_t M) { std::vector<std::string> S; auto seed = std::chrono::system_clock::now().time_since_epoch().count(); S.reserve(N); for (size_t i = 0; i < N; ++i) { S.push_back(rand_str(M, seed)); } auto S1 = S; auto S2 = S; auto S3 = S; auto S4 = S; auto S5 = S; auto S6 = S; std::cout << '1'; auto r1 = AllPairsLCS_b(S1); //base AllPairsLCS std::cout << ' ' << std::get<2>(r1) << std::endl; std::cout << '2'; auto r2 = AllPairsLCS_p(S2); //pruning std::cout << ' ' << std::get<2>(r2) << std::endl; std::cout << '3'; auto r3 = AllPairsLCS_s(S3); //sorting std::cout << ' ' << std::get<2>(r3) << std::endl; std::cout << '4'; auto r4 = AllPairsLCS_pab(S4); //pa-b std::cout << ' ' << std::get<2>(r4) << std::endl; std::cout << '5'; auto r5 = AllPairsLCS_pap(S5); //pa-p std::cout << ' ' << std::get<2>(r5) << std::endl; std::cout << '6'; auto r6 = AllPairsLCS_pas(S6); //pa-s std::cout << ' ' << std::get<2>(r6) << std::endl; }
PortTypeMapping* new_PortTypeMapping() { PortTypeMapping* pObj; /* Allocating memory */ pObj = (PortTypeMapping*)malloc(sizeof(PortTypeMapping)); if (pObj == NULL) { return NULL; } /* pointing to itself as we are creating base class object*/ pObj->pDerivedObj = pObj; memset(&pObj->generated_KMF_ID[0], 0, sizeof(pObj->generated_KMF_ID)); rand_str(pObj->generated_KMF_ID, 8); pObj->beanMethodName = NULL; pObj->serviceMethodName = NULL; pObj->paramTypes = NULL; pObj->eContainer = NULL; pObj->internalGetKey = PortTypeMapping_internalGetKey; pObj->metaClassName = PortTypeMapping_metaClassName; pObj->Delete = delete_PortTypeMapping; pObj->VisitAttributes = PortTypeMapping_VisitAttributes; pObj->VisitPathAttributes = PortTypeMapping_VisitPathAttributes; pObj->FindByPath = PortTypeMapping_FindByPath; return pObj; }
bool check_replace_name(replace_map* replace_map_point) { replace_map::iterator itr1 = replace_map_point->begin(); while(itr1 != replace_map_point->end()) { int break_flag = 0; replace_map::iterator itr2 = replace_map_point->begin(); for (; itr2->first != itr1->first && !break_flag; ) { if (itr1->second == itr2->second) { string replace_name; string varname = itr1->first; rand_str(&replace_name); replace_map_point->erase(itr1); replace_map_point->insert(replace_map::value_type(varname, replace_name)); itr1 = replace_map_point->find(varname); itr2 = replace_map_point->begin(); continue; } else itr2++; } itr1++; } return true; }
int main(int argc, char *argv[]) { int source,len,size=-1; int rank = -1; if (OSMP_Init(&argc, &argv) != OSMP_SUCCESS) { printf("OSMP_INIT Error \n"); exit(EXIT_FAILURE); } if (OSMP_Size(&size) != OSMP_SUCCESS || size!=43) { printf("OSMP_SIZE Error\n"); exit(EXIT_FAILURE); } if (OSMP_Rank(&rank) != OSMP_SUCCESS) { printf("OSMP_RANK Error \n"); exit(EXIT_FAILURE); } char *bufin, *bufout; if (rank == 0) { for (int i = 0; i < 20; i++) { bufout = malloc(32); rand_str(bufout, 32); printf("process %d sending random message %d to process 1: %s\n", rank,i, bufout); if (OSMP_Send(bufout, 32, 1) != OSMP_SUCCESS) { printf("OSMP_SEND Error \n"); exit(EXIT_FAILURE); } free(bufout); } } else if(rank==1){ sleep(5); for (int j = 0; j < 20; j++) { bufin = malloc(32); printf("Process %d trying to receive msg %d\n", rank, j); if (OSMP_Recv(bufin, 32, &source, &len) != OSMP_SUCCESS) { printf("OSMP_RECV Error: OSMP_Recv \n"); exit(EXIT_FAILURE); } printf("Process %d received %d bytes from process %d: %s\n", rank, len, source, bufin); free(bufin); } } if(OSMP_Finalize()!=OSMP_SUCCESS){ printf("OSMP_FINALIZE Error"); exit(EXIT_FAILURE); } return 0; }
gchar * passwd_get_random (void) { gchar *random_passwd; random_passwd = g_new0 (gchar, RANDOM_PASSWD_SIZE + 1); rand_str (random_passwd, RANDOM_PASSWD_SIZE); return random_passwd; }
/** * Allocate a new ICE Session * * @param icep Pointer to allocated ICE Session object * @param mode ICE Mode; Full-mode or Lite-mode * @param offerer True if we are SDP offerer, otherwise false * * @return 0 if success, otherwise errorcode */ int ice_alloc(struct ice **icep, enum ice_mode mode, bool offerer) { struct ice *ice; int err = 0; if (!icep) return EINVAL; ice = mem_zalloc(sizeof(*ice), ice_destructor); if (!ice) return ENOMEM; list_init(&ice->ml); ice->conf = conf_default; ice->lmode = mode; ice->tiebrk = rand_u64(); rand_str(ice->lufrag, sizeof(ice->lufrag)); rand_str(ice->lpwd, sizeof(ice->lpwd)); ice_determine_role(ice, offerer); if (ICE_MODE_FULL == ice->lmode) { err = stun_alloc(&ice->stun, NULL, NULL, NULL); if (err) goto out; /* Update STUN Transport */ stun_conf(ice->stun)->rto = ice->conf.rto; stun_conf(ice->stun)->rc = ice->conf.rc; } out: if (err) mem_deref(ice); else *icep = ice; return err; }
static void check_str(uint64_t i, char *str, bool mod) { char str2[] = "0000000000000000"; rand_str(i, str2); if (mod) str2[0] = 'A'; testutil_checkfmt(strcmp(str, str2), "strcmp failed, got %s, expected %s", str, str2); }
int main(int argc, char *argv[]) { int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; struct timespec start,stop; long accum; char buffer[256]; bzero(buffer,256); if (argc < 4) { fprintf(stderr,"usage %s hostname port message_length\n", argv[0]); exit(0); } portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); int message_length = atoi(argv[3]); char *string = (char*)malloc(message_length*sizeof(char*)); rand_str(string,message_length); clock_gettime(CLOCK_REALTIME, &start); n = write(sockfd,string,strlen(string)); if (n < 0) error("ERROR writing to socket"); n = read(sockfd,buffer,255); clock_gettime(CLOCK_REALTIME, &stop); if (n < 0) error("ERROR reading from socket"); accum = (stop.tv_sec - start.tv_sec)*1000000000 + (stop.tv_nsec - start.tv_nsec); uint64_t diff = getTimeDiff(start, stop); printf("Latency : %llu\n", (unsigned long long int)diff); //printf("%s\n",buffer); return 0; }
long test_row_put_list(HbCli myhbcli, std::string table, int klen, int vlen, int lnum) { long ms = 0; char key[klen+1]; char value[vlen+1]; RowMap rowMap; for (int i=0; i<COUNT; i++) { rand_str(key, klen); rand_str(value, vlen); StrMap columnMap; columnMap.insert(std::pair<std::string, std::string>("entry:m1", value)); rowMap.insert(std::pair<std::string, StrMap>(key, columnMap)); if (rowMap.size() == lnum) { gettimeofday(&tvpre, NULL); myhbcli.putRows(table, rowMap); rowMap.clear(); gettimeofday(&tvafter, NULL); ms += gen_ms(tvpre, tvafter); } } return ms; }
int initialize_population(GeneWrapper ** population, char * population_trace, bool random_initialize, int * population_size) { FILE *file; if ((file = fopen(population_trace, "r")) == NULL) { if (errno == ENOENT) { *population_size = POPULATION_SIZE; if (!random_initialize) { return -1; } printf("initial population cannot be found, randomly initialize one \n"); GeneWrapper * initial_population = (GeneWrapper *) malloc(sizeof(GeneWrapper) * (*population_size)); int i; char random_gene_string[51]; for (i = 0; i < * population_size; i++) { rand_str(random_gene_string, 50); initial_population[i].gene = malloc(sizeof(PacGene)); SetGeneFromString(random_gene_string, initial_population[i].gene); } * population = initial_population; return 0; } else { printf("some other error occured"); return -1; } }else { *population_size = 0; char line [1000]; while (fgets ( line, sizeof line, file ) != NULL ) { *population_size = *population_size + 1; } printf("initial population is read from file, size is %d \n", *population_size); rewind(file); GeneWrapper * initial_population = (GeneWrapper *) malloc(sizeof(GeneWrapper) * (*population_size)); int i = 0; char gene_string[51]; while (fgets ( line, sizeof line, file ) != NULL ) { strncpy(gene_string, line, 50); gene_string[50] = '\0'; initial_population[i].gene = malloc(sizeof(PacGene)); SetGeneFromString(gene_string, initial_population[i].gene); i ++; } fclose(file); *population = initial_population; return 0; } }
int main(int argc, char * argv[]) { int i, j ; char str[STRLENMAX]; size_t len; char *atom; int hit = 0; int miss = 0; clock_t s_new, f_new, s_len, f_len; printf("[test] %d atoms of maxsize = %d B\n",STRNUM, STRLENMAX); srand(time(NULL)); //prepare data for ( i=0; i< STRNUM ; i++ ) { len = (double) rand() / RAND_MAX * STRLENMAX - 1; strings[i].len = len; rand_str( strings[i].str, len); } //new atoms i = STRNUM; s_new = clock(); while( i-- > 0 ){ atom = (char *)Atom_string(strings[i].str); strings[i].atom = atom; } f_new = clock(); // hit len s_len = clock(); i = STRNUM; while( i-- > 0 ){ if (Atom_length(strings[i].atom) == strings[i].len) hit ++; else miss ++; } f_len = clock(); printf("new %f s\n",(float)(f_new - s_new) / CLOCKS_PER_SEC ); printf("len %f s\n",(float)(f_len- s_len) / CLOCKS_PER_SEC ); printf("hit %d / miss %d \n", hit, miss); return 0; }
int main(int argc, char *argv[]) { int rank = -1, source = -1, len = -1, size=-1; if (OSMP_Init(&argc, &argv) != OSMP_SUCCESS) { printf("OSMP_INIT Error\n"); exit(EXIT_FAILURE); } if (OSMP_Size(&size) != OSMP_SUCCESS || size!=2) { printf("OSMP_SIZE Error\n"); exit(EXIT_FAILURE); } if (OSMP_Rank(&rank) != OSMP_SUCCESS || rank == -1) { printf("OSMP_RANK Error\n"); exit(EXIT_FAILURE); } char *bufin, *bufout; bufout = malloc(32); if (rank == 0) { sleep(5); rand_str(bufout, 32); printf("process %d sending random message to process 1: %s\n", rank, bufout); if (OSMP_Send(bufout, 32, 1) != OSMP_SUCCESS) { printf("OSMP_SEND Error\n"); exit(EXIT_FAILURE); } free(bufout); } else if(rank==1){ bufin = malloc(32); printf("Process %d trying to receive msg (should block ~5 seconds)\n", rank); if (OSMP_Recv(bufin, 32, &source, &len) != OSMP_SUCCESS) { printf("OSMP_RECV Error\n"); exit(EXIT_FAILURE); } printf("Process %d received %d bytes from process %d: %s\n", rank, len, source, bufin); free(bufin); } if(OSMP_Finalize()!=OSMP_SUCCESS){ printf("OSMP_FINALIZE Error"); exit(EXIT_FAILURE); } return 0; }
int main (void) { struct timeval tv; gettimeofday(&tv, NULL); srand(tv.tv_usec); int k; printf("Pad # %u\n\n",rand()); for ( k = 1; k <= 20; ++k ) { printf("%i:\t",k); rand_str(); printf("\n"); } return 0; }
int test_sys_rand(void) { char str[64]; uint8_t buf[64]; volatile uint16_t u16 = rand_u16(); volatile uint32_t u32 = rand_u32(); volatile uint64_t u64 = rand_u64(); volatile char ch = rand_char(); (void)u16; (void)u32; (void)u64; (void)ch; rand_str(str, sizeof(str)); rand_bytes(buf, sizeof(buf)); return 0; }
int stress_test2() { int start, end, tmp, size; int i; for (i = 0; i < 10000; ++i) { start = rand() % (MAX_BLOCKS * BLOCK_SIZE); end = rand() % (MAX_BLOCKS * BLOCK_SIZE); if (start > end) { tmp = start; start = end; end = tmp; } size = end - start; rand_str(buffer, size); mydisk_write(start, size, buffer); mydisk_read(start, size, buffer2); if (memcmp(buffer, buffer2, size)) { return 1; } } return 0; }
int stress_test() { int i, id; static char dataset[MAX_BLOCKS][BLOCK_SIZE]; char tmp[BLOCK_SIZE]; for (i = 0; i < MAX_BLOCKS; ++i) { rand_str(dataset[i], BLOCK_SIZE); } for (i = 0; i < 10000; ++i) { id = rand() % MAX_BLOCKS; mydisk_write_block(id, dataset[id]); } for (i = 0; i < MAX_BLOCKS; ++i) { mydisk_read_block(i, tmp); if (memcmp(dataset[i], tmp, BLOCK_SIZE)) { return 1; } } return 0; }
NodeLink* new_NodeLink() { NodeLink* pObj; /* Allocating memory */ pObj = (NodeLink*)malloc(sizeof(NodeLink)); if (pObj == NULL) { return NULL; } /* pointing to itself as we are creating base class object*/ memset(&pObj->generated_KMF_ID[0], 0, sizeof(pObj->generated_KMF_ID)); rand_str(pObj->generated_KMF_ID, 8); pObj->networkType = NULL; pObj->estimatedRate = -1; pObj->lastCheck = NULL; pObj->zoneID = NULL; pObj->networkProperties = NULL; pObj->internalGetKey = NodeLink_internalGetKey; pObj->metaClassName = NodeLink_metaClassName; pObj->FindNetworkPropertiesByID = NodeLink_FindNetworkPropertiesByID; pObj->AddNetworkProperties = NodeLink_AddNetworkProperties; pObj->RemoveNetworkProperties = NodeLink_RemoveNetworkProperties; pObj->Delete = delete_NodeLink; pObj->VisitAttributes = NodeLink_VisitAttributes; pObj->VisitPathAttributes = NodeLink_VisitPathAttributes; pObj->VisitReferences = NodeLink_VisitReferences; pObj->VisitPathReferences = NodeLink_VisitPathReferences; pObj->FindByPath = NodeLink_FindByPath; return pObj; }
int main(int argc, char **argv) { DB *dbp; DB_ENV *dbenv; DBT key, data; db_recno_t recno; DB_TXN *xid; int num_xactions; int num_inserts_per_xaction; char *string; int i, j; if (argc != 3) { printf("usage: %s <num xactions> <num inserts per xaction>\n", argv[0]); exit(-1); } num_xactions = atoi(argv[1]); num_inserts_per_xaction = atoi(argv[2]); env_dir_create(); env_open(&dbenv); rand_str_init(); if (db_open(dbenv, &dbp, DATABASE, 0)) { return (1); } memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); recno = 1; for (i = 1; i <= num_xactions; i++ ) { dbenv->txn_begin(dbenv, NULL, &xid, 0); for (j = 0; j < num_inserts_per_xaction; j++) { string = rand_str(); key.size = sizeof(recno); key.data = &recno; data.size = strlen(string) + 1; // + 1 for the null terminator data.data = string; /* if(VERBOSE) { printf("%s\n", string); } */ dbp->put(dbp, xid, &key, &data, 0); recno++; /* Its unclear from BDB docs whether we should free string */ } xid->commit(xid, 0); } return 0; }
int main(int argc, char **argv) { AdrenoHashtable ht; AdrenoArray arr; int i; char tmp[30]; long double time; #ifdef USE_MEMORY_MANAGER AdrenoMM_Initialize(); #endif AdrenoHashtable_Initialize(&ht, AdrenoHashtable_Hash_Fnv, AdrenoHashtable_Len_String); AdrenoArray_Initialize(&arr); #define docount 10000 time = GetTime(); for (i = 0; i < docount; i++) { rand_str(tmp, sizeof(tmp)); AdrenoArray_Add(&arr, AdrenoStrdup(tmp)); } time = GetTime() - time; printf("Array add with rand_str + strdup: %Lf\n", time); time = GetTime(); for (i = 0; i < docount; i++) { AdrenoHashtable_Set(&ht, arr.Data[i], arr.Data[i]); } time = GetTime() - time; printf("Hashtable add: %Lf\n", time); time = GetTime(); for (i = 0; i < docount; i++) { AdrenoHashtable_Remove(&ht, arr.Data[i]); } time = GetTime() - time; printf("Hashtable remove: %Lf\n", time); time = GetTime(); while(arr.Count) { AdrenoFree(arr.Data[0]); AdrenoArray_Remove(&arr, 0); } time = GetTime() - time; printf("Array remove + free: %Lf\n", time); AdrenoHashtable_Destroy(&ht); AdrenoArray_Free(&arr); #ifdef USE_MEMORY_MANAGER AdrenoMM_Final(); #endif getchar(); return 0; }
int main(int argc, char *argv[]){ if ( argc != 2 ) { printf( "usage: %s <number of chars in password>", argv[0]); } else { int n = atoi(argv[1]); // password length char password[n]; unsigned char password_hash[MD5_DIGEST_LENGTH]; unsigned char bruteforce_hash[MD5_DIGEST_LENGTH]; int i,j; char *c = malloc((n+1)*sizeof(char)); int found = 0; // flag clock_t begin, end; double time_spent; // seed random number generator srand(time(NULL)); // generate a random password with specified length rand_str(password,n); printf("Generated random password: %s\n",password); // hash the password MD5(password, strlen(password), password_hash); printf("Starting password recovery...\n"); // start timing begin = clock(); // main loop to go through all combinations of passwords in the start and ending char range specified for(i=1;i<=n;i++){ if (!found) { for(j=0;j<i;j++) c[j]='0'; // starting char c[i]=0; do { MD5(c, strlen(c), bruteforce_hash); // check if the password hash and bruteforce hash are equal // if they are equal we have a match and found = 1 found = !memcmp(password_hash, bruteforce_hash, MD5_DIGEST_LENGTH); if (found) printf("Found a match for: %s\n",c); } while(inc(c) && !found); } } if (!found) printf("No match found for: %s\n",password); // stop timing end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("Time taken: %f ms\n",time_spent * 1000); free(c); } return 0; }
ContainerRoot* new_ContainerRoot() { ContainerRoot* pObj; /* Allocating memory */ pObj = (ContainerRoot*)malloc(sizeof(ContainerRoot)); if (pObj == NULL) { return NULL; } /* pointing to itself as we are creating base class object*/ pObj->pDerivedObj = pObj; memset(&pObj->generated_KMF_ID[0], 0, sizeof(pObj->generated_KMF_ID)); rand_str(pObj->generated_KMF_ID, 8); pObj->eContainer = ""; pObj->path = ""; pObj->nodes = NULL; pObj->typeDefinitions = NULL; pObj->repositories = NULL; pObj->dataTypes = NULL; pObj->libraries = NULL; pObj->hubs = NULL; pObj->mBindings = NULL; pObj->deployUnits = NULL; pObj->nodeNetworks = NULL; pObj->groups = NULL; pObj->internalGetKey = ContainerRoot_internalGetKey; pObj->metaClassName = ContainerRoot_metaClassName; pObj->Delete = delete_ContainerRoot; pObj->Visit = ContainerRoot_Visit; pObj->VisitPaths = ContainerRoot_VisitPaths; pObj->FindByPath = ContainerRoot_FindByPath; pObj->FindNodesByID = ContainerRoot_FindNodesByID; pObj->FindTypeDefsByID = ContainerRoot_FindTypeDefsByID; pObj->FindRepositoriesByID = ContainerRoot_FindRepositoriesByID; pObj->FindDataTypesByID = ContainerRoot_FindDataTypesByID; pObj->FindLibrariesByID = ContainerRoot_FindLibrariesByID; pObj->FindHubsByID = ContainerRoot_FindHubsByID; pObj->FindBindingsByID = ContainerRoot_FindBndingsByID; pObj->FindDeployUnitsByID = ContainerRoot_FindDeployUnitsByID; pObj->FindNodeNetworksByID = ContainerRoot_FindNodeNetworksByID; pObj->FindGroupsByID = ContainerRoot_FindGroupsByID; pObj->AddNodes = ContainerRoot_AddNodes; pObj->AddTypeDefinitions = ContainerRoot_AddTypeDefinitions; pObj->AddRepositories = ContainerRoot_AddRepositories; pObj->AddDataTypes = ContainerRoot_AddDataTypes; pObj->AddLibraries = ContainerRoot_AddLibraries; pObj->AddHubs = ContainerRoot_AddHubs; pObj->AddBindings = ContainerRoot_AddBindings; pObj->AddDeployUnits = ContainerRoot_AddDeployUnits; pObj->AddNodeNetworks = ContainerRoot_AddNodeNetworks; pObj->AddGroups = ContainerRoot_AddGroups; pObj->RemoveNodes = ContainerRoot_RemoveNodes; pObj->RemoveTypeDefinitions = ContainerRoot_RemoveTypeDefinitions; pObj->RemoveRepositories = ContainerRoot_RemoveRepositories; pObj->RemoveDataTypes = ContainerRoot_RemoveDataTypes; pObj->RemoveLibraries = ContainerRoot_RemoveLibraries; pObj->RemoveHubs = ContainerRoot_RemoveHubs; pObj->RemoveBindings = ContainerRoot_RemoveBindings; pObj->RemoveDeployUnits = ContainerRoot_RemoveDeployUnits; pObj->RemoveNodeNetworks = ContainerRoot_RemoveNodeNetworks; pObj->RemoveGroups = ContainerRoot_RemoveGroups; return pObj; }
int main(int argc, char *argv[]) { TEST_OPTS *opts, _opts; WT_CURSOR *rcursor, *wcursor; WT_ITEM key, value; WT_SESSION *session, *session2; pthread_t thread; uint64_t i; char str[] = "0000000000000000"; /* * Create a clean test directory for this run of the test program if the * environment variable isn't already set (as is done by make check). */ opts = &_opts; memset(opts, 0, sizeof(*opts)); testutil_check(testutil_parse_opts(argc, argv, opts)); testutil_make_work_dir(opts->home); testutil_check(wiredtiger_open(opts->home, NULL, "create,cache_size=200M", &opts->conn)); testutil_check( opts->conn->open_session(opts->conn, NULL, NULL, &session)); testutil_check( opts->conn->open_session(opts->conn, NULL, NULL, &session2)); testutil_check(session->create(session, name, "key_format=Q,value_format=S")); /* Populate the table with some data. */ testutil_check(session->open_cursor( session, name, NULL, "overwrite", &wcursor)); for (i = 0; i < NUM_DOCS; i++) { wcursor->set_key(wcursor, i); rand_str(i, str); wcursor->set_value(wcursor, str); testutil_check(wcursor->insert(wcursor)); } testutil_check(wcursor->close(wcursor)); printf("%d documents inserted\n", NUM_DOCS); /* Perform some random reads */ testutil_check(session->open_cursor( session, name, NULL, "next_random=true", &rcursor)); query_docs(rcursor, false); testutil_check(rcursor->close(rcursor)); /* Setup Transaction to pin the current values */ testutil_check( session2->begin_transaction(session2, "isolation=snapshot")); testutil_check(session2->open_cursor( session2, name, NULL, "next_random=true", &rcursor)); /* Perform updates in a txn to confirm that we see only the original. */ testutil_check(session->open_cursor( session, name, NULL, "overwrite", &wcursor)); for (i = 0; i < NUM_DOCS; i++) { rand_str(i, str); str[0] = 'A'; wcursor->set_key(wcursor, i); wcursor->set_value(wcursor, str); testutil_check(wcursor->update(wcursor)); } testutil_check(wcursor->close(wcursor)); printf("%d documents set to update\n", NUM_DOCS); /* Random reads, which should see the original values */ query_docs(rcursor, false); testutil_check(rcursor->close(rcursor)); /* Finish the txn */ testutil_check(session2->rollback_transaction(session2, NULL)); /* Random reads, which should see the updated values */ testutil_check(session2->open_cursor( session2, name, NULL, "next_random=true", &rcursor)); query_docs(rcursor, true); testutil_check(rcursor->close(rcursor)); /* Setup a pre-delete txn */ testutil_check( session2->begin_transaction(session2, "isolation=snapshot")); testutil_check(session2->open_cursor( session2, name, NULL, "next_random=true", &rcursor)); /* Delete all but one document */ testutil_check(session->open_cursor( session, name, NULL, "overwrite", &wcursor)); for (i = 0; i < NUM_DOCS - 1; i++) { wcursor->set_key(wcursor, i); testutil_check(wcursor->remove(wcursor)); } testutil_check(wcursor->close(wcursor)); printf("%d documents deleted\n", NUM_DOCS - 1); /* Random reads, which should not see the deletes */ query_docs(rcursor, true); testutil_check(rcursor->close(rcursor)); /* Rollback the txn so we can see the deletes */ testutil_check(session2->rollback_transaction(session2, NULL)); /* Find the one remaining document 3 times */ testutil_check(session2->open_cursor( session2, name, NULL, "next_random=true", &rcursor)); for (i = 0; i < 3; i++) { testutil_check(rcursor->next(rcursor)); testutil_check(rcursor->get_key(rcursor, &key)); testutil_check(rcursor->get_value(rcursor, &value)); /* There should only be one value available to us */ testutil_assertfmt((uint64_t)key.data == NUM_DOCS - 1, "expected %d and got %" PRIu64, NUM_DOCS - 1, (uint64_t)key.data); check_str((uint64_t)key.data, (char *)value.data, true); } printf("Found the deleted doc 3 times\n"); testutil_check(rcursor->close(rcursor)); /* Repopulate the table for compact. */ testutil_check(session->open_cursor( session, name, NULL, "overwrite", &wcursor)); for (i = 0; i < NUM_DOCS - 1; i++) { wcursor->set_key(wcursor, i); rand_str(i, str); str[0] = 'A'; wcursor->set_value(wcursor, str); testutil_check(wcursor->insert(wcursor)); } testutil_check(wcursor->close(wcursor)); /* Run random cursor queries while compact is running */ testutil_check(session2->open_cursor( session2, name, NULL, "next_random=true", &rcursor)); testutil_check(pthread_create(&thread, NULL, compact_thread, session)); query_docs(rcursor, true); testutil_check(rcursor->close(rcursor)); testutil_check(pthread_join(thread, NULL)); /* Delete everything. Check for infinite loops */ testutil_check(session->open_cursor( session, name, NULL, "overwrite", &wcursor)); for (i = 0; i < NUM_DOCS; i++) { wcursor->set_key(wcursor, i); testutil_check(wcursor->remove(wcursor)); } testutil_check(wcursor->close(wcursor)); testutil_check(session2->open_cursor( session2, name, NULL, "next_random=true", &rcursor)); for (i = 0; i < 3; i++) testutil_assert(rcursor->next(rcursor) == WT_NOTFOUND); printf("Successfully got WT_NOTFOUND\n"); testutil_cleanup(opts); return (EXIT_SUCCESS); }
int main() { int i,PIN1,PIN2,rtn,err,iter; char x[PGS],y[PGS]; octet X={sizeof(x), sizeof(x),x}; octet Y={sizeof(y),sizeof(y),y}; /* Master secret shares */ char ms1[PGS], ms2[PGS]; octet MS1={sizeof(ms1),sizeof(ms1),ms1}; octet MS2={sizeof(ms2),sizeof(ms2),ms2}; /* Hash values of CLIENT_ID */ char hcid[32]; octet HCID={sizeof(hcid),sizeof(hcid), hcid}; /* Client secret and shares */ char cs1[2*PFS+1], cs2[2*PFS+1], sec[2*PFS+1]; octet SEC={sizeof(sec),sizeof(sec),sec}; octet CS1={sizeof(cs1),sizeof(cs1), cs1}; octet CS2={sizeof(cs2),sizeof(cs2), cs2}; /* Server secret and shares */ char ss1[4*PFS], ss2[4*PFS], serverSecret[4*PFS]; octet ServerSecret={sizeof(serverSecret),sizeof(serverSecret),serverSecret}; octet SS1={sizeof(ss1),sizeof(ss1),ss1}; octet SS2={sizeof(ss2),sizeof(ss2),ss2}; /* Time Permit and shares */ char tp1[2*PFS+1], tp2[2*PFS+1], tp[2*PFS+1]; octet TP={sizeof(tp),sizeof(tp),tp}; octet TP1={sizeof(tp1),sizeof(tp1),tp1}; octet TP2={sizeof(tp2),sizeof(tp2),tp2}; /* Token stored on computer */ char token[2*PFS+1]; octet TOKEN={sizeof(token),sizeof(token),token}; char ut[2*PFS+1],u[2*PFS+1]; octet UT={sizeof(ut),sizeof(ut),ut}; octet U={sizeof(u),sizeof(u),u}; char hid[2*PFS+1],htid[2*PFS+1]; octet HID={0,sizeof(hid),hid}; octet HTID={0,sizeof(htid),htid}; char e[12*PFS], f[12*PFS]; octet E={sizeof(e),sizeof(e),e}; octet F={sizeof(f),sizeof(f),f}; int date = 0; unsigned long ran; int byte_count = 32; FILE *fp; char seed[32] = {0}; octet SEED = {sizeof(seed),sizeof(seed),seed}; csprng RNG; #ifdef __linux__ size_t readSize; fp = fopen("/dev/urandom", "r"); readSize = fread(&seed, 1, byte_count, fp); fclose(fp); #else /* non random seed value! */ time((time_t *)&ran); SEED.val[0]=ran; SEED.val[1]=ran>>8; SEED.val[2]=ran>>16; SEED.val[3]=ran>>24; for (i=4;i<byte_count;i++) SEED.val[i]=i+1; #endif printf("SEED 0x"); OCT_output(&SEED); /* initialise random number generator */ CREATE_CSPRNG(&RNG,&SEED); for(iter=1; iter<nRandomTests+1; iter++) { /* Generate Client master secret for MIRACL and Customer */ rtn = MPIN_RANDOM_GENERATE(&RNG,&MS1); if (rtn != 0) { printf("MPIN_RANDOM_GENERATE(&RNG,&MS1) Error %d\n", rtn); return 1; } rtn = MPIN_RANDOM_GENERATE(&RNG,&MS2); if (rtn != 0) { printf("MPIN_RANDOM_GENERATE(&RNG,&MS2) Error %d\n", rtn); return 1; } printf("MASTER SECRET MIRACL:= 0x"); OCT_output(&MS1); printf("MASTER SECRET CUSTOMER:= 0x"); OCT_output(&MS2); /* Generate server secret shares */ rtn = MPIN_GET_SERVER_SECRET(&MS1,&SS1); if (rtn != 0) { printf("MPIN_GET_SERVER_SECRET(&MS1,&SS1) Error %d\n", rtn); return 1; } rtn = MPIN_GET_SERVER_SECRET(&MS2,&SS2); if (rtn != 0) { printf("MPIN_GET_SERVER_SECRET(&MS2,&SS2) Error %d\n", rtn); return 1; } printf("SS1 = 0x"); OCT_output(&SS1); printf("SS2 = 0x"); OCT_output(&SS2); /* Combine server secret share */ rtn = MPIN_RECOMBINE_G2(&SS1, &SS2, &ServerSecret); if (rtn != 0) { printf("MPIN_RECOMBINE_G2(&SS1, &SS2, &ServerSecret) Error %d\n", rtn); return 1; } printf("ServerSecret = 0x"); OCT_output(&ServerSecret); /* Assign the End-User an ID */ char client_id[256]; octet CLIENT_ID = {0,sizeof(client_id),client_id}; rand_str(client_id,256); OCT_jstring(&CLIENT_ID,client_id); printf("CLIENT: ID %s\n", client_id); /* Hash CLIENT_ID */ MPIN_HASH_ID(&CLIENT_ID,&HCID); OCT_output(&HCID); srand ( time (NULL) ); PIN1 = rand()%MAX_RANGE; // Get random between 0 and MAX_RANGE PIN2 = PIN1; printf("PIN1 %d PIN2 %d\n", PIN1, PIN2); /* Generate client secret shares */ rtn = MPIN_GET_CLIENT_SECRET(&MS1,&HCID,&CS1); if (rtn != 0) { printf("MPIN_GET_CLIENT_SECRET(&MS1,&HCID,&CS1) Error %d\n", rtn); return 1; } rtn = MPIN_GET_CLIENT_SECRET(&MS2,&HCID,&CS2); if (rtn != 0) { printf("MPIN_GET_CLIENT_SECRET(&MS2,&HCID,&CS2) Error %d\n", rtn); return 1; } printf("CS1 = 0x"); OCT_output(&CS1); printf("CS2 = 0x"); OCT_output(&CS2); /* Combine client secret shares : TOKEN is the full client secret */ rtn = MPIN_RECOMBINE_G1(&CS1, &CS2, &TOKEN); if (rtn != 0) { printf("MPIN_RECOMBINE_G1(&CS1, &CS2, &TOKEN) Error %d\n", rtn); return 1; } printf("Client Secret = 0x"); OCT_output(&TOKEN); /* Client extracts PIN1 from secret to create Token */ rtn = MPIN_EXTRACT_PIN(&CLIENT_ID, PIN1, &TOKEN); if (rtn != 0) { printf("MPIN_EXTRACT_PIN( &CLIENT_ID, PIN, &TOKEN) Error %d\n", rtn); return 1; } printf("Token = 0x"); OCT_output(&TOKEN); /* Generate Time Permit shares */ date = today(); printf("Date %d \n", date); rtn = MPIN_GET_CLIENT_PERMIT(date,&MS1,&HCID,&TP1); if (rtn != 0) { printf("MPIN_GET_CLIENT_PERMIT(date,&MS1,&HCID,&TP1) Error %d\n", rtn); return 1; } rtn = MPIN_GET_CLIENT_PERMIT(date,&MS2,&HCID,&TP2); if (rtn != 0) { printf("MPIN_GET_CLIENT_PERMIT(date,&MS2,&HCID,&TP2) Error %d\n", rtn); return 1; } printf("TP1 = 0x"); OCT_output(&TP1); printf("TP2 = 0x"); OCT_output(&TP2); /* Combine Time Permit shares */ rtn = MPIN_RECOMBINE_G1(&TP1, &TP2, &TP); if (rtn != 0) { printf("MPIN_RECOMBINE_G1(&TP1, &TP2, &TP) Error %d\n", rtn); return 1; } printf("Time Permit = 0x"); OCT_output(&TP); /* This encoding makes Time permit look random */ if (MPIN_ENCODING(&RNG,&TP)!=0) printf("Encoding error\n"); printf("Encoded Time Permit= "); OCT_output(&TP); if (MPIN_DECODING(&TP)!=0) printf("Decoding error\n"); printf("Decoded Time Permit= "); OCT_output(&TP); /* Client first pass */ rtn = MPIN_CLIENT_1(date,&CLIENT_ID,&RNG,&X,PIN2,&TOKEN,&SEC,&U,&UT,&TP); if (rtn != 0) { printf("MPIN_CLIENT_1 ERROR %d\n", rtn); return 1; } /* Server calculates H(ID) and H(T|H(ID)) (if time permits enabled), and maps them to points on the curve HID and HTID resp. */ MPIN_SERVER_1(date,&CLIENT_ID,&HID,&HTID); /* Server generates Random number Y and sends it to Client */ rtn = MPIN_RANDOM_GENERATE(&RNG,&Y); if (rtn != 0) { printf("MPIN_RANDOM_GENERATE(&RNG,&Y) Error %d\n", rtn); return 1; } printf("Y = 0x"); OCT_output(&Y); /* Client second pass */ rtn = MPIN_CLIENT_2(&X,&Y,&SEC); if (rtn != 0) printf("MPIN_CLIENT_2(&X,&Y,&SEC) Error %d\n", rtn); printf("V = 0x"); OCT_output(&SEC); /* Server second pass */ rtn = MPIN_SERVER_2(date,&HID,&HTID,&Y,&ServerSecret,&U,&UT,&SEC,&E,&F); if (rtn != 0) { err=MPIN_KANGAROO(&E,&F); if (err==0) { printf("Iteration %d FAILURE Invalid Token Error Code %d\n", iter, rtn); return 1; } else { printf("Iteration %d FAILURE PIN Error %d, Error Code %d\n", iter, err, rtn); return 1; } } else { printf("Iteration %d SUCCESS Error Code %d\n\n", iter, rtn); } } return 0; }
int get_key_words(string s, var_map* var_map_point, replace_map* replace_map_point) { int length = s.size(); char* key_words[6]; char* reg = "reg"; char* wire = "wire"; char* parameter = "parameter"; char* input = "input"; char* output = "output"; char* module = "module"; key_words[0] = reg; key_words[1] = wire; key_words[2] = parameter; key_words[3] = input; key_words[4] = output; key_words[5] = module; int position[6]; for (int i = 0; i < 5; i++) { position[i] = s.find(key_words[i]); } for (int i = 0; i < 5; i++) { if (position[i] != -1) { bool is_error = true; //default, error happens int end = position[i] + strlen(key_words[i]); if (position[i] == 0) //key_word begin at the s[0] { if (is_separator(s[end])) //a separator follows the key_word is_error = false; //key_word is ture } else if (is_separator(s[position[i] - 1])) //key_word begin in the middle of s { if (is_separator(s[end])) is_error = false; } if (is_error) { position[i] = -1; continue; //if error happens, continue } //get the var name int var_begin = 0; int var_end = 0; int temp = end; while (!is_character(s[temp])) temp++; var_begin = temp; while (!is_separator(s[temp])) temp++; var_end = temp; string varname = s.substr(var_begin, var_end - var_begin); string replace_name; while (1) { int varname_repeat_flag = 0; int replace_name_repeat_flag = 0; //rand replace_name if (i != 3 && i != 4) { rand_str(&replace_name); // replace_name = varname + "_edited"; //for test } else replace_name = varname; //travel through the map to find if replace_name or var_name is repeated replace_map::iterator itr1 = replace_map_point->begin(); for (; itr1 != replace_map_point->end(); ++itr1) { if (itr1->first == varname) //if the varname has appeared before varname_repeat_flag = 1; // else if (itr1->second == replace_name) //if the replace name is repeated // replace_name_repeat_flag = 1; } if (varname_repeat_flag) break; else if (replace_name_repeat_flag) continue; else { var_map_point->insert(var_map::value_type(varname, i)); replace_map_point->insert(replace_map::value_type(varname, replace_name)); cout << var_map_point->size() << endl; // if (replace_name.size() != 20 && i != 3 && i != 4) // cout << "error!" << endl; } } } } return 0; }
void spider(void *pack,char *line,char * pathtable) { struct MemoryStruct chunk; FILE *fp=NULL; bool match_string=false,save_response=false,test_tamper=false; long status=0,length=0; int old=0,res=0,counter=0,counter_cookie=0,counter_agent=0,POST=0,timeout=0,debug_host=3; char *make=NULL,*make_cookie=NULL,*make_agent=NULL,*tamper=NULL,*responsetemplate=NULL,*tmp_response=NULL,*tmp_make=NULL,*tmp_make_cookie=NULL,*tmp_make_agent=NULL,*tmp_line=NULL,*tmp_line2=NULL; char **pack_ptr=(char **)pack,**arg = pack_ptr; char randname[16],line2[1024],log[2048],tabledata[4086],pathsource[1024]; if(arg[12]!=NULL) save_response=true; if(arg[8]!=NULL) timeout=atoi(arg[8]); // payload tamper if(arg[20]!=NULL) { tamper=arg[20]; if(strstr(tamper,"encode64")) { line=encode64(line,strlen(line)-1); test_tamper=true; } if(strstr(tamper,"randcase")) { line=rand_case(line); test_tamper=true; } if(strstr(tamper,"urlencode")) { line=urlencode(line); test_tamper=true; } if(strstr(tamper,"double_urlencode")) { line=double_urlencode(line); test_tamper=true; } if(strstr(tamper,"spaces2comment")) { line=spaces2comment(line); test_tamper=true; } if(strstr(tamper,"unmagicquote")) { line=unmagicquote(line); test_tamper=true; } if(strstr(tamper,"apostrophe2nullencode")) { line=apostrophe2nullencode(line); test_tamper=true; } if(strstr(tamper,"rand_comment")) { line=rand_comment(line); test_tamper=true; } if(strstr(tamper,"rand_space")) { line=rand_space(line); test_tamper=true; } if(test_tamper==false) { DEBUG("error at tamper argument\n"); exit(0); } } memset(pathsource,0,sizeof(char)*1023); if(save_response==false) { strcat(pathsource,"0"); } // brute POST/GET/COOKIES/UserAgent if(arg[21]==NULL) { POST=(arg[4]==NULL)?0:1; counter=char_type_counter(POST?arg[4]:arg[0],'^'); counter_cookie=char_type_counter(arg[13]!=NULL?arg[13]:"",'^'); counter_agent=char_type_counter(arg[19]!=NULL?arg[19]:"",'^'); old=counter; } else { char *file_request=readLine(arg[21]); counter=char_type_counter(file_request,'^'); old=counter; xfree((void**)&file_request); } chomp(line); // goto to fix signal stop if user do ctrl+c try_again: while ( old > 0 || counter_cookie > 0 || counter_agent > 0 ) { CURL *curl; // curl_global_init(CURL_GLOBAL_ALL); chunk.memory=NULL; chunk.size = 0; curl_socket_t sockfd; /* socket */ long sockextr; size_t iolen; curl = curl_easy_init(); // DEBUG("counts ^ : %d \n",old); if(arg[21]==NULL) { make=payload_injector( (POST?arg[4]:arg[0]),line,old); if(arg[13]!=NULL) make_cookie=payload_injector( arg[13],line,counter_cookie); if(arg[19]!=NULL) make_agent=payload_injector( arg[19],line,counter_agent); curl_easy_setopt(curl, CURLOPT_URL, POST?arg[0]:make); } else { // if is custom request char *request_file=readLine(arg[21]); make=payload_injector( request_file,line,old); curl_easy_setopt(curl, CURLOPT_URL, arg[0]); xfree((void**)&request_file); } if ( POST ) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, make); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); // load user agent if ( arg[6]!=NULL ) { curl_easy_setopt(curl, CURLOPT_USERAGENT, arg[6]); } else { curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (0d1n v0.1) "); } // json headers to use JSON if(arg[14]!=NULL) { struct curl_slist *headers = NULL; curl_slist_append(headers, arg[14]); if(arg[16]!=NULL) { curl_slist_append(headers, "Accept: application/json"); curl_slist_append(headers, "Content-Type: application/json"); } curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_slist_free_all(headers); } else { if(arg[16] != NULL) { struct curl_slist *headers = NULL; curl_slist_append(headers, "Accept: application/json"); curl_slist_append(headers, "Content-Type: application/json"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_slist_free_all(headers); } } //use custom method PUT,DELETE... if(arg[15]!=NULL) { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, arg[15]); } curl_easy_setopt(curl, CURLOPT_ENCODING,"gzip,deflate"); // load cookie jar if ( arg[3] != NULL ) { curl_easy_setopt(curl,CURLOPT_COOKIEFILE,arg[3]); curl_easy_setopt(curl,CURLOPT_COOKIEJAR,arg[3]); } else { curl_easy_setopt(curl,CURLOPT_COOKIEJAR,"odin_cookiejar.txt"); } // LOAD cookie fuzz if(arg[13]!=NULL) { curl_easy_setopt(curl,CURLOPT_COOKIE,make_cookie); } // LOAD UserAgent FUZZ if(arg[19]!=NULL) { curl_easy_setopt(curl,CURLOPT_USERAGENT,make_agent); } curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1); // Load cacert if ( arg[7] != NULL ) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2); curl_easy_setopt(curl, CURLOPT_CAINFO, arg[7]); } else { curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,0L); curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,0L); } if(timeout) curl_easy_setopt(curl,CURLOPT_TIMEOUT,timeout); // load single proxy if(arg[17] != NULL) { curl_easy_setopt(curl, CURLOPT_PROXY, arg[17]); // curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1); } // load random proxy in list if(arg[18] != NULL) { char *randproxy=Random_linefile(arg[18]); // printf("PROXY LOAD: %s\n",randproxy); curl_easy_setopt(curl, CURLOPT_PROXY, randproxy); // curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1); } if ( arg[9] != NULL ) curl_easy_setopt(curl,CURLOPT_SSLVERSION,(long)atoi(arg[9])); curl_easy_setopt(curl,CURLOPT_VERBOSE,0); curl_easy_setopt(curl,CURLOPT_HEADER,1); if(arg[21]!=NULL) { curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); } res=curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,&status); // custom http request if(arg[21]!=NULL) { curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr); sockfd = sockextr; if(!wait_on_socket(sockfd, 0, 60000L)) { DEBUG("error in socket at custom http request"); } res=curl_easy_send(curl, make, strlen(make), &iolen); // recv data while(1) { wait_on_socket(sockfd, 1, 60000L); chunk.memory=xmalloc(sizeof(char)*3024); res = curl_easy_recv(curl, chunk.memory, 3023, &iolen); chunk.size=strlen(chunk.memory); if(strlen(chunk.memory) > 8) break; if(CURLE_OK != res) break; } status=(long)parse_http_status(chunk.memory); //status=404; } // length of response if(chunk.size<=0) length=0.0; else length=chunk.size; if(status==0) { debug_host--; DEBUG("Problem in Host: \n %s",chunk.memory); if(debug_host<0) exit(0); goto try_again; } // arg[10] list to find with regex , arg[2] list without regex if( (arg[2]) || (arg[10]) ) { if(save_response==true) { memset(pathsource,0,sizeof(char)*1023); } fp = fopen((arg[2]!=NULL)?arg[2]:arg[10], "r"); if ( !fp ) { DEBUG("error to open response list"); exit(1); } while ( fgets(line2,1023,fp) != NULL) { chomp(line2); // find a string in response if(status != 0) { if ( arg[2] != NULL ) match_string=strstr(chunk.memory,line2)?true:false; if ( arg[10] != NULL ) match_string=strstr_regex(chunk.memory,line2)?true:false; } if(chunk.memory && (match_string == true) ) { if(make_cookie!=NULL) { fprintf(stdout,"%s [ %s %ld %s ] Payload: %s %s %s Grep: %s %s %s Params: %s \nCookie: %s %s\n",YELLOW,CYAN,status,YELLOW,GREEN,line,YELLOW,CYAN,line2,YELLOW,make,make_cookie,LAST); } if(make_agent!=NULL) { fprintf(stdout,"%s [ %s %ld %s ] Payload: %s %s %s Grep: %s %s %s Params: %s \nCookie: %s %s\n",YELLOW,CYAN,status,YELLOW,GREEN,line,YELLOW,CYAN,line2,YELLOW,make,make_agent,LAST); } else { fprintf(stdout,"%s [ %s %ld %s ] Payload: %s %s %s Grep: %s %s %s Params: %s %s\n",YELLOW,CYAN,status,YELLOW,GREEN,line,YELLOW,CYAN,line2,YELLOW,make,LAST); } if(save_response==true) { // create responses path memset(pathsource,0,sizeof(char)*1023); strncat(pathsource,"response_sources/",18); strncat(pathsource,arg[5], 15); mkdir(pathsource,S_IRWXU|S_IRWXG|S_IRWXO); snprintf(pathsource,986,"response_sources/%s/%s.html",arg[5],rand_str(randname, sizeof randname)); } // write log file snprintf(log,2047,"[ %ld ] Payload: %s Grep: %s Params: %s cookie: %s UserAgent: %s \n Path Response Source: %s\n",status,line,line2,make,(make_cookie!=NULL)?make_cookie:" ",(make_agent!=NULL)?make_agent:" ",pathsource); WriteFile(arg[5],log); memset(log,0,2047); if(save_response==true) { // write highlights response responsetemplate=NULL; responsetemplate=readLine(TEMPLATE); WriteFile(pathsource,responsetemplate); memset(responsetemplate,0,strlen(responsetemplate)-1); tmp_response=NULL; tmp_response=html_entities(chunk.memory); WriteFile(pathsource,tmp_response); memset(tmp_response,0,strlen(tmp_response)-1); WriteFile(pathsource,"</pre></html>"); } // create datatables tmp_make=html_entities(make); tmp_line2=html_entities(line2); tmp_line=html_entities(line); if(make_cookie!=NULL) { tmp_make_cookie=html_entities(make_cookie); snprintf(tabledata,4085,"[\"<a class=\\\"fancybox fancybox.iframe\\\" href=\\\"../%s\\\">%ld </a>\",\"%ld\",\"%s cookie: %s\",\"%s\",\"%s\"],\n",pathsource,status,length,tmp_make,tmp_make_cookie,tmp_line2,tmp_line); memset(tmp_make_cookie,0,strlen(tmp_make_cookie)-1); } if(make_agent!=NULL) { tmp_make_agent=html_entities(make_agent); snprintf(tabledata,4085,"[\"<a class=\\\"fancybox fancybox.iframe\\\" href=\\\"../%s\\\">%ld </a>\",\"%ld\",\"%s UserAgent: %s\",\"%s\",\"%s\"],\n",pathsource,status,length,tmp_make,tmp_make_agent,tmp_line2,tmp_line); memset(tmp_make_agent,0,strlen(tmp_make_agent)-1); } else { snprintf(tabledata,4085,"[\"<a class=\\\"fancybox fancybox.iframe\\\" href=\\\"../%s\\\">%ld </a>\",\"%ld\",\"%s\",\"%s\",\"%s\"],\n",pathsource,status,length,tmp_make,tmp_line2,tmp_line); } WriteFile(pathtable,tabledata); // memset(tmp_make,0,strlen(tmp_make)-1); // memset(tmp_make_cookie,0,strlen(tmp_make_cookie)-1); // memset(tmp_make_agent,0,strlen(tmp_make_agent)-1); memset(tmp_line,0,strlen(tmp_line)-1); memset(tmp_line2,0,strlen(tmp_line2)-1); memset(tabledata,0,4085); memset(pathsource,0,strlen(pathsource)-1); } } if( fclose(fp) == EOF ) { DEBUG("Error in close()"); exit(1); } fp=NULL; } else { if(counter_cookie) { fprintf(stdout,"%s [ %s %ld %s ] Payload: %s %s %s Params: %s %s\n Cookie: %s %s\n",YELLOW,CYAN,status,YELLOW,GREEN,line,YELLOW,CYAN,make,make_cookie,LAST); } if(counter_agent) { fprintf(stdout,"%s [ %s %ld %s ] Payload: %s %s %s Params: %s %s\n UserAgent: %s %s\n",YELLOW,CYAN,status,YELLOW,GREEN,line,YELLOW,CYAN,make,make_agent,LAST); } else { fprintf(stdout,"%s [ %s %ld %s ] Payload: %s %s %s Params: %s %s %s\n",YELLOW,CYAN,status,YELLOW,GREEN,line,YELLOW,CYAN,make,LAST); } if(save_response==true) { // memset(pathsource,0,sizeof(char)*1023); strncat(pathsource,"response_sources/",18); strncat(pathsource,arg[5], 15); mkdir(pathsource,S_IRWXU|S_IRWXG|S_IRWXO); snprintf(pathsource,986,"response_sources/%s/%s.html",arg[5],rand_str(randname, sizeof randname)); } //write logs snprintf(log,2047,"[%ld Payload: %s Params: %s Cookie: %s UserAgent: %s \n Path Response Source: %s\n",status,line,make,(make_cookie!=NULL)?make_cookie:" ",(make_agent!=NULL)?make_agent:" ",pathsource); WriteFile(arg[5],log); memset(log,0,2047); if(save_response==true) { // write response source with highlights responsetemplate=readLine(TEMPLATE); WriteFile(pathsource,responsetemplate); //memset(responsetemplate,0,strlen(responsetemplate)-1); tmp_response=html_entities(chunk.memory); WriteFile(pathsource,tmp_response); //memset(tmp_response,0,strlen(tmp_response)-1); WriteFile(pathsource,"</pre></html>"); } // create datatables tmp_make=html_entities(make); tmp_line=html_entities(line); if(counter_cookie) { tmp_make_cookie=html_entities(make_cookie); snprintf(tabledata,4085,"[\"<a class=\\\"fancybox fancybox.iframe\\\" href=\\\"../%s\\\">%ld </a>\",\"%ld\",\"%s cookie: %s\",\"\",\"%s\"],\n",pathsource,status,length,tmp_make,tmp_make_cookie,tmp_line); // memset(tmp_make_cookie,0,strlen(tmp_make_cookie)-1); } if(counter_agent) { tmp_make_agent=html_entities(make_agent); snprintf(tabledata,4085,"[\"<a class=\\\"fancybox fancybox.iframe\\\" href=\\\"../%s\\\">%ld </a>\",\"%ld\",\"%s UserAgent: %s\",\"\",\"%s\"],\n",pathsource,status,length,tmp_make,tmp_make_agent,tmp_line); } else { snprintf(tabledata,4047,"[\"<a class=\\\"fancybox fancybox.iframe\\\" href=\\\"../%s\\\">%ld </a>\",\"%ld\",\"%s\",\"\",\"%s\"],\n",pathsource,status,length,tmp_make,tmp_line); } WriteFile(pathtable,tabledata); memset(tmp_make,0,strlen(tmp_make)-1); memset(tmp_line,0,strlen(tmp_line)-1); memset(tabledata,0,4085); memset(pathsource,0,strlen(pathsource)-1); //DEBUG("part B"); } //DEBUG("END PARTS"); // memset(make,0,strlen(make)-1); // memset(make_cookie,0,strlen(make_cookie)-1); // memset(make_agent,0,strlen(make_agent)-1); // memset(pathsource,0,strlen(pathsource)-1); xfree((void **)&chunk.memory); // curl_easy_cleanup(curl); // curl_global_cleanup(); if(old>0) old--; if(counter_cookie > 0) counter_cookie--; if(counter_agent > 0) counter_agent--; debug_host=3; } xfree((void **)&make_agent); xfree((void **)&make_cookie); xfree((void **)&make); xfree((void **)&tmp_make); xfree((void **)&tmp_make_cookie); xfree((void **)&tmp_make_agent); xfree((void **)&tmp_line); xfree((void **)&tmp_line2); xfree((void **)&responsetemplate); xfree((void **)&tmp_response); if(arg[20] != NULL) xfree((void **)&line); // DEBUG("GOOO3"); }