├── log4j-analysis ├── img │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ └── 10.png ├── playbook-files │ ├── check4logFOURj.ps1 │ └── check4logFOURj.sh ├── README.md └── evaluation-script │ └── evalPB.py ├── log4shell-detector ├── img │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ └── 07.png └── README.md ├── sysmon-maintenance ├── img │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ └── 11.png ├── playbook-files │ ├── sysmon-uninstall.ps1 │ ├── sysmon-configupdate.ps1 │ └── sysmon-install.ps1 └── README.md ├── README.md └── LICENSE /log4j-analysis/img/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/01.png -------------------------------------------------------------------------------- /log4j-analysis/img/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/02.png -------------------------------------------------------------------------------- /log4j-analysis/img/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/03.png -------------------------------------------------------------------------------- /log4j-analysis/img/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/04.png -------------------------------------------------------------------------------- /log4j-analysis/img/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/05.png -------------------------------------------------------------------------------- /log4j-analysis/img/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/06.png -------------------------------------------------------------------------------- /log4j-analysis/img/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/07.png -------------------------------------------------------------------------------- /log4j-analysis/img/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/08.png -------------------------------------------------------------------------------- /log4j-analysis/img/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/09.png -------------------------------------------------------------------------------- /log4j-analysis/img/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4j-analysis/img/10.png -------------------------------------------------------------------------------- /log4shell-detector/img/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/01.png -------------------------------------------------------------------------------- /log4shell-detector/img/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/02.png -------------------------------------------------------------------------------- /log4shell-detector/img/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/03.png -------------------------------------------------------------------------------- /log4shell-detector/img/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/04.png -------------------------------------------------------------------------------- /log4shell-detector/img/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/05.png -------------------------------------------------------------------------------- /log4shell-detector/img/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/06.png -------------------------------------------------------------------------------- /log4shell-detector/img/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/log4shell-detector/img/07.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/01.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/02.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/03.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/04.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/05.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/06.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/07.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/08.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/09.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/10.png -------------------------------------------------------------------------------- /sysmon-maintenance/img/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neo23x0/asgard-playbooks/master/sysmon-maintenance/img/11.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Playbooks for ASGARD 2 | 3 | ## Available Playbooks 4 | - [Sysmon Maintenance](sysmon-maintenance): Playbooks for (un-)installing Sysmon and updating its configuration 5 | - [log4j-analysis](log4j-analysis): Playbooks for checking for hints of log4j usage on a system 6 | - [log4shell-detector](log4shell-detector): Playbooks for executing log4shell-detector, finding exploitation attempts in log files 7 | -------------------------------------------------------------------------------- /sysmon-maintenance/playbook-files/sysmon-uninstall.ps1: -------------------------------------------------------------------------------- 1 | # OS Arch for Exe 2 | $OsArch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture 3 | $SysmonExe = "Sysmon.exe" 4 | if ($OsArch -match "32-Bit"){ $SysmonExe = "Sysmon.exe" } else {$SysmonExe = "Sysmon64.exe"} 5 | 6 | # Uninstall Sysmon if installed 7 | if (Test-Path "$env:windir\SysmonDrv.sys") { iex("$SysmonExe -accepteula -u") } 8 | 9 | # Sometimes the exe is removed by -u, sometimes not 10 | if (Test-Path "$env:windir\$SysmonExe") { 11 | echo "Removing $SysmonExe." 12 | del "$env:windir\$SysmonExe" 13 | } 14 | -------------------------------------------------------------------------------- /sysmon-maintenance/playbook-files/sysmon-configupdate.ps1: -------------------------------------------------------------------------------- 1 | param( $config='sysmonconfig.xml' ) 2 | 3 | # Script Path 4 | $ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition 5 | 6 | # OS Arch for Exe 7 | $OsArch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture 8 | $SysmonExe = "Sysmon.exe" 9 | if ($OsArch -match "32-Bit"){ $SysmonExe = "Sysmon.exe" } else {$SysmonExe = "Sysmon64.exe"} 10 | 11 | # Update Sysmon config if Sysmon is installed 12 | if (Test-Path "$env:windir\SysmonDrv.sys") { 13 | iex("$SysmonExe -accepteula -c $ScriptPath\$config") 14 | } 15 | else { 16 | throw 'Sysmon is not installed on this system' 17 | } 18 | 19 | -------------------------------------------------------------------------------- /sysmon-maintenance/playbook-files/sysmon-install.ps1: -------------------------------------------------------------------------------- 1 | param ($config='sysmonconfig.xml') 2 | 3 | # Script Path 4 | $ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition 5 | 6 | # OS Arch for Exe 7 | $OsArch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture 8 | $SysmonExe = "Sysmon.exe" 9 | if ($OsArch -match "32-Bit"){ $SysmonExe = "Sysmon.exe" } else {$SysmonExe = "Sysmon64.exe"} 10 | 11 | # Uninstall previous Sysmon version if installed 12 | if (Test-Path "$env:windir\SysmonDrv.sys") { iex("$ScriptPath\$SysmonExe -accepteula -u") } 13 | 14 | # Install Sysmon with config 15 | iex("$ScriptPath\$SysmonExe -accepteula -i $config") 16 | # Throw an error if the installation was not successful 17 | if(!$?) { 18 | throw 'Error during Sysmon Installation.' 19 | } 20 | -------------------------------------------------------------------------------- /log4j-analysis/playbook-files/check4logFOURj.ps1: -------------------------------------------------------------------------------- 1 | $date = Get-Date -Format "yyyy-MM-dd_HHmm" 2 | $ErrorActionPreference= 'silentlycontinue' 3 | $outdir = "results" 4 | $out = -join($outdir, "\",$env:COMPUTERNAME,"_check4logFOURj_",$date) 5 | mkdir $outdir 6 | 7 | handle | Select-String "log4j" | out-file "$out.win.openfiles" 8 | 9 | foreach ($drive in gdr -PSProvider 'FileSystem' | select -exp Root) 10 | { 11 | dir -Recurse $drive |Select-Object FullName | Select-String -Pattern "log4j" | out-file "$out.win.fsfiles" 12 | } 13 | 14 | Get-WmiObject Win32_Process | Select-Object CommandLine | Select-String "log4j" | out-file "$out.win.processes" 15 | 16 | foreach ($drive in gdr -PSProvider 'FileSystem' | select -exp Root) 17 | { 18 | gci $drive -rec -force -include *.jar | foreach {select-string "JndiLookup.class" $_} | select -exp Path | out-file "$out.win.jndiclass" 19 | } 20 | -------------------------------------------------------------------------------- /log4j-analysis/playbook-files/check4logFOURj.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | outdir="results" 4 | out="$outdir/$(hostname)_check4logFOURj_$(date +'%Y-%m-%d_%H%M')" 5 | 6 | echo "$(date -Is) Start running checks" 7 | [[ ! -e "${outdir}" ]] && mkdir "${outdir}" 8 | 9 | if [[ -n $(which ps) ]]; then 10 | ps aux 2>/dev/null | egrep '[l]og4j' > "${out}.lnx.processes" 11 | else 12 | echo "[ERROR] ps not found on $(hostname)" > "${out}.lnx.processes" 13 | fi 14 | 15 | if [[ -n $(which find) ]]; then 16 | find / -iname "log4j*" 2>/dev/null > "${out}.lnx.fsfiles" 17 | else 18 | echo "[ERROR] find not found on $(hostname)" > "${out}.lnx.fsfiles" 19 | fi 20 | 21 | if [[ -n $(which lsof) ]]; then 22 | lsof 2>/dev/null | grep log4j > "${out}.lnx.openfiles" 23 | else 24 | echo "[ERROR] lsof not found on $(hostname)" > "${out}.lnx.openfiles" 25 | fi 26 | 27 | grep -r --include *.[wj]ar "JndiLookup.class" / 2>&1 | grep matches > "${out}.lnx.jndiclass" 28 | 29 | echo "$(date -Is) Finished running checks. Results can be found at ${outdir}" 30 | -------------------------------------------------------------------------------- /log4shell-detector/README.md: -------------------------------------------------------------------------------- 1 | # Playbooks and Scripts for ASGARD to execute log4shell-detector 2 | This playbook enables the usage of the [log4shell-detector](https://github.com/Neo23x0/log4shell-detector) script with ASGARD Management Center. 3 | 4 | The script checks local log files for indicators of exploitation attempts, even heavily obfuscated ones that string or regular expression based patterns wouldn't detect. 5 | 6 | ## Playbook Creation 7 | For the playbooks to work some files need to be put into the `/var/lib/nextron/asgard2/playbook-files` directory of ASGARD: 8 | 9 | 1. The package of Florian Roth's log4shell-detector repository in ZIP format. Download [here](https://github.com/Neo23x0/log4shell-detector) and rename to `log4shell-detector.zip`. 10 | 11 | You can use the file upload feature during playbook creation to achieve that: 12 | 13 | ![01.png](img/01.png) 14 | 15 | If you need to edit or update the file, you can do that using scp, rsync, WinSCP or whatever tool you use for Linux file transfer. Do not forget to change the file ownership to **asgard2:asgard2** 16 | (e.g. `chown asgard2: /var/lib/nextron/asgard2/playbook-files/log4shell-detector.zip`), if it was changed by uploading. 17 | 18 | 19 | ### How to Create a Playbook 20 | *This section explains how to create a playbook in detail. If you are familiar with ASGARD's playbook creation, see the overview of the next section.* 21 | 22 | Go to **Response Control > Playbooks > Add Playbook**, enter 23 | * Name: Run log4shell-detector 24 | * Description: Runs the log4shell-detector python script on selected asset(s). 25 | 26 | and click **Add Playbook**. 27 | 28 | ![02.png](img/02.png) 29 | 30 | Next add the single playbook steps. Therefore click anywhere on the newly created playbook to open its drop-down menu and then choose **Add Step** for each of the following Steps: 31 | 32 | ![03.png](img/03.png) 33 | 34 | 1. Upload log4shell-detector 35 | 36 | ![04.png](img/04.png) 37 | 38 | - Choose the already uploaded 'log4shell-detector.zip' or select **Upload New File** if you want to upload it from the browser. 39 | - Check 'Unzip' box 40 | 41 | 2. Execute log4shell-detector 42 | 43 | ![05.png](img/05.png) 44 | 45 | - Commands: `cd log4shell-detector-main; python log4shell-detector.py --silent -p $path$` 46 | 47 | 48 | ### Overview - Log4shell Detector Playbook 49 | 50 | ![06.png](img/06.png) 51 | 52 | Text transcription of the screenshot: 53 | * Name: Run log4shell-detector 54 | * Description: Runs the log4shell-detector python script on selected asset(s). 55 | * Step 1: 56 | * Name: Upload log4shell-detector 57 | * Type: Download File from ASGARD MC 58 | * Unzip: Checked 59 | * Step 2: 60 | * Name: Execute log4shell-detector 61 | * Type: Run Command Line on Endsystem 62 | * Command: `cd log4shell-detector-main; python log4shell-detector.py --silent $scandirs$` 63 | 64 | ## Run a Task Example: 65 | You need to specify the location(s) which should be scanned. 66 | 67 | We suggest to use `--auto` to let the script look for log files, that are currently written to. 68 | 69 | If you want to enter specific direcories you can enter them using the `-p` flag (e.g. `-p /var/log /opt/myapp/logs`). 70 | 71 | ![07.png](img/07.png) 72 | -------------------------------------------------------------------------------- /sysmon-maintenance/README.md: -------------------------------------------------------------------------------- 1 | # Sysmon Maintenance Playbooks and Scripts for ASGARD 2 | 3 | ## Playbook Creation 4 | For the playbooks to work, some files need to be put into the `/var/lib/nextron/asgard2/playbook-files` directory of ASGARD: 5 | 6 | 1. A current version of [Sysmon.zip](https://download.sysinternals.com/files/Sysmon.zip) 7 | 2. Your Sysmon config called `sysmonconfig.xml` 8 | 3. The playbook Powershell scripts from this repo's [playbook-files](playbook-files) 9 | 10 | You can use the file upload feature during playbook creation to achieve that: 11 | 12 | ![01.png](img/01.png) 13 | 14 | If you need to edit or update the files, you can do that using scp, rsync, WinSCP or whatever tool you use for Linux file transfer. 15 | Do not forget to change the file ownership to **asgard2:asgard2** 16 | (e.g. `chown asgard2: /var/lib/nextron/asgard2/playbook-files/[Ss]ysmon*`), if it was changed by uploading. 17 | 18 | ### Choosing a Sysmon configuration 19 | If you do not have a Sysmon configuration yet, there are several options we suggest: 20 | 21 | 1. The Nextron Systems fork of SwiftOnSecurity's [sysmon-config](https://github.com/Neo23x0/sysmon-config) 22 | 2. The SwiftOnSecurity [sysmon-config](https://github.com/SwiftOnSecurity/sysmon-config) 23 | 3. Olaf Hartong's [sysmon-modular](https://github.com/olafhartong/sysmon-modular) 24 | 25 | In general we suggest our own config, as we test our rules with it and include changes from the upstream configuration. But depending on your preferences, either of those listed configurations are good starting points for writing your own config. 26 | 27 | NOTE: Test your configuration and configuration changes before rolling them out to a greater number of systems. Every environment is unique. 28 | 29 | ### How to Create a Playbook 30 | *This section explains how to create a playbook for the Sysmon installation in detail. If you are familiar with ASGARD's playbook creation, see the overview of the Sysmon playbooks in the next 3 sections.* 31 | 32 | Go to **Response Control > Playbooks > Add Playbook**, enter 33 | * Name: Sysmon Install 34 | * Description: Installs Sysmon with the current configuration to the selected asset(s). 35 | 36 | and click **Add Playbook**. 37 | ![02.png](img/02.png) 38 | 39 | Next add the single playbook steps. Therefore click anywhere on the newly created playbook to open its drop-down menu and then choose **Add Step** for each of the following Steps: 40 | ![03.png](img/03.png) 41 | 1. Fetch Sysmon.zip from ASGARD and unzip it 42 | ![04.png](img/04.png) 43 | - Check the Unzip box 44 | 2. Fetch sysmonconfig.xml from ASGARD 45 | ![05.png](img/05.png) 46 | - The name `sysmonconfig.xml` is used in the installer script 47 | 3. Fetch Sysmon Install Script from ASGARD 48 | ![06.png](img/06.png) 49 | 4. Execute Sysmon Install Script 50 | ![07.png](img/07.png) 51 | - Commands: `powershell -exec bypass .\sysmon-install.ps1` 52 | 53 | 54 | 55 | 56 | ### Overview - Sysmon Install Playbook 57 | ![08.png](img/08.png) 58 | Text transcription of the screenshot: 59 | * Name: Sysmon Install 60 | * Description: Installs Sysmon with the current configuration to the selected asset(s). 61 | * Step 1: 62 | * Name: Fetch Sysmon.zip from ASGARD and unzip it 63 | * Step 2: 64 | * Name: Fetch sysmonconfig.xml from ASGARD 65 | * Step 3: 66 | * Name: Fetch Sysmon Install Script from ASGARD 67 | * Step 4: 68 | * Name: Execute Sysmon Install Script 69 | * Commands: `powershell -exec bypass .\sysmon-install.ps1` 70 | 71 | 72 | ### Overview - Sysmon Config Update Playbook 73 | ![09.png](img/09.png) 74 | Text transcription of the screenshot: 75 | * Name: Sysmon Configuration Update 76 | * Description: Updates the Sysmon configuration on the selected asset(s). 77 | * Step 1: 78 | * Name: Fetch sysmonconfig.xml from ASGARD 79 | * Step 2: 80 | * Name: Fetch Sysmon Update Script from ASGARD 81 | * Step 3: 82 | * Name: Execute Sysmon Update Script 83 | * Commands: `powershell -exec bypass .\sysmon-configupdate.ps1` 84 | 85 | 86 | ### Overview - Sysmon Uninstall Playbook 87 | ![10.png](img/10.png) 88 | Text transcription of the screenshot: 89 | * Name: Sysmon Uninstall 90 | * Description: Uninstalls Sysmon from the selected asset(s). 91 | * Step 1: 92 | * Name: Fetch Sysmon Uninstall Script from ASGARD 93 | * Step 2: 94 | * Name: Execute Sysmon Uninstall Script 95 | * Commands: `powershell -exec bypass .\sysmon-uninstall.ps1` 96 | 97 | ### Using multiple Sysmon configurations 98 | If you use more than one sysmon config, you can upload your configurations to ASGARD under different names and using an additional Sysmon Config Update Playbook. You can give an additional parameter to the Sysmon update or install script to use a different configuration. An example for updating the Sysmon config for domain controllers is given below: 99 | ![11.png](img/11.png) 100 | Text transcription of the screenshot: 101 | * Name: Sysmon Config Update for DCs 102 | * Description: Updates the Sysmon configuration on the selected asset(s) to use the sysmonconfig-dcs.xml configuration file. 103 | * Step 1: 104 | * Name: Fetch sysmonconfig-dcs.xml from ASGARD 105 | * Step 2: 106 | * Name: Fetch Sysmon Update Script from ASGARD 107 | * Step 3: 108 | * Name: Execute Sysmon Update Script 109 | * Commands: `powershell -exec bypass .\sysmon-configupdate.ps1 sysmonconfig-dcs.xml` 110 | 111 | -------------------------------------------------------------------------------- /log4j-analysis/README.md: -------------------------------------------------------------------------------- 1 | # Playbooks for ASGARD to find Log4j Usage 2 | We wrote scripts for Windows and Linux hosts to be used in ASGARD Management Center that scan the host for traces of log4j usage and a script to evaluate the results. 3 | 4 | ## Playbook Creation 5 | For the playbooks to work some files need to be put into the `/var/lib/nextron/asgard2/playbook-files` directory of ASGARD: 6 | 7 | 1. The playbook scripts from this repo's [playbook-files](playbook-files) 8 | 9 | You can use the file upload feature during playbook creation to achieve that: 10 | 11 | ![01.png](img/01.png) 12 | 13 | If you need to edit or update the files, you can do that using scp, rsync, WinSCP or whatever tool you use for Linux file transfer. Do not forget to change the file ownership to **asgard2:asgard2** 14 | (e.g. `chown asgard2: /var/lib/nextron/asgard2/playbook-files/check4logFOURj*`), if it was changed by uploading. 15 | 16 | 17 | ### How to Create a Playbook 18 | *This section explains how to create a playbook in detail. If you are familiar with ASGARD's playbook creation, see the overview of the next 2 sections.* 19 | 20 | Go to **Response Control > Playbooks > Add Playbook**, enter 21 | * Name: check4logFOURj Linux 22 | * Description: Runs checks on selected Linux asset(s) in order to find possible log4j instances 23 | 24 | and click **Add Playbook**. 25 | 26 | ![02.png](img/02.png) 27 | 28 | Next add the single playbook steps. Therefore click anywhere on the newly created playbook to open its drop-down menu and then choose **Add Step** for each of the following Steps: 29 | 30 | ![03.png](img/03.png) 31 | 32 | 1. Upload check script 33 | 34 | ![04.png](img/04.png) 35 | 36 | - Choose the already uploaded script or select **Upload New File** if you want to upload it from the browser. 37 | 38 | 2. Execute check script 39 | 40 | ![05.png](img/05.png) 41 | 42 | - Commands 1: `chmod u+x check4logFOURj.sh` 43 | - Commands 2: `bash check4logFOURj.sh` 44 | 45 | 3. Download results 46 | 47 | ![06.png](img/06.png) 48 | 49 | - Path to File / Directory: results 50 | - Check the 'Is Directory' box 51 | - Check the 'Recursively' box 52 | 53 | ### Overview - check4logFOURj Linux Playbook 54 | 55 | ![07.png](img/07.png) 56 | 57 | Text transcription of the screenshot: 58 | * Name: check4logFOURj Linux 59 | * Description: Runs checks on selected Linux asset(s) in order to find possible log4j instances 60 | * Step 1: 61 | * Name: Upload check script 62 | * Type: Download File from ASGARD MC 63 | * Step 2: 64 | * Name: Execute check script 65 | * Type: Run Command Line on Endsystem 66 | * Commands: 67 | - `chmod u+x check4logFOURj.sh` 68 | - `bash check4logFOURj.sh` 69 | * Step 3: 70 | * Name: Download results 71 | * Type: Upload File to ASGARD MC 72 | * Path to File / Directory: results 73 | * Is Directory: checked 74 | * Recursively: checked 75 | 76 | ### Overview - check4logFOURj Windows Playbook 77 | 78 | ![08.png](img/08.png) 79 | 80 | Text transcription of the screenshot: 81 | * Name: check4logFOURj Windows 82 | * Description: Runs checks on selected Windows asset(s) in order to find possible log4j instances 83 | * Step 1: 84 | * Name: Upload check script 85 | * Type: Download File from ASGARD MC 86 | * Step 2: 87 | * Name: Execute check script 88 | * Type: Run Command Line on Endsystem 89 | * Commands: 90 | - `powershell -exec bypass .\check4logFOURj.ps1` 91 | * Step 3: 92 | * Name: Download results 93 | * Type: Upload File to ASGARD MC 94 | * Path to File / Directory: results 95 | * Is Directory: checked 96 | * Recursively: checked 97 | 98 | ## The Evaluation Script 99 | The evaluation script can be found in this repository at [evaluation-script](evaluation-script). The script takes ZIP files generated by ASGARD Group Tasks (issued under Response Control) 100 | and outputs as text directly on the command line and offers flags to output json or csv files. 101 | 102 | ### Run a Group Task Example: 103 | 104 | The evaluation script expects the results of the playbooks defined here. Also the script expects the results in a ZIP archive. So if you only plan to scan one system, scan it with a Group Task. 105 | 106 | ![09.png](img/09.png) 107 | 108 | ### Evaluation Script Examples 109 | 110 | The help text: 111 | 112 | ```none 113 | python evalPB.py --help 114 | usage: evalPB.py [-h] [-v] [--json JSONPATH] [--csv CSVPATH] inputfile [inputfile ...] 115 | 116 | Evaluate Playbook Results 117 | 118 | positional arguments: 119 | inputfile Input Zip file(s) downloaded from ASGARD Playbook 120 | 121 | options: 122 | -h, --help show this help message and exit 123 | -v, --verbose Also print low level events (not containing a vulnerable log4j2 version string) 124 | --json JSONPATH Dump results into json with the given path 125 | --csv CSVPATH Dump results into csv with the given path 126 | ``` 127 | 128 | Save output as CSV: 129 | 130 | ```none 131 | python evalPB.py --csv log4j-inventory.csv results-1234.zip 132 | ``` 133 | 134 | Add verbose outputs (Does not filter out non-vulnerable versions, but therefore contains findings without any version string present): 135 | 136 | ```none 137 | python evalPB.py --verbose --csv log4j-inventory.csv results-1234.zip 138 | ``` 139 | 140 | You can also add multiple playbook results (e.g. from Windows and Linux hosts): 141 | ```none 142 | python evalPB.py --verbose --csv log4j-inventory.csv results-win.zip results-lin.zip 143 | ``` 144 | 145 | The result can then be evaluated with an auto filter table: 146 | 147 | ![10.png](img/10.png) 148 | 149 | -------------------------------------------------------------------------------- /log4j-analysis/evaluation-script/evalPB.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | from typing import Optional 6 | import zipfile 7 | import argparse 8 | import tempfile 9 | import os 10 | import tarfile 11 | import re 12 | import datetime 13 | import json 14 | import csv 15 | import shutil 16 | 17 | #Main Dictionary that carries all results globally 18 | results = {} 19 | 20 | def main(): 21 | parser = argparse.ArgumentParser(description='Evaluate Playbook Results') 22 | parser.add_argument('inputfile', help='Input Zip file(s) downloaded from ASGARD Playbook', nargs='+') 23 | parser.add_argument('-v', '--vulnerable', dest='vulnerable', help='Only print findings of vulnarable versions', action="store_true") 24 | parser.add_argument('--json', dest='jsonpath', help='Dump results into json with the given path') 25 | parser.add_argument('--csv', dest='csvpath', help='Dump results into csv with the given path') 26 | try: 27 | args = parser.parse_args() 28 | except argparse.ArgumentError as exc: 29 | print (exc.message, '\n', exc.argument) 30 | return 1 31 | 32 | #Match for these: log4j-api-2.12.1.jar - all versions from 2.0.0 to 2.15.* 33 | log4jre = re.compile(".+log4j-.{0,10}(2\.([0-9]\.|1[0-5])\.[0-9]+).*") 34 | 35 | # Setup Temporary directory 36 | try: 37 | workdir = tempfile.mkdtemp(dir='.') 38 | except Exception as err: 39 | print("Something went wrong while creating tmp workdir: "+err) 40 | 41 | try: 42 | for infile in args.inputfile: 43 | with zipfile.ZipFile(infile, 'r') as zip_ref: 44 | zip_ref.extractall(workdir) 45 | except Exception as err: 46 | print("Error with open zip file:"+ str(err)) 47 | return 1 48 | 49 | # Walk over the dict in search for the downloaded result files 50 | try: 51 | for root, dirs, files in os.walk(workdir): 52 | for file in files: 53 | # Only unpack the Files from "step-3" which are the downloaded result files 54 | if '-step-3-' in file: 55 | with tarfile.open(os.path.join(root,file), 'r:gz') as tfile: 56 | tfile.extractall(path=workdir+"") 57 | # Remove Tar.GZ file 58 | os.remove(os.path.join(root,file)) 59 | except Exception as err: 60 | print("Something went wrong while extracting the tarfiles: "+ str(err)) 61 | 62 | validfileendings = ["processes","fsfiles", "openfiles", "jndiclass"] 63 | # Walk over every file thats now in the directory 64 | for root, dirs, files in os.walk(workdir): 65 | for file in files: 66 | # Check for the filetype, only analyze known filetypes 67 | ending = file.split(".") 68 | if not ending[-1] in validfileendings: 69 | continue 70 | type = ending[-1] 71 | 72 | host, datet = parsefilename(file) 73 | 74 | # Open file and do the checks 75 | try: 76 | with open(os.path.join(root,file)) as fileReader: 77 | 78 | for line in fileReader: 79 | line = line.strip() 80 | # Skip empty lines 81 | if line == "": 82 | continue 83 | 84 | event = {} 85 | 86 | event["host"] = host 87 | event["date"] = datet 88 | event["type"] = type 89 | 90 | # By default, the event just logs the line 91 | event["event"] = line 92 | 93 | # Default event level is low 94 | event["level"] = "low" 95 | 96 | # Events of type jndiclass are always high 97 | if event["type"] == "jndiclass": 98 | event["level"] = "high" 99 | 100 | # Do the Regex Version check 101 | matches = log4jre.match(line) 102 | if matches: 103 | # If the detected log4j version is vulnarable, set event level to high 104 | event["level"] = "high" 105 | # Prefix the logline with the detected log4j version 106 | event["event"] = "log4j Version: "+matches[1]+" - "+ event["event"] 107 | 108 | add2dict(host, event) 109 | 110 | except Exception as err: 111 | print("Something went wrong with reading the result files: " +str(err)) 112 | try: 113 | # Dump as json 114 | if args.jsonpath: 115 | path = args.jsonpath 116 | with open(path, 'w') as fp: 117 | json.dump(results, fp,indent=2, sort_keys=True) 118 | 119 | # Dump as csv 120 | if args.csvpath: 121 | path = args.csvpath 122 | with open(path, 'w') as csvfile: 123 | w = csv.DictWriter(csvfile, ["Host", "Level", "Type", "Event"]) 124 | w.writeheader() 125 | for host in results: 126 | for event in results[host]["events"]: 127 | w.writerow({"Host":event["host"],"Level":event["level"], "Type":event["type"],"Event": event["event"]}) 128 | except Exception as err: 129 | print("Something went wrong while dumping files: " + str(err)) 130 | 131 | # Print Out Results in STDOUT 132 | for host in results: 133 | for event in results[host]["events"]: 134 | # Print all events when vulnerable is false 135 | if args.vulnerable == False: 136 | printevent( event) 137 | # Otherwise just print only high events 138 | elif event["level"] == "high": 139 | printevent( event) 140 | 141 | try: 142 | # Remove TMP Directory 143 | shutil.rmtree(workdir) 144 | except Exception as err: 145 | print("Something went wrong while cleaning up: "+str(err)) 146 | return 147 | 148 | def printevent( event): 149 | print("HOST: "+event["host"] + "; LEVEL: " + event["level"] + "; TYPE: "+event["type"]+"; EVENT: "+ event["event"]) 150 | 151 | def add2dict(host, event): 152 | # Add event to the dictionary 153 | if host in results: 154 | results[host]["events"].append(event) 155 | else: 156 | # Initialize the host in the dict 157 | results[host] = {} 158 | results[host]["events"] = [event] 159 | 160 | def parsefilename(file): 161 | # Parse the filenames for the Host and the date. Example filename: 162 | # DESKTOP-SV334Q3_check4logFOURj_2021-12-15_1442.win.fsfiles 163 | regex = re.compile("(.+)_check4logFOURj_(.+)\..+\..+") 164 | matches = regex.match(file) 165 | 166 | hostname = matches[1] 167 | dtime = str(datetime.datetime.strptime(matches[2], '%Y-%m-%d_%H%M')) 168 | return hostname, dtime 169 | 170 | 171 | 172 | if __name__ == '__main__': 173 | sys.exit(main()) 174 | 175 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------