Tools for analysing AppleScript malware, including run-only scripts:
osatool decompileturns compiled, run-only.scptfiles back into source; see the blog post for how it works.osatool disassembleprints a compiled script's bytecode. It's built on a vendored copy of Jinmo/applescript-disassembler, which the decompiler also uses to load scripts.osatool emulatetriages a sample: it emulates the script with a fake Mac and reports the commands it runs, what it downloads and uploads, the files it reads and drops, and the IOCs.
From PyPI:
pip install applescript-toolsPython 3.10 or later, on any OS. For the latest from GitHub:
pip install git+https://github.com/pberba/applescript-tools. Or, from a
checkout, with uv:
git clone https://github.com/pberba/applescript-tools
cd applescript-tools
uv sync
uv run osatool --helpPass the sample as it is, whatever its file name: a compiled script, an applet, source text, a shell script, or the zip it came in.
osatool emulate sample.scpt # a compiled script, run-only or not
osatool emulate Sample.app # an applet, or a .scptd bundle
osatool emulate sample.applescript # source text: parsed offline, so no osacompile and no Mac
osatool emulate dropper.sh # a shell script, with the AppleScript it passes to osascript
osatool emulate ~/Downloads/<sha256>.zip # a VirusTotal/MalwareBazaar zip (password "infected"), read in memoryFor example, a script that builds its command at run time:
set u to "https://docs.example.invalid/" & "x"
do shell script "curl -s " & u & " -o /tmp/a.txt"$ osatool emulate sample.applescript
== Dropped files ==
/tmp/a.txt «downloaded hxxps://docs[.]example[.]invalid/x»
== IOCs ==
shell_commands:
curl -s hxxps://docs[.]example[.]invalid/x -o /tmp/a.txt
urls:
hxxps://docs[.]example[.]invalid/x
domains:
docs[.]example[.]invalid
files_written:
/tmp/a.txt
status: completed steps: 2
(-v shows the trace; -vv also shows: 1 decoded string(s), 1 unanswered question(s), 1 next step(s))The report is the files the script drops and its IOCs: every shell command,
URLs, domains, files written and read, apps. A warning: line says when the
script used something the emulator has no model for. -v adds the trace of
what it did, in order, and the list of what isn't emulated, and -vv the
decoded strings, the questions nothing answered and the next steps for this
sample. Typically:
osatool emulate sample.scpt -v # with the trace
osatool emulate sample.scpt --brute-force --assume-files # past anti-VM checks, into a stealer's target list
osatool emulate sample.scpt --answers a.toml --update-answers # unanswered questions go in a.toml as "?"…
# …replace the ones you know, and run it again
osatool emulate sample.scpt -i # or answer on the terminalSee docs/emulator.md.
osatool decompile sample.scpt > sample.applescript # also sample zips and JXA
osatool disassemble sample.scpt # the bytecodeThe decompiled output compiles, and recompiles to the same bytecode as the original. See docs/decompiler.md and docs/disassembler.md.
osacompile -x -o demo/demo_runonly.scpt demo/demo_source.applescript # compile run-only
osadecompile demo/demo_runonly.scpt # errOSASourceNotAvailable (-1756)
osatool decompile demo/demo_runonly.scpt > demo/demo_output.out
osatool emulate demo/demo_runonly.scpt -kThis project was applescript-decompiler. The old names keep working: the
commands applescript_decompile, applescript_disassemble and
applescript_emulate, and the imports applescript_decompiler.*, which are
the same modules as applescript_tools.*.
| Tool | Docs |
|---|---|
osatool emulate |
emulator.md: triage, the report, getting further, options · answers-file.md: answering what the emulator can't, changing the fake Mac · brute-force.md: how --brute-force explores both sides of ifs · emulation-model.md: what's modelled, limits, where IOCs come from, code layout |
osatool decompile |
decompiler.md: usage, and how decompilation works · scripting-dictionaries.md: adding app dictionaries |
osatool disassemble |
disassembler.md |
| offline compiler | compiler.md: parsing source text without osacompile |
| the Python library | library-usage.md |
| development | development.md: setup · testing.md: tests, fixtures, debugging a decompilation |