使用 Android NDK 演示 printf 或 __android_log_print 漏洞
Demonstrating printf or __android_log_print Vulnerabilities With Android NDK
我有兴趣通过 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是开源的。
从寻找__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 特别不支持%n
格式说明符,因为它们容易受到攻击。
https://android.googlesource.com/platform/bionic/+/400b073ee38ecc2a38234261b221e3a7afc0498e/tests/stdio_test.cpp#328
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用ndk-build.cmd构建Android.so文件
- Android NDK传感器向事件队列报告奇怪的间隔
- 如何用数字处理log(0)
- Android P-9.0.0_r53 Logcat主缓冲区超出定义大小
- 安装opencv失败-粘贴CMakeError.log的内容
- OpenCV Android C++ imwrite not found
- Android NDK 编译 LAME HAVE_MPGLIB > 'interface.h' 文件未找到
- 如何使用 Boost Asio 在 Android 上获取我的本地 udp IP 地址?
- Android Studio 中带有静态库的原生C++代码
- 如何在 Android Studio 4 中编译 C/C++ 原生代码
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- Android 在编译二进制文件时重建静态库
- 我只想在Android 4.4中使用C++11库
- 无法将标准库导入本机 android 项目中的头文件
- Android Java USB for native cpp
- Android ndk: utils/Log.h: 没有这样的文件或目录编译终止
- Android ndk log unicode (wide characters)
- boost for android building boost log
- 为什么Android NDK log.h __android_log_print链接错误