which inputs can i use to exploit the buffer overflow in this program to execute the win() function

i want to use the overflow in some methods of the program to run another function win()

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
#define MAX_PRIORITY_STRSIZE 10 /* len(str(2**32)) */
#define MAX_TITLE_SIZE 0x20
#define MAX_TODOS 0x30
void win(void)
{
execl("/bin/get_flag", "get_flag", NULL);
}
bool read_title(char* buf, size_t buf_size)
{
if(!fgets(buf, buf_size, stdin))
{
printf("Could not read title...n");
return false;
}
if(buf[0] == 'n')
{
printf("Title cannot be empty!n");
return false;
}
/* Remove newline in title */
strtok(buf, "n");
if(strlen(buf) > MAX_TITLE_SIZE)
{
printf("Title too long!");
return false;
}
return true;
}
bool read_priority(char* priority_buf, size_t buf_size, int32_t* ret)
{
printf("Priority: ");
if(!fgets(priority_buf, buf_size, stdin))
{
printf("Could not read priority...n");
return false;
}
if(sscanf(priority_buf, "%d", ret) != 1)
{
printf("Invalid input!");
return false;
}
return true;
}
void print_welcome(void)
{
printf("Welcome to ToDo-List-as-a-Service Demo!n"
"Manage ToDo-List to your liking with a simple terminal interface!n");
}
void print_menu(void)
{
puts("=================================");
puts(" What would you like to do next?");
puts(" A: Add ToDo");
puts(" C: Mark ToDo as completed");
puts(" D: Delete ToDo");
puts(" E: Edit ToDo Title");
puts(" I: Increase Priority");
puts(" L: List ToDos");
puts(" P: Edit ToDo Priority");
puts(" Q: Quit");
puts("=================================");
printf("> ");
}
</code>
<code> #define MAX_PRIORITY_STRSIZE 10 /* len(str(2**32)) */ #define MAX_TITLE_SIZE 0x20 #define MAX_TODOS 0x30 void win(void) { execl("/bin/get_flag", "get_flag", NULL); } bool read_title(char* buf, size_t buf_size) { if(!fgets(buf, buf_size, stdin)) { printf("Could not read title...n"); return false; } if(buf[0] == 'n') { printf("Title cannot be empty!n"); return false; } /* Remove newline in title */ strtok(buf, "n"); if(strlen(buf) > MAX_TITLE_SIZE) { printf("Title too long!"); return false; } return true; } bool read_priority(char* priority_buf, size_t buf_size, int32_t* ret) { printf("Priority: "); if(!fgets(priority_buf, buf_size, stdin)) { printf("Could not read priority...n"); return false; } if(sscanf(priority_buf, "%d", ret) != 1) { printf("Invalid input!"); return false; } return true; } void print_welcome(void) { printf("Welcome to ToDo-List-as-a-Service Demo!n" "Manage ToDo-List to your liking with a simple terminal interface!n"); } void print_menu(void) { puts("================================="); puts(" What would you like to do next?"); puts(" A: Add ToDo"); puts(" C: Mark ToDo as completed"); puts(" D: Delete ToDo"); puts(" E: Edit ToDo Title"); puts(" I: Increase Priority"); puts(" L: List ToDos"); puts(" P: Edit ToDo Priority"); puts(" Q: Quit"); puts("================================="); printf("> "); } </code>

#define MAX_PRIORITY_STRSIZE 10 /* len(str(2**32)) */
#define MAX_TITLE_SIZE 0x20
#define MAX_TODOS 0x30

void win(void)
{
    execl("/bin/get_flag", "get_flag", NULL);
}

bool read_title(char* buf, size_t buf_size)
{
    if(!fgets(buf, buf_size, stdin))
    {
        printf("Could not read title...n");
        return false;
    }

    if(buf[0] == 'n')
    {
        printf("Title cannot be empty!n");
        return false;
    }

    /* Remove newline in title */
    strtok(buf, "n");

    if(strlen(buf) > MAX_TITLE_SIZE)
    {
        printf("Title too long!");
        return false;
    }
    return true;
}



bool read_priority(char* priority_buf, size_t buf_size, int32_t* ret)
{
    printf("Priority: ");
    if(!fgets(priority_buf, buf_size, stdin))
    {
        printf("Could not read priority...n");
        return false;
    }

    if(sscanf(priority_buf, "%d", ret) != 1)
    {
        printf("Invalid input!");
        return false;
    }
    return true;
}

void print_welcome(void)
{
    printf("Welcome to ToDo-List-as-a-Service Demo!n"
             "Manage ToDo-List to your liking with a simple terminal interface!n");
}


void print_menu(void)
{
    puts("=================================");
    puts(" What would you like to do next?");
    puts(" A: Add ToDo");
    puts(" C: Mark ToDo as completed");
    puts(" D: Delete ToDo");
    puts(" E: Edit ToDo Title");
    puts(" I: Increase Priority");
    puts(" L: List ToDos");
    puts(" P: Edit ToDo Priority");
    puts(" Q: Quit");
    puts("=================================");
    printf("> ");
}

The functions above are what’s important for this question. During testing I’ve found that :

  1. During add ToDo, if we input large amounts of numbers in priority, the title will be automatically part of the inputted numbers in priority without further entering the title, e.g.

a
Priority: 1111111111111111111111111111111
Title: ToDo ‘11111111111111111111’ added!

  1. If we edit said ToDo’s priority to large amount of numbers, specifically more than 9 digits, the title also changes however into other numbers.

I’m sure this could be a buffer overflow problem and we could exploit this to run the win() program, but I don’t know which inputs to put. I ran lldc (since I use a mac) and found out that win_address = 0x100003040
main_address = 0x1000039b0

New contributor

Darren Hendarmin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật