1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
.. _elf-module:
##########
ELF module
##########
.. versionadded:: 3.2.0
The ELF module is very similar to the :ref:`pe-module`, but for ELF files. This
module exposes most of the fields present in an ELF header. Let's see some
examples:
.. code-block:: yara
import "elf"
rule single_section
{
condition:
elf.number_of_sections == 1
}
rule elf_64
{
condition:
elf.machine == elf.EM_X86_64
}
Reference
---------
.. c:type:: type
Integer with one of the following values:
.. c:type:: ET_NONE
No file type.
.. c:type:: ET_REL
Relocatable file.
.. c:type:: ET_EXEC
Executable file.
.. c:type:: ET_DYN
Shared object file.
.. c:type:: ET_CORE
Core file.
*Example: elf.type == elf.ET_EXEC*
.. c:type:: machine
Integer with one of the following values:
.. c:type:: EM_NONE
.. c:type:: EM_M32
.. c:type:: EM_SPARC
.. c:type:: EM_386
.. c:type:: EM_68K
.. c:type:: EM_88K
.. c:type:: EM_860
.. c:type:: EM_MIPS
.. c:type:: EM_MIPS_RS3_LE
.. c:type:: EM_PPC
.. c:type:: EM_PPC64
.. c:type:: EM_ARM
.. c:type:: EM_X86_64
.. c:type:: EM_AARCH64
*Example: elf.machine == elf.EM_X86_64*
.. c:type:: entry_point
Entry point raw offset or virtual address depending on whether YARA is
scanning a file or process memory respectively. This is equivalent to the
deprecated ``entrypoint`` keyword.
.. c:type:: number_of_sections
Number of sections in the ELF file.
.. c:type:: sections
A zero-based array of section objects, one for each section the ELF has.
Individual sections can be accessed by using the [] operator. Each section
object has the following attributes:
.. c:member:: name
Section's name.
*Example: elf.sections[3].name == ".bss"*
.. c:member:: size
Section's size in bytes. Unless the section type is SHT_NOBITS, the
section occupies sh_size bytes in the file. A section of
:c:type:`SHT_NOBITS` may have a non-zero size, but it occupies no space
in the file.
.. c:member:: offset
Offset from the beginning of the file to the first byte in the section.
One section type, :c:type:`SHT_NOBITS` described below, occupies no
space in the file, and its :c:member:`offset` member locates the
conceptual placement in the file.
.. c:member:: type
Integer with one of the following values:
.. c:type:: SHT_NULL
This value marks the section as inactive; it does not have
an associated section. Other members of the section header have
undefined values.
.. c:type:: SHT_PROGBITS
The section holds information defined by the program, whose format
and meaning are determined solely by the program.
.. c:type:: SHT_SYMTAB
The section holds a symbol table.
.. c:type:: SHT_STRTAB
The section holds a string table. An object file may have multiple
string table sections.
.. c:type:: SHT_RELA
The section holds relocation entries.
.. c:type:: SHT_HASH
The section holds a symbol hash table.
.. c:type:: SHT_DYNAMIC
The section holds information for dynamic linking.
.. c:type:: SHT_NOTE
The section holds information that marks the file in some way.
.. c:type:: SHT_NOBITS
A section of this type occupies no space in the file but otherwise resembles :c:type:`SHT_PROGBITS`.
.. c:type:: SHT_REL
The section holds relocation entries.
.. c:type:: SHT_SHLIB
This section type is reserved but has unspecified semantics.
.. c:type:: SHT_DYNSYM
This section holds dynamic linking symbols.
.. c:member:: flags
Integer with section's flags as defined below:
.. c:type:: SHF_WRITE
The section contains data that should be writable during process
execution.
.. c:type:: SHF_ALLOC
The section occupies memory during process execution. Some control sections do not reside in the memory image of an object file; this attribute is off for those sections.
.. c:type:: SHF_EXECINSTR
The section contains executable machine instructions.
*Example: elf.sections[2].flags & elf.SHF_WRITE*
.. c:member:: address
.. versionadded:: 3.6.0
The virtual address the section starts at.
.. c:type:: number_of_segments
.. versionadded:: 3.4.0
Number of segments in the ELF file.
.. c:type:: segments
.. versionadded:: 3.4.0
A zero-based array of segment objects, one for each segment the ELF has.
Individual segments can be accessed by using the [] operator. Each segment
object has the following attributes:
.. c:member:: alignment
Value to which the segments are aligned in memory and in the file.
.. c:member:: file_size
Number of bytes in the file image of the segment. It may be zero.
.. c:member:: flags
A combination of the following segment flags:
.. c:type:: PF_R
The segment is readable.
.. c:type:: PF_W
The segment is writable.
.. c:type:: PF_X
The segment is executable.
.. c:member:: memory_size
In-memory segment size.
.. c:member:: offset
Offset from the beginning of the file where the segment resides.
.. c:member:: physical_address
On systems for which physical addressing is relevant, contains the
segment's physical address.
.. c:member:: type
Type of segment indicated by one of the following values:
.. c:type:: PT_NULL
.. c:type:: PT_LOAD
.. c:type:: PT_DYNAMIC
.. c:type:: PT_INTERP
.. c:type:: PT_NOTE
.. c:type:: PT_SHLIB
.. c:type:: PT_PHDR
.. c:type:: PT_LOPROC
.. c:type:: PT_HIPROC
.. c:type:: PT_GNU_STACK
.. c:member:: virtual_address
Virtual address at which the segment resides in memory.
.. c:type:: dynamic_section_entries
.. versionadded:: 3.6.0
Number of entries in the dynamic section in the ELF file.
.. c:type:: dynamic
.. versionadded:: 3.6.0
A zero-based array of dynamic objects, one for each entry in found in the
ELF's dynamic section. Individual dynamic objects can be accessed by using
the [] operator. Each dynamic object has the following attributes:
.. c:member:: type
Value that describes the type of dynamic section. Builtin values are:
.. c:type:: DT_NULL
.. c:type:: DT_NEEDED
.. c:type:: DT_PLTRELSZ
.. c:type:: DT_PLTGOT
.. c:type:: DT_HASH
.. c:type:: DT_STRTAB
.. c:type:: DT_SYMTAB
.. c:type:: DT_RELA
.. c:type:: DT_RELASZ
.. c:type:: DT_RELAENT
.. c:type:: DT_STRSZ
.. c:type:: DT_SYMENT
.. c:type:: DT_INIT
.. c:type:: DT_FINI
.. c:type:: DT_SONAME
.. c:type:: DT_RPATH
.. c:type:: DT_SYMBOLIC
.. c:type:: DT_REL
.. c:type:: DT_RELSZ
.. c:type:: DT_RELENT
.. c:type:: DT_PLTREL
.. c:type:: DT_DEBUG
.. c:type:: DT_TEXTREL
.. c:type:: DT_JMPREL
.. c:type:: DT_BIND_NOW
.. c:type:: DT_INIT_ARRAY
.. c:type:: DT_FINI_ARRAY
.. c:type:: DT_INIT_ARRAYSZ
.. c:type:: DT_FINI_ARRAYSZ
.. c:type:: DT_RUNPATH
.. c:type:: DT_FLAGS
.. c:type:: DT_ENCODING
.. c:member:: value
A value associated with the given type. The type of value (address,
size, etc.) is dependant on the type of dynamic entry.
.. c:type:: symtab_entries
.. versionadded:: 3.6.0
Number of entries in the symbol table found in the ELF file.
.. c:type:: symtab
.. versionadded:: 3.6.0
A zero-based array of symbol objects, one for each entry in found in the
ELF's SYMBTAB. Individual symbol objects can be accessed by using the []
operator. Each symbol object has the following attributes:
.. c:member:: name
The symbol's name.
.. c:member:: value
A value associated with the symbol. Generally a virtual address.
.. c:member:: size
The symbol's size.
.. c:member:: type
The type of symbol. Built values are:
.. c:type:: STT_NOTYPE
.. c:type:: STT_OBJECT
.. c:type:: STT_FUNC
.. c:type:: STT_SECTION
.. c:type:: STT_FILE
.. c:type:: STT_COMMON
.. c:type:: STT_TLS
.. c:member:: bind
The binding of the symbol. Builtin values are:
.. c:type:: STB_LOCAL
.. c:type:: STB_GLOBAL
.. c:type:: STB_WEAK
.. c:member:: shndx
The section index which the symbol is associated with.
.. c:function:: telfhash()
Function returning Telfhash - TLSH hash of the ELF export and import symbols.
*Example: elf.telfhash() == "t166a00284751084526486df8b5df5b2fccb3f511dbc188c37156f5e714a11bc5d71014d"*
.. c:function:: import_md5()
Function returning Import Hash - MD5 hash of the ELF imported symbols.
*Example: elf.import_md5() == "c3eca50cbb03400a6e91b9fe48da0c0c"*
|