static int _redirect(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); uint32_t dest = luaL_checkunsigned(L,1); uint32_t source = luaL_checkunsigned(L,2); int type = luaL_checkinteger(L,3); int session = luaL_checkinteger(L,4); int mtype = lua_type(L,5); switch (mtype) { case LUA_TSTRING: { size_t len = 0; void * msg = (void *)lua_tolstring(L,5,&len); if (len == 0) { msg = NULL; } session = skynet_send(context, source, dest, type, session , msg, len); save_session(L, type, session); break; } case LUA_TLIGHTUSERDATA: { void * msg = lua_touserdata(L,5); int size = luaL_checkinteger(L,6); session = skynet_send(context, source, dest, type | PTYPE_TAG_DONTCOPY, session, msg, size); save_session(L, type, session); break; } default: luaL_error(L, "skynet.redirect invalid param %s", lua_typename(L,mtype)); } return 0; }
/* +-----------------------------------+ * | Save Related Functions | * +-----------------------------------+ */ void on_save_file_okbutton_clicked (GtkButton *button, gpointer user_data) { gchar *filename; GtkWidget *dialog; gint result = GTK_RESPONSE_OK; filename = (char*) gtk_file_selection_get_filename(GTK_FILE_SELECTION (save_file_window)); if( !access(filename, F_OK) ) { dialog = gtk_message_dialog_new(GTK_WINDOW(save_file_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "File '%s' exists. Overwrite?", filename); result = gtk_dialog_run( GTK_DIALOG(dialog) ); gtk_widget_destroy( dialog ); } gtk_widget_hide(save_file_window); flush(); if( GTK_RESPONSE_OK == result ) { save_session( filename ); } }
/* save_yourself handler for the master client */ static gboolean client_save_yourself_cb (GnomeClient *client, gint phase, GnomeSaveStyle save_style, gboolean shutdown, GnomeInteractStyle interact_style, gboolean fast, gpointer data) { const char *prefix; char *argv[4] = { NULL }; save_session (client); prefix = gnome_client_get_config_prefix (client); /* Tell the session manager how to discard this save */ argv[0] = "rm"; argv[1] = "-rf"; argv[2] = gnome_config_get_real_path (prefix); argv[3] = NULL; gnome_client_set_discard_command (client, 3, argv); /* Tell the session manager how to clone or restart this instance */ argv[0] = (char *) program_argv0; argv[1] = NULL; /* "--debug-session"; */ gnome_client_set_clone_command (client, 1, argv); gnome_client_set_restart_command (client, 1, argv); return TRUE; }
/* die handler for the master client */ static void client_die_cb (GnomeClient *client, gpointer data) { if (! client->save_yourself_emitted) save_session (client); gtk_main_quit (); }
/***************************************************************************** * on_session_save_activate() *****************************************************************************/ void on_session_save_activate(GtkWidget *UNUSED(widget), gpointer data) { SESSION *session = get_current_session(); char *directory = (char *) data; /* if no directory was provided, use the current session directory */ if ((directory == NULL) || (directory[0] == '\0')) { if ((session->directory != NULL) && (session->directory[0] != '\0')) { directory = get_session_directory_from_entry(GTK_ENTRY(session_entry)); session->directory = directory; } else { directory = session->directory; } } /* if we still don't have a directory, run the save-as dialog */ if (directory == NULL) { run_session_save_as_dialog(NULL, NULL); } /* save the session with the given directory */ else { switch (setting_bank_mem_mode) { case BANK_MEM_AUTOSAVE: /* save session without overwrite protection */ if (save_session(directory, session_io_start) == 0) { update_gui_session_name(); save_session_bank(); } break; case BANK_MEM_WARN: case BANK_MEM_PROTECT: /* save session with overwrite protection */ if (!check_session_overwrite(directory)) { if (save_session(directory, session_io_start) == 0) { update_gui_session_name(); save_session_bank(); } } break; } } }
static int _sendname(lua_State *L, struct skynet_context * context, const char * dest) { int type = luaL_checkinteger(L, 2); int session = 0; if (lua_isnil(L,3)) { type |= PTYPE_TAG_ALLOCSESSION; } else { session = luaL_checkinteger(L,3); } int mtype = lua_type(L,4); switch (mtype) { case LUA_TSTRING: { size_t len = 0; void * msg = (void *)lua_tolstring(L,4,&len); session = skynet_sendname(context, dest, type, session , msg, len); save_session(L, type, session); break; } case LUA_TNIL : session = skynet_sendname(context, dest, type, session , NULL, 0); save_session(L, type, session); break; case LUA_TLIGHTUSERDATA: { luaL_checktype(L, 4, LUA_TLIGHTUSERDATA); void * msg = lua_touserdata(L,4); int size = luaL_checkinteger(L,5); session = skynet_sendname(context, dest, type | PTYPE_TAG_DONTCOPY, session, msg, size); save_session(L, type, session); break; } default: luaL_error(L, "skynet.send invalid param %s", lua_typename(L,lua_type(L,4))); } if (session < 0) { luaL_error(L, "skynet.send session (%d) < 0", session); } lua_pushinteger(L,session); return 1; }
static void save_game_function (ui_object *obj, void *arg) { char *text; #if DEBUG_MODULE debug_filtered_log("Filename query"); #endif text = get_ui_object_text (save_current_filename); if (text) { if (strlen (text) > 0) { strcpy (full_filename, current_session->data_path); strcat (full_filename, "//Campaign//"); strcat (full_filename, text); strcat (full_filename, ".sav"); if (file_exist (full_filename)) { save_session (obj, arg); } else { save_session (obj, arg); } } } }
void SessionPersist::prepare_save(const uint8_t* random, uint32_t keys_checksum, mbedtls_ssl_context* context, message_id_t next_id) { if (context->state == MBEDTLS_SSL_HANDSHAKE_OVER) { this->keys_checksum = keys_checksum; in_epoch = context->in_epoch; memcpy(out_ctr, context->out_ctr, 8); memcpy(randbytes, random, sizeof(randbytes)); this->next_coap_id = next_id; save_session(context->session); size = sizeof(*this); } else { size = 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; }
/* 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()); } }
/* unsigned address string address integer type integer session string message lightuserdata message_ptr integer len */ static int _send(lua_State *L) { struct skynet_context * context = lua_touserdata(L, lua_upvalueindex(1)); int addr_type = lua_type(L,1); uint32_t dest = 0; switch(addr_type) { case LUA_TNUMBER: dest = lua_tounsigned(L,1); break; case LUA_TSTRING: { const char * addrname = lua_tostring(L,1); if (addrname[0] == '.' || addrname[0] == ':') { dest = skynet_queryname(context, addrname); if (dest == 0) { luaL_error(L, "Invalid name %s", addrname); } } else if ('0' <= addrname[0] && addrname[0] <= '9') { luaL_error(L, "Invalid name %s: must not start with a digit", addrname); } else { return _sendname(L, context, addrname); } break; } default: return luaL_error(L, "address must be number or string, got %s",lua_typename(L,addr_type)); } int type = luaL_checkinteger(L, 2); int session = 0; if (lua_isnil(L,3)) { type |= PTYPE_TAG_ALLOCSESSION; } else { session = luaL_checkinteger(L,3); } int mtype = lua_type(L,4); switch (mtype) { case LUA_TSTRING: { size_t len = 0; void * msg = (void *)lua_tolstring(L,4,&len); if (len == 0) { msg = NULL; } session = skynet_send(context, 0, dest, type, session , msg, len); save_session(L, type, session); break; } case LUA_TLIGHTUSERDATA: { void * msg = lua_touserdata(L,4); int size = luaL_checkinteger(L,5); session = skynet_send(context, 0, dest, type | PTYPE_TAG_DONTCOPY, session, msg, size); save_session(L, type, session); break; } default: luaL_error(L, "skynet.send invalid param %s", lua_typename(L, lua_type(L,4))); } if (session < 0) { // send to invalid address // todo: maybe throw error is better return 0; } lua_pushinteger(L,session); return 1; }
/***************************************************************************** * run_session_save_as_dialog() *****************************************************************************/ void run_session_save_as_dialog(GtkWidget *UNUSED(widget), gpointer data) { SESSION *session = get_current_session(); char *directory = (char *) data; char *session_dir; DIR_LIST *pdir = session_dir_list; GError *error; /* create dialog if needed */ if (session_save_dialog == NULL) { create_session_save_dialog(); } /* add all session dirs as shortcut folders */ while (pdir != NULL) { if ((!pdir->save_shortcut)) { error = NULL; gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(session_save_dialog), pdir->name, &error); if (error != NULL) { PHASEX_ERROR("Error %d: %s\n", error->code, error->message); g_error_free(error); } pdir->save_shortcut = 1; } pdir = pdir->next; } /* set filename and current directory */ if ((directory == NULL) || (*directory == '\0')) { directory = session->directory; } /* if we have a directory, and it's not the sessiondump, set and select it */ if ((directory != NULL) && (strcmp(directory, user_session_dump_dir) != 0)) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(session_save_dialog), directory); } /* if there is no filename, try to set the current directory */ else if ((session->parent_dir != NULL) && (* (session->parent_dir) != '\0')) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(session_save_dialog), session->parent_dir); } else { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(session_save_dialog), user_session_dir); } /* set position in session bank to save session */ /* session_io_start should already be set properly at this point. */ gtk_spin_button_set_value(GTK_SPIN_BUTTON(session_save_start_spin), (session_io_start + 1)); /* run the dialog and save if necessary */ if (gtk_dialog_run(GTK_DIALOG(session_save_dialog)) == GTK_RESPONSE_ACCEPT) { session_dir = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(session_save_dialog)); session_io_start = (unsigned int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(session_save_start_spin)) - 1; /* hide dialog and save session */ gtk_widget_hide(session_save_dialog); switch (setting_bank_mem_mode) { case BANK_MEM_AUTOSAVE: /* save session without overwrite protection */ if (save_session(session_dir, session_io_start) == 0) { update_gui_session_name(); save_session_bank(); } break; case BANK_MEM_WARN: case BANK_MEM_PROTECT: /* save session with overwrite protection */ if (!check_session_overwrite(session_dir)) { if (save_session(session_dir, session_io_start) == 0) { update_gui_session_name(); save_session_bank(); } } break; } g_free(session_dir); } else { /* save this widget for next time */ gtk_widget_hide(session_save_dialog); } }
void https_service_conn(int conn_sock, SSL_CTX *ctx) { char buf[MAX_BUF_LENGTH]; int count, retv; struct message *msg; /* openssl library definitions */ SSL* ssl; ssl = SSL_new(ctx); if (ssl == NULL) { perror("cannot create SSL object!"); return; } SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); SSL_set_fd(ssl, conn_sock); SSL_set_accept_state(ssl); retv = SSL_accept(ssl); if (retv < 0) goto ERROR; count = SSL_read(ssl, buf, MAX_BUF_LENGTH-1); if (count < 0) goto ERROR; buf[count] = '\0'; printf(buf); if (!strncmp(buf, "GET", 3)) { char url[256]; strtok(buf, " "); strcpy(url, https_s.dir); strcat(url, strtok(NULL, " ")); if (strcmp(url, "index.html")) { write_url_ssl(ssl, buf, url); } else if (strcmp(url, "guest_panel.html")) { if (check_privileges()) { write_url_ssl(ssl, buf, url); } else { write_404_ssl(ssl, buf, "<html><body>You don't have access! Go away!</body></html>"); } } else if (strcmp(url, "admin_panel.html")) { if (check_privileges() == ADMIN_PRIV) { write_url_ssl(ssl, buf, url); } else { write_404_ssl(ssl, buf, "<html><body>You don't have access! Go away!</body></html>"); } } } if (!strncmp(buf, "POST", 4)) { int i; char *tmp; char *password; char *username; int admin_login = 1; int guest_login = 1; char *ble = buf; if ((tmp = strstr(buf, "username")) != NULL) { if (strcmp("username", strtok(tmp, "=&"))) { admin_login = 0; guest_login = 0; } username = strtok(NULL, "=&"); printf("user: %s\n", username); if (strcmp(username, https_d.admin_username)) admin_login = 0; if (strcmp(username, https_d.guest_username)) guest_login = 0; if (strcmp("password", strtok(NULL, "=&"))) { admin_login = 0; guest_login = 0; } password = strtok(NULL, "=&"); printf("pass: %s\n", password); if (strcmp(password, https_d.admin_password)) admin_login = 0; if (strcmp(password, https_d.guest_password)) guest_login = 0; if (admin_login) { /* * save session id with appropriate flag */ save_session(ssl, ADMIN_PRIV); write_url_ssl(ssl, buf, "admin_login.html"); } if (guest_login) { /* * save session id with appropriate flag */ save_session(ssl, GUEST_PRIV); write_url_ssl(ssl, buf, "guest_login.html"); } if (!admin_login && !guest_login) { write_404_ssl(ssl, buf, "<html><body>Logging has failed! Go away!</body></html>"); } //printf(buf); } else if ((tmp = strstr(buf, "killall")) != NULL) { /* killal has been issued */ if (check_privileges(ssl) == ADMIN_PRIV) { system("killall.sh"); } else { write_404_ssl(ssl, buf, "<html><body>You cannot do that!Go away!</body></html>"); } } else if ((tmp = strstr(buf, "poweroff")) != NULL) { if (check_privileges(ssl) == ADMIN_PRIV) { system("poweroff.sh"); } else { write_404_ssl(ssl, buf, "<html><body>You cannot do that!Go away!</body></html>"); } } else if ((tmp = strstr(buf, "something")) != NULL) { if (check_privileges(ssl) == ADMIN_PRIV) { system("something.sh"); } else { write_404_ssl(ssl, buf, "<html><body>You cannot do that!Go away!</body></html>"); } } } SSL_shutdown(ssl); SSL_free(ssl); close(conn_sock); exit(EXIT_SUCCESS); ERROR: SSL_shutdown(ssl); SSL_free(ssl); close(conn_sock); exit(EXIT_FAILURE); }
void save_session(boost::optional <SessionT> const& session) { if (session) save_session(session.get()); }