Skip to content

Commit f27424d

Browse files
Parametrized --sleep/--delay seconds. Added -h/--help. (#293)
* Parametrized --delay/--sleep * Added -h/--help message. Updated README with --help message (Usage)
1 parent aa9150d commit f27424d

File tree

2 files changed

+105
-7
lines changed

2 files changed

+105
-7
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,39 @@ It performs a bunch of common malware tricks with the goal of seeing if you stay
2424

2525
![Logo](https://i.imgur.com/jEFhsJT.png)
2626

27+
### Usage
28+
```
29+
$ ./al-khaser.exe -h
30+
Usage: al-khaser.exe [OPTIONS]
31+
Options:
32+
--check <type> Enable specific check(s). Can be used multiple times. Valid types are:
33+
TLS (Thread Local Storage callback checks)
34+
DEBUG (Anti-debugging checks)
35+
INJECTION (Code injection checks)
36+
GEN_SANDBOX (Generic sandbox checks)
37+
VBOX (VirtualBox detection)
38+
VMWARE (VMware detection)
39+
VPC (Virtual PC detection)
40+
QEMU (QEMU detection)
41+
KVM (KVM detection)
42+
XEN (Xen detection)
43+
WINE (Wine detection)
44+
PARALLELS (Parallels detection)
45+
HYPERV (Hyper-V detection)
46+
CODE_INJECTIONS (Additional code injection techniques)
47+
TIMING_ATTACKS (Timing/sleep-based sandbox evasion)
48+
DUMPING_CHECK (Dumping memory/process checks)
49+
ANALYSIS_TOOLS (Analysis tools detection)
50+
ANTI_DISASSM (Anti-disassembly checks)
51+
--sleep <seconds> Set sleep/delay duration in seconds (default: 600).
52+
--delay <seconds> Alias for --sleep.
53+
-h, --help Show this help message and exit.
54+
55+
Examples:
56+
al-khaser.exe --check DEBUG --check TIMING_ATTACKS --sleep 30
57+
al-khaser.exe --check VMWARE --check QEMU
58+
al-khaser.exe --sleep 30
59+
```
2760

2861
## Download
2962

al-khaser/Al-khaser.cpp

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ BOOL ENABLE_TIMING_ATTACKS = FALSE;
2222
BOOL ENABLE_DUMPING_CHECK = FALSE;
2323
BOOL ENABLE_ANALYSIS_TOOLS_CHECK = FALSE;
2424
BOOL ENABLE_ANTI_DISASSM_CHECKS = FALSE;
25+
const char* PROGRAM_NAME = "al-khaser.exe";
2526

2627

2728
void EnableDefaultChecks() {
@@ -66,20 +67,84 @@ void EnableChecks(std::string checkType) {
6667
else if (checkType == "ANTI_DISASSM") ENABLE_ANTI_DISASSM_CHECKS = TRUE;
6768
}
6869

70+
void print_help(const char* prog_name){
71+
printf(
72+
"Usage: %s [OPTIONS]\n"
73+
"Options:\n"
74+
" --check <type> Enable specific check(s). Can be used multiple times. Valid types are:\n"
75+
" TLS (Thread Local Storage callback checks)\n"
76+
" DEBUG (Anti-debugging checks)\n"
77+
" INJECTION (Code injection checks)\n"
78+
" GEN_SANDBOX (Generic sandbox checks)\n"
79+
" VBOX (VirtualBox detection)\n"
80+
" VMWARE (VMware detection)\n"
81+
" VPC (Virtual PC detection)\n"
82+
" QEMU (QEMU detection)\n"
83+
" KVM (KVM detection)\n"
84+
" XEN (Xen detection)\n"
85+
" WINE (Wine detection)\n"
86+
" PARALLELS (Parallels detection)\n"
87+
" HYPERV (Hyper-V detection)\n"
88+
" CODE_INJECTIONS (Additional code injection techniques)\n"
89+
" TIMING_ATTACKS (Timing/sleep-based sandbox evasion)\n"
90+
" DUMPING_CHECK (Dumping memory/process checks)\n"
91+
" ANALYSIS_TOOLS (Analysis tools detection)\n"
92+
" ANTI_DISASSM (Anti-disassembly checks)\n"
93+
" --sleep <seconds> Set sleep/delay duration in seconds (default: 600).\n"
94+
" --delay <seconds> Alias for --sleep.\n"
95+
" -h, --help Show this help message and exit.\n"
96+
"\n"
97+
"Examples:\n"
98+
" %s --check DEBUG --check TIMING_ATTACKS --sleep 30\n"
99+
" %s --check VMWARE --check QEMU\n"
100+
" %s --sleep 30\n"
101+
"\n"
102+
"If no --check options are given, all checks are executed by default.\n"
103+
"If no other options are given, the default delay is 600 seconds.\n",
104+
prog_name, prog_name, prog_name, prog_name
105+
);
106+
}
69107

70-
int main(int argc, char* argv[])
71-
{
108+
int main(int argc, char* argv[]){
72109
/* enable functions */
110+
UINT delayInSeconds = 600U; // default value
111+
int enabled_checks = 0;
112+
73113
if (argc > 1) {
74-
for (int i = 1; i < argc; i += 2) {
75-
if (strcmp(argv[i], "--check") == 0 && (i + 1 < argc)) {
114+
for (int i = 1; i < argc; ++i) {
115+
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
116+
//print_help(argv[0]);
117+
print_help(PROGRAM_NAME);
118+
return 0;
119+
} else if ((strcmp(argv[i], "--sleep") == 0 || strcmp(argv[i], "--delay") == 0) && i + 1 < argc) {
120+
char* endptr;
121+
errno = 0;
122+
long val = strtol(argv[i + 1], &endptr, 10);
123+
124+
if (errno == ERANGE || val > UINT_MAX || val <= 0) {
125+
printf("[!] Invalid delay value: %s. Using default %u seconds.\n", argv[i + 1], delayInSeconds);
126+
}
127+
else if (endptr == argv[i + 1] || *endptr != '\0') {
128+
printf("[!] Non-numeric delay value: %s. Using default %u seconds.\n", argv[i + 1], delayInSeconds);
129+
}
130+
else {
131+
delayInSeconds = (UINT)val;
132+
}
133+
i++; // skip the value
134+
} else if ((strcmp(argv[i], "--check") == 0) && i + 1 < argc) {
76135
EnableChecks(argv[i + 1]);
136+
enabled_checks++;
137+
i++; // skip the value
77138
}
139+
// Add more flags here as needed
140+
// else if (strcmp(argv[i], "--otherflag") == 0) { ... }
78141
}
79142
}
80-
else {
143+
144+
if (!enabled_checks) {
81145
EnableDefaultChecks();
82146
}
147+
83148

84149
/* Resize the console window for better visibility */
85150
resize_console_window();
@@ -326,9 +391,9 @@ int main(int argc, char* argv[])
326391
/* Timing Attacks */
327392
if (ENABLE_TIMING_ATTACKS) {
328393
print_category(TEXT("Timing-attacks"));
329-
UINT delayInSeconds = 600U;
394+
330395
UINT delayInMillis = delayInSeconds * 1000U;
331-
printf("\n[*] Delay value is set to %u minutes ...\n", delayInSeconds / 60);
396+
printf("\n[*] Delay value is set to %u seconds (%u minutes) ...\n", delayInSeconds, delayInSeconds / 60);
332397

333398
exec_check(timing_NtDelayexecution, delayInMillis, TEXT("Performing a sleep using NtDelayExecution ..."));
334399
exec_check(timing_sleep_loop, delayInMillis, TEXT("Performing a sleep() in a loop ..."));

0 commit comments

Comments
 (0)