MetaCTF GdbSetmem printflag fix

This commit is contained in:
thomashaw
2021-10-19 15:33:57 +01:00
parent 47d973df5a
commit d254b3f633
2 changed files with 35 additions and 33 deletions

View File

@@ -10,6 +10,34 @@
void printflag();
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;
}
//Hash function created by Thomas Wang and taken from https://naml.us/post/inverse-of-a-hash-function/
unsigned long long int hash(unsigned long long int key) {
@@ -100,34 +128,6 @@ 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;

View File

@@ -8,6 +8,8 @@
#define USERDEF0 AAAAAA
#define USERDEF1 BBBBBB
void printflag();
//Hash function created by Thomas Wang and taken from https://naml.us/post/inverse-of-a-hash-function/
unsigned long long int hash(unsigned long long int key) {
@@ -61,11 +63,6 @@ void print_pswd(unsigned long long int key) {
printf("%llu\n", inverse_hash(key));
}
void print_good(void) {
puts("Good Job.");
printflag();
}
void printflag()
{
int fd;
@@ -94,6 +91,11 @@ void printflag()
return;
}
void print_good(void) {
puts("Good Job.");
printflag();
}
void segv_handler(int sig) {
printf("Segmentation fault. Try again.\n");
exit(0);