diff --git a/modules/build/puppet/secgen_functions/manifests/install_setgid_binary.pp b/modules/build/puppet/secgen_functions/manifests/install_setgid_binary.pp index 417efbdc8..822ae5121 100644 --- a/modules/build/puppet/secgen_functions/manifests/install_setgid_binary.pp +++ b/modules/build/puppet/secgen_functions/manifests/install_setgid_binary.pp @@ -75,7 +75,7 @@ define secgen_functions::install_setgid_binary ( strings_to_leak => [$flag], owner => 'root', group => $group, - mode => '0400', + mode => '0440', leaked_from => "$source_module_name/$challenge_name", require => [Group[$group], File["$challenge_directory/$challenge_name"]], # notify => Exec["remove_$compile_directory"], diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Ltrace/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Ltrace/program.c.template index ec596c8db..f0be79268 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Ltrace/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Ltrace/program.c.template @@ -1,5 +1,6 @@ #include #include +#include #define USERDEF "AAAAAA" char msg[] = @@ -23,6 +24,35 @@ void print_msg() { printf("%s",msg); } + +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { char buff[20]; char pass[20]; @@ -44,7 +74,7 @@ int main(int argc, char* argv[]) { if (strcmp(buff,pass)) { printf ("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Readelf/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Readelf/program.c.template index 39b2cea90..6cfd736c6 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Readelf/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch1_Readelf/program.c.template @@ -26,6 +26,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { char buff[9]; @@ -38,7 +66,7 @@ int main(int argc, char* argv[]) if (strcmp(buff,USERDEF)) { printf("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Endian/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Endian/program.c.template index 53c6f03e1..8caf2212f 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Endian/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Endian/program.c.template @@ -45,6 +45,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char password[9]; @@ -72,7 +100,7 @@ int main() { // Compare user input with USERDEF if (!strncmp(answer,USERDEF,8)) { - printf("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Showkey/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Showkey/program.c.template index cf0d20564..21e9140f0 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Showkey/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_01_Showkey/program.c.template @@ -91,6 +91,34 @@ int octcmp(const char *pass, const char *buff) return res; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { char pass[20]; char hexbuff[30]; @@ -122,7 +150,7 @@ int main(int argc, char* argv[]) { printf("Hex OK? %d Dec OK? %d Oct OK? %d\n",!hres,!dres,!ores); printf("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_IntOverflow/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_IntOverflow/program.c.template index 3818810ec..e73201745 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_IntOverflow/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_IntOverflow/program.c.template @@ -43,6 +43,34 @@ void print_msg() { printf(msg2,USERDEF0,USERDEF1,USERDEF2); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { unsigned char addc, c=USERDEF0; unsigned short adds, s=USERDEF1; @@ -65,7 +93,7 @@ int main() { c+= addc; s+=adds; i+=addi; if (!c && !s && !i) - printf("Good Job.\n"); + printflag(); else { sleep(1); printf("isZero(char)? %d isZero(short)? %d isZero(int)? %d\n",!c, !s, !i); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_TwosComplement/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_TwosComplement/program.c.template index 7b8130ffa..d171b7f43 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_TwosComplement/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_TwosComplement/program.c.template @@ -37,7 +37,7 @@ void print_msg() { } void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } @@ -68,6 +68,34 @@ void try() { print_nogood(); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { print_msg(); try(); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_XorInt/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_XorInt/program.c.template index a81bada0a..fa93f1d3c 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_XorInt/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_03_XorInt/program.c.template @@ -38,6 +38,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(void) { unsigned int key=USERDEF; unsigned int pass; @@ -49,7 +77,7 @@ int main(void) { printf("I have XOR encrypted the value you entered (%x).\n",pass); printf("The encrypted result is: %x\n", pass^key); if ((pass^key) == 0) - printf("Good Job.\n"); + printflag(); else printf("Try again.\n"); } else { diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_05_FloatConvert/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_05_FloatConvert/program.c.template index 9084141ea..429b85043 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_05_FloatConvert/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch1-2/Ch2_05_FloatConvert/program.c.template @@ -34,6 +34,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { float f1,f2; unsigned int *ip; @@ -68,6 +96,6 @@ int main() { printf("Try again.\n"); } else - printf("Good Job.\n"); + printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format0_Leak/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format0_Leak/program.c.template index 372184dfb..c642cd75a 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format0_Leak/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format0_Leak/program.c.template @@ -88,6 +88,34 @@ void format_string(char *input, char *password){ printf("\n"); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(){ // Declare variables for password generation char input[9], password[9]; @@ -127,7 +155,7 @@ int main(){ format_string(input, password); if(flag) printf("Try again.\n"); - else printf("Good Job.\n"); + else printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format1_LeakDollar/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format1_LeakDollar/program.c.template index e836ffd03..2230c8884 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format1_LeakDollar/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format1_LeakDollar/program.c.template @@ -65,6 +65,34 @@ void format_string(char input[], char fakeoutput[9], char output[9]){ printf("\n"); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(){ // Declare variables for password generation char input[9], output[9]; @@ -102,7 +130,7 @@ int main(){ format_string(input, "almost!!", output); if(flag) printf("Try again.\n"); - else printf("Good Job.\n"); + else printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format2_nCorruptKey/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format2_nCorruptKey/program.c.template index 58c8020f3..a9698e4bc 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format2_nCorruptKey/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format2_nCorruptKey/program.c.template @@ -55,6 +55,34 @@ int format_string(char input[]) { return key; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char input[51]; int i; @@ -79,7 +107,7 @@ int main() { printf("The key is equal to %d.\n", key); if(key != USERDEF){ - printf("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format3_nWriteKey/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format3_nWriteKey/program.c.template index 59b5816da..34bb83391 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format3_nWriteKey/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format3_nWriteKey/program.c.template @@ -51,6 +51,34 @@ int format_string(char input[]) { return key; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char input[51]; int i; @@ -75,7 +103,7 @@ int main() { printf("The key is equal to %d.\n", key); if(key == USERDEF){ - printf("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format4_nWriteFnP/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format4_nWriteFnP/program.c.template index 55cc7131b..c94d243a2 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format4_nWriteFnP/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format4_nWriteFnP/program.c.template @@ -42,7 +42,7 @@ void print_msg() { // Good/Again void print_good(){ - printf("Good Job.\n"); + printflag(); } void print_again(){ @@ -66,6 +66,34 @@ void format_string(char input[]) { return; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char input[51]; int i; diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format5_nTargetWrite/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format5_nTargetWrite/program.c.template index 444f7098d..77940cdea 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format5_nTargetWrite/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format5_nTargetWrite/program.c.template @@ -65,6 +65,34 @@ int format_string(char input[]) { } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char input[128]; int i; @@ -90,7 +118,7 @@ int main() { // Check if key has been hijacked if(key == USERDEF){ - printf("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format6_PLTHijack/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format6_PLTHijack/program.c.template index 20d1589a5..5040ffa6a 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format6_PLTHijack/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3-ExtraFormatStr/Ch3_Format6_PLTHijack/program.c.template @@ -37,7 +37,7 @@ void print_msg() { // Good/Again void print_good(){ - printf("Good Job.\n"); + printflag(); exit(0); } @@ -60,6 +60,33 @@ void format_string(char input[]) { return; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} // Main int main() { diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbIntro/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbIntro/program.c.template index f0296148d..632326a1f 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbIntro/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbIntro/program.c.template @@ -65,6 +65,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { char buff[20]; char pass[20]; @@ -90,7 +118,7 @@ int main(int argc, char* argv[]) { } printf ("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbRegs/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbRegs/program.c.template index a3c10125e..a877dacd4 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbRegs/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbRegs/program.c.template @@ -16,7 +16,7 @@ char msg[] = "retval_in_rax(). Use the print command to reveal it (e.g. p $rax)\n\n"; void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } @@ -47,6 +47,34 @@ long retval_in_rax() { return j; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main () { print_msg(); int usercode; diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbSetmem/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbSetmem/program.c.template index 23bf64eae..4d6ffad09 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbSetmem/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_00_GdbSetmem/program.c.template @@ -60,7 +60,7 @@ void print_pswd(unsigned long long int key) { } void print_good(void) { - puts("Good Job."); + printflag(); } void segv_handler(int sig) { @@ -95,6 +95,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(void) { signal(SIGSEGV, segv_handler); int x=1024; diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_01_GdbPractice/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_01_GdbPractice/program.c.template index ccc8a9264..a84736e3e 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_01_GdbPractice/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_01_GdbPractice/program.c.template @@ -14,6 +14,34 @@ void pwdFunction(char* p) { int y = 2; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { int i; char buf[20]; @@ -30,6 +58,6 @@ int main(int argc, char* argv[]) { printf("Try again.\n"); return 0; } - printf("Good Job.\n"); + printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_02_AsciiInstr/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_02_AsciiInstr/program.c.template index 72954ef49..580d8458f 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_02_AsciiInstr/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_02_AsciiInstr/program.c.template @@ -28,6 +28,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char c0=USERDEF0; @@ -59,6 +87,6 @@ int main() if (flag) printf ("Try again.\n"); else - printf("Good Job.\n"); + printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_FnPointer/program.c b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_FnPointer/program.c index 3e0a4a8f3..6cec2833b 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_FnPointer/program.c +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_FnPointer/program.c @@ -35,6 +35,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { unsigned long int x; @@ -53,7 +81,7 @@ int main() } void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_LinkedList/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_LinkedList/program.c.template index 7e9d68b38..6c6cde1f7 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_LinkedList/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_04_LinkedList/program.c.template @@ -54,7 +54,7 @@ void segv_handler(int sig) { } void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } @@ -108,6 +108,34 @@ void try_command() { ferrets_before(b); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { funcp fg=print_good; // printf("the password is %i for debugging only\n\n", USERDEF); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorLong/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorLong/program.c.template index 54b606ddc..a2c3aa40f 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorLong/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorLong/program.c.template @@ -28,6 +28,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + unsigned long foo=USERDEF0; int main() { @@ -49,6 +77,6 @@ int main() { printf("Try again.\n"); return 0; } - printf("Good Job.\n"); + printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorStr/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorStr/program.c.template index 1a6c5c20f..69a5cf497 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorStr/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.1-3.5/Ch3_05_XorStr/program.c.template @@ -24,6 +24,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + char c[9]=USERDEF0; char in[9]; @@ -43,6 +71,6 @@ int main() { return 0; } } - printf("Good Job.\n"); + printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_Conditionals/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_Conditionals/program.c.template index 01a1c4979..f38204270 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_Conditionals/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_Conditionals/program.c.template @@ -36,7 +36,7 @@ void print_msg() { } void print_good(void){ - printf("Good Job.\n"); + printflag(); } void print_again(void){ @@ -55,6 +55,34 @@ int check_code(int input){ return 1; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main (int argc, char** argv) { int a, b, code, input; print_msg(); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_LoopMulti/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_LoopMulti/program.c.template index cf9705b7d..15233d3d1 100755 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_LoopMulti/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_LoopMulti/program.c.template @@ -51,6 +51,34 @@ void loop_multi(unsigned int *a) { a[2]--; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { unsigned int a[3]; @@ -64,7 +92,7 @@ int main() { loop_multi(a); if (!a[0] && !a[1] && !a[2]) - printf("Good Job.\n"); + printflag(); else { sleep(1); printf("Num1_OK? %d Num2_OK? %d Num3_OK? %d\n",!a[0], !a[1], !a[2]); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_SwitchTable/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_SwitchTable/program.c.template index aebdb50ef..158529b9b 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_SwitchTable/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_06_SwitchTable/program.c.template @@ -24,6 +24,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { int i; @@ -38,7 +66,7 @@ int main() { case USERDEF+2: printf("Try again.\n"); break; case USERDEF+3: - printf("Good Job.\n"); break; + printflag(); break; default: printf("Try again.\n"); } return 0; diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_FloatReturn/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_FloatReturn/program.c.template index b4ff6a9ed..612854cbd 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_FloatReturn/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_FloatReturn/program.c.template @@ -43,6 +43,35 @@ void print_msg() { printf("%s",msg); } + +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { float f,input; @@ -56,7 +85,7 @@ int main(int argc, char* argv[]) { if (input!=f) { printf ("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsRegs/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsRegs/program.c.template index b44146d4d..11805dc74 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsRegs/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsRegs/program.c.template @@ -37,6 +37,34 @@ int foo(char *a, char *b, char *c, char *d, char *e, char *f) { return flag; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char buff[12]; char chaff0[] = "IeuxMect"; @@ -56,7 +84,7 @@ int main() { scanf("%11s", buff); if ( foo("TYdfExPX", "Ys1QXVxq", "uyQMBeoD", "Kr3Pp6kr", chaff10, buff)) { - printf ("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsStack/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsStack/program.c.template index c0ca201aa..115a64682 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsStack/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_ParamsStack/program.c.template @@ -55,6 +55,34 @@ int foo(char *a, char *b, char *c, char *d, char *e, char *f, char *g, char *h, return flag; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char buff[12]; char chaff11[] = "Y8FinB6z"; @@ -68,7 +96,7 @@ int main() { scanf("%11s", buff); if ( foo("TYdfExPX", chaff0, chaff1, chaff2, "Ys1QXVxq", "uyQMBeoD", "Kr3Pp6kr", chaff10, chaff9, buff)) { - printf ("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_SegvBacktrace/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_SegvBacktrace/program.c.template index 1925064f2..750f12061 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_SegvBacktrace/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_SegvBacktrace/program.c.template @@ -119,6 +119,35 @@ int foo(char* a0, char* a1, char* a2, char* a3, char* a4, char* a5, char* a6, ch } return flag; } + +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { print_msg(); printf("Enter the password: "); @@ -126,7 +155,7 @@ int main() { scanf("%19s", ans); if (foo(CH00,CH01,CH02,CH03,CH04,CH05,CH06,CH07,CH08,CH09,CH10,CH11,CH12,CH13,CH14,CH15,CH16,CH17,CH18,CH19,ans,USERDEF)) { - printf ("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); orange("ora"); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticInt/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticInt/program.c.template index fb1e4d45e..963c8bfcb 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticInt/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticInt/program.c.template @@ -26,7 +26,7 @@ void print_msg() { } void print_good(void){ - printf("Good Job.\n"); + printflag(); } void print_again(void){ @@ -38,6 +38,34 @@ int check_code(int input, int answer) { else return 0; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main (int argc, char** argv) { int a, b, code, input; print_msg(); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticStrcmp/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticStrcmp/program.c.template index 62b8351df..5c7f160b7 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticStrcmp/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.6-3.7/Ch3_07_StaticStrcmp/program.c.template @@ -23,6 +23,34 @@ void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { char buff[20]; @@ -45,7 +73,7 @@ int main(int argc, char* argv[]) if (strcmp(buff,pass)) { printf ("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_CanaryBypass/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_CanaryBypass/program.c.template index d29899b9a..2de8547e4 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_CanaryBypass/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_CanaryBypass/program.c.template @@ -20,7 +20,7 @@ char msg[] = "of $rsp when the retq instruction at the end of prompt_user is reached.\n\n"; void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } @@ -39,6 +39,34 @@ void prompt_user() { *over_addr = user_addr; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char *argv[]) { print_msg(); prompt_user(); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_HijackPLT/program.c b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_HijackPLT/program.c index 03c77a6bb..4b23d7ace 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_HijackPLT/program.c +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_HijackPLT/program.c @@ -20,7 +20,7 @@ char msg[] = " scanf(\"%lx \%lx\");\n\n"; void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } void segv_handler(int sig) { @@ -34,6 +34,33 @@ void ill_handler(int sig) { void print_msg() { printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} int main() { unsigned long int *ip; diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_ScanfOverflow/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_ScanfOverflow/program.c.template index 7fa1ccf49..98fda52ea 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_ScanfOverflow/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_ScanfOverflow/program.c.template @@ -32,11 +32,39 @@ void user_input(char *pass) printf("Enter the password: "); scanf("%s",buff); if(strcmp(ret,pass)==0) - printf("Good Job.\n"); + printflag(); else printf("Try again\n"); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_StackSmash/program.c b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_StackSmash/program.c index 17b8ff2e1..4c3077263 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_StackSmash/program.c +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_07_StackSmash/program.c @@ -19,7 +19,7 @@ char msg[] = "the function you want to return to.\n\n"; void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } void segv_handler(int sig) { @@ -44,6 +44,33 @@ void print_msg() { else printf("%s",msg); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} int main () { signal(SIGSEGV, segv_handler); print_msg(); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_2DArrays/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_2DArrays/program.c.template index 2a1c59c2a..659a11a1b 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_2DArrays/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_2DArrays/program.c.template @@ -50,6 +50,34 @@ void add_cells() { thirdArray[0][JUMPCC] = 0xDEADBEEF; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { long ans=0; @@ -62,7 +90,7 @@ int main(int argc, char* argv[]) if ((scanf("%ld",&ans) != 1) || (ans != USERDEF)) { printf("Try again.\n"); } else { - printf("Good Job.\n"); + printflag(); } return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_Matrix/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_Matrix/program.c.template index 1eba34e01..1e9404c9a 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_Matrix/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_08_Matrix/program.c.template @@ -34,6 +34,34 @@ void detectTrace (void) { }; }; +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(void){ int i,j; print_msg(); @@ -62,7 +90,7 @@ int main(void){ printf("Enter the password: "); scanf("%d",&pwd); if(pwd == array[USERDEF0][USERDEF1]){ - printf("Good Job.\n"); + printflag(); } else{ sleep(2); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_09_Structs/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_09_Structs/program.c.template index 7e7f99bb2..ade18abab 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_09_Structs/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch3.7-3.9/Ch3_09_Structs/program.c.template @@ -34,7 +34,7 @@ void segv_handler(int sig) { } void print_good() { - printf("Good Job.\n"); + printflag(); exit(0); } @@ -58,6 +58,34 @@ void try_command() { f[i](); } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { funcp fg=print_good; signal(SIGSEGV, segv_handler); diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch5_08_LoopUnroll/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch5_08_LoopUnroll/program.c.template index 450c4fc0d..07f3b8928 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch5_08_LoopUnroll/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch5_08_LoopUnroll/program.c.template @@ -99,6 +99,34 @@ int unroll9(int *nums){ return val; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char *argv[]){ int u1,u2,u3,g1,g2,g3,i; int nums[100]; @@ -116,7 +144,7 @@ int main(int argc, char *argv[]){ if ((scanf("%d %d %d", &g1, &g2, &g3) != 3) || (u1 != g1) || (u2 != g2) || (u3 != g3)) printf("Try again.\n"); else - printf("Good Job.\n"); + printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch7_13_LdPreloadGetUID/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch7_13_LdPreloadGetUID/program.c.template index d0e0ec298..74f5f2292 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch7_13_LdPreloadGetUID/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch7_13_LdPreloadGetUID/program.c.template @@ -51,6 +51,34 @@ void detectTrace(void) { }; }; +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char input[10], output[10]; int i,flag,cnt = 0; @@ -89,7 +117,7 @@ int main() { } if(flag) printf("Try again.\n"); - else printf("Good Job.\n"); + else printflag(); return 0; } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_PsSignals/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_PsSignals/program.c.template index fc0f6c4a3..1e1140f12 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_PsSignals/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_PsSignals/program.c.template @@ -79,6 +79,34 @@ void fork_decoys(){ } } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main(int argc, char* argv[]) { int status,i; @@ -140,5 +168,5 @@ int main(int argc, char* argv[]) if (strncmp(p,pass,strlen(p))) printf("Try again.\n"); else - printf("Good Job.\n"); + printflag(); } diff --git a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_Signals/program.c.template b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_Signals/program.c.template index 80d41a40d..69096d27b 100644 --- a/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_Signals/program.c.template +++ b/modules/utilities/unix/ctf/metactf/files/repository/src_csp/Ch5-8/Ch8_05_Signals/program.c.template @@ -139,6 +139,34 @@ int foo(char *a, char *b, char *c, char *d, char *e, char *f) { return flag; } +void printflag() +{ + int fd; + int len; + unsigned char data[128]; + + fd = open("flag", O_RDONLY); + + if ( fd <= 0 ) { + printf("Failed to open flag.\n"); + return; + } + + len = lseek( fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + if ( len > 128 ) { + len = 128; + } + + memset(data, 0, 128); + read( fd, data, len); + close(fd); + + printf("%s\n", data); + return; +} + int main() { char buff[12]; char chaff0[] = "IeuxMect"; @@ -160,7 +188,7 @@ int main() { scanf("%11s", buff); if ( foo("TYdfExPX", "Ys1QXVxq", "uyQMBeoD", "Kr3Pp6kr", chaff10, buff)) { - printf ("Good Job.\n"); + printflag(); } else { printf("Try again.\n"); }