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/bblinus/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.
64 lines (51 sloc)
1.44 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 <fcntl.h> | |
| #include <signal.h> | |
| #include <fmtmsg.h> | |
| #include <sys/time.h> | |
| void (*f)(int); | |
| char *msg; | |
| #define SAFE_FREE(x) \ | |
| do { \ | |
| if (x) { \ | |
| free(x); \ | |
| } \ | |
| } while (0); | |
| #define FLAG "{{ flag_path }}" | |
| void read_flag() | |
| { | |
| int fd = -1; | |
| char buf[512] = {0}; | |
| fd = open(FLAG, O_RDONLY); | |
| if(fd == -1) return; | |
| read(fd, &buf, sizeof(buf)-1); | |
| printf("%s\n", buf); | |
| close(fd); | |
| exit(0); | |
| } | |
| void sh(int num) { | |
| SAFE_FREE(msg); | |
| fmtmsg(MM_PRINT | MM_SOFT | MM_OPSYS | MM_NRECOV, "challenge:sh", MM_ERROR, | |
| "interrupted with signal", MM_NULLACT, MM_NULLTAG); | |
| f(EXIT_FAILURE); | |
| } | |
| int main(int argc, char **argv) { | |
| struct sigaction newaction; | |
| if (argc <= 1) { | |
| fprintf(stderr, "%s <message>\n", | |
| argv[0] == NULL ? "./challenge" : argv[0]); | |
| return EXIT_FAILURE; | |
| } | |
| f = _exit; | |
| newaction.sa_handler = sh; | |
| sigemptyset(&newaction.sa_mask); | |
| newaction.sa_flags = SA_RESETHAND; | |
| sigaction(SIGTERM, &newaction, NULL); | |
| msg = strdup(argv[1]); | |
| puts(msg); | |
| SAFE_FREE(msg); | |
| return EXIT_SUCCESS; | |
| } |