repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
ios-uipasteboard.mdMarkdown122 lines8.9 KiBsource raw download

title: "iOS Pasteboard" section: "Mobile" sectionSlug: "mobile-pentesting" sourcePath: "src/mobile-pentesting/ios-pentesting/ios-uipasteboard.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/ios-pentesting/ios-uipasteboard.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

iOS Pasteboard#

Data sharing within and across applications on iOS devices is facilitated by UIPasteboard, which has two primary categories:[1][4]

Security considerations play a significant role when utilizing pasteboards. For instance:[1][2]

Ensuring that sensitive information is not inadvertently stored on the global pasteboard is crucial. Additionally, applications should be designed to prevent the misuse of global pasteboard data for unintended actions, and developers are encouraged to implement measures to prevent copying of sensitive information to the clipboard.[2]

Privacy-aware attack surface (iOS 16+)#

A paste prompt is both a protection and a useful test signal. Copy a unique, non-sensitive canary in a separate app, cold-start the target, and do not invoke any paste UI. A prompt at launch, resume, or view presentation indicates that the target attempted a programmatic value read. Repeat the flow while denying and allowing access, and correlate it with hooked selectors and network traffic to determine whether the app gates the read correctly or tries to upload the value. Finally, compare this with an explicit paste through the edit menu or UIPasteControl; this separates expected user-driven behavior from automatic clipboard harvesting.[3][6]

Do not confuse classification with content access. detectPatterns(for:) / detectedPatterns(for:) can disclose that an item resembles a URL, number, email address, phone number, postal address, tracking number, or other supported pattern without returning its value and without notifying the user. This is still a small metadata oracle worth recording during an assessment. Conversely, detectValues(for:) / detectedValues(for:) returns matched values and must be treated as a content read. Hook both API families to discover apps that first classify the pasteboard and only read it when a desired pattern matches.[4][7]

For sensitive writes, inspect whether the application supplies both UIPasteboard.OptionsKey.localOnly and expirationDate. localOnly keeps the item out of Handoff/Universal Clipboard, while expirationDate asks the system to remove it after a bounded interval. Their absence does not prove exploitability, but it increases the exposure window and number of reachable devices.[4]

import UniformTypeIdentifiers

UIPasteboard.general.setItems(
  [[UTType.utf8PlainText.identifier: token]],
  options: [
    .localOnly: true,
    .expirationDate: Date().addingTimeInterval(60)
  ]
)

Static Analysis#

For static analysis, search the source code or binary for:[3][4]

Dynamic Analysis#

Dynamic analysis involves hooking or tracing specific methods:[3]

Key details to monitor include:

An example of monitoring tool usage is objection's pasteboard monitor, which polls the generalPasteboard every 5 seconds for changes and outputs the new data. On iOS 16 and later this is an active read, not a transparent observer: injected polling executes in the target process and can itself trigger or alter paste-approval behavior. First capture the application's own UIPasteboard calls with hooks, then use polling in a separate run so that the monitor is not mistaken for application behavior.[3][6]

Here's a simple JavaScript script example, inspired by the objection's approach, to read and log changes from the pasteboard every 5 seconds:

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)

References#