跳过内容

MASTG-TECH-0134: 监控剪贴板

您可以监控剪贴板,以检查是否有敏感数据被复制到其中。这对于检测潜在的数据泄露或 iOS 应用程序中剪贴板的滥用非常有用。

获取剪贴板信息

  • 通过挂钩 pasteboardWithName:create: 并检查其输入参数,或者挂钩 pasteboardWithUniqueName 并检查其返回值,来获取剪贴板名称。
  • 获取第一个可用的剪贴板项目:例如,对于字符串,使用 string 方法。或者,使用标准数据类型的其他任何方法。
  • 使用 numberOfItems 获取项目数。
  • 使用便捷方法检查标准数据类型的存在,例如 hasImageshasStringshasURLs(从 iOS 10 开始)。
  • 使用containsPasteboardTypes: inItemSet:检查其他数据类型(通常是 UTI)。您可以检查更具体的数据类型,例如作为 public.png 和 public.tiff 的图片(UTI)或自定义数据,例如 com.mycompany.myapp.mytype。请记住,在这种情况下,只有 *声明了解* 该类型的应用程序才能理解写入剪贴板的数据。这与我们在UIActivity Sharing 部分中看到的内容相同。使用itemSetWithPasteboardTypes:并设置相应的 UTI 来检索它们。
  • 通过挂钩 setItems:options: 并检查其 UIPasteboardOptionLocalOnlyUIPasteboardOptionExpirationDate 选项,来检查排除或过期的项目。

监控敏感数据

如果只是寻找字符串,您可能想使用来自 * objection for iOS* 的命令 ios pasteboard monitor

钩入 iOS UIPasteboard 类,并每 5 秒轮询一次 generalPasteboard 以获取数据。 如果找到与之前轮询不同的新数据,该数据将转储到屏幕。

您也可以构建自己的剪贴板监视器,该监视器监视如上所示的特定信息。

例如,此脚本(灵感来自objection 的剪贴板监视器背后的脚本)每 5 秒读取一次剪贴板项目。如果有新的内容,它将打印出来

const UIPasteboard = ObjC.classes.UIPasteboard;
    const Pasteboard = UIPasteboard.generalPasteboard();
    var items = "";
    var count = Pasteboard.changeCount().toString();

setInterval(function () {
      const currentCount = Pasteboard.changeCount().toString();
      const currentItems = Pasteboard.items().toString();

      if (currentCount === count) { return; }

      items = currentItems;
      count = currentCount;

      console.log('[* Pasteboard changed] count: ' + count +
      ' hasStrings: ' + Pasteboard.hasStrings().toString() +
      ' hasURLs: ' + Pasteboard.hasURLs().toString() +
      ' hasImages: ' + Pasteboard.hasImages().toString());
      console.log(items);

    }, 1000 * 5);

在输出中,我们可以看到以下内容

[* Pasteboard changed] count: 64 hasStrings: true hasURLs: false hasImages: false
(
    {
        "public.utf8-plain-text" = hola;
    }
)
[* Pasteboard changed] count: 65 hasStrings: true hasURLs: true hasImages: false
(
    {
        "public.url" = "https://codeshare.frida.re/";
        "public.utf8-plain-text" = "https://codeshare.frida.re/";
    }
)
[* Pasteboard changed] count: 66 hasStrings: false hasURLs: false hasImages: true
(
    {
        "com.apple.uikit.image" = "<UIImage: 0x1c42b23c0> size {571, 264} orientation 0 scale 1.000000";
        "public.jpeg" = "<UIImage: 0x1c44a1260> size {571, 264} orientation 0 scale 1.000000";
        "public.png" = "<UIImage: 0x1c04aaaa0> size {571, 264} orientation 0 scale 1.000000";
    }
)

您会看到首先复制了一段文字,其中包括字符串 "hola"。 之后,复制了一个 URL,最后,复制了一张图片。 其中一些可以通过不同的 UTI 获得。 其他应用程序会考虑这些 UTI 以允许粘贴此数据或不允许。