【问题标题】:Demonstrating printf or __android_log_print Vulnerabilities With Android NDK使用 Android NDK 演示 printf 或 __android_log_print 漏洞
【发布时间】:2019-08-18 19:09:47
【问题描述】:

我有兴趣通过 NDK 应用演示 printf 漏洞。需要明确的是,我知道要登录控制台,我们可以使用__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 c++ c android-ndk printf


    【解决方案1】:

    您确实意识到 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);
    }
    

    我最终看到了:https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/stdio/vfprintf.cpp

    第 453-454 行:

      case 'n':
        __fortify_fatal("%%n not allowed on Android");
    

    代码中还引用了通过 FORTIFY 的额外安全性,这在以下博客文章中进行了描述:

    https://android-developers.googleblog.com/2017/04/fortify-in-android.html

    【讨论】:

    • 什么!?它是开源的??
    • 不知道我们俩是不是在讽刺。无论您何时尝试深入了解 Android 杂草,都可以阅读源代码以了解它是如何处理事情的。
    • 是的,我一直在阅读一些试图追踪此类内容的来源。猜猜我只是没有击中正确的东西。这向我解释了为什么__android_log_print() 会以它的方式运行。非常感谢你的帮忙。你必须原谅我,但我仍然很困惑为什么 printf() 根本不起作用。
    • printf() 发送到控制台。在 Android 的上下文中,没有控制台。请参阅:How to get “printf” messages written in NDK application? 如果您尝试浏览代码,this post on printflike modifier 可能会有所帮助。
    【解决方案2】:

    Android 不支持 %n 格式说明符,因为它们很容易受到攻击。

    https://android.googlesource.com/platform/bionic/+/400b073ee38ecc2a38234261b221e3a7afc0498e/tests/stdio_test.cpp#328

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-14
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多