Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
libctfso-corrupt-penguin/ansible/roles/neoboffy/templates/challenge.c.j2
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
108 lines (90 sloc)
2.22 KB
This file contains 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 <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <string.h> | |
| #include <stddef.h> | |
| // definitions | |
| // | |
| #define FLAG_PATH "{{ flag_path }}" | |
| #define BUFSZ (128-8) | |
| char *cp = NULL; | |
| char *item_list = NULL; | |
| enum { | |
| RUNNING, | |
| STOPPED, | |
| PROBE_FILE | |
| }; | |
| unsigned char state = STOPPED; | |
| char default_list[] = { | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | |
| }; | |
| // prototypes | |
| // | |
| void jobmgmt(void); | |
| void read_flag(void); | |
| void start_polling(void (*)(void)); | |
| // implementation | |
| // | |
| void jobmgmt(void) | |
| { | |
| if(state == STOPPED) { | |
| printf("running job.\n"); | |
| state = RUNNING; | |
| } else if(state == RUNNING) { | |
| printf("ending job.\n"); | |
| state = STOPPED; | |
| } else if(state == PROBE_FILE) { | |
| printf("reading flag file.\n"); | |
| read_flag(); | |
| state = STOPPED; | |
| } else { | |
| printf("unknown state %d.. bailing.\n", state); | |
| exit(1); | |
| } | |
| } | |
| void read_flag(void) | |
| { | |
| FILE *fp = NULL; | |
| char buffer[BUFSZ] = {0}; | |
| fp = fopen(FLAG_PATH, "r"); | |
| if(fp) { | |
| fgets(buffer, sizeof(buffer), fp); | |
| fclose(fp); | |
| printf("%s\n", buffer); | |
| } else { | |
| perror("fopen " FLAG_PATH " failed"); | |
| } | |
| exit(1); | |
| } | |
| void start_polling(void (*state_change)(void)) | |
| { | |
| int cnt = 0xdeadbeef; | |
| char buffer[BUFSZ] = {0x41}; | |
| cp = buffer; | |
| state_change(); // running | |
| for(cnt = 0; cnt <= BUFSZ; cnt++) { | |
| *cp++ = item_list[cnt]; | |
| } | |
| state_change(); // stopped | |
| } | |
| int main(int argc, char **argv) | |
| { | |
| void (*cb)(void) = jobmgmt; | |
| item_list = (argc <= 1 ? default_list : argv[1]); | |
| start_polling(cb); | |
| return 0; | |
| } |