├── samples ├── demo-qa-issues.yar ├── demo2.yar ├── demo-broken.yar ├── demo-bad.yar ├── private-rule-example.yar ├── demo.yar ├── demo3.yar └── gen_webshells.yar ├── .gitignore ├── README.md └── LICENSE /samples/demo-qa-issues.yar: -------------------------------------------------------------------------------- 1 | 2 | rule Demo_Rule_2_Short_Atom : APT { 3 | meta: 4 | description = "Rule that has a short atom" 5 | author = "Florian Roth" 6 | date = "2023-01-04" 7 | reference = "https://github.com/Neo23x0/yaraQA" 8 | score = 0 9 | strings: 10 | $s1 = { 01 02 03 } 11 | condition: 12 | all of them 13 | } 14 | -------------------------------------------------------------------------------- /samples/demo2.yar: -------------------------------------------------------------------------------- 1 | 2 | rule HKTL_EXPL_POC_LibSSH_Auth_Bypass_CVE_2023_2283_Jun23_1 { 3 | meta: 4 | myinf = "Detects POC code used in attacks against libssh vulnerability CVE-2023-2283" 5 | author = "Florian Roth" 6 | score = 85 7 | url = "https://www.test.de" 8 | date = "2023-10-01" 9 | id = "ccd8d370af123" 10 | strings: 11 | $s1 = "nprocs = %d" ascii fullword 12 | $s2 = "fork failed: %s" ascii fullword 13 | condition: 14 | uint16(0) == 0x457f and all of them 15 | } 16 | -------------------------------------------------------------------------------- /samples/demo-broken.yar: -------------------------------------------------------------------------------- 1 | rule Rule_With_Issue { 2 | meta: 3 | description = "This is a broken rule" 4 | author = "Florian Roth" 5 | date = "2023-11-07" 6 | strings: 7 | $a1 = "this is a test" 8 | $a2 = "another string for the test" 9 | condition: 10 | 3 of them 11 | } 12 | 13 | rule Rule_With_Error { 14 | meta: 15 | description = "This is a broken rule" 16 | author = "Florian Roth" 17 | date = "2023-11-07" 18 | strings: 19 | $a1 = "this is a test" 20 | $a2 = "another string for the test" 21 | condition: 22 | all of ($s*) 23 | } 24 | -------------------------------------------------------------------------------- /samples/demo-bad.yar: -------------------------------------------------------------------------------- 1 | rule Linux_Trojan_Iroffer_53692410 { 2 | meta: 3 | author = "Elastic Security" 4 | id = "53692410-4213-4550-890e-4c62867937bc" 5 | fingerprint = "f070ee35ad42d9d30021cc2796cfd2859007201c638f98f42fdbec25c53194fb" 6 | creation_date = "2021-01-12" 7 | last_modified = "2021-09-16" 8 | threat_name = "Linux.Trojan.Iroffer" 9 | reference_sample = "e76508141970efb3e4709bcff83772da9b10169c599e13e58432257a7bb2defa" 10 | severity = 100 11 | arch_context = "x86" 12 | scan_context = "file, memory" 13 | license = "Elastic License v2" 14 | os = "linux" 15 | strings: 16 | $a = { 69 6E 67 20 55 6E 6B 6E 6F 77 6E 20 4D 73 67 6C 6F 67 20 54 61 67 } 17 | condition: 18 | all of them 19 | } 20 | 21 | 22 | rule CISA_10478915_01 : trojan installs_other_components { 23 | meta: 24 | author = "CISA Code & Media Analysis" 25 | incident = "10478915" 26 | date = "2023-11-06" 27 | last_modified = "20231108_1500" 28 | actor = "n/a" 29 | family = "n/a" 30 | capabilities = "installs-other-components" 31 | malware_Type = "trojan" 32 | tool_type = "information-gathering" 33 | description = "Detects trojan .bat samples" 34 | sha256 = "98e79f95cf8de8ace88bf223421db5dce303b112152d66ffdf27ebdfcdf967e9" 35 | id = "db351fe25ae9d5f2f" 36 | strings: 37 | $s1 = { 63 3a 5c 77 69 6e 64 6f 77 73 5c 74 61 73 6b 73 5c 7a 2e 74 78 74 } 38 | $s2 = { 72 65 67 20 73 61 76 65 20 68 6b 6c 6d 5c 73 79 73 74 65 6d 20 63 3a 5c 77 69 6e 64 6f 77 73 5c 74 61 73 6b 73 5c 65 6d } 39 | $s3 = { 6d 61 6b 65 63 61 62 20 63 3a 5c 75 73 65 72 73 5c 70 75 62 6c 69 63 5c 61 2e 70 6e 67 20 63 3a 5c 77 69 6e 64 6f 77 73 5c 74 61 73 6b 73 5c 61 2e 63 61 62 } 40 | condition: 41 | uint16(0) == 0x6540 and all of them 42 | } 43 | -------------------------------------------------------------------------------- /samples/private-rule-example.yar: -------------------------------------------------------------------------------- 1 | private rule ELF 2 | { 3 | strings: 4 | $h01 = { 7F 45 4C 46 (01|02) (01|02) 01 } 5 | condition: 6 | $h01 at 0 7 | } 8 | 9 | private rule EXE 10 | { 11 | condition: 12 | uint16(0) == 0x5A4D and uint32(uint32(0x3C)) == 0x00004550 13 | } 14 | 15 | rule manjusaka_payload_encoded_hexstring 16 | { 17 | meta: 18 | author = "Avast Threat Intel Team" 19 | source = "https://github.com/avast/ioc" 20 | strings: 21 | // ELF v01 and v02 22 | $s01 = "1f8b08000000000000ff7cdd099c1ae5fd3ff031e620c6038d5aea493df18a24c688372626c1180d468d78d465b34b96357be0ee2612354ab5553caa68ad454d158f2a566b51ab454d2dde" 23 | // ELF v03 (dev) 24 | $s02 = "1f8b08000000000000ff94dd09982355d9fffd62d89a45880a181621804240c10888718328a8ed864144a3029d66ba67d2cc4c4fecee8180a85114f3284b4096b00d619380085111f3284a" 25 | // ELF v03 26 | $s03 = "1f8b08000000000000ff94dd0b982355b5fffde21eee011503a204440d201001317a148278890a1804348ad269667a260d3d33b1bb19820246bc10914bb80811618c80108f084110232204" 27 | // ELF v04 28 | $s04 = "1f8b08000000000000ff94dd07981bd5d9fffdb131208a41b4075123ba280101c6112d88d04468a22b01b25abc6b6bf17aadecae4140008540103582001110401483e8a28b2e4a4074d197" 29 | // MZ v01 30 | $s11 = "1f8b08000000000000ffecbd09784cd7ff077c26c924631977828958c284694d5092da12eb8448ce302108a248628ba82d65862025e924b8aeabdaeaa2abb6bfaebad74f83fe4804a1d5d6" 31 | // MZ v02 32 | $s12 = "1f8b08000000000000ffecbd097414c5faff5d9d7502849e400209201974c4441113371240c8842cd5d00361070502224bdc403203a82c8993d1146d2b7ac5e5ba5cdcb9aea85c36176612" 33 | // MZ v03 (dev) 34 | $s13 = "1f8b08000000000000ffecbd7b7854d5d928be7632496620710d4874522e9991ad4e94627641491425031378b7ae1150046a1168a1237ca2419801542e893b53b3d8eeafb4b5777b8eb5fd" 35 | // MZ v03 36 | $s14 = "1f8b08000000000000ffecbd7b7854d5d530be4f32496620710f9ae8a45c3223479d28d51c414934960c4c601ddd23a811a845a0858e50d120cc002a97c49369b3399e96b6dacb5bfb7dbe" 37 | // MZ v04 38 | $s15 = "1f8b08000000000000ffecbd79785445d6305eb7934e3a90e676846887451abc68c7b5e33293284b37e924a7e506a222a022c45119501c23744b1c194ce6764b2a97abcc88233a3aaee38a" 39 | condition: 40 | (EXE or ELF) and ( 41 | any of ($s0*) and 42 | any of ($s1*) 43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /samples/demo.yar: -------------------------------------------------------------------------------- 1 | import "pe" 2 | 3 | rule LOG_F5_BIGIP_Exploitation_Artefacts_CVE_2021_22986_Mar21_1 : LOG { 4 | meta: 5 | description = "Detects forensic artefacts indicating successful exploitation of F5 BIG IP appliances as reported by NCCGroup" 6 | reference = "https://research.nccgroup.com/2021/03/18/rift-detection-capabilities-for-recent-f5-big-ip-big-iq-icontrol-rest-api-vulnerabilities-cve-2021-22986/" 7 | status = "experimental" 8 | my_bogus_date = "01.01.2020" 9 | id = "ab48d370af123" 10 | strings: 11 | $x1 = "\",\"method\":\"POST\",\"uri\":\"http://localhost:8100/mgmt/tm/util/bash\",\"status\":200," ascii 12 | $x2 = "[com.f5.rest.app.RestServerServlet] X-F5-Auth-Token doesn't have value, so skipping" ascii 13 | condition: 14 | 1 of them 15 | } 16 | 17 | rule SUSP_ThemeBleed_Theme_Sep23 { 18 | meta: 19 | description = "Detects domain or IP placement in Windows theme files" 20 | author = "@m_haggis, @nas_bench" 21 | reference = "https://github.com/gabe-k/themebleed" 22 | score = 75 23 | strings: 24 | $s1 = /Path=\\\\[0-9a-zA-Z\.-]{1,20}\\/ 25 | $s2 = "[VisualStyles]" 26 | $s3 = "[Theme]" 27 | 28 | condition: 29 | filesize < 1MB and all of them 30 | } 31 | 32 | rule SUSP_Bad_Regex_Sep23 { 33 | meta: 34 | description = "Detects a bad regex" 35 | author = "Noob" 36 | reference = "https://github.com/gabe-k/themebleed" 37 | score = 75 38 | strings: 39 | $sr1 = /[\w\-.]{1,3}@[\w\-.]{1,3}/ 40 | condition: 41 | $sr1 42 | } 43 | 44 | rule WinnieThePooh{ 45 | meta: 46 | desc = "Detects a fictional malware named WinnieThePooh exploiting CVE-2021-1675" 47 | author = "Florian's Evil Twin" 48 | url = "https://en.wikipedia.org/wiki/Censorship_of_Winnie-the-Pooh_in_China" 49 | created = "2021-06-29" 50 | modified = "2023-12-13" 51 | tags = "rat, arcom" 52 | strings: 53 | $x1 = "\\WinnieThePooh.pdb" ascii 54 | $x2 = "\\pipe\\WinnieThePooh" ascii 55 | 56 | $s1 = "] dumping creds" 57 | $s2 = "\\temp\\lsass.dmp" 58 | condition: 59 | uint16(0) == 0x5A4D 60 | and filesize < 1MB 61 | and ( 62 | 1 of ($x*) 63 | or 2 of them 64 | ) 65 | and not pe.number_of_signatures > 0 66 | } 67 | -------------------------------------------------------------------------------- /samples/demo3.yar: -------------------------------------------------------------------------------- 1 | rule win_cobalt_sleep_encrypt 2 | { 3 | meta: 4 | author = "Matthew @ Embee_Research" 5 | created = "2023/08/27" 6 | info = "Detects Sleep Encryption Logic Found in Cobalt Strike Deployments" 7 | sha_256 = "26b2f12906c3590c8272b80358867944fd86b9f2cc21ee6f76f023db812e5bb1" 8 | sha_1 = "14b1a681fea9c0833f20ecc6ef231dfb7cc62a3d" 9 | strings: 10 | 11 | /* 12 | Encryption Round 1 / Decrypt Code 13 | 0000000000CCFD2E | 4E:8B0408 | mov r8,qword ptr ds:[rax+r9] 14 | 0000000000CCFD32 | B8 4FECC44E | mov eax,4EC4EC4F 15 | 0000000000CCFD37 | 41:F7E3 | mul r11d 16 | 0000000000CCFD3A | 41:8BC3 | mov eax,r11d 17 | 0000000000CCFD3D | C1EA 02 | shr edx,2 18 | 0000000000CCFD40 | 41:FFC3 | inc r11d 19 | 0000000000CCFD43 | 6BD2 0D | imul edx,edx,D 20 | 0000000000CCFD46 | 2BC2 | sub eax,edx 21 | 0000000000CCFD48 | 8A4C18 18 | mov cl,byte ptr ds:[rax+rbx+18] 22 | 0000000000CCFD4C | 41:300C38 | xor byte ptr ds:[r8+rdi],cl 23 | 0000000000CCFD50 | 48:8B43 10 | mov rax,qword ptr ds:[rbx+10] 24 | 0000000000CCFD54 | 41:8BFB | mov edi,r11d 25 | 0000000000CCFD57 | 4A:3B7C08 08 | cmp rdi,qword ptr ds:[rax+r9+8] 26 | 27 | Encryption Round 2 / Possible Re-encrypt Code 28 | 0000000000CCFD93 | 49:8BF9 | mov rdi,r9 29 | 0000000000CCFD96 | 4C:8B03 | mov r8,qword ptr ds:[rbx] 30 | 0000000000CCFD99 | B8 4FECC44E | mov eax,4EC4EC4F 31 | 0000000000CCFD9E | 41:F7E1 | mul r9d 32 | 0000000000CCFDA1 | 41:8BC1 | mov eax,r9d 33 | 0000000000CCFDA4 | C1EA 02 | shr edx,2 34 | 0000000000CCFDA7 | 41:FFC1 | inc r9d 35 | 0000000000CCFDAA | 6BD2 0D | imul edx,edx,D 36 | 0000000000CCFDAD | 2BC2 | sub eax,edx 37 | 0000000000CCFDAF | 8A4C18 18 | mov cl,byte ptr ds:[rax+rbx+18] 38 | 0000000000CCFDB3 | 42:300C07 | xor byte ptr ds:[rdi+r8],cl 39 | 0000000000CCFDB7 | 48:FFC7 | inc rdi 40 | 0000000000CCFDBA | 45:3BCB | cmp r9d,r11d 41 | 42 | */ 43 | 44 | 45 | $r1_nokey = {4E 8B 04 08 B8 ?? ?? ?? ?? 41 F7 E3 41 8B C3 C1 EA 02 41 FF C3 6B D2 0D 2B C2 8A 4C 18 18 41 30 0C 38 48 8B 43 10 41 8B FB 4A 3B 7C 08 08} 46 | 47 | $r2_nokey = {49 8B F9 4C 8B 03 B8 ?? ?? ?? ?? 41 F7 E1 41 8B C1 C1 EA 02 41 FF C1 6B D2 0D 2B C2 8A 4C 18 18 42 30 0C 07 48 FF C7 45 3B CB} 48 | 49 | condition: 50 | //uint16(0) == 0x5a4d and 51 | //filesize < 3000KB and 52 | ($r1_nokey or $r2_nokey) 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /samples/gen_webshells.yar: -------------------------------------------------------------------------------- 1 | import "math" 2 | // only needed for debugging of module math: 3 | //import "console" 4 | 5 | rule WEBSHELL_ASP_OBFUSC 6 | { 7 | meta: 8 | description = "ASP webshell obfuscated" 9 | license = "Detection Rule License 1.1 https://github.com/Neo23x0/signature-base/blob/master/LICENSE" 10 | author = "Arnim Rupp (https://github.com/ruppde)" 11 | reference = "Internal Research" 12 | score = 75 13 | date = "2021/01/12" 14 | modified = "2023-07-05" 15 | hash = "ad597eee256de51ffb36518cd5f0f4aa0f254f27517d28fb7543ae313b15e112" 16 | hash = "e0d21fdc16e0010b88d0197ebf619faa4aeca65243f545c18e10859469c1805a" 17 | hash = "54a5620d4ea42e41beac08d8b1240b642dd6fd7c" 18 | hash = "fc44fd7475ee6c0758ace2b17dd41ed7ea75cc73" 19 | hash = "be2fedc38fc0c3d1f925310d5156ccf3d80f1432" 20 | hash = "3175ee00fc66921ebec2e7ece8aa3296d4275cb5" 21 | hash = "d6b96d844ac395358ee38d4524105d331af42ede" 22 | hash = "cafc4ede15270ab3f53f007c66e82627a39f4d0f" 23 | 24 | strings: 25 | $asp_obf1 = "/*-/*-*/" wide ascii 26 | $asp_obf2 = "u\"+\"n\"+\"s" wide ascii 27 | $asp_obf3 = "\"e\"+\"v" wide ascii 28 | $asp_obf4 = "a\"+\"l\"" wide ascii 29 | $asp_obf5 = "\"+\"(\"+\"" wide ascii 30 | $asp_obf6 = "q\"+\"u\"" wide ascii 31 | $asp_obf7 = "\"u\"+\"e" wide ascii 32 | $asp_obf8 = "/*//*/" wide ascii 33 | 34 | //strings from private rule capa_asp 35 | $tagasp_short1 = /<%[^"]/ wide ascii 36 | // also looking for %> to reduce fp (yeah, short atom but seldom since special chars) 37 | $tagasp_short2 = "%>" wide ascii 38 | 39 | // classids for scripting host etc 40 | $tagasp_classid1 = "72C24DD5-D70A-438B-8A42-98424B88AFB8" nocase wide ascii 41 | $tagasp_classid2 = "F935DC22-1CF0-11D0-ADB9-00C04FD58A0B" nocase wide ascii 42 | $tagasp_classid3 = "093FF999-1EA0-4079-9525-9614C3504B74" nocase wide ascii 43 | $tagasp_classid4 = "F935DC26-1CF0-11D0-ADB9-00C04FD58A0B" nocase wide ascii 44 | $tagasp_classid5 = "0D43FE01-F093-11CF-8940-00A0C9054228" nocase wide ascii 45 | $tagasp_long10 = "<%@ " wide ascii 46 | // <% eval 47 | $tagasp_long11 = /<% \w/ nocase wide ascii 48 | $tagasp_long12 = "<%ex" nocase wide ascii 49 | $tagasp_long13 = "<%ev" nocase wide ascii 50 | 51 | // <%@ LANGUAGE = VBScript.encode%> 52 | // <%@ Language = "JScript" %> 53 | 54 | // <%@ WebHandler Language="C#" class="Handler" %> 55 | // <%@ WebService Language="C#" Class="Service" %> 56 | 57 | // <%@Page Language="Jscript"%> 58 | // <%@ Page Language = Jscript %> 59 | // <%@PAGE LANGUAGE=JSCRIPT%> 60 | // <%@ Page Language="Jscript" validateRequest="false" %> 61 | // <%@ Page Language = Jscript %> 62 | // <%@ Page Language="C#" %> 63 | // <%@ Page Language="VB" ContentType="text/html" validaterequest="false" AspCompat="true" Debug="true" %> 64 | //