yara 分析器

article/2025/9/23 8:00:22

1.下载源码

wget https://github.com/VirusTotal/yara/archive/refs/tags/v4.2.3.tar.gz

2.预编译

tar -zxf yara-4.2.0.tar.gz
cd yara-4.2.0
./bootstrap.shyum -y install automake libtool make gcc pkg-config
yum -y flex bison

3.编译与安装

./bootstrap.sh
./configure
make
sudo make install

4.跑测试用例

[root@localhost yara-4.2.3]# make check
Making check in libyara
make[1]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make  check-am
make[2]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make[2]: Nothing to be done for `check-am'.
make[2]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make[1]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make[1]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3'
make  test-arena test-alignment test-atoms test-api test-rules test-pe test-elf test-version test-bitmask test-math test-stack test-re-split test-async test-exception   test-dotnet  
make[2]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3'
make[2]: `test-arena' is up to date.
make[2]: `test-alignment' is up to date.
make[2]: `test-atoms' is up to date.
make[2]: `test-api' is up to date.
make[2]: `test-rules' is up to date.
make[2]: `test-pe' is up to date.
make[2]: `test-elf' is up to date.
make[2]: `test-version' is up to date.
make[2]: `test-bitmask' is up to date.
make[2]: `test-math' is up to date.
make[2]: `test-stack' is up to date.
make[2]: `test-re-split' is up to date.
make[2]: `test-async' is up to date.
make[2]: `test-exception' is up to date.
make[2]: `test-dotnet' is up to date.
make[2]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3'
make  check-TESTS
make[2]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3'
make[3]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3'
PASS: test-arena
PASS: test-alignment
PASS: test-atoms
PASS: test-api
PASS: test-rules
PASS: test-pe
PASS: test-elf
PASS: test-version
PASS: test-bitmask
PASS: test-math
PASS: test-stack
PASS: test-re-split
PASS: test-async
PASS: test-exception
PASS: test-dotnet
make[4]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3'
Making all in libyara
make[5]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make  all-am
make[6]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make[6]: Nothing to be done for `all-am'.
make[6]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make[5]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3/libyara'
make[5]: Entering directory `/mnt/hgfs/GitHub/yara-4.2.3'
make[5]: Nothing to be done for `all-am'.
make[5]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3'
make[4]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3'
============================================================================
Testsuite summary for yara 4.2.3
============================================================================
# TOTAL: 15
# PASS:  15
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
make[3]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3'
make[2]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3'
make[1]: Leaving directory `/mnt/hgfs/GitHub/yara-4.2.3'

5.待分析文件,手动分析

查看文件详细信息

[root@localhost yara-4.2.3]# file tests/data/tiny-idata-5200 
tests/data/tiny-idata-5200: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows

以十六进制导出文件

[root@localhost yara-4.2.3]# hexdump tests/data/tiny-idata-5200 
0000000 5a4d 0090 0003 0000 0004 0000 ffff 0000
0000010 00b8 0000 0000 0000 0040 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000 0000 0000
0000030 0000 0000 0000 0000 0000 0000 0080 0000
0000040 1f0e 0eba b400 cd09 b821 4c01 21cd 6854
0000050 7369 7020 6f72 7267 6d61 6320 6e61 6f6e
0000060 2074 6562 7220 6e75 6920 206e 4f44 2053
0000070 6f6d 6564 0d2e 0a0d 0024 0000 0000 0000
0000080 4550 0000 014c 0007 56b8 56fc 0000 0000
0000090 0000 0000 00e0 030f 010b 1a02 2000 0000
00000a0 7000 0000 1000 0000 14e0 0000 1000 0000
00000b0 3000 0000 0000 0040 1000 0000 1000 0000
00000c0 0004 0000 0001 0000 0004 0000 0000 0000
00000d0 9000 0000 1000 0000 a8dc 0000 0003 0000
00000e0 0000 0020 1000 0000 0000 0010 1000 0000
00000f0 0000 0000 0010 0000 0000 0000 0000 0000
0000100 6000 0000 0590 0000 0000 0000 0000 0000
0000110 0000 0000 0000 0000 0000 0000 0000 0000
*
0000140 8004 0000 0018 0000 0000 0000 0000 0000
0000150 0000 0000 0000 0000 6104 0000 00c8 0000
0000160 0000 0000 0000 0000 0000 0000 0000 0000
0000170 0000 0000 0000 0000 742e 7865 0074 0000
0000180 1774 0000 1000 0000 2000 0000 1000 0000
0000190 0000 0000 0000 0000 0000 0000 0060 6050
00001a0 642e 7461 0061 0000 0030 0000 3000 0000
00001b0 1000 0000 3000 0000 0000 0000 0000 0000
00001c0 0000 0000 0040 c030 722e 6164 6174 0000
00001d0 0550 0000 4000 0000 1000 0000 4000 0000
00001e0 0000 0000 0000 0000 0000 0000 0040 4030
00001f0 622e 7373 0000 0000 0400 0000 5000 0000
0000200 0000 0000 0000 0000 0000 0000 0000 0000
0000210 0000 0000 0080 c060 692e 6164 6174 0000
0000220 0590 0000 6000 0000 1000 0000 5200 0000
0000230 0000 0000 0000 0000 0000 0000 0040 c030
0000240 432e 5452 0000 0000 0034 0000 7000 0000
0000250 1000 0000 6000 0000 0000 0000 0000 0000
0000260 0000 0000 0040 c030 742e 736c 0000 0000
0000270 0020 0000 8000 0000 1000 0000 7000 0000
0000280 0000 0000 0000 0000 0000 0000 0040 c030
0000290 0000 0000 0000 0000 0000 0000 0000 0000

各个段和符号表的信息

[root@localhost yara-4.2.3]# objdump -x tests/data/tiny-idata-5200 tests/data/tiny-idata-5200:     file format pei-i386
tests/data/tiny-idata-5200
architecture: i386, flags 0x00000102:
EXEC_P, D_PAGED
start address 0x004014e0Characteristics 0x30frelocations strippedexecutableline numbers strippedsymbols stripped32 bit wordsdebugging information removedTime/Date		Thu Mar 31 06:44:08 2016
Magic			010b	(PE32)
MajorLinkerVersion	2
MinorLinkerVersion	26
SizeOfCode		00002000
SizeOfInitializedData	00007000
SizeOfUninitializedData	00001000
AddressOfEntryPoint	000014e0
BaseOfCode		00001000
BaseOfData		00003000
ImageBase		00400000
SectionAlignment	00001000
FileAlignment		00001000
MajorOSystemVersion	4
MinorOSystemVersion	0
MajorImageVersion	1
MinorImageVersion	0
MajorSubsystemVersion	4
MinorSubsystemVersion	0
Win32Version		00000000
SizeOfImage		00009000
SizeOfHeaders		00001000
CheckSum		0000a8dc
Subsystem		00000003	(Windows CUI)
DllCharacteristics	00000000
SizeOfStackReserve	00200000
SizeOfStackCommit	00001000
SizeOfHeapReserve	00100000
SizeOfHeapCommit	00001000
LoaderFlags		00000000
NumberOfRvaAndSizes	00000010The Data Directory
Entry 0 00000000 00000000 Export Directory [.edata (or where ever we found it)]
Entry 1 00006000 00000590 Import Directory [parts of .idata]
Entry 2 00000000 00000000 Resource Directory [.rsrc]
Entry 3 00000000 00000000 Exception Directory [.pdata]
Entry 4 00000000 00000000 Security Directory
Entry 5 00000000 00000000 Base Relocation Directory [.reloc]
Entry 6 00000000 00000000 Debug Directory
Entry 7 00000000 00000000 Description Directory
Entry 8 00000000 00000000 Special Directory
Entry 9 00008004 00000018 Thread Storage Directory [.tls]
Entry a 00000000 00000000 Load Configuration Directory
Entry b 00000000 00000000 Bound Import Directory
Entry c 00006104 000000c8 Import Address Table Directory
Entry d 00000000 00000000 Delay Import Directory
Entry e 00000000 00000000 CLR Runtime Header
Entry f 00000000 00000000 ReservedThere is an import table in .idata at 0x406000The Import Tables (interpreted .idata section contents)vma:            Hint    Time      Forward  DLL       FirstTable   Stamp     Chain    Name      Thunk00006000	72754374 746e6572 636f7250 00737365 654701c5Sections:
Idx Name          Size      VMA       LMA       File off  Algn0 .text         00001774  00401000  00401000  00001000  2**4CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA1 .data         00000030  00403000  00403000  00003000  2**2CONTENTS, ALLOC, LOAD, DATA2 .rdata        00000550  00404000  00404000  00004000  2**2CONTENTS, ALLOC, LOAD, READONLY, DATA3 .bss          00000400  00405000  00405000  00000000  2**5ALLOC4 .idata        00000590  00406000  00406000  00005200  2**2CONTENTS, ALLOC, LOAD, DATA5 .CRT          00000034  00407000  00407000  00006000  2**2CONTENTS, ALLOC, LOAD, DATA6 .tls          00000020  00408000  00408000  00007000  2**2CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
no symbols

readelf命令查看各个段的详细信息

[root@localhost yara-4.2.3]# readelf -a tests/data/tiny-idata-5200
readelf: tests/data/tiny-idata-5200: Error: Not an ELF file - it has the wrong magic bytes at the start

使用readelf读tiny-idata-5200文件出错了,这是因为readelf是读取linux下的elf格式的文件,然而tiny-idata-5200是windows下的pe格式,需要使用readpe来读取

PE(Portable Executable)意为可移植的可执行的文件,常见的EXE、DLL、OCX、SYS、COM都是PE格式文件,Windows操作系统上的程序文件(可能是间接被执行,如DLL)。
ELF(Executable and Linkable Format)意为可执行与可链接格式,一种用于二进制文件、可执行文件、目标代码、共享库和核心转储格式文件,是UNIX系统实验室(USL)作为应用程序二进制接口(Application Binary Interface,ABI)而开发和发布的,也是Linux的主要可执行文件格式。


centos中安装readpe

pip3.7 install readpe
[root@localhost yara-4.2.3]# readpe tests/data/tiny-idata-5200 -Hs
##############
# DOS_HEADER #
##############
╒══════════╤══════════════════════════════════════════╤═════════════════════╕
│ Offset   │ Name                                     │ Value               │
╞══════════╪══════════════════════════════════════════╪═════════════════════╡
│ 0x0      │ Magic number                             │ 5a4d "MZ"           │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x2      │ Bytes on last page of file               │ 0x90                │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x4      │ Pages in file                            │ 0x3                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x6      │ Relocations                              │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x8      │ Size of header in paragraphs             │ 0x4                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0xa      │ Minimum extra paragraphs needed          │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0xc      │ Maximum extra paragraphs needed          │ 0xffff              │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0xe      │ Initial (relative) SS value              │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x10     │ Initial SP value                         │ 0xb8                │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x12     │ Checksum                                 │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x14     │ Initial IP value                         │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x16     │ Initial (relative) CS value              │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x18     │ File address of relocation table         │ 0x40                │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x1a     │ Overlay number                           │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x1c     │ Reserved words[4]                        │ 0,0,0,0             │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x24     │ OEM identifier (for OEM information)     │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x26     │ OEM information; OEM identifier specific │ 0x0                 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x28     │ Reserved words[10]                       │ 0,0,0,0,0,0,0,0,0,0 │
├──────────┼──────────────────────────────────────────┼─────────────────────┤
│ 0x3c     │ File address of new exe header           │ 0x80                │
╘══════════╧══════════════════════════════════════════╧═════════════════════╛###############
# FILE_HEADER #
###############
╒══════════╤══════════════════════╤════════════╤════════════════════════════════╕
│ Offset   │ Name                 │ Value      │ Description                    │
╞══════════╪══════════════════════╪════════════╪════════════════════════════════╡
│ 0x84     │ Machine              │ 0x14c      │ IMAGE_FILE_MACHINE_I386        │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│ 0x86     │ NumberOfSections     │ 0x7        │ 7                              │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│ 0x88     │ TimeDateStamp        │ 0x56FC56B8 │ Wed Mar 30 22:44:08 2016 UTC   │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│ 0x8c     │ PointerToSymbolTable │ 0x0        │ 0                              │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│ 0x90     │ NumberOfSymbols      │ 0x0        │ 0                              │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│ 0x94     │ SizeOfOptionalHeader │ 0xe0       │ 224                            │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│ 0x96     │ Characteristics      │ 0x30f      │ 783                            │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│          │                      │ 0x1        │ IMAGE_FILE_RELOCS_STRIPPED     │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│          │                      │ 0x2        │ IMAGE_FILE_EXECUTABLE_IMAGE    │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│          │                      │ 0x4        │ IMAGE_FILE_LINE_NUMS_STRIPPED  │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│          │                      │ 0x8        │ IMAGE_FILE_LOCAL_SYMS_STRIPPED │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│          │                      │ 0x100      │ IMAGE_FILE_32BIT_MACHINE       │
├──────────┼──────────────────────┼────────────┼────────────────────────────────┤
│          │                      │ 0x200      │ IMAGE_FILE_DEBUG_STRIPPED      │
╘══════════╧══════════════════════╧════════════╧════════════════════════════════╛###################
# OPTIONAL_HEADER #
###################
╒══════════╤═════════════════════════════╤══════════╤═══════════════╕
│ Offset   │ Name                        │ Value    │ Description   │
╞══════════╪═════════════════════════════╪══════════╪═══════════════╡
│ 0x98     │ Magic                       │ 0x10b    │ NT32          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0x9a     │ MajorLinkerVersion          │ 0x2      │ 2             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0x9b     │ MinorLinkerVersion          │ 0x1a     │ 26            │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0x9c     │ SizeOfCode                  │ 0x2000   │ 8192          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xa0     │ SizeOfInitializedData       │ 0x7000   │ 28672         │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xa4     │ SizeOfUninitializedData     │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xa8     │ AddressOfEntryPoint         │ 0x14e0   │ 5344          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xac     │ BaseOfCode                  │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xb0     │ BaseOfData                  │ 0x3000   │ 12288         │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xb4     │ ImageBase                   │ 0x400000 │ 4194304       │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xb8     │ SectionAlignment            │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xbc     │ FileAlignment               │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xc0     │ MajorOperatingSystemVersion │ 0x4      │ 4             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xc2     │ MinorOperatingSystemVersion │ 0x0      │ 0             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xc4     │ MajorImageVersion           │ 0x1      │ 1             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xc6     │ MinorImageVersion           │ 0x0      │ 0             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xc8     │ MajorSubsystemVersion       │ 0x4      │ 4             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xca     │ MinorSubsystemVersion       │ 0x0      │ 0             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xcc     │ Reserved1                   │ 0x0      │ 0             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xd0     │ SizeOfImage                 │ 0x9000   │ 36864         │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xd4     │ SizeOfHeaders               │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xd8     │ CheckSum                    │ 0xa8dc   │ 43228         │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xdc     │ Subsystem                   │ 0x3      │ WINDOWS_CUI   │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xde     │ DllCharacteristics          │ 0x0      │ 0             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xe0     │ SizeOfStackReserve          │ 0x200000 │ 2097152       │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xe4     │ SizeOfStackCommit           │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xe8     │ SizeOfHeapReserve           │ 0x100000 │ 1048576       │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xec     │ SizeOfHeapCommit            │ 0x1000   │ 4096          │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xf0     │ LoaderFlags                 │ 0x0      │ 0             │
├──────────┼─────────────────────────────┼──────────┼───────────────┤
│ 0xf4     │ NumberOfRvaAndSizes         │ 0x10     │ 16            │
╘══════════╧═════════════════════════════╧══════════╧═══════════════╛####################
# DATA_DIRECTORIES #
####################
╒══════════╤══════════════════════════════════════╤═══════════════════╤════════╕
│ Offset   │ Data Directory                       │ Virtual Address   │ Size   │
╞══════════╪══════════════════════════════════════╪═══════════════════╪════════╡
│ 0xf8     │ IMAGE_DIRECTORY_ENTRY_EXPORT         │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x100    │ IMAGE_DIRECTORY_ENTRY_IMPORT         │ 0x6000            │ 0x590  │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x108    │ IMAGE_DIRECTORY_ENTRY_RESOURCE       │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x110    │ IMAGE_DIRECTORY_ENTRY_EXCEPTION      │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x118    │ IMAGE_DIRECTORY_ENTRY_SECURITY       │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x120    │ IMAGE_DIRECTORY_ENTRY_BASERELOC      │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x128    │ IMAGE_DIRECTORY_ENTRY_DEBUG          │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x130    │ IMAGE_DIRECTORY_ENTRY_COPYRIGHT      │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x138    │ IMAGE_DIRECTORY_ENTRY_GLOBALPTR      │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x140    │ IMAGE_DIRECTORY_ENTRY_TLS            │ 0x8004            │ 0x18   │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x148    │ IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x150    │ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x158    │ IMAGE_DIRECTORY_ENTRY_IAT            │ 0x6104            │ 0xc8   │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x160    │ IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x168    │ IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR │ 0x0               │ 0x0    │
├──────────┼──────────────────────────────────────┼───────────────────┼────────┤
│ 0x170    │ IMAGE_DIRECTORY_ENTRY_RESERVED       │ 0x0               │ 0x0    │
╘══════════╧══════════════════════════════════════╧═══════════════════╧════════╛
############
# SECTIONS #
############
╒════════╤═════════════╤════════════╤═════════════════╤════════════════╤═══════════════════╤═════════╤═══════════╕
│ Name   │ Raw Addr.   │ Raw Size   │ Virtual Addr.   │ Virtual Size   │ Characteristics   │ Flags   │   Entropy │
╞════════╪═════════════╪════════════╪═════════════════╪════════════════╪═══════════════════╪═════════╪═══════════╡
│ .text  │ 0x1000      │ 0x2000     │ 0x1000          │ 0x1774         │ 0x60500060        │ R-E     │ 4.89182   │
├────────┼─────────────┼────────────┼─────────────────┼────────────────┼───────────────────┼─────────┼───────────┤
│ .data  │ 0x3000      │ 0x1000     │ 0x3000          │ 0x30           │ 0xc0300040        │ RW-     │ 0.0892371 │
├────────┼─────────────┼────────────┼─────────────────┼────────────────┼───────────────────┼─────────┼───────────┤
│ .rdata │ 0x4000      │ 0x1000     │ 0x4000          │ 0x550          │ 0x40300040        │ R--     │ 2.42312   │
├────────┼─────────────┼────────────┼─────────────────┼────────────────┼───────────────────┼─────────┼───────────┤
│ .bss   │ 0x0         │ 0x0        │ 0x5000          │ 0x400          │ 0xc0600080        │ RW-     │ 0         │
├────────┼─────────────┼────────────┼─────────────────┼────────────────┼───────────────────┼─────────┼───────────┤
│ .idata │ 0x5200      │ 0x1000     │ 0x6000          │ 0x590          │ 0xc0300040        │ RW-     │ 1.59346   │
├────────┼─────────────┼────────────┼─────────────────┼────────────────┼───────────────────┼─────────┼───────────┤
│ .CRT   │ 0x6000      │ 0x1000     │ 0x7000          │ 0x34           │ 0xc0300040        │ RW-     │ 0.0447354 │
├────────┼─────────────┼────────────┼─────────────────┼────────────────┼───────────────────┼─────────┼───────────┤
│ .tls   │ 0x7000      │ 0x1000     │ 0x8000          │ 0x20           │ 0xc0300040        │ RW-     │ 0.0336544 │
╘════════╧═════════════╧════════════╧═════════════════╧════════════════╧═══════════════════╧═════════╧═══════════╛

6.yara规则匹配源码分析

测试调用入口

  assert_true_rule_file("import \"pe\" \rule test { \condition: \pe.imports(\"KERNEL32.dll\", \"DeleteCriticalSection\") \}","tests/data/tiny-idata-51ff");

参数1是否配置 

"import \"pe\" \
      rule test { \
        condition: \
          pe.imports(\"KERNEL32.dll\", \"DeleteCriticalSection\") \
      }"

参数2待配置的文件

"tests/data/tiny-idata-51ff"

 判断文件是否匹配上规则,read_file先将待分析文件整体读到buf中,然后matches_blob进行匹配

#define assert_true_rule_file(rule, filename)                           \do {                                                                  \char* buf;                                                          \size_t sz;                                                          \if ((sz = read_file(prefix_top_srcdir(filename), &buf)) == -1) {    \fprintf(stderr, "%s:%d: cannot read file '%s'\n",                 \__FILE__, __LINE__, filename);                            \exit(EXIT_FAILURE);                                               \}                                                                   \if (!matches_blob(rule, (uint8_t*) (buf), sz, NULL, 0)) {           \fprintf(stderr, "%s:%d: rule does not match contents of"          \"'%s' (but should)\n",                                    \__FILE__, __LINE__, filename);                            \exit(EXIT_FAILURE);                                               \}                                                                   \free(buf);                                                          \} while (0);

 匹配函数matches_blob

int matches_blob(char* rule,uint8_t* blob,size_t blob_size,uint8_t* module_data,size_t module_data_size)
{YR_DEBUG_FPRINTF(2, stderr, "+ %s(blob_size=%zu) {\n", __FUNCTION__, blob_size);YR_RULES* rules;if (blob == NULL){blob = (uint8_t*) "dummy";blob_size = 5;}if (compile_rule(rule, &rules) != ERROR_SUCCESS){fprintf(stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error);exit(EXIT_FAILURE);}SCAN_CALLBACK_CTX ctx = {.matches = 0,.module_data = module_data,.module_data_size = module_data_size,};int flags = SCAN_FLAGS_NO_TRYCATCH;YR_CALLBACK_FUNC callback = _scan_callback;void* user_data = &ctx;int timeout = 0;int scan_result;if (matches_blob_uses_default_iterator){scan_result = yr_rules_scan_mem(rules, blob, blob_size, flags, callback, user_data, timeout);}else{YR_SCANNER* scanner;assert_true_expr(ERROR_SUCCESS == yr_scanner_create(rules, &scanner));yr_scanner_set_callback(scanner, callback, user_data);yr_scanner_set_timeout(scanner, timeout);yr_scanner_set_flags(scanner, flags);YR_MEMORY_BLOCK_ITERATOR iterator;YR_TEST_ITERATOR_CTX iterator_ctx;init_test_iterator(&iterator, &iterator_ctx, blob, blob_size);scan_result = yr_scanner_scan_mem_blocks(scanner, &iterator);yr_scanner_destroy(scanner);}if (scan_result != ERROR_SUCCESS){fprintf(stderr,"failed to scan using rule << %s >>: error: %d\n",rule,scan_result);exit(EXIT_FAILURE);}yr_rules_destroy(rules);YR_DEBUG_FPRINTF(2, stderr, "} = %u AKA ctx.matches // %s()\n", ctx.matches, __FUNCTION__);return ctx.matches;
}

 matches_blob调用栈流程图

参考

Getting started — yara 4.2.0 documentation

linux实践之ELF文件分析 - 走看看


http://chatgpt.dhexx.cn/article/AmFox5rY.shtml

相关文章

yara安装与使用

yara安装与使用 环境及安装工具使用yara规则编写strings部分转义大小写字符集表示匹配单个词组文本字符串 condition部分infilesizeatentrypointint8/16/32、uint8/16/32of??&#xff1f;[X-Y]them/($*)!for xxx of xxx &#xff1a;(xxx)for xxx i in (xxx) &#xff1a;(xx…

yara规则初识

一、YARA介绍 YARA 是一个免费开源工具&#xff0c;旨在帮助安全人员检测和分类恶意软件&#xff0c;但它不应仅限于这一种用途。YARA规则还可以帮助检测特定文件或您可能想要检测的任何内容。目前使用YARA 的知名软件有赛门铁克、火眼、卡巴斯基、VirusTotal、安天等。 YARA的…

Yara规则概述

一、Yara概述 YARA是一款旨在帮助恶意软件研究人员识别和分类恶意软件样本的开源工具&#xff08;由virustotal的软件工程师Victor M. Alvarezk开发&#xff09;&#xff0c;使用YARA可以基于文本或二进制模式创建恶意软件家族描述信息&#xff0c;当然也可以是其他匹配信息。…

这五个资源超多的资源网站 请务必珍藏起来

现在很多人都会在网上找资源&#xff0c;如今互联网的快速发展也让大家找起资源来非常的容易&#xff0c;只要有好的资源网站&#xff0c;就不怕没有找不到的资源。而今天我和大家分享的就是几个资源超多的网站&#xff0c;希望你们不再缺少资源。 1、落花网 这个就很厉害了&…

这5款电影资源网站,让人第一眼就心动,第二眼就流连忘返!

工作烦心了一天&#xff0c;回到家忙完事情泡一杯热腾腾的咖啡&#xff0c;拿起手机或平板&#xff0c;打开电影网站&#xff0c;惬意的躺在沙发上享受自己心仪的电影带给你的快乐时光吧&#xff01; 今天小编为大家推荐几款电影资源网站&#xff0c;喜欢的小伙伴千万不要错过&…

盘点程序员必备的免费资源网站

文章目录 1、软件资源类1、JDK国内镜像资源站2、 Arm原生 JDK&#xff08;为 M1系列Mac而生&#xff09;3、程序员大礼包 2、工具类1、在线工具2、菜鸟工具3、爱资料 2、算法&题库1、LeetCode2、LintCode3、牛客网 3、在线资源1、Github2、Stack Overflow3、CSDN4、天堂电影…

游戏美术资源网站推荐

梚辰 2022.4.25 未经授权禁止转发 最近我整理了一下以前使用过的购买游戏美术资源的网站&#xff0c;现在把这些分享给大家&#xff0c;希望对大家有些帮助。 1.Unity Asset Store&#xff08;Unity资源商店&#xff09; 这些Unity资源商店可以算是Unity官方的资源库了&#x…

晶体结构资源网站

晶体结构资源网站 1、无机晶体结构数据查询软件ICSD&#xff08;findit&#xff09;2、[晶体原型百科全书aflowlib](http://aflowlib.org/prototype-encyclopedia/index.html)3、[Crystallography Open Database](http://www.crystallography.net/cod/search.html)4、[American…

免费资源网站,你想要的全都有【各类宝藏资源 】

这6个免费资源网站&#xff0c;能帮你找到所有想要资源 前言 今天就把多年收藏整理的各类资源网站全都分享出来&#xff0c;都是完全免费的“资源”网站&#xff0c;质量非常高&#xff0c;一起来看看吧&#xff01; 1、我爱分享网 网站整理了办公软件、解压软件、截图工具、…

刷机资源网站推荐

是不是各位想刷机的朋友找不到资源站今天就来推荐一下&#xff08;资源均来源于网络&#xff0c;如果侵权请联系删除&#xff09; 1.萤火虫资源站 首页 - 首页 - &#x1f448;萤火虫资源站 (kamiui.ml) 资源比较充足还有OneDrive资源 2.Mindows工具箱 mindows.cn 可以把你的手…

珍藏已久的6个资源网站,每天让你不愁找不到资源,你值得拥有

想必如果你是一名在网上混迹多年的老网民,手上一定有几套属于自己的网站,有时候想要什么直接在里面搜索十分方便!也不需要满网进行瞎找,但是这类网站起来很快倒下来也很多,所以在很多时候我们要不断的更新自己手头上的资源。 这里我也整理了6款适合我们工作学习中常用的网…

你还在为找资源而发愁?这里有最佳的5个资源网站!

搜索引擎在我们工作生活中是举足轻重的工具了&#xff0c;想要在如此庞大的互联网资源库中找到自己需要的信息也是不简单的&#xff0c;这里给大家分享5个优质的资源网站&#xff0c;看完你肯定有相见恨晚的感觉。 1、纳米学习 http://www.1nami.com/ 这是一个集合了网易云课…

13个免费资源网站,你想要的全都有!【各类宝藏资源,建议收藏】

前言 前段时间&#xff0c;博主写了一篇文章关于如何用Python自制一款音乐播放器&#xff0c;有不少粉丝私信我说&#xff0c;这些高颜值UI设计模板都是从哪里找的&#xff0c;可以把网址分享出来嘛~ 当然没问题&#xff0c;今天就把多年收藏整理的各类资源网站全都分享出来&…

​遗传算法优化神经网络实现数据预测

作者 | 李秋键 责编 | 寇雪芹 头图 | 下载于视觉中国 出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09; 引言 随着人工智能和大数据的发展&#xff0c;大量实验和数据处理等流程对算法的要求也随之变得越来越高&#xff0c;故综合以及灵活运用不同的算法以实现更高效的…

Python实现GWO智能灰狼优化算法优化支持向量机回归模型(svr算法)项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后获取。 1.项目背景 灰狼优化算法(GWO)&#xff0c;由澳大利亚格里菲斯大学学者 Mirjalili 等人于2014年提出来的一种群智能…

基于遗传算法GA算法优化BP神经网络(Python代码实现)

一、 概述 BP-GA算法的设计︰基于遗传算法的BP神经网络算法(以下简称BP-GA)就是在BP神经网络的学习过程中,将权重和阀值描述为染色体,并选取适宜的适应函数,然后进行GA迭代,直到某种意义上的收敛.与普通BP学习算法相比,算法 BP一GA的优势在于可以处理一些传统方法不能处理的例子…

Python实现WOA智能鲸鱼优化算法优化支持向量机分类模型(SVC算法)项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后获取。 1.项目背景 鲸鱼优化算法 (whale optimization algorithm,WOA)是 2016 年由澳大利亚格里菲斯大学的Mirjalili 等提出…

基于灰狼算法优化支持向量机的数据分类算法及其MATLAB实现-附代码

基于灰狼算法优化支持向量机的数据分类算法及其MATLAB实现-附代码 文章目录 基于灰狼算法优化支持向量机的数据分类算法及其MATLAB实现-附代码1 GWO-SVM 模型1.1 灰狼优化器GWO1.2 支持向量机分类SVM 2 基于GWO-SVM 的分类算法2.1 优化变量与目标函数的选取2.2 GWO-SVM 建模步骤…

基于麻雀算法优化LSTM回归预测(matlab)

基于麻雀算法优化LSTM回归预测&#xff08;matlab&#xff09; 概述&#xff1a; 麻雀算法构思lstm原理麻雀优化lstm原理代码及结果展示 第一部分 麻雀算法构思 众所周知&#xff0c;麻雀是常见的留鸟而且非常喜欢群居。这种生物是非常聪明的&#xff0c;有很强的记忆力&am…

鲸鱼优化算法优化BP神经网络回归预测的算法设计-附代码

鲸鱼优化算法WOA优化BP神经网络回归预测模型以及MATLAB代码实现 文章目录 鲸鱼优化算法WOA优化BP神经网络回归预测模型以及MATLAB代码实现1. 算法描述2. 鲸鱼优化算法优化BP神经网络预测的步骤与流程图设计3. WOA-BP预测算法的参数设置4. 运行结果5. MATLAB代码 1. 算法描述 鲸…