libfuzzer demo-01

在上CS110l中有一个程序用来说明C/C++内存不安全的问题,我学到这里想着就用libfuzzer来fuzzer一下吧,顺便学习一下libfuzzer。

libfuzzer我已经搭建好了的,你可以根据https://github.com/Dor1s/libfuzzer-workshop来搭建环境。

源程序:

#include <stdio.h>
#include <string.h>

int main()
{
    char s[100];
    int i;
    
    printf("\nEnter a string:");
    gets(s);

    for(i = 0; s[i] != '\0'; i++)
    {
        if ( s[i] >= 'a' && s[i] <= 'z')
        {
            s[i] = s[i] - 32;
        }
    }

    printf("\nString in Upper Case = %s", s);
    return 0;
}

很明显,这里是有缓冲区溢出的漏洞,gets函数不安全。最后发现,gets在C++11中被移除了,这个程序编译不过,放弃。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 注销 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 注销 /  更改 )

Connecting to %s