Example #1
0
static void crack(int offset,char *in){
	if (offset >= current_stringSize)
	{
		#ifdef CONFIG_MD5
			if (HashSumAndCompare(pKey, (void*)in)){
		#else
			if (HashSumAndCompare(pKey, (void*)in, current_stringSize)){
		#endif
			in[current_stringSize]='\0';
			printf("Match string found: %s\n",in);
			exit(0);
		}
	}
	else
	{
		int i;
		for(i=0;i<=alphaSize;i++)
		{
			in[offset] = alpha[i]; // Put letter on string
			crack(offset+1,in);
		}
	}
}

struct thread_data{
        int tam;
	char initChar;
};
static struct thread_data *thread_data_array;

static void callCrack_thread(void *threadarg){
	struct thread_data *my_data;
        my_data = (struct thread_data *) threadarg;
	char in[19];
	#ifdef CONFIG_MD5
		uint32_t *iin = (void *)in;
     		iin[5] = ((uint32_t)my_data->tam << 3); /* FIXME: This is the ugliest code of ever */
		in[my_data->tam]=0x80;
	#endif
	in[0]=my_data->initChar;
	current_stringSize=my_data->tam;
        crack(1,in);
}

static void callCrack_size(int size){
        int j;
	pthread_t request[alphaSize];
        for (j=0; j < alphaSize; j++)
        {
		thread_data_array[j].tam = size;
		thread_data_array[j].initChar = alpha[j];
		pthread_create(&request[j], NULL, (void*) callCrack_thread, &thread_data_array[j]);
	}
	for (j=0; j < alphaSize; j++){
                (void) pthread_join(request[j], NULL);
        }
	return;
}
Example #2
0
  void RequestApplication::fromApp( const FIX::Message& message, const FIX::SessionID& sessionId )
    throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType )
  {
#ifndef NDEBUG
    if ( message.getHeader().getField( FIX::FIELD::SenderCompID ).find( orderGeneratorId ) == std::string::npos )
    {
      dismantleFIX( "INBOUND", message.toString() ) ;
    }
#endif

    try
    {
      crack( message, sessionId ); 
    }
    catch( std::exception &e )
    {
      FIX42::Reject fixReject;
      fixReject.setField( FIX::FIELD::RefSeqNum, message.getHeader().getField( FIX::FIELD::MsgSeqNum ) ) ;
      fixReject.setField( FIX::FIELD::RefMsgType, message.getHeader().getField( FIX::FIELD::MsgType ) ) ;
      // fixReject.setField( FIX::FIELD::RefTagID,
      fixReject.setField( FIX::FIELD::Text, e.what() ) ;
      // fixReject.setField( FIX::FIELD::SessionRejectReason ( sessionRejectReason ) ) ;
    
      try
      {
        FIX::Session::sendToTarget ( fixReject, sessionId ) ;

      }
      catch ( FIX::SessionNotFound &e )
      {
        std::cout << "Error on Sending execution report " << e.what() << std::endl ;
      }
    }
  }
	void draw()
	{
		//if(on_screen==0) return;
		//float newx=player.x+player.side;float newy=player.y+2*player.side;
		float newx=x;float newy=y;
		if(dir==1)  newx+=BSPEED;
		if(dir==2)  newy+=BSPEED;
		if(dir==3)  newx-=BSPEED;
		if(dir==4)  newy-=BSPEED;

			//setfillstyle(1,BLACK);
			//floodfill(x,y,colour);
			setcolor(BLACK);
			circle(x,y,radius);


			setcolor(colour);
			x=newx;y=newy;
			circle(x,y,radius);
			//floodfill(x,y,colour);


		if(newx<0||newx>getmaxx()) {on_screen=0;setcolor(BLACK);circle(x,y,radius);}
		if(newy<0||newy>getmaxy()) {on_screen=0;setcolor(BLACK);circle(x,y,radius);}

		crack();
		hit();
	}
Example #4
0
File: crack.c Project: Nooxet/cs50
int main(int argc, char *argv[])
{
    if (argc != 2) {
        printf("Usage: %s <passwd file>\n", argv[0]);
        exit(1);
    }

    FILE *passwd = fopen(argv[1], "r");
    if (passwd == NULL) {
        printf("Failed to open %s\n", argv[1]);
        exit(1);
    }
    
    char cred[64];  // store credentials, username:password
    char *pass;     // pointer to the password part in cred
    
    while (fgets(cred, 64, passwd) != NULL) {
        /* remove trailing newline char '\n' */
        cred[strlen(cred) - 1] = '\0';
        
        pass = cred;
        while (*pass++ != ':');

        printf("cracking %s...\n", cred);
        crack(pass);
    }
    
    fclose(passwd);
}
void Application::fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType )
{
  crack( message, sessionID );
  //std::cout << std::endl << "IN: " << message.toXML() << std::endl;

}
Example #6
0
int main(int argc, char *argv[])
{
  int i;
  if (argc <= 1)
    printf("usage: %s hash\n", argv[0]);
  for (i = 1; i < argc; i++)
    crack(argv[i]);
  return 0;
}
Example #7
0
/**
 * Do a given number of zipfian reads on a cog.
 *
 * @param cog - the given cog
 * @param alpha - zipfian rate of decay
 * @param number - number of reads to do on a cog
 * @param range - the key range for reads
 * @return the resulting BTree
 */
struct cog *zipfianReads(struct cog *cog, double alpha, long number, long range) {
  for (long i = 0; i < number; i++) {
    long a = zipf(alpha, range);
    long b = zipf(alpha, range);
    long low = a <= b ? a : b;
    long high = a > b ? a : b;
    cog = crack(cog, low, high);
  }
  return cog;
}
Example #8
0
/**
 * Do a given number of random reads on a cog.
 *
 * @param cog - the given cog
 * @param number - number of reads to do on a cog
 * @param range - the key range for reads
 * @return the resulting BTree
 */
struct cog *randomReads(struct cog *cog, long number, long range) {
  for (long i = 0; i < number; i++) {
    long a = rand() % range;
    long b = rand() % range;
    long low = a <= b ? a : b;
    long high = a > b ? a : b;
    cog = crack(cog, low, high);
  }
  return cog;
}
Example #9
0
void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CPoint Button1(165,122);
	CPoint Button2(350,122);
	if (isRect(point,Button1))
	{
		crack();
	}
	if (isRect(point,Button2)) restore();
	SendMessage(WM_NCLBUTTONDOWN,(WPARAM)HTCAPTION,(LPARAM)HTCAPTION);
	CDialog::OnLButtonDown(nFlags, point);
}
//
// Create a ProtectedPasswordAclSubject
//
ProtectedPasswordAclSubject *ProtectedPasswordAclSubject::Maker::make(const TypedList &list) const
{
    CssmAutoData password(Allocator::standard(Allocator::sensitive));
    if (list.length() == 1) {
        char pass[] = "secret";
        CssmData password = CssmData::wrap(pass, 6);	        //@@@ get password from PP
        return new ProtectedPasswordAclSubject(Allocator::standard(Allocator::sensitive), password);
    } else {
        ListElement *password;
        crack(list, 1, &password, CSSM_LIST_ELEMENT_DATUM);
        return new ProtectedPasswordAclSubject(Allocator::standard(Allocator::sensitive), *password);
    }
}
Example #11
0
int view_query(int a, int b){
  #ifdef RANDOM_CRACK_PER_QUERY
    for (int i=0; i<RANDOM_CRACK_PER_QUERY; i++)
      naive_random_crack();
  #endif
  
  #ifdef RANDOM_CRACK_EVERY_NTH_QUERY
    static int nth = 0;
    if (++nth % RANDOM_CRACK_EVERY_NTH_QUERY == 0)
      naive_random_crack();
  #endif

  int cnt = crack(a,b);
  n_cracks += ci.size();
  return cnt;
}
Example #12
0
//
// Create a PasswordAclSubject
//
PasswordAclSubject *PasswordAclSubject::Maker::make(const TypedList &list) const
{
    Allocator &alloc = Allocator::standard(Allocator::sensitive);
	switch (list.length()) {
	case 1:
		return new PasswordAclSubject(alloc, true);
	case 2:
		{
			ListElement *password;
			crack(list, 1, &password, CSSM_LIST_ELEMENT_DATUM);
			return new PasswordAclSubject(alloc, password->data());
		}
	default:
		CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
	}
}
Example #13
0
void Effects::reset() {
	crack(false);
	shader.begin();
		shader.setUniform1i("fx_flip", 2);
		shader.setUniform1i("fx_mirror", 2);
		shader.setUniform1i("fx_invert", 2);
		shader.setUniform1i("fx_ripple", 2);
		shader.setUniform1i("fx_posterize", 2);
		shader.setUniform1i("fx_pixelate", 2);
		shader.setUniform1i("fx_wave", 2);
		shader.setUniform1i("fx_swirl", 2);
		shader.setUniform1i("fx_reflect", 2);
		shader.setUniform1i("fx_shake", 2);
		shader.setUniform1i("fx_love", 2);
	shader.end();
}
Example #14
0
static void handlePacket01(char *buffer, int socketDesc) {
    printf("Packet data: pos %d, count %d\n", buffer[1], buffer[2]);
    packet01_t packet = {0};
    crkres_t crkres = {0};
    if (crack(&buffer[3], buffer[1], buffer[2], &crkres)) {
        printf("n1: %s n2: %s\n", crkres.n1, crkres.n2);
        packet.n1 = crkres.n1;
        packet.n2 = crkres.n2;
        packet.result = 1;
    } else {
        packet.result = 0;
        printf("Factors are not in this interval\n");
    }
    sendPacket01(packet, socketDesc);
    free(crkres.n1);
    free(crkres.n2);
}
Example #15
0
int main(void)
{
   int rfd, flags, i, count;
   char buffer[SIZE];
   char** arr;

   flags = O_RDONLY;
   rfd = open(INPUT, flags);

   count = countLines(buffer, rfd);

   lseek(rfd, 0, SEEK_SET); //rewind the file, http://linux.die.net/man/2/lseek

   arr = (char**) malloc(count * sizeof(char*));

   for(i = 0; i < count; i++)
   {
      arr[i] = (char*) malloc((hash+1) * sizeof(char));
   }

   i = 0;
   while(readLine(buffer, SIZE, rfd) >= hash) 
   {
      strcpy(arr[i], buffer);
      i++;
   }

   for(i = 0; i < count; i++)
   {
      crack(arr[i]);

      free(arr[i]);
      arr[i] = NULL;
   }

   free(arr);
   arr = NULL;

   close(rfd);

   return 1;
}
Example #16
0
void Effects::applyEffect(const string& fx) {
	
	if(fx == "flip") {
		flip(true);
	}
	else if(fx == "mirror") {
		mirror(true);
	}
	else if(fx == "invert") {
		invert(true);
	}
	else if(fx == "ripple") {
		ripple(true, 3.5);
	}
	else if(fx == "posterize") {
		posterize(true);
	}
	else if(fx == "pixelate") {
		pixelate(true, pixelate_x, pixelate_y);
	}
	else if(fx == "wave") {
		wave(true, wave_speed, wave_displace, wave_num);
	}	
	else if(fx == "swirl") {
		swirl(true, swirl_radius, swirl_angle);
	}
	else if(fx == "shake") {
		shake(true, shake_duration, shake_number, shake_amplitude);
	}
	else if(fx == "reflect") {
		reflect(true);
	}
	else if(fx == "crack") {
		crack(true);
	}
	else if(fx == "love") {
		love(true);
	}
}
Example #17
0
int openMP(char **passwdsTC, char **saltFP, int qtPTC){
    //char **passwdsTC;
    //char **saltFP;
    char *str;
    //int qtPTC;
    int nProcs = omp_get_num_procs();
    PassSlice *slices;
    int i;

   /* if(argv[1]==NULL){
        printf("File name omitted!");
        exit(1);
    }
    if(argv[2]==NULL){
        printf("Number of Passwords omitted!");
        exit(1);
    }

    str = argv[1];

    qtPTC = atoi(argv[2]);
    */
    //if(setTp(3)==0)exit(1);
    slices = initSlices(nProcs);
    //passwdsTC = passwsToCrack(str,qtPTC);
    //saltFP = saltsForPassws(passwdsTC, qtPTC);
    
    #pragma omp parallel shared(slices, qtPTC, saltFP, passwdsTC) private(i)
    {    
    #pragma omp for
        for(i=0;i<nProcs;i++){
            crack(slices[i].begin,passwdsTC, saltFP, qtPTC, slices[i].interval);
        }
    }
    //crack(initials[0],pCrackL,saltL,P_T,D_T,nCRACK);
    return 0;
}
Example #18
0
int reaver_main(int argc, char **argv)
{
	int ret_val = EXIT_FAILURE, r = 0;
	time_t start_time = 0, end_time = 0;
	struct wps_data *wps = NULL;

	globule_init();
	init_default_settings();

	fprintf(stderr, "\nReaver v%s WiFi Protected Setup Attack Tool\n", get_version());
	fprintf(stderr, "Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <*****@*****.**>\n\n");

	if(argc < 2)
	{
		ret_val = reaver_usage(argv[0]);
		goto end;
	}

	/* Process the command line arguments */
	if(process_arguments(argc, argv) == EXIT_FAILURE)
	{
		ret_val = reaver_usage(argv[0]);
		goto end;
	}

	/* Double check reaver_usage */
	if(!get_iface() || (memcmp(get_bssid(), NULL_MAC, MAC_ADDR_LEN) == 0))
	{
		reaver_usage(argv[0]);
		goto end;
	}

	/* If no MAC address was provided, get it ourselves */
	if(memcmp(get_mac(), NULL_MAC, MAC_ADDR_LEN) == 0)
	{
		if(!read_iface_mac())
		{
			fprintf(stderr, "[-] Failed to retrieve a MAC address for interface '%s'!\n", get_iface());
			goto end;
		}
	}

	/* Sanity checking on the message timeout value */	
	if(get_m57_timeout() > M57_MAX_TIMEOUT) 
	{
		set_m57_timeout(M57_MAX_TIMEOUT);
	}
	else if(get_m57_timeout() <= 0)
	{
		set_m57_timeout(M57_DEFAULT_TIMEOUT);
	}

	/* Sanity checking on the receive timeout value */
	if(get_rx_timeout() <= 0)
	{
		set_rx_timeout(DEFAULT_TIMEOUT);
	}

	/* Initialize signal handlers */
	sigint_init();
	sigalrm_init();

	/* Mark the start time */
	start_time = time(NULL);

	/* Do it. */
	crack();

	/* Mark the end time */
	end_time = time(NULL);

	/* Check our key status */
	if(get_key_status() == KEY_DONE)
	{
		wps = get_wps();

		cprintf(VERBOSE,  		    "[+] Pin cracked in %d seconds\n", (int) (end_time - start_time));
		cprintf(CRITICAL, 		    "[+] WPS PIN: '%s'\n", get_pin());
		if(wps->key)      cprintf(CRITICAL, "[+] WPA PSK: '%s'\n", wps->key);
		if(wps->essid)    cprintf(CRITICAL, "[+] AP SSID: '%s'\n", wps->essid);

		/* Run user-supplied command */
		if(get_exec_string())
		{
			r = system(get_exec_string());
		}

		ret_val = EXIT_SUCCESS;
	}
	else 
	{
		cprintf(CRITICAL, "[-] Failed to recover WPA key\n");
	}
	
	save_session();

end:
	globule_deinit();
	return ret_val;
}
Example #19
0
void Application::fromApp( const FIX::Message& message,
                           const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType )
{ crack( message, sessionID ); }
Example #20
0
		void fromApp( const FIX::Message& message, const SessionID& sessionID)
			throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType ) {
				// Header header = message.getHeader();
//				std::cout << "Generic Message received" << std::endl;
				crack( message, sessionID);
			};
Example #21
0
int
cmdloop(void)
{
    char *line;
    const char *elline;
    int cmd_argc, rval = 0, known;
#define scratch known
    char **cmd_argv;
    struct cmdtable *cmdp;
    History *hist;
    EditLine *elptr;
    HistEvent he;

    curinode = check_ginode(ROOTINO);
    curinum = ROOTINO;
    printactive(0);

    hist = history_init();
    history(hist, &he, H_SETSIZE, 100);	/* 100 elt history buffer */

    elptr = el_init("fsdb", stdin, stdout, stderr);
    el_set(elptr, EL_EDITOR, "emacs");
    el_set(elptr, EL_PROMPT, prompt);
    el_set(elptr, EL_HIST, history, hist);
    el_source(elptr, NULL);

    while ((elline = el_gets(elptr, &scratch)) != NULL && scratch != 0) {
	if (check_debug)
	    printf("command `%s'\n", elline);

	history(hist, &he, H_ENTER, elline);

	line = strdup(elline);
	cmd_argv = crack(line, &cmd_argc);
	/*
	 * el_parse returns -1 to signal that it's not been handled
	 * internally.
	 */
	if (el_parse(elptr, cmd_argc, (const char **)cmd_argv) != -1)
	    continue;
	if (cmd_argc) {
	    known = 0;
	    for (cmdp = cmds; cmdp->cmd; cmdp++) {
		if (!strcmp(cmdp->cmd, cmd_argv[0])) {
		    if ((cmdp->flags & FL_WR) == FL_WR && nflag)
			warnx("`%s' requires write access", cmd_argv[0]),
			    rval = 1;
		    else if (cmd_argc >= cmdp->minargc &&
			cmd_argc <= cmdp->maxargc)
			rval = (*cmdp->handler)(cmd_argc, cmd_argv);
		    else if (cmd_argc >= cmdp->minargc &&
			(cmdp->flags & FL_ST) == FL_ST) {
			strcpy(line, elline);
			cmd_argv = recrack(line, &cmd_argc, cmdp->maxargc);
			rval = (*cmdp->handler)(cmd_argc, cmd_argv);
		    } else
			rval = argcount(cmdp, cmd_argc, cmd_argv);
		    known = 1;
		    break;
		}
	    }
	    if (!known)
		warnx("unknown command `%s'", cmd_argv[0]), rval = 1;
	} else
	    rval = 0;
	free(line);
	if (rval < 0)
	    /* user typed "quit" */
	    return 0;
	if (rval)
	    warnx("rval was %d", rval);
    }
    el_end(elptr);
    history_end(hist);
    return rval;
}
Example #22
0
void FixProviderImpl::fromApp(const FIX::Message& message, const FIX::SessionID& sessionId)
        throw(FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType) {
    crack(message, sessionId);
}
Example #23
0
int main(int argc, char **argv){

  unsigned char *buffer = calloc(0x100, sizeof(char));
  unsigned char *password = calloc(0x7, sizeof(char));
  int i;
  int dicloaded = 0;
  int verbose = 1;
  
  char *dicpath = malloc(0x20 * sizeof(char));
  int read_and_exit = 0;
  
  // put the getopt thing up here.

  char opt;

  int lag = DELAY;
  
  while ((opt = getopt(argc, argv, "t:rqd:")) != -1){
    switch (opt) {
    case 't':
      lag = atoi(optarg);
      break;
    case 'r':
      read_and_exit = 1;
      break;
    case 'q':
      verbose = 0;
      break;
    case 'd':
      strncpy(dicpath, optarg, 0x19);
      dicloaded = 1;
      break;
    default:
      break;
      //printf("USAGE MESSAGE goes here.\n");
    }
  }
  
  if (ioperm(CMOS_ADDR, 2, 1)){ // ask permission (set to 1) for ports 0x70, 0x71
    perror("ioperm");
    exit (1);
 }

  printf( RED"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"COLOR_RESET
          "            -=oO( CMOS DEBA5E12 )Oo=- \n"
          "Please wait while we dump your CMOS parameters.\n"
          RED"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"COLOR_RESET);
  
  read_cmos(buffer, verbose, lag);

  if (read_and_exit){
    goto finish;
  }
  if (dicloaded){
    goto cracker;
  }
  /* This part deals with the checksum. */
  char ans;
  printf("CMOS CHECKSUM @ 0x%2.2x: 0x%2.2x\n", CHKSUM_INDEX, *(buffer + CHKSUM_INDEX));
  printf("FLIP TO FORCE RESET (OR UNDO PRIOR FLIP) (y/N)? ");
  scanf("%c",&ans);
  if (ans == 'Y' || ans == 'y'){
    outb(CHKSUM_INDEX, CMOS_ADDR);
    usleep(lag);
    outb(~(*(buffer + CHKSUM_INDEX)), CMOS_DATA);
    usleep(lag);
    printf("*** "RED"CHECKSUM INVERTED! CMOS[0x%2.2x] = 0x%2.2x "COLOR_RESET" ***\n", CHKSUM_INDEX, inb(CMOS_DATA));
  }

 cracker:
  /* This part deals with the password. */
  memcpy(password, (buffer + PSWD_INDEX), 6);
  printf("\nENCRYPTED PASSWORD AT BYTES 0x%2.2x TO 0x%2.2x: ", PSWD_INDEX, PSWD_INDEX + PSWD_LEN);
  for (i = 0; i < 6; i++)
    printf("%2.2x ",*(password+i));
  printf("\n");

  if (!dicloaded){
    printf("To attempt to crack, enter path to dictionary file:\n>> ");
    scanf("%s", dicpath);
  }
  char cracked[16];

  if (crack(cracked, password, dicpath) != 0){
    printf("Sorry. The password has not been cracked.\n");
  } else {
    printf(RED"EUREKA:"COLOR_RESET" %s\n", cracked);
  }
  ///////////////////////////
 finish:

  /* Tidy things up. */
  if (ioperm(0x71, 2, 0)){  // we don't need perms anymore (set to 0)
    perror("ioperm");
    exit(1);
  }

  free(password);
  free(buffer);
  
  exit (0);
}
Example #24
0
int main(int argc, char *argv[]) {
   char *file = 0;			// filename passwordfile
   char pass[MAXENCPWDLENGTH+1] = "";	// encrypted password
   char *user = 0;			// username in passwordfile
   char *lsf  = 0;			// filename loadsourcefile
   char *pf   = 0;			// filename progressfile
   int  rf    = 0;			// runtime limit
   int  chr   = 0;			// characterset
   int  pws   = 1;			// min passwordlength
   int  pwl   = DEFAULTPWLENGTH;	// max passwordlength
   int  ui    = 10;			// console update interval
   int  vo    = 0;			// verbose output
   int  i     = 0;			// loop variable
   FILE *fp_lsf;			// loadsourcefile
   FILE *fp_file;			// passwordfile
   FILE *fp_cset;			// character set file
   char line[255];			// tmp buffer
   char vp_stat[255];			// last saved status
   char * linebuf = NULL;

   printf("\nViper v1.6 (Hale 05/12/2000) - C version by Frank4DD (05/05/2014)\n");
   printf("Wiltered Fire - www.wilter.com/wf, incl. bugfixes by David C. Rankin\n\n");
	
   /* need help? */
   if ( argc == 1 || (!(strcmp (argv[1], "-h"))) || (!(strcmp (argv[1], "-?"))) ) {
      help();
   }
	
   /* verbose output on? */
   for (i = 1; i < argc; i++) {
      if (! (strcmp (argv[i], "-v"  ))) { vo = 1; i++;}
   }
	
   if (vo) {
      if ( (argc != 2) && (argc != 4) && (argc != 6) &&
           (argc != 8) && (argc != 10) && (argc != 12) 
            && (argc != 14) && (argc != 16) ) {
         printf("missing value for argument: try viper -h\n");
         exit(-1);
      }
   }
   else {
      if ( (argc != 1) && (argc != 3) && (argc != 5) &&
           (argc != 7) && (argc != 9) && (argc != 11) 
	    && (argc != 13) && (argc != 15) ) {
         printf("missing value for argument: try viper -h\n");
         exit(-1);
      }
   }
	
   /* process command line arguments */
   for (i = 1; i < argc; i++) { 	
      if (! (strcmp (argv[i], "-f"  ))) { file =      argv[i+1] ; i++;}
      else if (! (strcmp (argv[i], "-u"  ))) { user =      argv[i+1] ; i++;}
      else if (! (strcmp (argv[i], "-c"  ))) { chr  = atoi(argv[i+1]); i++;}
      else if (! (strcmp (argv[i], "-pwl"))) { pwl  = atoi(argv[i+1]); i++;}
      else if (! (strcmp (argv[i], "-ui" ))) { ui   = atoi(argv[i+1]); i++;}
      else if (! (strcmp (argv[i], "-pws"))) { pws  = atoi(argv[i+1]); i++;}
      else if (! (strcmp (argv[i], "-lsf"))) { lsf  =      argv[i+1] ; i++;}
      else if (! (strcmp (argv[i], "-pf" ))) { pf   =      argv[i+1] ; i++;}
      else if (! (strcmp (argv[i], "-rf" ))) { rf   = atoi(argv[i+1]); i++;}
      else if (! (strcmp (argv[i], "-v"  ))) { continue; }
      else { printf("Unknown argument \"%s\": try viper -h\n", argv[i]); exit(-1); }
   }
	
   /* break early if calling from file */
   if (lsf) {
      if ( (fp_lsf = fopen(lsf, "r+")) == NULL ) {
         printf("Error: Can't open %s!\n", lsf);
         exit(-1);
      }
      fscanf (fp_lsf, "%s", vp_stat);
		
      /* check to see if run has been completed */
	
      if (! (strcmp (vp_stat, FIN_IDENT))) {
         printf("The saved run has been completed.\n");
         printf("Check %s for details.\n", lsf);
         fclose(fp_lsf);
         exit(-1);
      }
			
      /* continue otherwise */
      fscanf (fp_lsf, "%d", &lsf_out.ci_pws);
      fscanf (fp_lsf, "%d", &lsf_out.ci_pwl);
      fscanf (fp_lsf, "%s", lsf_out.ci_pass);
      fscanf (fp_lsf, "%s", lsf_out.ci_user);
      fscanf (fp_lsf, "%s", lsf_out.ci_dnum);
      fscanf (fp_lsf, "%s", lsf_out.ci_cset);
      fscanf (fp_lsf, "%s", lsf_out.ci_pf);
      fscanf (fp_lsf, "%d", &lsf_out.ci_ui);
      fclose(fp_lsf);
      lsf_out.ci_rf = 0;
      lsf_out.ci_vo = vo;
      printf("...loaded parameters from file %s.\n", lsf);
      crack(lsf_out);
   }
	
   /* check for required arguments */
   if (!file) {
      printf("Error: Password filename required!\n");
      exit(-1);
   }
   else if (!user) {
      printf("Error: Username required!\n");
      exit(-1);
   }
	
   /* attempt to load account from file */
   else if ( (fp_file = fopen(file, "r")) == NULL ) {
      printf("Error: Can't open %s!\n", file);
      exit(-1);
   }
		
   while ( (fscanf (fp_file, "%s", line) != EOF) ) {
      if (! (strcmp (user, strtok(line, ":"))) ) {
         linebuf = strtok(NULL, ":");
         if ( !linebuf ) {
            printf("No password for user %s!\n", user);
            exit(-1);
         }
         strcpy(pass, linebuf);
         if ( !pass || (strlen(pass)) <  4 ) {
            printf("Error: Bad password for user %s!\n", user);
            exit(-1);
         }
         printf("Found: user %s pw: %s\n", user, pass);
      }
   }
   fclose(fp_file);
   if ( !pass || (strlen(pass)) <  4 ) {
      printf("Error: No user %s in file %s!\n", user, file);
      exit(-1);
   }

   /* load character set */
   if ( (fp_cset = fopen(CHARSET_FILE, "r")) == NULL ) {
      printf("Error: Can't open %s!\n", CHARSET_FILE);
      exit(-1);
   }

   while ( (fscanf (fp_cset, "%s", line) != EOF) ) {
      if ( chr == (atoi(line)) ) {
         fscanf (fp_cset, "%s", lsf_out.ci_cset);
          break;
      }
   }
	
   if ( !lsf_out.ci_cset || (strlen(lsf_out.ci_cset)) < 2 ) {
      printf("Error: Bad charset %d in %s!\n", chr, CHARSET_FILE);
      exit(-1);
   }
   else {
      printf("Found: Charset %d in %s\n", chr, CHARSET_FILE);
   }
	
   fclose(fp_cset);
	
   /* write data in struct */
   lsf_out.ci_rf = rf;
   if (pf) { strcpy (lsf_out.ci_pf, pf); }
   lsf_out.ci_pws = pws;
   lsf_out.ci_pwl = pwl;
   strcpy (lsf_out.ci_pass, pass);
   strcpy (lsf_out.ci_user, user);
   lsf_out.ci_ui = ui;
   lsf_out.ci_vo = vo;
   printf("...command line parameters loaded.\n");
   crack(lsf_out);
}
Example #25
0
int main(int argc, char **argv)
{

    int flg;
    char inName[FILENAME_MAX], outName[FILENAME_MAX];
    char tmpName[FILENAME_MAX];
    FILE *outF;

    Mf_nomerge = 1;
    while (flg = crack (argc, argv, "F|f|BbNnTtVvMm", 0)) {
        switch (flg) {
        case 'f':
        case 'F':
            if (*arg_option)
                fold = atoi(arg_option);
            else
                fold = 80;
            break;
        case 'm':
        case 'M':
            Mf_nomerge = 0;
            break;
        case 'n':
        case 'N':
            notes++;
            break;
        case 't':
        case 'T':
        case 'b':
        case 'B':
            times++;
            break;
        case 'v':
        case 'V':
            Onmsg  = "On ch=%d note=%s vol=%d\n";
            Offmsg = "Off ch=%d note=%s vol=%d\n";
            PoPrmsg = "PolyPr ch=%d note=%s val=%d\n";
            Parmsg = "Param ch=%d con=%d val=%d\n";
            Pbmsg  = "Pb ch=%d val=%d\n";
            PrChmsg = "ProgCh ch=%d prog=%d\n";
            ChPrmsg = "ChanPr ch=%d val=%d\n";
            break;
        case EOF:
            PauseAndGo(1); //exit(1);
        }
    }
    if ( arg_index < argc ) {
        strcpy(inName, argv[arg_index++]);
        if((midiFile = efopen (inName, "rb")) == NULL)
            PauseAndGo(1); //exit(1);
    } else {
        fprintf(stderr, "***Error: No input file specified.\n" );
        PauseAndGo(1); //exit(1);
    }
    if (arg_index < argc ) {
        strcpy(outName, argv[arg_index]);
    } else {
        strcpy(outName, inName);
        strcpy(getLastc(outName, '.'), ".mtx"); /* replace or append ".mtx" as file extension */
    }

    /* if outName already exists, rename it. */
    strcpy(tmpName, outName);
    if (mtxFile = fopen(tmpName, "r")) {
        do {
            fclose(mtxFile);
            strcpy(getLastc(tmpName, '.'), "$.mtx");
        } while (mtxFile = fopen(tmpName, "r"));
        if (rename(outName, tmpName)) {
            fprintf(stderr, "***Error: Output file %s exists and cannot be renamed.\n",
                    outName);
            PauseAndGo(1); //exit(1);
        } else {
            fprintf(stderr, "Notice: Output file %s already exits.\n\tIt is renamed as %s\n",
                    outName, tmpName);
        }
    }

    if ((mtxFile = fopen(outName, "w")) == NULL) {
        fprintf(stderr, "***Error: Can't open outputfile %s\n", outName);
        fprintf(stderr, "%s\n", strerror(errno));
        PauseAndGo(1); //exit(1);
    }

    fprintf(stderr, "Writing output to %s ...  ", outName);

    ReadMidifile();
    if (ferror(mtxFile)) {
        fprintf(stderr, "***Error while writing to output file %s\n", outName);
        fprintf(stderr, "%s\n", strerror(errno));
        PauseAndGo(1); //exit(1);
    }
    fseek(mtxFile, 0, SEEK_END); /* just to be sure */
    fprintf(stderr, "%ld bytes written.\n", ftell(mtxFile));

    fclose(midiFile);
    fclose(mtxFile);
    PauseAndGo(0); //exit(0);
}
Example #26
0
uint parallelCrack(uchar *cite, uint citeLength, uint checksum, uchar *correctKey, uint minKeyLen, uint maxKeyLen)
{
    // Not suited for parallel cracking, not worth the effort
    if (minKeyLen < 2) return crack(cite, citeLength, checksum, correctKey, minKeyLen, maxKeyLen);

    // Iterating over possible key lengths
    for (uint len = minKeyLen - 1; len < maxKeyLen; ++len) {
        uint keyBytes = len + 1;

        __block bool found = false;
        __block uint correctKeyLength = 0;
        
        dispatch_queue_t queue  = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_queue_t serial = dispatch_queue_create("cx.main.crack", DISPATCH_QUEUE_SERIAL);

        dispatch_apply(16, queue, ^(size_t i) {
            uchar highByte = (uchar) i;
            
            // Key: null-terminated!
            uchar *key = malloc(sizeof(uchar) * (keyBytes + 1));
            key[keyBytes] = 0;

            // Plaintext: null-terminated!
            uchar *plain = malloc(sizeof(uchar) * (citeLength + 1));
            plain[citeLength] = 0;
            
            for (uchar lowByte = 0; lowByte < 16; ++lowByte) {
                key[keyBytes-1] = (highByte << 4) + lowByte;
                printf("HIBYTE: %" SCNu8 " LOBYTE: %" SCNu8 "\n%" SCNu8 "\n", highByte, lowByte, key[keyBytes-1]);

                // For debugging
                // key[keyBytes-1] = 110;

                uint subspaceBytes = keyBytes - 1;

                // Initialize key to 0
                for (uint byte = 0; byte < subspaceBytes; ++byte) {
                    key[byte] = 0;
                }

                bool done = false;

                // Interpreting maybeKey as arbitrary precision integer
                while(!done && !found) {
                    for (uint byte = 0; byte < subspaceBytes; ++byte) {
                        if (key[byte] < 255) {
                            key[byte]++;

                            //  xorWithStart
                            if (xorWithPart(cite, citeLength, key, keyBytes, plain)) {
                                done = true;
                                dispatch_sync(serial, ^{
                                    found = true;
                                    correctKeyLength = keyBytes;
                                    for (uint b = 0; b < keyBytes; ++b) {
                                        correctKey[b] = key[b];
                                    }
                                });
                            }
                            //if (csum(plain, citeLength) == checksum) {}
                            break;
                        }
                        
                        // Increment until reaching "MAXINT"
                        else if (byte + 1 == subspaceBytes) {
                            done = true;
                            break;
                        }
                        
                        else key[byte] = 0;
                    }
                }
//
// Origin forms
//
AclSubject *OriginMaker::make(const TypedList &list) const
{
	ListElement *args[1];
	crack(list, 1, args, CSSM_LIST_ELEMENT_WORDID);
		return new OriginAclSubject(*args[0]);
}
Example #28
0
static int
cmdloop(void)
{
	char *line = NULL;
	const char *elline;
	int cmd_argc, rval = 0, known;
#define scratch known
	char **cmd_argv;
	struct cmdtable *cmdp;
	History *hist;
	EditLine *elptr;
	HistEvent hev;

	curinode = ginode(ROOTINO);
	curinum = ROOTINO;
	printactive();

	hist = history_init();
	history(hist, &hev, H_SETSIZE, 100);	/* 100 elt history buffer */

	elptr = el_init(__progname, stdin, stdout, stderr);
	el_set(elptr, EL_EDITOR, "emacs");
	el_set(elptr, EL_PROMPT, prompt);
	el_set(elptr, EL_HIST, history, hist);
	el_source(elptr, NULL);

	while ((elline = el_gets(elptr, &scratch)) != NULL && scratch != 0) {
		if (debug)
			printf("command `%s'\n", line);

		history(hist, &hev, H_ENTER, elline);

		line = strdup(elline);
		if (line == NULL)
			errx(1, "out of memory");
		cmd_argv = crack(line, &cmd_argc);
		if (cmd_argc) {
			/*
			 * el_parse returns -1 to signal that it's not been handled
			 * internally.
			 */
			if (el_parse(elptr, cmd_argc, (const char **)cmd_argv) != -1)
				continue;
			known = 0;
			for (cmdp = cmds; cmdp->cmd; cmdp++) {
				if (!strcmp(cmdp->cmd, cmd_argv[0])) {
					if (cmd_argc >= cmdp->minargc &&
					    cmd_argc <= cmdp->maxargc)
						rval = (*cmdp->handler)(cmd_argc,
						    cmd_argv);
					else
						rval = argcount(cmdp,
						    cmd_argc, cmd_argv);
					known = 1;
					break;
				}
			}
			if (!known) {
				warnx("unknown command `%s'", cmd_argv[0]);
				rval = 1;
			}
		} else
			rval = 0;
		free(line);
		if (rval < 0)
			return rval;
		if (rval)
			warnx("rval was %d", rval);
	}
	el_end(elptr);
	history_end(hist);
	return rval;
}
Example #29
0
int main(int argc, char **argv) {
	struct goh_state st;
	int opt;
	struct fs_ctx s;
	enum action action = ACTION_CRACK;
	char *key = NULL;
	const char *filenamein = "-";
	const char *filenameout = "-";
	char *text = NULL;
	struct charset cs;
	struct crack_args cka;

	cs_init(&cs);
	memset(&cka, 0, sizeof(cka));

	/* Parse the options. */
	goh_init(&st, opt_desc, ARRAY_LENGTH(opt_desc), argc, argv, 1);
	st.usagehelp = "[options]\n";

	while ((opt = goh_nextoption(&st)) >= 0) {
		switch (opt) {
		case 'i':
			filenamein = st.argval;
			break;

		case 'o':
			filenameout = st.argval;
			break;

		case 'e':
			action = ACTION_ENCRYPT;
			break;

		case 'd':
			action = ACTION_DECRYPT;
			break;

		case 'k':
			key = st.argval;
			break;

		case 'l':
			cka.klen = atoi(st.argval);
			break;

		case OPT_KASISKI_MIN_LENGTH:
			cka.ka_minlen = atoi(st.argval);
			break;

		case OPT_SHOW_KASISKI_TABLE:
			cka.ka_show_table = 1;
			break;

		case OPT_SHOW_KASISKI_LENGTH:
			cka.ka_show_length = 1;
			break;

		case 'c':
			cs_add(&cs, st.argval);
			break;

		default:
			custom_error("Unrecognized option (shouldn't happen)");
			break;
		}
	}


	/* Common command line mistake. */
	if (st.argidx != argc)
		custom_error("Useless argument %s", argv[st.argidx]);

	goh_fini(&st);

	/* Check for some invalid options combinations. */
	if (action != ACTION_CRACK && key == NULL)
		custom_error("Encryption and decryption take a --key");

	if (action == ACTION_CRACK && key != NULL)
		custom_error("--key need either --encrypt or --decrypt");

	if (cka.klen > 0 && key != NULL)
		custom_warn("Unnecessary key length option with an actual key");

	if (cka.klen > 0 && key != NULL && cka.klen != strlen(key))
		custom_error("Key length option doesn't match "
		             "the length of the key");

	if (cka.ka_minlen > 0 && action != ACTION_CRACK)
		custom_error("--kasiski-min-length can only be used in "
		             "cracking mode");

	if (cka.ka_minlen > 0 && cka.klen > 0)
		custom_warn("Useless option --kasiski-min-length when the key "
		            "length is given");

	if (cka.ka_show_table != 0 && action != ACTION_CRACK)
		custom_error("--show-kasiski-table can only be used in "
		             "cracking mode");

	if (cka.ka_show_table != 0 && cka.klen > 0)
		custom_warn("Option --show-kasiski-table ignored when a key "
		            "length is given");

	if (cka.ka_show_length != 0 && action != ACTION_CRACK)
		custom_error("--show-kasiski-length can only be used in "
		             "cracking mode");

	if (cka.ka_show_length != 0 && cka.klen > 0)
		custom_warn("Option --show-kasiski-length ignored when a key "
		            "length is given");

	/* Default charset. */
	if (cs.chars_size == 0) {
		cs_add(&cs, CHARSET_UPPER);
		cs_add(&cs, CHARSET_LOWER);
	}


	/* Start to do the job. */
	text = read_file(filenamein);
	fs_init(&s, text, &cs);
	cka.str = &s;

	if (action == ACTION_CRACK)
		crack(&cka);
	else
		simple_action(&s, key, action);

	write_file(filenameout, text);

	fs_fini(&s);
	free(text);
	cs_fini(&cs);


	return EXIT_SUCCESS;
}
Example #30
0
int dbLoad(int did, char_t *filename, int flags)
{
    gstat_t		sbuf;
    char_t		*buf, *keyword, *value, *path, *ptr;
    char_t		*tablename;
    int			fd, tid, row;
    dbTable_t	*pTable;

    a_assert(did >= 0);

    fmtAlloc(&path, FNAMESIZE, T("%s/%s"), basicGetProductDir(), filename);
    trace(4, T("DB: About to read data file <%s>\n"), path);

    if (gstat(path, &sbuf) < 0) {
        trace(3, T("DB: Failed to stat persistent data file.\n"));
        bfree(B_L, path);
        return -1;
    }

    fd = gopen(path, O_RDONLY | O_BINARY, 0666);
    bfree(B_L, path);

    if (fd < 0) {
        trace(3, T("DB: No persistent data file present.\n"));
        return -1;
    }

    if (sbuf.st_size <= 0) {
        trace(3, T("DB: Persistent data file is empty.\n"));
        gclose(fd);
        return -1;
    }
    /*
     *	Read entire file into temporary buffer
     */
    buf = balloc(B_L, sbuf.st_size + 1);
#ifdef CE
    if (readAscToUni(fd, &buf, sbuf.st_size) != (int)sbuf.st_size) {
#else
    if (gread(fd, buf, sbuf.st_size) != (int)sbuf.st_size) {
#endif
        trace(3, T("DB: Persistent data read failed.\n"));
        bfree(B_L, buf);
        gclose(fd);
        return -1;
    }

    gclose(fd);
    *(buf + sbuf.st_size) = '\0';

    row = -1;
    tid = -1;
    pTable = NULL;
    ptr = gstrtok(buf, T("\n"));
    tablename = NULL;

    do {
        if (crack(ptr, &keyword, &value) < 0) {
            trace(5, T("DB: Failed to crack line %s\n"), ptr);
            continue;
        }

        a_assert(keyword && *keyword);

        if (gstrcmp(keyword, KEYWORD_TABLE) == 0) {
            /*
             *			Table name found, check to see if it's registered
             */
            if (tablename) {
                bfree(B_L, tablename);
            }

            tablename = bstrdup(B_L, value);
            tid = dbGetTableId(did, tablename);

            if (tid >= 0) {
                pTable = dbListTables[tid];
            } else {
                pTable = NULL;
            }

        } else if (gstrcmp(keyword, KEYWORD_ROW) == 0) {
            /*
             *			Row/Record indicator found, add a new row to table
             */
            if (tid >= 0) {
                int nRows = dbGetTableNrow(did, tablename);

                if (dbSetTableNrow(did, tablename, nRows + 1) == 0) {
                    row = nRows;
                }
            }

        } else if (row != -1) {
            /*
             *			some other data found, assume it's a COLUMN=value
             */
            int nColumn = GetColumnIndex(tid, keyword);

            if ((nColumn >= 0) && (pTable != NULL)) {
                int nColumnType = pTable->columnTypes[nColumn];
                if (nColumnType == T_STRING) {
                    dbWriteStr(did, tablename, keyword, row, value);
                } else {
                    dbWriteInt(did, tablename, keyword, row, gstrtoi(value));
                }
            }
        }
    } while ((ptr = gstrtok(NULL, T("\n"))) != NULL);

    if (tablename) {
        bfree(B_L, tablename);
    }

    bfree(B_L, buf);

    return 0;
}

/******************************************************************************/
/*
 *	Return a table id given the table name
 */

int dbGetTableId(int did, char_t *tablename)
{
    int			tid;
    dbTable_t	*pTable;

    a_assert(tablename);

    for (tid = 0; (tid < dbMaxTables); tid++) {
        if ((pTable = dbListTables[tid]) != NULL) {
            if (gstrcmp(tablename, pTable->name) == 0) {
                return tid;
            }
        }
    }

    return -1;
}