sam*_*m_c 1 c c++ printf android android-ndk
我对printf通过 NDK 应用程序演示漏洞感兴趣。需要明确的是,我知道要登录控制台,我们可以使用__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "Print : %d %s",someVal, someStr);. 我试过了,我知道它有效。但我明确地想演示 的漏洞printf(),特别是使用说明%n符写入指向的位置。
有没有办法使printf()工作达到这种效果,或者是否可以通过 实现__android_log_print()?我用android/log.h标题尝试了它,但它没有用。
我可以通过运行一些类似printf(%s%s%s%s%s%s%s%s%s%s). 但同样,我不能操纵指针。
出于一般知识的目的,为什么它printf()首先不起作用以及如何__android_log_print()防止这些漏洞利用?
您确实意识到 Android 是开源的。
从寻找__android_log_print()
和找到它开始:https : //android.googlesource.com/platform/system/core/+/refs/heads/master/liblog/logger_write.cpp
int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
va_list ap;
char buf[LOG_BUF_SIZE];
va_start(ap, fmt);
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
va_end(ap);
return __android_log_write(prio, tag, buf);
}
Run Code Online (Sandbox Code Playgroud)
我最终看到了:https : //android.googlesource.com/platform/bionic/+/refs/heads/master/libc/stdio/vfprintf.cpp
第 453-454 行:
case 'n':
__fortify_fatal("%%n not allowed on Android");
Run Code Online (Sandbox Code Playgroud)
代码中还引用了通过 FORTIFY 实现的额外安全性,以下博客文章中对此进行了描述:
https://android-developers.googleblog.com/2017/04/fortify-in-android.html