├── pafish ├── Output │ └── MingW │ │ └── .gitignore ├── pafish.ico ├── cuckoo.h ├── sandboxie.h ├── types.h ├── wine.h ├── qemu.h ├── debuggers.h ├── bochs.h ├── hooks.h ├── sandboxie.c ├── cpu.h ├── rtt.h ├── vmware.h ├── gensandbox.h ├── config.h ├── wine.c ├── vbox.h ├── common.h ├── hooks.c ├── qemu.c ├── debuggers.c ├── Objects │ └── MingW │ │ └── pafish_private.rc ├── bochs.c ├── cuckoo.c ├── Makefile64.linux ├── Makefile.win ├── Makefile.linux ├── vmware.c ├── utils.h ├── common.c ├── gensandbox.c ├── cpu.c ├── vbox.c ├── utils.c ├── rtt.c └── main.c ├── .gitignore ├── screenshots ├── v02 │ ├── pafish_wine.png │ ├── pafish_vmware.png │ └── pafish_dbg_vbox.png ├── v052 │ └── native_system.jpg ├── v01 │ ├── pafish_sandboxie.png │ └── pafish_virtualbox.png ├── v057 │ └── pafish_vbox_win8.png └── v06 │ └── pafish_native_win10.png ├── .github └── FUNDING.yml ├── README.md ├── Vagrantfile ├── CHANGELOG └── LICENSE.txt /pafish/Output/MingW/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.exe 3 | *.log 4 | hi_* 5 | .vagrant 6 | *.res 7 | -------------------------------------------------------------------------------- /pafish/pafish.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/pafish/pafish.ico -------------------------------------------------------------------------------- /screenshots/v02/pafish_wine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v02/pafish_wine.png -------------------------------------------------------------------------------- /pafish/cuckoo.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CUCKOO_H 3 | #define CUCKOO_H 4 | 5 | int cuckoo_check_tls(); 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /screenshots/v02/pafish_vmware.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v02/pafish_vmware.png -------------------------------------------------------------------------------- /screenshots/v052/native_system.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v052/native_system.jpg -------------------------------------------------------------------------------- /pafish/sandboxie.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SANBOXIE_H 3 | #define SANBOXIE_H 4 | 5 | int sboxie_detect_sbiedll(); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /screenshots/v01/pafish_sandboxie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v01/pafish_sandboxie.png -------------------------------------------------------------------------------- /screenshots/v02/pafish_dbg_vbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v02/pafish_dbg_vbox.png -------------------------------------------------------------------------------- /screenshots/v01/pafish_virtualbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v01/pafish_virtualbox.png -------------------------------------------------------------------------------- /screenshots/v057/pafish_vbox_win8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v057/pafish_vbox_win8.png -------------------------------------------------------------------------------- /screenshots/v06/pafish_native_win10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a0rtega/pafish/HEAD/screenshots/v06/pafish_native_win10.png -------------------------------------------------------------------------------- /pafish/types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TYPES_H 3 | #define TYPES_H 4 | 5 | #define TRUE 1 6 | #define FALSE 0 7 | 8 | typedef char * string; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pafish/wine.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef WINE_H 3 | #define WINE_H 4 | 5 | int wine_detect_get_unix_file_name(); 6 | 7 | int wine_reg_key1(); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /pafish/qemu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef QEMU_H 3 | #define QEMU_H 4 | 5 | int qemu_reg_key1(); 6 | 7 | int qemu_reg_key2(); 8 | 9 | int qemu_cpu_name(); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pafish/debuggers.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef DEBUG_H 3 | #define DEBUG_H 4 | 5 | int debug_isdebuggerpresent(); 6 | 7 | int debug_outputdebugstring(); 8 | 9 | int debug_beingdebugged_peb(); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pafish/bochs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef BOCHS_H 3 | #define BOCHS_H 4 | 5 | int bochs_reg_key1(); 6 | 7 | int bochs_cpu_amd1(); 8 | 9 | int bochs_cpu_amd2(); 10 | 11 | int bochs_cpu_intel1(); 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /pafish/hooks.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HOOKS_H 3 | #define HOOKS_H 4 | 5 | int check_hook_DeleteFileW_m1(); 6 | 7 | int check_hook_ShellExecuteExW_m1(); 8 | 9 | int check_hook_CreateProcessA_m1(); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pafish/sandboxie.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sandboxie.h" 5 | #include "types.h" 6 | 7 | int sboxie_detect_sbiedll() { 8 | if (GetModuleHandle("sbiedll.dll") != NULL) { 9 | return TRUE; 10 | } 11 | else { 12 | return FALSE; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /pafish/cpu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CPU_H 3 | #define CPU_H 4 | 5 | int cpu_rdtsc(); 6 | 7 | int cpu_rdtsc_force_vmexit(); 8 | 9 | int cpu_hv(); 10 | 11 | void cpu_write_vendor(char *); 12 | void cpu_write_hv_vendor(char *); 13 | void cpu_write_brand(char *); 14 | 15 | int cpu_known_vm_vendors(); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /pafish/rtt.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_H 2 | #define RTT_H 3 | 4 | int rtt_mouse_presence(); 5 | 6 | int rtt_mouse_move(); 7 | 8 | int rtt_mouse_speed_limit(); 9 | 10 | int rtt_mouse_click(); 11 | 12 | int rtt_mouse_double_click(); 13 | 14 | int rtt_confirm_dialog(); 15 | 16 | int rtt_plausible_confirm_dialog(); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /pafish/vmware.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef VMWARE_H 3 | #define VMWARE_H 4 | 5 | int vmware_reg_key1(); 6 | 7 | int vmware_reg_key2(); 8 | 9 | int vmware_sysfile1(); 10 | 11 | int vmware_sysfile2(); 12 | 13 | int vmware_mac(); 14 | 15 | int vmware_adapter_name(); 16 | 17 | int vmware_devices(); 18 | 19 | int vmware_wmi_serial(); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /pafish/gensandbox.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GENSAND_H 3 | #define GENSAND_H 4 | 5 | int gensandbox_username(); 6 | 7 | int gensandbox_path(); 8 | 9 | int gensandbox_common_names(); 10 | 11 | int gensandbox_drive_size(); 12 | 13 | int gensandbox_drive_size2(); 14 | 15 | int gensandbox_sleep_patched(); 16 | 17 | int gensandbox_one_cpu(); 18 | 19 | int gensandbox_one_cpu_GetSystemInfo(); 20 | 21 | int gensandbox_less_than_onegb(); 22 | 23 | int gensandbox_uptime(); 24 | 25 | int gensandbox_IsNativeVhdBoot(); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /pafish/config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CONFIG_H 3 | #define CONFIG_H 4 | 5 | /* This output flag enables sending of DNS 6 | * requests when pafish detects products. 7 | */ 8 | #define ENABLE_DNS_TRACE 1 9 | 10 | /* This output flag enables writing traces of 11 | * detections to a PE section of the pafish 12 | * image in memory. Memory dumps of unpacked executables 13 | * may reveal the detected products. 14 | * Output format: "analysis-start trace1,trace2, analysis-end" 15 | */ 16 | #define ENABLE_PE_IMG_TRACE 1 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /pafish/wine.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "wine.h" 5 | #include "types.h" 6 | #include "utils.h" 7 | 8 | int wine_detect_get_unix_file_name() { 9 | HMODULE k32; 10 | k32 = GetModuleHandle("kernel32.dll"); 11 | if (k32 != NULL) { 12 | if (GetProcAddress(k32, "wine_get_unix_file_name") != NULL) { 13 | return TRUE; 14 | } 15 | else { 16 | return FALSE; 17 | } 18 | } 19 | else { 20 | return FALSE; 21 | } 22 | } 23 | 24 | int wine_reg_key1() { 25 | return pafish_exists_regkey(HKEY_CURRENT_USER, "SOFTWARE\\Wine"); 26 | } 27 | -------------------------------------------------------------------------------- /pafish/vbox.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef VBOX_H 3 | #define VBOX_H 4 | 5 | int vbox_reg_key1(); 6 | int vbox_reg_key2(); 7 | int vbox_reg_key3(); 8 | int vbox_reg_key4(); 9 | int vbox_reg_key5(); 10 | int vbox_reg_key7(); 11 | int vbox_reg_key8(); 12 | int vbox_reg_key9(int writelogs); 13 | int vbox_reg_key10(); 14 | 15 | int vbox_sysfile1(int writelogs); 16 | int vbox_sysfile2(int writelogs); 17 | 18 | int vbox_mac(); 19 | 20 | int vbox_devices(int writelogs); 21 | 22 | int vbox_traywindow(); 23 | 24 | int vbox_network_share(); 25 | 26 | int vbox_processes(int writelogs); 27 | 28 | int vbox_wmi_devices(); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /pafish/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef COMM_H 3 | #define COMM_H 4 | 5 | unsigned short init_cmd_colors(); 6 | 7 | void restore_cmd_colors(unsigned short); 8 | 9 | void print_header(); 10 | 11 | void print_traced(); 12 | 13 | void print_not_traced(); 14 | 15 | void print_warning(char * msg); 16 | 17 | void write_log(char msg[]); 18 | 19 | void write_trace(char product[]); 20 | 21 | void write_trace_dns(char product[]); 22 | 23 | void write_trace_pe_img(char product[], BOOLEAN add_comma); 24 | 25 | void print_check_group(char * text); 26 | 27 | void exec_check(char * text, int (*callback)(), char * text_log, char * text_trace); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /pafish/hooks.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "hooks.h" 5 | #include "types.h" 6 | 7 | /* Thx Inaki for this! (@virtualminds_es) */ 8 | static int check_hook_m1(DWORD * dwAddress) { 9 | BYTE *b = (BYTE *)dwAddress; 10 | return (*b == 0x8b) && (*(b+1) == 0xff) ? FALSE : TRUE; 11 | } 12 | 13 | /* Causes FP in Win 8 */ 14 | int check_hook_DeleteFileW_m1() { 15 | return check_hook_m1((DWORD *)DeleteFileW); 16 | } 17 | 18 | int check_hook_ShellExecuteExW_m1() { 19 | return check_hook_m1((DWORD *)ShellExecuteExW); 20 | } 21 | 22 | int check_hook_CreateProcessA_m1() { 23 | return check_hook_m1((DWORD *)CreateProcessA); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [a0rtega] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /pafish/qemu.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "qemu.h" 6 | #include "types.h" 7 | #include "utils.h" 8 | #include "cpu.h" 9 | 10 | int qemu_reg_key1() { 11 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "QEMU"); 12 | } 13 | 14 | int qemu_reg_key2() { 15 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "QEMU"); 16 | } 17 | 18 | int qemu_cpu_name() { 19 | char cpu_brand[49]; 20 | cpu_write_brand(cpu_brand); 21 | return !memcmp(cpu_brand, "QEMU Virtual CPU", 16) ? TRUE : FALSE; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /pafish/debuggers.c: -------------------------------------------------------------------------------- 1 | 2 | #define _WIN32_WINNT 0x0501 /* _WIN32_WINNT_WINXP */ 3 | 4 | #include 5 | 6 | #include "debuggers.h" 7 | #include "utils.h" 8 | #include "types.h" 9 | 10 | int debug_isdebuggerpresent() { 11 | if (IsDebuggerPresent()) 12 | return TRUE; 13 | else 14 | return FALSE; 15 | } 16 | 17 | int debug_outputdebugstring() { 18 | DWORD err = 99; /* Random error */ 19 | SetLastError(err); 20 | /* If we're been debugging, this shouldn't 21 | drop an error. */ 22 | OutputDebugString("useless"); 23 | if (GetLastError() == err){ 24 | return TRUE; 25 | } 26 | else { 27 | return FALSE; 28 | } 29 | } 30 | 31 | int debug_beingdebugged_peb() { 32 | struct _PEB_wine * PEB; 33 | PEB = pafish_get_PEB(); 34 | return PEB->BeingDebugged == 1 ? TRUE : FALSE; 35 | } 36 | -------------------------------------------------------------------------------- /pafish/Objects/MingW/pafish_private.rc: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "pafish.ico" 5 | 6 | 1 VERSIONINFO 7 | FILEVERSION 0,6,0,0 8 | PRODUCTVERSION 0,6,0,0 9 | FILETYPE VFT_APP 10 | BEGIN 11 | BLOCK "StringFileInfo" 12 | BEGIN 13 | BLOCK "040904E4" 14 | BEGIN 15 | VALUE "CompanyName", "" 16 | VALUE "FileVersion", "" 17 | VALUE "FileDescription", "Paranoid Fish is paranoid" 18 | VALUE "InternalName", "" 19 | VALUE "LegalCopyright", "" 20 | VALUE "LegalTrademarks", "" 21 | VALUE "OriginalFilename", "" 22 | VALUE "ProductName", "Paranoid Fish" 23 | VALUE "ProductVersion", "" 24 | END 25 | END 26 | BLOCK "VarFileInfo" 27 | BEGIN 28 | VALUE "Translation", 0x0409, 1252 29 | END 30 | END 31 | 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | pafish-logo 3 | 4 | # Pafish 5 | 6 | Pafish is a testing tool that uses different techniques to detect virtual machines and malware analysis environments in the same way that malware families do. 7 | 8 | The project is free and open source; the code of all the anti-analysis techniques is publicly available. Pafish executables for Windows (x86 32-bit and 64-bit) can be downloaded from the [releases page](https://github.com/a0rtega/pafish/releases). 9 | 10 | ![pafish screenshot](https://github.com/a0rtega/pafish/raw/dev/screenshots/v06/pafish_native_win10.png) 11 | 12 | # Scope 13 | 14 | The goal of this project is to collect techniques commonly observed in malware samples to evade analysis systems. This allows analysts to study them and test whether the analysis environments are properly implemented. 15 | 16 | # Building Pafish 17 | 18 | Pafish is written in C and can be built with `Mingw-w64` and `make`. 19 | 20 | The wiki page "[How to build](https://github.com/a0rtega/pafish/wiki/How-to-build)" contains detailed instructions. 21 | 22 | # Author 23 | 24 | Alberto Ortega and many awesome [contributors](https://github.com/a0rtega/pafish/graphs/contributors). 25 | 26 | # License 27 | 28 | [GPL-3.0](LICENSE.txt) 29 | 30 | -------------------------------------------------------------------------------- /pafish/bochs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "bochs.h" 6 | #include "cpu.h" 7 | #include "types.h" 8 | #include "utils.h" 9 | 10 | /* 11 | Reference for CPUID functions: https://www.symantec.com/avcenter/reference/Virtual_Machine_Threats.pdf 12 | */ 13 | 14 | int bochs_reg_key1() { 15 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "BOCHS"); 16 | } 17 | 18 | int bochs_cpu_amd1() { 19 | char cpu_brand[49]; 20 | cpu_write_brand(cpu_brand); 21 | /* It checks the lowercase P in 'processor', an actual AMD returns Processor */ 22 | return !memcmp(cpu_brand, "AMD Athlon(tm) processor", 24) ? TRUE : FALSE; 23 | } 24 | 25 | int bochs_cpu_amd2() { 26 | int eax; 27 | __asm__ volatile(".intel_syntax noprefix;" 28 | "xor eax, eax;" 29 | "cpuid;" 30 | "cmp ecx, 0x444d4163;" /* AMD CPU? */ 31 | "jne b2not_detected;" 32 | "mov eax, 0x8fffffff;" /* query easter egg */ 33 | "cpuid;" 34 | "jecxz b2detected;" /* ECX value not filled */ 35 | "b2not_detected: xor eax, eax; jmp b2exit;" 36 | "b2detected: mov eax, 0x1;" 37 | "b2exit: nop;" 38 | ".att_syntax;" 39 | : "=a"(eax)); 40 | return eax ? TRUE : FALSE; 41 | } 42 | 43 | int bochs_cpu_intel1() { 44 | char cpu_brand[49]; 45 | cpu_write_brand(cpu_brand); 46 | /* This processor name is not known to be valid in an actual CPU */ 47 | return !memcmp(cpu_brand, " Intel(R) Pentium(R) 4 CPU ", 47) ? TRUE : FALSE; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /pafish/cuckoo.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "types.h" 6 | #include "cuckoo.h" 7 | 8 | /** 9 | * Cuckoo Sandbox definitions. 10 | */ 11 | /** 12 | * Extra space allocated with the hooks information structure. 13 | */ 14 | #define TLS_HOOK_INFO_RETADDR_SPACE 0x100 15 | 16 | /** 17 | * Hook information stored by Cuckoo at FS:[TLS_HOOK_INFO]. 18 | */ 19 | struct hook_info { 20 | unsigned int depth_count; 21 | unsigned int hook_count; 22 | unsigned int retaddr_esp; 23 | unsigned int last_error; 24 | unsigned int ret_last_error; 25 | unsigned int eax; 26 | unsigned int ecx; 27 | unsigned int edx; 28 | unsigned int ebx; 29 | unsigned int esp; 30 | unsigned int ebp; 31 | unsigned int esi; 32 | unsigned int edi; 33 | }; 34 | 35 | /** 36 | * Read the address of the hooks information in the TLS. 37 | */ 38 | struct hook_info *read_hook_info() { 39 | void *result = NULL; 40 | 41 | __asm__ volatile ("mov %%fs:0x44,%%eax" : "=a" (result)); 42 | 43 | return result; 44 | } 45 | 46 | /** 47 | * Cuckoo stores the return addresses in a extra space allocated in conjunction 48 | * with the hook information function. The only way to check if the structure 49 | * is valid is to calculate what is the minimum and maximum value for the 50 | * return address value location. 51 | */ 52 | int cuckoo_check_tls() { 53 | struct hook_info *info = read_hook_info(); 54 | 55 | if (info == NULL) { 56 | return FALSE; 57 | } 58 | 59 | unsigned int minimum = ((unsigned int) info + sizeof(struct hook_info)); 60 | unsigned int maximum = minimum + TLS_HOOK_INFO_RETADDR_SPACE; 61 | 62 | return (info != NULL) && (info->retaddr_esp >= minimum && info->retaddr_esp <= maximum) ? 63 | TRUE : FALSE; 64 | } 65 | -------------------------------------------------------------------------------- /pafish/Makefile64.linux: -------------------------------------------------------------------------------- 1 | 2 | CC = x86_64-w64-mingw32-gcc 3 | LINK = x86_64-w64-mingw32-gcc 4 | WINDRES = x86_64-w64-mingw32-windres 5 | OBJ = Objects/MingW/main64.o Objects/MingW/common64.o Objects/MingW/utils64.o Objects/MingW/debuggers64.o Objects/MingW/sandboxie64.o \ 6 | Objects/MingW/vbox64.o Objects/MingW/gensandbox64.o Objects/MingW/wine64.o Objects/MingW/vmware64.o \ 7 | Objects/MingW/qemu64.o Objects/MingW/cpu64.o Objects/MingW/bochs64.o \ 8 | Objects/MingW/rtt64.o Objects/MingW/pafish_private64.res 9 | LINKOBJ = $(OBJ) 10 | LIBS = -lwsock32 -liphlpapi -lsetupapi -lmpr -lole32 -lwbemuuid -loleaut32 -lws2_32 -s 11 | INCS = 12 | BIN = Output/MingW/pafish64.exe 13 | CFLAGS = $(INCS) -Wall -Wextra -Wpedantic -O0 -Wno-cast-function-type 14 | 15 | all: $(BIN) 16 | 17 | clean: 18 | rm -f Objects/MingW/*.o 19 | rm -f Objects/MingW/*.res 20 | rm -f Output/MingW/*.exe 21 | 22 | $(BIN): $(OBJ) 23 | $(LINK) $(LINKOBJ) -o "$(BIN)" $(LIBS) 24 | 25 | Objects/MingW/main64.o: $(GLOBALDEPS) main.c 26 | $(CC) -c main.c -o Objects/MingW/main64.o $(CFLAGS) 27 | 28 | Objects/MingW/common64.o: $(GLOBALDEPS) common.c 29 | $(CC) -c common.c -o Objects/MingW/common64.o $(CFLAGS) 30 | 31 | Objects/MingW/utils64.o: $(GLOBALDEPS) utils.c 32 | $(CC) -c utils.c -o Objects/MingW/utils64.o $(CFLAGS) 33 | 34 | Objects/MingW/debuggers64.o: $(GLOBALDEPS) debuggers.c 35 | $(CC) -c debuggers.c -o Objects/MingW/debuggers64.o $(CFLAGS) 36 | 37 | Objects/MingW/sandboxie64.o: $(GLOBALDEPS) sandboxie.c 38 | $(CC) -c sandboxie.c -o Objects/MingW/sandboxie64.o $(CFLAGS) 39 | 40 | Objects/MingW/vbox64.o: $(GLOBALDEPS) vbox.c 41 | $(CC) -c vbox.c -o Objects/MingW/vbox64.o $(CFLAGS) 42 | 43 | Objects/MingW/gensandbox64.o: $(GLOBALDEPS) gensandbox.c 44 | $(CC) -c gensandbox.c -o Objects/MingW/gensandbox64.o $(CFLAGS) 45 | 46 | Objects/MingW/wine64.o: $(GLOBALDEPS) wine.c 47 | $(CC) -c wine.c -o Objects/MingW/wine64.o $(CFLAGS) 48 | 49 | Objects/MingW/vmware64.o: $(GLOBALDEPS) vmware.c 50 | $(CC) -c vmware.c -o Objects/MingW/vmware64.o $(CFLAGS) 51 | 52 | Objects/MingW/qemu64.o: $(GLOBALDEPS) qemu.c 53 | $(CC) -c qemu.c -o Objects/MingW/qemu64.o $(CFLAGS) 54 | 55 | Objects/MingW/cpu64.o: $(GLOBALDEPS) cpu.c 56 | $(CC) -c cpu.c -o Objects/MingW/cpu64.o $(CFLAGS) 57 | 58 | Objects/MingW/bochs64.o: $(GLOBALDEPS) bochs.c 59 | $(CC) -c bochs.c -o Objects/MingW/bochs64.o $(CFLAGS) 60 | 61 | Objects/MingW/rtt64.o: $(GLOBALDEPS) rtt.c 62 | $(CC) -c rtt.c -o Objects/MingW/rtt64.o $(CFLAGS) 63 | 64 | Objects/MingW/pafish_private64.res: Objects/MingW/pafish_private.rc 65 | $(WINDRES) Objects/MingW/pafish_private.rc --input-format=rc -o Objects/MingW/pafish_private64.res -O coff 66 | -------------------------------------------------------------------------------- /pafish/Makefile.win: -------------------------------------------------------------------------------- 1 | 2 | CC = gcc.exe 3 | LINK = gcc.exe 4 | WINDRES = windres.exe 5 | OBJ = Objects/MingW/main.o Objects/MingW/common.o Objects/MingW/utils.o Objects/MingW/debuggers.o Objects/MingW/sandboxie.o \ 6 | Objects/MingW/vbox.o Objects/MingW/gensandbox.o Objects/MingW/wine.o Objects/MingW/vmware.o \ 7 | Objects/MingW/qemu.o Objects/MingW/hooks.o Objects/MingW/cpu.o Objects/MingW/cuckoo.o Objects/MingW/bochs.o \ 8 | Objects/MingW/rtt.o Objects/MingW/pafish_private.res 9 | LINKOBJ = $(OBJ) 10 | LIBS = -lwsock32 -liphlpapi -lsetupapi -lmpr -lole32 -lwbemuuid -loleaut32 -lws2_32 -s 11 | INCS = 12 | BIN = Output/MingW/pafish.exe 13 | CFLAGS = $(INCS) -Wall -Wextra -Wpedantic -O0 14 | 15 | all: $(BIN) 16 | 17 | clean: 18 | del /Q Objects\MingW\*.o 19 | del /Q Objects\MingW\*.res 20 | del /Q Output\MingW\*.exe 21 | 22 | $(BIN): $(OBJ) 23 | $(LINK) $(LINKOBJ) -o "$(BIN)" $(LIBS) 24 | 25 | Objects/MingW/main.o: $(GLOBALDEPS) main.c 26 | $(CC) -c main.c -o Objects/MingW/main.o $(CFLAGS) 27 | 28 | Objects/MingW/common.o: $(GLOBALDEPS) common.c 29 | $(CC) -c common.c -o Objects/MingW/common.o $(CFLAGS) 30 | 31 | Objects/MingW/utils.o: $(GLOBALDEPS) utils.c 32 | $(CC) -c utils.c -o Objects/MingW/utils.o $(CFLAGS) 33 | 34 | Objects/MingW/debuggers.o: $(GLOBALDEPS) debuggers.c 35 | $(CC) -c debuggers.c -o Objects/MingW/debuggers.o $(CFLAGS) 36 | 37 | Objects/MingW/sandboxie.o: $(GLOBALDEPS) sandboxie.c 38 | $(CC) -c sandboxie.c -o Objects/MingW/sandboxie.o $(CFLAGS) 39 | 40 | Objects/MingW/vbox.o: $(GLOBALDEPS) vbox.c 41 | $(CC) -c vbox.c -o Objects/MingW/vbox.o $(CFLAGS) 42 | 43 | Objects/MingW/gensandbox.o: $(GLOBALDEPS) gensandbox.c 44 | $(CC) -c gensandbox.c -o Objects/MingW/gensandbox.o $(CFLAGS) 45 | 46 | Objects/MingW/wine.o: $(GLOBALDEPS) wine.c 47 | $(CC) -c wine.c -o Objects/MingW/wine.o $(CFLAGS) 48 | 49 | Objects/MingW/vmware.o: $(GLOBALDEPS) vmware.c 50 | $(CC) -c vmware.c -o Objects/MingW/vmware.o $(CFLAGS) 51 | 52 | Objects/MingW/qemu.o: $(GLOBALDEPS) qemu.c 53 | $(CC) -c qemu.c -o Objects/MingW/qemu.o $(CFLAGS) 54 | 55 | Objects/MingW/hooks.o: $(GLOBALDEPS) hooks.c 56 | $(CC) -c hooks.c -o Objects/MingW/hooks.o $(CFLAGS) 57 | 58 | Objects/MingW/cpu.o: $(GLOBALDEPS) cpu.c 59 | $(CC) -c cpu.c -o Objects/MingW/cpu.o $(CFLAGS) 60 | 61 | Objects/MingW/cuckoo.o: $(GLOBALDEPS) cuckoo.c 62 | $(CC) -c cuckoo.c -o Objects/MingW/cuckoo.o $(CFLAGS) 63 | 64 | Objects/MingW/bochs.o: $(GLOBALDEPS) bochs.c 65 | $(CC) -c bochs.c -o Objects/MingW/bochs.o $(CFLAGS) 66 | 67 | Objects/MingW/rtt.o: $(GLOBALDEPS) rtt.c 68 | $(CC) -c rtt.c -o Objects/MingW/rtt.o $(CFLAGS) 69 | 70 | Objects/MingW/pafish_private.res: Objects/MingW/pafish_private.rc 71 | $(WINDRES) Objects/MingW/pafish_private.rc --input-format=rc -o Objects/MingW/pafish_private.res -O coff 72 | -------------------------------------------------------------------------------- /pafish/Makefile.linux: -------------------------------------------------------------------------------- 1 | 2 | CC = i686-w64-mingw32-gcc 3 | LINK = i686-w64-mingw32-gcc 4 | WINDRES = i686-w64-mingw32-windres 5 | OBJ = Objects/MingW/main.o Objects/MingW/common.o Objects/MingW/utils.o Objects/MingW/debuggers.o Objects/MingW/sandboxie.o \ 6 | Objects/MingW/vbox.o Objects/MingW/gensandbox.o Objects/MingW/wine.o Objects/MingW/vmware.o \ 7 | Objects/MingW/qemu.o Objects/MingW/hooks.o Objects/MingW/cpu.o Objects/MingW/cuckoo.o Objects/MingW/bochs.o \ 8 | Objects/MingW/rtt.o Objects/MingW/pafish_private.res 9 | LINKOBJ = $(OBJ) 10 | LIBS = -lwsock32 -liphlpapi -lsetupapi -lmpr -lole32 -lwbemuuid -loleaut32 -lws2_32 -s 11 | INCS = 12 | BIN = Output/MingW/pafish.exe 13 | CFLAGS = $(INCS) -Wall -Wextra -Wpedantic -O0 14 | 15 | all: $(BIN) 16 | 17 | clean: 18 | rm -f Objects/MingW/*.o 19 | rm -f Objects/MingW/*.res 20 | rm -f Output/MingW/*.exe 21 | 22 | $(BIN): $(OBJ) 23 | $(LINK) $(LINKOBJ) -o "$(BIN)" $(LIBS) 24 | 25 | Objects/MingW/main.o: $(GLOBALDEPS) main.c 26 | $(CC) -c main.c -o Objects/MingW/main.o $(CFLAGS) 27 | 28 | Objects/MingW/common.o: $(GLOBALDEPS) common.c 29 | $(CC) -c common.c -o Objects/MingW/common.o $(CFLAGS) 30 | 31 | Objects/MingW/utils.o: $(GLOBALDEPS) utils.c 32 | $(CC) -c utils.c -o Objects/MingW/utils.o $(CFLAGS) 33 | 34 | Objects/MingW/debuggers.o: $(GLOBALDEPS) debuggers.c 35 | $(CC) -c debuggers.c -o Objects/MingW/debuggers.o $(CFLAGS) 36 | 37 | Objects/MingW/sandboxie.o: $(GLOBALDEPS) sandboxie.c 38 | $(CC) -c sandboxie.c -o Objects/MingW/sandboxie.o $(CFLAGS) 39 | 40 | Objects/MingW/vbox.o: $(GLOBALDEPS) vbox.c 41 | $(CC) -c vbox.c -o Objects/MingW/vbox.o $(CFLAGS) 42 | 43 | Objects/MingW/gensandbox.o: $(GLOBALDEPS) gensandbox.c 44 | $(CC) -c gensandbox.c -o Objects/MingW/gensandbox.o $(CFLAGS) 45 | 46 | Objects/MingW/wine.o: $(GLOBALDEPS) wine.c 47 | $(CC) -c wine.c -o Objects/MingW/wine.o $(CFLAGS) 48 | 49 | Objects/MingW/vmware.o: $(GLOBALDEPS) vmware.c 50 | $(CC) -c vmware.c -o Objects/MingW/vmware.o $(CFLAGS) 51 | 52 | Objects/MingW/qemu.o: $(GLOBALDEPS) qemu.c 53 | $(CC) -c qemu.c -o Objects/MingW/qemu.o $(CFLAGS) 54 | 55 | Objects/MingW/hooks.o: $(GLOBALDEPS) hooks.c 56 | $(CC) -c hooks.c -o Objects/MingW/hooks.o $(CFLAGS) 57 | 58 | Objects/MingW/cpu.o: $(GLOBALDEPS) cpu.c 59 | $(CC) -c cpu.c -o Objects/MingW/cpu.o $(CFLAGS) 60 | 61 | Objects/MingW/cuckoo.o: $(GLOBALDEPS) cuckoo.c 62 | $(CC) -c cuckoo.c -o Objects/MingW/cuckoo.o $(CFLAGS) 63 | 64 | Objects/MingW/bochs.o: $(GLOBALDEPS) bochs.c 65 | $(CC) -c bochs.c -o Objects/MingW/bochs.o $(CFLAGS) 66 | 67 | Objects/MingW/rtt.o: $(GLOBALDEPS) rtt.c 68 | $(CC) -c rtt.c -o Objects/MingW/rtt.o $(CFLAGS) 69 | 70 | Objects/MingW/pafish_private.res: Objects/MingW/pafish_private.rc 71 | $(WINDRES) Objects/MingW/pafish_private.rc --input-format=rc -o Objects/MingW/pafish_private.res -O coff 72 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # All Vagrant configuration is done below. The "2" in Vagrant.configure 5 | # configures the configuration version (we support older styles for 6 | # backwards compatibility). Please don't change it unless you know what 7 | # you're doing. 8 | Vagrant.configure("2") do |config| 9 | # The most common configuration options are documented and commented below. 10 | # For a complete reference, please see the online documentation at 11 | # https://docs.vagrantup.com. 12 | 13 | # Every Vagrant development environment requires a box. You can search for 14 | # boxes at https://vagrantcloud.com/search. 15 | config.vm.box = "ubuntu/bionic64" 16 | 17 | # Disable automatic box update checking. If you disable this, then 18 | # boxes will only be checked for updates when the user runs 19 | # `vagrant box outdated`. This is not recommended. 20 | # config.vm.box_check_update = false 21 | 22 | # Create a forwarded port mapping which allows access to a specific port 23 | # within the machine from a port on the host machine. In the example below, 24 | # accessing "localhost:8080" will access port 80 on the guest machine. 25 | # NOTE: This will enable public access to the opened port 26 | # config.vm.network "forwarded_port", guest: 80, host: 8080 27 | 28 | # Create a forwarded port mapping which allows access to a specific port 29 | # within the machine from a port on the host machine and only allow access 30 | # via 127.0.0.1 to disable public access 31 | # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" 32 | 33 | # Create a private network, which allows host-only access to the machine 34 | # using a specific IP. 35 | # config.vm.network "private_network", ip: "192.168.33.10" 36 | 37 | # Create a public network, which generally matched to bridged network. 38 | # Bridged networks make the machine appear as another physical device on 39 | # your network. 40 | # config.vm.network "public_network" 41 | 42 | # Share an additional folder to the guest VM. The first argument is 43 | # the path on the host to the actual folder. The second argument is 44 | # the path on the guest to mount the folder. And the optional third 45 | # argument is a set of non-required options. 46 | # config.vm.synced_folder "../data", "/vagrant_data" 47 | 48 | # Provider-specific configuration so you can fine-tune various 49 | # backing providers for Vagrant. These expose provider-specific options. 50 | # Example for VirtualBox: 51 | # 52 | # config.vm.provider "virtualbox" do |vb| 53 | # # Display the VirtualBox GUI when booting the machine 54 | # vb.gui = true 55 | # 56 | # # Customize the amount of memory on the VM: 57 | # vb.memory = "1024" 58 | # end 59 | # 60 | # View the documentation for the provider you are using for more 61 | # information on available options. 62 | 63 | # Enable provisioning with a shell script. Additional provisioners such as 64 | # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the 65 | # documentation for more information about their specific syntax and use. 66 | config.vm.provision "shell", inline: <<-SHELL 67 | apt-get update 68 | apt-get install -y make mingw-w64 69 | cd /vagrant/pafish 70 | make -f Makefile.linux 71 | SHELL 72 | end 73 | -------------------------------------------------------------------------------- /pafish/vmware.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "vmware.h" 8 | #include "types.h" 9 | #include "utils.h" 10 | #include "common.h" 11 | 12 | int vmware_reg_key1() { 13 | if ( pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "VMWARE") || 14 | pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 1\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "VMWARE") || 15 | pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 2\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "VMWARE") 16 | ) 17 | return TRUE; 18 | else 19 | return FALSE; 20 | } 21 | 22 | int vmware_reg_key2() { 23 | return pafish_exists_regkey(HKEY_LOCAL_MACHINE, "SOFTWARE\\VMware, Inc.\\VMware Tools"); 24 | } 25 | 26 | int vmware_sysfile1() { 27 | return pafish_exists_file("C:\\WINDOWS\\system32\\drivers\\vmmouse.sys"); 28 | } 29 | 30 | int vmware_sysfile2() { 31 | return pafish_exists_file("C:\\WINDOWS\\system32\\drivers\\vmhgfs.sys"); 32 | } 33 | 34 | int vmware_mac() { 35 | /* 36 | VMware is any of 37 | 00:05:69 38 | 00:0C:29 39 | 00:1C:14 40 | 00:50:56 41 | */ 42 | if (pafish_check_mac_vendor("\x00\x05\x69")) { 43 | return TRUE; 44 | } 45 | else if (pafish_check_mac_vendor("\x00\x0C\x29")) { 46 | return TRUE; 47 | } 48 | else if (pafish_check_mac_vendor("\x00\x1C\x14")) { 49 | return TRUE; 50 | } 51 | else if (pafish_check_mac_vendor("\x00\x50\x56")) { 52 | return TRUE; 53 | } 54 | else { 55 | return FALSE; 56 | } 57 | } 58 | 59 | int vmware_adapter_name() { 60 | return pafish_check_adapter_name("VMware"); 61 | } 62 | 63 | int vmware_devices(int writelogs) { 64 | HANDLE h; 65 | const int count = 2; 66 | string strs[count]; 67 | int res = FALSE, i = 0; 68 | char message[200]; 69 | 70 | strs[0] = "\\\\.\\HGFS"; 71 | strs[1] = "\\\\.\\vmci"; 72 | for (i=0; i < count; i++) { 73 | h = CreateFile(strs[i], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 74 | if (h != INVALID_HANDLE_VALUE) { 75 | snprintf(message, sizeof(message)-sizeof(message[0]), "VMWare traced using device %s", strs[i]); 76 | if (writelogs) write_log(message); 77 | res = TRUE; 78 | } 79 | } 80 | return res; 81 | } 82 | 83 | /** 84 | * Check the serial number ("VMware") in the returned rows. 85 | */ 86 | int vmware_wmi_check_row(IWbemClassObject *row) { 87 | CIMTYPE type = CIM_ILLEGAL; 88 | VARIANT value; 89 | 90 | HRESULT hresult = row->lpVtbl->Get(row, L"SerialNumber", 0, &value, &type, 0); 91 | 92 | if (FAILED(hresult) || V_VT(&value) == VT_NULL || type != CIM_STRING) { 93 | return FALSE; 94 | } 95 | 96 | return (wcsstr(V_BSTR(&value), L"VMware") != NULL) ? TRUE : FALSE; 97 | } 98 | 99 | /** 100 | * Check for the computer serial using WMI. 101 | */ 102 | int vmware_wmi_serial() { 103 | IWbemServices *services = NULL; 104 | 105 | if (wmi_initialize(L"root\\cimv2", &services) != TRUE) { 106 | return FALSE; 107 | } 108 | 109 | int result = wmi_check_query(services, L"WQL", L"SELECT SerialNumber FROM Win32_Bios", 110 | &vmware_wmi_check_row); 111 | 112 | wmi_cleanup(services); 113 | 114 | return result; 115 | } 116 | -------------------------------------------------------------------------------- /pafish/utils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef UTILS_H 3 | #define UTILS_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef _WDMDDK_ 10 | typedef struct _RTL_BITMAP { 11 | ULONG SizeOfBitMap; 12 | PULONG Buffer; 13 | } RTL_BITMAP, *PRTL_BITMAP; 14 | #endif 15 | 16 | /* 17 | PEB data structure 18 | https://github.com/wine-mirror/wine/blob/1aff1e6a370ee8c0213a0fd4b220d121da8527aa/include/winternl.h#L268 19 | */ 20 | typedef struct _PEB_wine 21 | { /* win32/win64 */ 22 | BOOLEAN InheritedAddressSpace; /* 000/000 */ 23 | BOOLEAN ReadImageFileExecOptions; /* 001/001 */ 24 | BOOLEAN BeingDebugged; /* 002/002 */ 25 | BOOLEAN SpareBool; /* 003/003 */ 26 | HANDLE Mutant; /* 004/008 */ 27 | HMODULE ImageBaseAddress; /* 008/010 */ 28 | PPEB_LDR_DATA LdrData; /* 00c/018 */ 29 | RTL_USER_PROCESS_PARAMETERS *ProcessParameters; /* 010/020 */ 30 | PVOID SubSystemData; /* 014/028 */ 31 | HANDLE ProcessHeap; /* 018/030 */ 32 | PRTL_CRITICAL_SECTION FastPebLock; /* 01c/038 */ 33 | PVOID /*PPEBLOCKROUTINE*/ FastPebLockRoutine; /* 020/040 */ 34 | PVOID /*PPEBLOCKROUTINE*/ FastPebUnlockRoutine; /* 024/048 */ 35 | ULONG EnvironmentUpdateCount; /* 028/050 */ 36 | PVOID KernelCallbackTable; /* 02c/058 */ 37 | ULONG Reserved[2]; /* 030/060 */ 38 | PVOID /*PPEB_FREE_BLOCK*/ FreeList; /* 038/068 */ 39 | ULONG TlsExpansionCounter; /* 03c/070 */ 40 | PRTL_BITMAP TlsBitmap; /* 040/078 */ 41 | ULONG TlsBitmapBits[2]; /* 044/080 */ 42 | PVOID ReadOnlySharedMemoryBase; /* 04c/088 */ 43 | PVOID ReadOnlySharedMemoryHeap; /* 050/090 */ 44 | PVOID *ReadOnlyStaticServerData; /* 054/098 */ 45 | PVOID AnsiCodePageData; /* 058/0a0 */ 46 | PVOID OemCodePageData; /* 05c/0a8 */ 47 | PVOID UnicodeCaseTableData; /* 060/0b0 */ 48 | ULONG NumberOfProcessors; /* 064/0b8 */ 49 | ULONG NtGlobalFlag; /* 068/0bc */ 50 | } PEB_wine, *PPEB_wine; 51 | 52 | int pafish_disable_wow64_fs_redirection(void * old); 53 | 54 | int pafish_revert_wow64_fs_redirection(void * old); 55 | 56 | int pafish_iswow64(); 57 | 58 | struct _PEB_wine * pafish_get_PEB(); 59 | 60 | int pafish_exists_regkey(HKEY hKey, char * regkey); 61 | 62 | int pafish_exists_regkey_value_str(HKEY, char *, char *, char *); 63 | 64 | int pafish_exists_file(char * filename); 65 | 66 | int pafish_check_mac_vendor(char * mac_vendor); 67 | 68 | int pafish_check_adapter_name(char * name); 69 | 70 | /** 71 | * Prototype for the WMI caller implemented function for checking the 72 | * WMI query results. 73 | */ 74 | typedef int (*wmi_check_row) (IWbemClassObject *); 75 | 76 | int wmi_initialize(const wchar_t *, IWbemServices **); 77 | 78 | int wmi_check_query(IWbemServices *, const wchar_t *, const wchar_t *, 79 | wmi_check_row check_row); 80 | 81 | void wmi_cleanup(IWbemServices *); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /pafish/common.c: -------------------------------------------------------------------------------- 1 | 2 | #define _WIN32_WINNT 0x0501 /* _WIN32_WINNT_WINXP */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "config.h" 11 | #include "common.h" 12 | #include "types.h" 13 | 14 | char pafish_pe_img_log[2048]; 15 | 16 | unsigned short init_cmd_colors() { 17 | CONSOLE_SCREEN_BUFFER_INFO csbi; 18 | HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); 19 | // Get original console colors 20 | GetConsoleScreenBufferInfo(handler, &csbi); 21 | SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY); 22 | // Return original console colors 23 | return csbi.wAttributes; 24 | } 25 | 26 | void restore_cmd_colors(unsigned short original_colors) { 27 | HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); 28 | // Restore original console colors 29 | SetConsoleTextAttribute(handler, original_colors); 30 | } 31 | 32 | void print_header() { 33 | HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); 34 | printf("* Pafish ("); 35 | SetConsoleTextAttribute(handler, 11); 36 | printf("Paranoid Fish"); 37 | SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY); 38 | printf(") *\n\n"); 39 | } 40 | 41 | void print_traced() { 42 | HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); 43 | SetConsoleTextAttribute(handler, 207); 44 | printf("traced!\n"); 45 | SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY); 46 | } 47 | 48 | void print_not_traced() { 49 | HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); 50 | SetConsoleTextAttribute(handler, 10); 51 | printf("OK\n"); 52 | SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY); 53 | } 54 | 55 | void print_warning(char * msg) { 56 | HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); 57 | SetConsoleTextAttribute(handler, 224); 58 | printf("%s\n", msg); 59 | SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY); 60 | } 61 | 62 | void write_log(char msg[]) { 63 | FILE *log; 64 | char logstr[1024]; 65 | snprintf(logstr, sizeof(logstr)-sizeof(logstr[0]), "\n[pafish] %s", msg); 66 | log = fopen("pafish.log", "a"); 67 | fputs(logstr, log); 68 | fclose(log); 69 | } 70 | 71 | void write_trace(char product[]) { 72 | FILE *trace; 73 | trace = fopen(product, "a"); 74 | fclose(trace); 75 | #if ENABLE_DNS_TRACE 76 | write_trace_dns(product); 77 | #endif 78 | #if ENABLE_PE_IMG_TRACE 79 | write_trace_pe_img(product, TRUE); 80 | #endif 81 | } 82 | 83 | void write_trace_dns(char product[]) { 84 | char * dns, tld[] = ".pafish"; 85 | int i; 86 | struct addrinfo* result; 87 | int error; 88 | 89 | dns = calloc(strlen(product) + strlen(tld) + sizeof(char), sizeof(char)); 90 | strncpy(dns, product, strlen(product)); 91 | strncat(dns, tld, strlen(tld)); 92 | for (i = 0; i < (int)strlen(dns); i++) { 93 | if (dns[i] == '_') 94 | dns[i] = '-'; 95 | } 96 | 97 | error = getaddrinfo(dns, NULL, NULL, &result); 98 | if (!error) 99 | freeaddrinfo(result); 100 | free(dns); 101 | } 102 | 103 | void write_trace_pe_img(char product[], BOOLEAN add_comma) { 104 | strncat(pafish_pe_img_log, product, strlen(product)); 105 | if (add_comma) 106 | strncat(pafish_pe_img_log, ",", 2); 107 | } 108 | 109 | void print_check_group(char * text) { 110 | printf("\n[-] %s\n", text); 111 | } 112 | 113 | void exec_check(char * text, int (*callback)(), char * text_log, char * text_trace) { 114 | int check_result; 115 | int (*callback_writeslog)(int) = callback; 116 | 117 | printf("[*] %s ... ", text); 118 | 119 | /* Handle functions that write logs */ 120 | if (text_log) 121 | check_result = callback(); 122 | else 123 | check_result = callback_writeslog(TRUE); 124 | 125 | if (check_result == TRUE) { 126 | /* Some checks write their own logs */ 127 | if (text_log) 128 | write_log(text_log); 129 | print_traced(); 130 | write_trace(text_trace); 131 | } 132 | else print_not_traced(); 133 | } 134 | 135 | -------------------------------------------------------------------------------- /pafish/gensandbox.c: -------------------------------------------------------------------------------- 1 | 2 | #define _WIN32_WINNT 0x0501 /* _WIN32_WINNT_WINXP */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "types.h" 12 | #include "gensandbox.h" 13 | #include "utils.h" 14 | 15 | /** 16 | * Prototype for IsNativeVhdBoot, which is only available in >= Windows 8 17 | */ 18 | typedef BOOL (WINAPI * IsNativeVhdBoot) (BOOL *); 19 | 20 | 21 | int gensandbox_username() { 22 | char username[200]; 23 | size_t i; 24 | DWORD usersize = sizeof(username); 25 | GetUserName(username, &usersize); 26 | for (i = 0; i < strlen(username); i++) { /* case-insensitive */ 27 | username[i] = toupper(username[i]); 28 | } 29 | if (strstr(username, "SANDBOX") != NULL) { 30 | return TRUE; 31 | } 32 | if (strstr(username, "VIRUS") != NULL) { 33 | return TRUE; 34 | } 35 | if (strstr(username, "MALWARE") != NULL) { 36 | return TRUE; 37 | } 38 | return FALSE; 39 | } 40 | 41 | int gensandbox_path() { 42 | char path[500]; 43 | size_t i; 44 | DWORD pathsize = sizeof(path); 45 | GetModuleFileName(NULL, path, pathsize); 46 | for (i = 0; i < strlen(path); i++) { /* case-insensitive */ 47 | path[i] = toupper(path[i]); 48 | } 49 | if (strstr(path, "\\SAMPLE") != NULL) { 50 | return TRUE; 51 | } 52 | if (strstr(path, "\\VIRUS") != NULL) { 53 | return TRUE; 54 | } 55 | if (strstr(path, "SANDBOX") != NULL) { 56 | return TRUE; 57 | } 58 | return FALSE; 59 | } 60 | 61 | int gensandbox_common_names() { 62 | DWORD dwSize = MAX_PATH; 63 | char szLogicalDrives[MAX_PATH] = {0}; 64 | DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives); 65 | BOOL exists; 66 | 67 | if (dwResult > 0 && dwResult <= MAX_PATH) 68 | { 69 | char* szSingleDrive = szLogicalDrives; 70 | char filename[MAX_PATH] = {0}; 71 | while(*szSingleDrive) 72 | { 73 | if (GetDriveType(szSingleDrive) != DRIVE_REMOVABLE ) { 74 | snprintf(filename, MAX_PATH, "%ssample.exe",szSingleDrive); 75 | exists = pafish_exists_file(filename); 76 | if (exists) return TRUE; 77 | snprintf(filename, MAX_PATH, "%smalware.exe",szSingleDrive); 78 | exists = pafish_exists_file(filename); 79 | if (exists) return TRUE; 80 | } 81 | szSingleDrive += strlen(szSingleDrive) + 1; 82 | } 83 | } 84 | return FALSE; 85 | } 86 | 87 | int gensandbox_drive_size() { 88 | HANDLE drive; 89 | BOOL result; 90 | GET_LENGTH_INFORMATION size; 91 | DWORD lpBytesReturned; 92 | 93 | drive = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 94 | if (drive == INVALID_HANDLE_VALUE) { 95 | // Someone is playing tricks. Or not enough privileges. 96 | CloseHandle(drive); 97 | return FALSE; 98 | } 99 | result = DeviceIoControl(drive, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &size, 100 | sizeof(GET_LENGTH_INFORMATION), &lpBytesReturned, NULL); 101 | CloseHandle(drive); 102 | if (result != 0) { 103 | if (size.Length.QuadPart / 1073741824 <= 60) /* <= 60 GB */ 104 | return TRUE; 105 | } 106 | return FALSE; 107 | } 108 | 109 | int gensandbox_drive_size2() { 110 | ULARGE_INTEGER total_bytes; 111 | 112 | if (GetDiskFreeSpaceExA("C:\\", NULL, &total_bytes, NULL)) 113 | { 114 | if (total_bytes.QuadPart / 1073741824 <= 60) /* <= 60 GB */ 115 | return TRUE; 116 | } 117 | return FALSE; 118 | } 119 | 120 | int gensandbox_sleep_patched() { 121 | DWORD time1; 122 | 123 | time1 = GetTickCount(); 124 | Sleep(500); 125 | if ((GetTickCount() - time1) > 450 ) return FALSE; 126 | else return TRUE; 127 | } 128 | 129 | int gensandbox_one_cpu() { 130 | struct _PEB_wine * PEB; 131 | PEB = pafish_get_PEB(); 132 | return PEB->NumberOfProcessors < 2 ? TRUE : FALSE; 133 | } 134 | 135 | int gensandbox_one_cpu_GetSystemInfo() { 136 | SYSTEM_INFO siSysInfo; 137 | GetSystemInfo(&siSysInfo); 138 | return siSysInfo.dwNumberOfProcessors < 2 ? TRUE : FALSE; 139 | } 140 | 141 | int gensandbox_less_than_onegb() { 142 | MEMORYSTATUSEX statex; 143 | statex.dwLength = sizeof (statex); 144 | 145 | GlobalMemoryStatusEx(&statex); 146 | return (statex.ullTotalPhys/1024) < 1048576 ? TRUE : FALSE; 147 | } 148 | 149 | int gensandbox_uptime() { 150 | /* < ~12 minutes */ 151 | return GetTickCount() < 0xAFE74 ? TRUE : FALSE; 152 | } 153 | 154 | int gensandbox_IsNativeVhdBoot() { 155 | BOOL isnative = FALSE; 156 | IsNativeVhdBoot fnnative = (IsNativeVhdBoot) GetProcAddress( 157 | GetModuleHandleA("kernel32"), "IsNativeVhdBoot"); 158 | /* IsNativeVhdBoot always returns 1 on query success */ 159 | if (fnnative) 160 | fnnative(&isnative); 161 | return (isnative) ? TRUE : FALSE; 162 | } 163 | 164 | -------------------------------------------------------------------------------- /pafish/cpu.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "types.h" 8 | #include "cpu.h" 9 | 10 | static inline unsigned long long rdtsc_diff() { 11 | unsigned long long ret, ret2; 12 | unsigned eax, edx; 13 | __asm__ volatile("rdtsc" : "=a" (eax), "=d" (edx)); 14 | ret = ((unsigned long long)eax) | (((unsigned long long)edx) << 32); 15 | __asm__ volatile("rdtsc" : "=a" (eax), "=d" (edx)); 16 | ret2 = ((unsigned long long)eax) | (((unsigned long long)edx) << 32); 17 | return ret2 - ret; 18 | } 19 | 20 | static inline unsigned long long rdtsc_diff_vmexit() { 21 | unsigned long long ret, ret2; 22 | unsigned eax, edx; 23 | __asm__ volatile("rdtsc" : "=a" (eax), "=d" (edx)); 24 | ret = ((unsigned long long)eax) | (((unsigned long long)edx) << 32); 25 | /* vm exit forced here. it uses: eax = 0; cpuid; */ 26 | __asm__ volatile("cpuid" : /* no output */ : "a"(0x00)); 27 | /**/ 28 | __asm__ volatile("rdtsc" : "=a" (eax), "=d" (edx)); 29 | ret2 = ((unsigned long long)eax) | (((unsigned long long)edx) << 32); 30 | return ret2 - ret; 31 | } 32 | 33 | static inline void cpuid_vendor_00(char * vendor) { 34 | int ebx = 0, ecx = 0, edx = 0; 35 | 36 | __asm__ volatile("cpuid" \ 37 | : "=b"(ebx), \ 38 | "=c"(ecx), \ 39 | "=d"(edx) \ 40 | : "a"(0x00)); 41 | sprintf(vendor , "%c%c%c%c", ebx, (ebx >> 8), (ebx >> 16), (ebx >> 24)); 42 | sprintf(vendor+4, "%c%c%c%c", edx, (edx >> 8), (edx >> 16), (edx >> 24)); 43 | sprintf(vendor+8, "%c%c%c%c", ecx, (ecx >> 8), (ecx >> 16), (ecx >> 24)); 44 | vendor[12] = 0x00; 45 | } 46 | 47 | static inline void cpuid_hv_vendor_00(char * vendor) { 48 | int ebx = 0, ecx = 0, edx = 0; 49 | 50 | __asm__ volatile("cpuid" \ 51 | : "=b"(ebx), \ 52 | "=c"(ecx), \ 53 | "=d"(edx) \ 54 | : "a"(0x40000000)); 55 | sprintf(vendor , "%c%c%c%c", ebx, (ebx >> 8), (ebx >> 16), (ebx >> 24)); 56 | sprintf(vendor+4, "%c%c%c%c", ecx, (ecx >> 8), (ecx >> 16), (ecx >> 24)); 57 | sprintf(vendor+8, "%c%c%c%c", edx, (edx >> 8), (edx >> 16), (edx >> 24)); 58 | vendor[12] = 0x00; 59 | } 60 | 61 | static inline void cpuid_brand(char * brand, uint32_t eax_value) { 62 | int eax = 0, ebx = 0, ecx = 0, edx = 0; 63 | 64 | __asm__ volatile("cpuid" \ 65 | : "=a"(eax), \ 66 | "=b"(ebx), \ 67 | "=c"(ecx), \ 68 | "=d"(edx) \ 69 | : "a"(eax_value)); 70 | sprintf(brand , "%c%c%c%c", eax, (eax >> 8), (eax >> 16), (eax >> 24)); 71 | sprintf(brand+4 , "%c%c%c%c", ebx, (ebx >> 8), (ebx >> 16), (ebx >> 24)); 72 | sprintf(brand+8 , "%c%c%c%c", ecx, (ecx >> 8), (ecx >> 16), (ecx >> 24)); 73 | sprintf(brand+12, "%c%c%c%c", edx, (edx >> 8), (edx >> 16), (edx >> 24)); 74 | } 75 | 76 | static inline int cpuid_hv_bit() { 77 | int ecx; 78 | __asm__ volatile("cpuid" \ 79 | : "=c"(ecx) \ 80 | : "a"(0x01)); 81 | return (ecx >> 31) & 0x1; 82 | } 83 | 84 | int cpu_rdtsc() { 85 | int i; 86 | unsigned long long avg = 0; 87 | for (i = 0; i < 10; i++) { 88 | avg = avg + rdtsc_diff(); 89 | Sleep(500); 90 | } 91 | avg = avg / 10; 92 | return (avg < 750 && avg > 0) ? FALSE : TRUE; 93 | } 94 | 95 | int cpu_rdtsc_force_vmexit() { 96 | int i; 97 | unsigned long long avg = 0; 98 | for (i = 0; i < 10; i++) { 99 | avg = avg + rdtsc_diff_vmexit(); 100 | Sleep(500); 101 | } 102 | avg = avg / 10; 103 | return (avg < 1000 && avg > 0) ? FALSE : TRUE; 104 | } 105 | 106 | int cpu_hv() { 107 | return cpuid_hv_bit() ? TRUE : FALSE; 108 | } 109 | 110 | void cpu_write_vendor(char * vendor) { 111 | cpuid_vendor_00(vendor); 112 | } 113 | 114 | void cpu_write_hv_vendor(char * vendor) { 115 | cpuid_hv_vendor_00(vendor); 116 | } 117 | 118 | void cpu_write_brand(char * brand) { 119 | int eax; 120 | /* Check if Processor Brand String is supported */ 121 | __asm__ volatile(".intel_syntax noprefix;" 122 | "mov eax, 0x80000000;" 123 | "cpuid;" 124 | "cmp eax, 0x80000004;" 125 | "xor eax, eax;" 126 | "setge al;" 127 | ".att_syntax;" 128 | : "=a"(eax) 129 | ); 130 | /* It's supported, so fill char * brand */ 131 | if (eax) { 132 | cpuid_brand(brand, 0x80000002); 133 | cpuid_brand(brand+16, 0x80000003); 134 | cpuid_brand(brand+32, 0x80000004); 135 | brand[48] = 0x00; 136 | } 137 | } 138 | 139 | int cpu_known_vm_vendors() { 140 | const int count = 6; 141 | int i; 142 | char cpu_hv_vendor[13]; 143 | string strs[count]; 144 | strs[0] = "KVMKVMKVM\0\0\0"; /* KVM */ 145 | strs[1] = "Microsoft Hv"; /* Microsoft Hyper-V or Windows Virtual PC */ 146 | strs[2] = "VMwareVMware"; /* VMware */ 147 | strs[3] = "XenVMMXenVMM"; /* Xen */ 148 | strs[4] = "prl hyperv "; /* Parallels */ 149 | strs[5] = "VBoxVBoxVBox"; /* VirtualBox */ 150 | cpu_write_hv_vendor(cpu_hv_vendor); 151 | for (i = 0; i < count; i++) { 152 | if (!memcmp(cpu_hv_vendor, strs[i], 12)) return TRUE; 153 | } 154 | return FALSE; 155 | } 156 | 157 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2 | v06 3 | 4 | See https://github.com/a0rtega/pafish/releases 5 | 6 | v058 7 | 8 | - Bugfix release 9 | - Fix "LocalFree after advanced list" #49 10 | - Fix typo 11 | - Add Wpedantic 12 | 13 | v057 14 | 15 | - Fix "Failure to detect Xen" #47 16 | - Add hypervisor information 17 | 18 | v056 19 | 20 | - Added new checks 21 | - IsNativeVhdBoot #46 22 | - OS uptime check #45 23 | 24 | - Added a DNS request trace for each detection #43 25 | - Disabled check_hook_DeleteFileW_m1 because it causes FP in Win 8 26 | 27 | v055 28 | 29 | - Added new checks 30 | - Neutrino bot bochs detection #40 31 | - Qemu detection based on CPU brand string 32 | - Bochs detections based on CPU brand string 33 | - VMware detection based on network adapter name 34 | - Minor refactor userland hook detection, added 35 | 2 more functions to check. 36 | 37 | - Added cpu functions to query Processor Brand String 38 | - Some refactoring, specially main.c, making it easier 39 | to add new checks. 40 | 41 | v054 42 | 43 | - Added new checks (Hacking Team antiVM) 44 | - VirtualBox device identifiers using WMI 45 | - VMware serial number using WMI 46 | - HT's cuckoo evasion turned into detection 47 | (TLS_HOOK_INFO_RETADDR_SPACE address alloc check) 48 | - Fixes 49 | - Fix #37 warning on MinGW linux 50 | 51 | - Contributors to this release 52 | serializingme 53 | 54 | v053 55 | 56 | - Added new checks 57 | - Systems with less than 1GB of memory 58 | - Wine registry key HKCU\\SOFTWARE\\Wine 59 | - VMware pseudo-devices 60 | - VMware MAC addresses 61 | 62 | - Fixes 63 | - Handle filesystem redirection in x86_64 systems 64 | - Handle registry redirection in x86_64 systems 65 | - A proper fix for Linux compilation 66 | 67 | - Contributors to this release 68 | serializingme 69 | 70 | v052 71 | 72 | - Minor release to add two different NumberOfProcessors based detection used by 73 | new Dyre malware version: 74 | gensandbox_one_cpu() 75 | gensandbox_one_cpu_GetSystemInfo() 76 | - Fixes #25 (compilation error in linux) 77 | 78 | v051 79 | 80 | - Minor release to add a new detection based on CPU information, 81 | Checking the difference between CPU timestamp counters (rdtsc) forcing VM exit 82 | - gcc -O0 due to errors in low level functions caused by the 83 | optimizations 84 | - Minor coding style changes 85 | 86 | v05 87 | 88 | - Added a new set of detections based on CPU information 89 | - rdtsc timing detection 90 | - cpuid vendor string 91 | - cpuid hv bit 92 | - Added a new generic sandbox detection for sample.exe and malware.exe 93 | in drives root 94 | - Added a new VirtualBox detection based on SystemBiosDate 95 | - Added more ports to Scsi in VMWare 96 | - Greatly reduced icon size 97 | 98 | - Bugfixes 99 | - Restore CLI colors when finish 100 | 101 | - Code style 102 | - Now CFLAGS includes -Wall -Wextra 103 | - cppcheck scan 104 | - With this, lots of code style changes and minor fixes 105 | have been done 106 | 107 | - Contributors for this release 108 | Inaki Rodriguez 109 | mlw.re 110 | Sanchit Karve 111 | Mikael Keri 112 | 113 | v04 114 | 115 | - Added new VirtualBox detections and system traces 116 | - HKLM\\HARDWARE\\ACPI\\DSDT\\VBOX__ 117 | - HKLM\\HARDWARE\\ACPI\\FADT\\VBOX__ 118 | - HKLM\\HARDWARE\\ACPI\\RSDT\\VBOX__ 119 | - HKLM\\SYSTEM\\ControlSet001\\Services\\VBox* 120 | - C:\\WINDOWS\\system32\\drivers\\VBox* 121 | - C:\\WINDOWS\\system32\\vbox* 122 | - C:\\program files\\oracle\\virtualbox guest additions\\ 123 | - MAC address starting with 08:00:27 124 | - Pseudo devices (VBoxMiniRdrDN, VBoxTrayIPC) 125 | - VBoxTray windows 126 | - VBox network share 127 | - VBox processes (vboxservice.exe, vboxtray.exe) 128 | - Added GetTickCount() sleep patching detection 129 | - Added new way to get disk size (GetDiskFreeSpaceExA) 130 | 131 | Developers: 132 | - Build system migrated to pure MinGW (make + gcc) + windres for resources 133 | - utils.c now contains repetitive functions 134 | - TRUE FALSE types defined in types.h, no more confusion when returning 135 | 136 | Contributions: 137 | - Thanks to Thorsten Sick (https://github.com/Thorsten-Sick) for it's 138 | valuable contributions, most of this release is thanks to him. 139 | 140 | v03 141 | 142 | - Added disk size < 50 GB detection trick 143 | - Added ring3 hooks detection trick 144 | - Created files when detections match are more 145 | accurate now 146 | - Sleep time in lack of mouse activity detection 147 | increased to 1750 ms 148 | 149 | v025 150 | 151 | - New colors schema 152 | - Added file creation traces when detection to 153 | follow them 154 | - Added one new detection for VirtualBox 155 | 156 | v024 157 | 158 | - From now, official pafish executables will be signed, readme for 159 | more information 160 | 161 | v023 162 | 163 | - Added two new detections for generic sandboxes (username, file path) 164 | - Added one new detection for VMware (driver file) 165 | - Added one new detection for Qemu (reg key) 166 | 167 | v022 168 | 169 | - Added one new detection for Qemu 170 | 171 | v02 172 | 173 | - Now pafish writes a log file (pafish.log) to 174 | easily track detections 175 | 176 | - Deleted one dummy detection for Sandboxie 177 | 178 | - Added two new detections for VirtualBox 179 | - Added one new detection for wine 180 | - Added three new detections for VMware 181 | - Added one new detection for generic sandboxes 182 | 183 | - Some coding style improvements 184 | - gcc optimization flag in compilation -O1 185 | 186 | v01 187 | 188 | - First version 189 | 190 | -------------------------------------------------------------------------------- /pafish/vbox.c: -------------------------------------------------------------------------------- 1 | 2 | #define _WIN32_WINNT 0x0501 /* _WIN32_WINNT_WINXP */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "vbox.h" 11 | #include "utils.h" 12 | #include "types.h" 13 | #include "common.h" 14 | 15 | /** 16 | * SCSI registry key check 17 | **/ 18 | int vbox_reg_key1() { 19 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "VBOX"); 20 | } 21 | 22 | /** 23 | * SystemBiosVersion registry key check 24 | **/ 25 | int vbox_reg_key2() { 26 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "VBOX"); 27 | } 28 | 29 | /** 30 | * VirtualBox Guest Additions key check 31 | **/ 32 | int vbox_reg_key3() { 33 | return pafish_exists_regkey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Oracle\\VirtualBox Guest Additions"); 34 | } 35 | 36 | /** 37 | * VideoBiosVersion key check 38 | **/ 39 | int vbox_reg_key4() { 40 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "VideoBiosVersion", "VIRTUALBOX"); 41 | } 42 | 43 | /** 44 | * ACPI Regkey detection 45 | **/ 46 | int vbox_reg_key5() { 47 | return pafish_exists_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\DSDT\\VBOX__"); 48 | } 49 | 50 | /** 51 | * FADT ACPI Regkey detection 52 | **/ 53 | int vbox_reg_key7() { 54 | return pafish_exists_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\FADT\\VBOX__"); 55 | } 56 | 57 | /** 58 | * RSDT ACPI Regkey detection 59 | **/ 60 | int vbox_reg_key8() { 61 | return pafish_exists_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\RSDT\\VBOX__"); 62 | } 63 | 64 | /** 65 | * VirtualBox Services Regkey detection 66 | **/ 67 | int vbox_reg_key9(int writelogs) { 68 | int res = FALSE, i; 69 | const int count = 5; 70 | char message[200]; 71 | 72 | string strs[count]; 73 | strs[0] = "SYSTEM\\ControlSet001\\Services\\VBoxGuest"; 74 | strs[1] = "SYSTEM\\ControlSet001\\Services\\VBoxMouse"; 75 | strs[2] = "SYSTEM\\ControlSet001\\Services\\VBoxService"; 76 | strs[3] = "SYSTEM\\ControlSet001\\Services\\VBoxSF"; 77 | strs[4] = "SYSTEM\\ControlSet001\\Services\\VBoxVideo"; 78 | for (i=0; i < count; i++) { 79 | if (pafish_exists_regkey(HKEY_LOCAL_MACHINE, strs[i])) { 80 | snprintf(message, sizeof(message)-sizeof(message[0]), "VirtualBox traced using Reg key HKLM\\%s", strs[i]); 81 | if (writelogs) write_log(message); 82 | res = TRUE; 83 | } 84 | } 85 | return res; 86 | } 87 | 88 | /** 89 | * HARDWARE\\DESCRIPTION\\System SystemBiosDate == 06/23/99 90 | **/ 91 | int vbox_reg_key10() { 92 | return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System", "SystemBiosDate", "06/23/99"); 93 | } 94 | 95 | /** 96 | * VirtualBox driver files in \\WINDOWS\\system32\\drivers\\ 97 | **/ 98 | int vbox_sysfile1(int writelogs) { 99 | const int count = 4; 100 | string strs[count]; 101 | int res = FALSE, i = 0; 102 | char message[200]; 103 | 104 | strs[0] = "C:\\WINDOWS\\system32\\drivers\\VBoxMouse.sys"; 105 | strs[1] = "C:\\WINDOWS\\system32\\drivers\\VBoxGuest.sys"; 106 | strs[2] = "C:\\WINDOWS\\system32\\drivers\\VBoxSF.sys"; 107 | strs[3] = "C:\\WINDOWS\\system32\\drivers\\VBoxVideo.sys"; 108 | for (i=0; i < count; i++) { 109 | if (pafish_exists_file(strs[i])) { 110 | snprintf(message, sizeof(message)-sizeof(message[0]), "VirtualBox traced using driver file %s", strs[i]); 111 | if (writelogs) write_log(message); 112 | res = TRUE; 113 | } 114 | } 115 | return res; 116 | } 117 | 118 | /** 119 | * VirtualBox other system files 120 | **/ 121 | int vbox_sysfile2(int writelogs) { 122 | const int count = 14; 123 | string strs[count]; 124 | int res = FALSE, i = 0; 125 | char message[200]; 126 | 127 | strs[0] = "C:\\WINDOWS\\system32\\vboxdisp.dll"; 128 | strs[1] = "C:\\WINDOWS\\system32\\vboxhook.dll"; 129 | strs[2] = "C:\\WINDOWS\\system32\\vboxmrxnp.dll"; 130 | strs[3] = "C:\\WINDOWS\\system32\\vboxogl.dll"; 131 | strs[4] = "C:\\WINDOWS\\system32\\vboxoglarrayspu.dll"; 132 | strs[5] = "C:\\WINDOWS\\system32\\vboxoglcrutil.dll"; 133 | strs[6] = "C:\\WINDOWS\\system32\\vboxoglerrorspu.dll"; 134 | strs[7] = "C:\\WINDOWS\\system32\\vboxoglfeedbackspu.dll"; 135 | strs[8] = "C:\\WINDOWS\\system32\\vboxoglpackspu.dll"; 136 | strs[9] = "C:\\WINDOWS\\system32\\vboxoglpassthroughspu.dll"; 137 | strs[10] = "C:\\WINDOWS\\system32\\vboxservice.exe"; 138 | strs[11] = "C:\\WINDOWS\\system32\\vboxtray.exe"; 139 | strs[12] = "C:\\WINDOWS\\system32\\VBoxControl.exe"; 140 | strs[13] = "C:\\program files\\oracle\\virtualbox guest additions\\"; 141 | for (i = 0; i < count; i++) { 142 | if (pafish_exists_file(strs[i])) { 143 | snprintf(message, sizeof(message)-sizeof(message[0]), "VirtualBox traced using system file %s", strs[i]); 144 | if (writelogs) write_log(message); 145 | res = TRUE; 146 | } 147 | } 148 | return res; 149 | } 150 | 151 | /** 152 | * NIC MAC check 153 | **/ 154 | int vbox_mac() { 155 | /* VirtualBox mac starts with 08:00:27 */ 156 | return pafish_check_mac_vendor("\x08\x00\x27"); 157 | } 158 | 159 | /** 160 | * VirtualBox devices 161 | **/ 162 | int vbox_devices(int writelogs) { 163 | HANDLE h; 164 | const int count = 4; 165 | string strs[count]; 166 | int res = FALSE, i = 0; 167 | char message[200]; 168 | 169 | /* Got this list from https://github.com/cuckoobox/community/blob/master/modules/signatures/antivm_vbox_devices.py */ 170 | strs[0] = "\\\\.\\VBoxMiniRdrDN"; 171 | strs[1] = "\\\\.\\pipe\\VBoxMiniRdDN"; 172 | strs[2] = "\\\\.\\VBoxTrayIPC"; 173 | strs[3] = "\\\\.\\pipe\\VBoxTrayIPC"; 174 | for (i=0; i < count; i++) { 175 | h = CreateFile(strs[i], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 176 | if (h != INVALID_HANDLE_VALUE) { 177 | snprintf(message, sizeof(message)-sizeof(message[0]), "VirtualBox traced using device %s", strs[i]); 178 | if (writelogs) write_log(message); 179 | res = TRUE; 180 | } 181 | } 182 | return res; 183 | } 184 | 185 | /** 186 | * Checking for Tray window 187 | * https://twitter.com/waleedassar 188 | **/ 189 | int vbox_traywindow() { 190 | HWND h1, h2; 191 | h1 = FindWindow("VBoxTrayToolWndClass", NULL); 192 | h2 = FindWindow(NULL, "VBoxTrayToolWnd"); 193 | if (h1 || h2) return TRUE; 194 | else return FALSE; 195 | } 196 | 197 | /** 198 | * Checking network shared 199 | * https://twitter.com/waleedassar 200 | **/ 201 | int vbox_network_share() { 202 | unsigned long pnsize = 0x1000; 203 | char provider[pnsize]; 204 | /* a0rtega : any reason for this to be in the heap :?, changed to stack */ 205 | //char * provider = (char *)LocalAlloc(LMEM_ZEROINIT, pnsize); 206 | 207 | int retv = WNetGetProviderName(WNNC_NET_RDR2SAMPLE, provider, &pnsize); 208 | if (retv == NO_ERROR) { 209 | if (lstrcmpi(provider, "VirtualBox Shared Folders") == 0) { 210 | //LocalFree(provider); 211 | return TRUE; 212 | } 213 | else { 214 | //LocalFree(provider); 215 | return FALSE; 216 | } 217 | } 218 | return FALSE; 219 | } 220 | 221 | /** 222 | * Checking for virtual box processes 223 | **/ 224 | int vbox_processes(int writelogs) { 225 | int res = FALSE; 226 | HANDLE hpSnap; 227 | PROCESSENTRY32 pentry; 228 | 229 | hpSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); 230 | if (hpSnap != INVALID_HANDLE_VALUE) { 231 | pentry.dwSize = sizeof (PROCESSENTRY32); 232 | } 233 | else { 234 | return FALSE; 235 | } 236 | 237 | if(!Process32First(hpSnap, &pentry)) { 238 | CloseHandle(hpSnap); 239 | return FALSE; 240 | } 241 | 242 | do { 243 | if (lstrcmpi(pentry.szExeFile, "vboxservice.exe") == 0) { 244 | if (writelogs) write_log("VirtualBox traced using vboxservice.exe process"); 245 | res = TRUE; 246 | } 247 | if (lstrcmpi(pentry.szExeFile, "vboxtray.exe") == 0) { 248 | if (writelogs) write_log("VirtualBox traced using vboxtray.exe process"); 249 | res = TRUE; 250 | } 251 | } while (Process32Next(hpSnap, &pentry)); 252 | return res; 253 | } 254 | 255 | /** 256 | * Check if the device identifier ("PCI\\VEN_80EE&DEV_CAFE") in the returned rows. 257 | */ 258 | int vbox_wmi_check_row(IWbemClassObject *row) { 259 | CIMTYPE type = CIM_ILLEGAL; 260 | VARIANT value; 261 | 262 | HRESULT hresult = row->lpVtbl->Get(row, L"DeviceId", 0, &value, &type, 0); 263 | 264 | if (FAILED(hresult) || V_VT(&value) == VT_NULL || type != CIM_STRING) { 265 | return FALSE; 266 | } 267 | 268 | return (wcsstr(V_BSTR(&value), L"PCI\\VEN_80EE&DEV_CAFE") != NULL) ? TRUE : FALSE; 269 | } 270 | 271 | /** 272 | * Check for devices VirtualBox devices using WMI. 273 | */ 274 | int vbox_wmi_devices() { 275 | IWbemServices *services = NULL; 276 | 277 | if (wmi_initialize(L"root\\cimv2", &services) != TRUE) { 278 | return FALSE; 279 | } 280 | 281 | int result = wmi_check_query(services, L"WQL", L"SELECT DeviceId FROM Win32_PnPEntity", 282 | &vbox_wmi_check_row); 283 | 284 | wmi_cleanup(services); 285 | 286 | return result; 287 | } 288 | -------------------------------------------------------------------------------- /pafish/utils.c: -------------------------------------------------------------------------------- 1 | 2 | #define _WIN32_WINNT 0x0501 /* _WIN32_WINNT_WINXP */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "utils.h" 14 | #include "types.h" 15 | 16 | #ifndef KEY_WOW64_32KEY 17 | #define KEY_WOW64_32KEY 0x0200 18 | #endif 19 | 20 | #ifndef KEY_WOW64_64KEY 21 | #define KEY_WOW64_64KEY 0x0100 22 | #endif 23 | 24 | /** 25 | * Prototypes for the Wow64 API's since they aren't available in all Windows 26 | * versions, most notably Windows XP 32 bits. 27 | */ 28 | typedef BOOL (WINAPI *DisableWow64FsRedirectionProto) (void*); 29 | 30 | typedef BOOL (WINAPI *RevertWow64FsRedirectionProto) (void*); 31 | 32 | typedef BOOL (WINAPI *IsWow64ProcessProto) (HANDLE, BOOL*); 33 | 34 | /** 35 | * Wrapper function for Wow64DisableWow64FsRedirection. The function returns 36 | * FALSE if the Wow64DisableWow64FsRedirection is not found or the invocation 37 | * fails. The old value is returned in the argument old. 38 | */ 39 | int pafish_disable_wow64_fs_redirection(void * old) { 40 | DisableWow64FsRedirectionProto fndisable = (DisableWow64FsRedirectionProto) GetProcAddress( 41 | GetModuleHandleA("kernel32"), "Wow64DisableWow64FsRedirection"); 42 | 43 | return (fndisable) && (fndisable(old) != 0) ? TRUE : FALSE; 44 | } 45 | 46 | /** 47 | * Wrapper function for Wow64RevertWow64FsRedirection. The function returns 48 | * FALSE if the Wow64RevertWow64FsRedirection is not found or the invocation 49 | * fails. The old value is to be provided using the argument old. 50 | */ 51 | int pafish_revert_wow64_fs_redirection(void * old) { 52 | RevertWow64FsRedirectionProto fnrevert = (RevertWow64FsRedirectionProto) GetProcAddress( 53 | GetModuleHandleA("kernel32"), "Wow64RevertWow64FsRedirection"); 54 | 55 | return (fnrevert) && (fnrevert(old) != 0) ? TRUE : FALSE; 56 | } 57 | 58 | /** 59 | * Wrapper function for IsWow64Process. The function returns TRUE if the 60 | * current process is running under Wow64, FALSE otherwise or if the 61 | * invocation failed. 62 | */ 63 | int pafish_iswow64() { 64 | int result = FALSE; 65 | 66 | IsWow64ProcessProto fniswow = (IsWow64ProcessProto) GetProcAddress( 67 | GetModuleHandleA("kernel32"), "IsWow64Process"); 68 | 69 | return (fniswow) && (fniswow(GetCurrentProcess(), &result) != 0) ? result : FALSE; 70 | } 71 | 72 | struct _PEB_wine * pafish_get_PEB() { 73 | struct _PEB_wine * PEB_ptr; 74 | __asm__ volatile ( 75 | #if __i386__ 76 | "mov %%fs:0x18, %%eax;" 77 | "mov %%ds:0x30(%%eax), %%eax;" 78 | #endif 79 | #if __x86_64__ 80 | "mov %%gs:0x30, %%rax;" 81 | "mov %%ds:0x60(%%rax), %%rax;" 82 | #endif 83 | : "=a"(PEB_ptr)); 84 | return PEB_ptr; 85 | } 86 | 87 | int pafish_exists_regkey(HKEY hKey, char * regkey_s) { 88 | HKEY regkey; 89 | LONG ret; 90 | 91 | if (pafish_iswow64()) { 92 | ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ | KEY_WOW64_64KEY, ®key); 93 | } 94 | else { 95 | ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, ®key); 96 | } 97 | if (ret == ERROR_SUCCESS) { 98 | RegCloseKey(regkey); 99 | return TRUE; 100 | } 101 | else 102 | return FALSE; 103 | } 104 | 105 | int pafish_exists_regkey_value_str(HKEY hKey, char * regkey_s, char * value_s, char * lookup) { 106 | HKEY regkey; 107 | LONG ret; 108 | DWORD size; 109 | char value[1024], * lookup_str; 110 | size_t lookup_size; 111 | 112 | lookup_size = strlen(lookup); 113 | lookup_str = malloc(lookup_size+sizeof(char)); 114 | strncpy(lookup_str, lookup, lookup_size+sizeof(char)); 115 | 116 | size = sizeof(value); 117 | if (pafish_iswow64()) { 118 | ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ | KEY_WOW64_64KEY, ®key); 119 | } 120 | else { 121 | ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, ®key); 122 | } 123 | if (ret == ERROR_SUCCESS) { 124 | ret = RegQueryValueEx(regkey, value_s, NULL, NULL, (BYTE*)value, &size); 125 | RegCloseKey(regkey); 126 | if (ret == ERROR_SUCCESS) { 127 | size_t i; 128 | for (i = 0; i < strlen(value); i++) { /* case-insensitive */ 129 | value[i] = toupper(value[i]); 130 | } 131 | for (i = 0; i < lookup_size; i++) { /* case-insensitive */ 132 | lookup_str[i] = toupper(lookup_str[i]); 133 | } 134 | if (strstr(value, lookup_str) != NULL) { 135 | free(lookup_str); 136 | return TRUE; 137 | } 138 | } 139 | } 140 | free(lookup_str); 141 | return FALSE; 142 | } 143 | 144 | int pafish_exists_file(char * filename) { 145 | DWORD res = INVALID_FILE_ATTRIBUTES; 146 | 147 | if (pafish_iswow64() == TRUE) { 148 | void *old = NULL; 149 | 150 | // Disable redirection immediately prior to calling GetFileAttributes. 151 | if (pafish_disable_wow64_fs_redirection(&old) ) { 152 | res = GetFileAttributes(filename); 153 | 154 | // Ignoring MSDN recommendation of exiting if this call fails. 155 | pafish_revert_wow64_fs_redirection(old); 156 | } 157 | } 158 | else { 159 | res = GetFileAttributes(filename); 160 | } 161 | 162 | return (res != INVALID_FILE_ATTRIBUTES) ? TRUE : FALSE; 163 | } 164 | 165 | int pafish_check_mac_vendor(char * mac_vendor) { 166 | unsigned long alist_size = 0, ret; 167 | 168 | ret = GetAdaptersAddresses(AF_UNSPEC,0,0,0,&alist_size); 169 | if(ret==ERROR_BUFFER_OVERFLOW) { 170 | IP_ADAPTER_ADDRESSES* palist = (IP_ADAPTER_ADDRESSES*)LocalAlloc(LMEM_ZEROINIT,alist_size); 171 | void * palist_free = palist; 172 | if(palist) { 173 | GetAdaptersAddresses(AF_UNSPEC,0,0,palist,&alist_size); 174 | char mac[6]={0}; 175 | while (palist){ 176 | if (palist->PhysicalAddressLength==0x6){ 177 | memcpy(mac,palist->PhysicalAddress,0x6); 178 | if (!memcmp(mac_vendor, mac, 3)) { /* First 3 bytes are the same */ 179 | LocalFree(palist_free); 180 | return TRUE; 181 | } 182 | } 183 | palist = palist->Next; 184 | } 185 | LocalFree(palist_free); 186 | } 187 | } 188 | return FALSE; 189 | } 190 | 191 | int pafish_check_adapter_name(char * name) { 192 | unsigned long alist_size = 0, ret; 193 | wchar_t aux[1024]; 194 | 195 | mbstowcs(aux, name, sizeof(aux)-sizeof(aux[0])); 196 | 197 | ret = GetAdaptersAddresses(AF_UNSPEC, 0, 0, 0, &alist_size); 198 | if (ret == ERROR_BUFFER_OVERFLOW) { 199 | IP_ADAPTER_ADDRESSES *palist = (IP_ADAPTER_ADDRESSES*)LocalAlloc(LMEM_ZEROINIT, alist_size); 200 | void * palist_free = palist; 201 | if (palist) { 202 | if (GetAdaptersAddresses(AF_UNSPEC, 0, 0, palist, &alist_size) == ERROR_SUCCESS) { 203 | while (palist) { 204 | if (wcsstr(palist->Description, aux)) { 205 | LocalFree(palist_free); 206 | return TRUE; 207 | } 208 | palist = palist->Next; 209 | } 210 | } 211 | LocalFree(palist_free); 212 | } 213 | } 214 | return FALSE; 215 | } 216 | 217 | /** 218 | * Initialise the WMI client that will connect to the local machine WMI 219 | * namespace. It will return TRUE if the connection was successful, FALSE 220 | * otherwise. 221 | */ 222 | int wmi_initialize(const wchar_t *query_namespace, IWbemServices **services) { 223 | BSTR namespace; 224 | IWbemLocator *locator = NULL; 225 | int result; 226 | 227 | HRESULT hresult = CoInitializeEx(0, COINIT_MULTITHREADED); 228 | 229 | if (FAILED(hresult)) { 230 | return FALSE; 231 | } 232 | 233 | hresult = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, 234 | RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); 235 | 236 | if (FAILED(hresult)) { 237 | CoUninitialize(); 238 | 239 | return FALSE; 240 | } 241 | 242 | hresult = CoCreateInstance(&CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, 243 | &IID_IWbemLocator, (LPVOID *) & locator); 244 | 245 | if (FAILED(hresult)) { 246 | CoUninitialize(); 247 | 248 | return FALSE; 249 | } 250 | 251 | namespace = SysAllocString(query_namespace); 252 | 253 | // Connect to the namespace with the current user and obtain pointer 254 | // services to make IWbemServices calls. 255 | hresult = locator->lpVtbl->ConnectServer(locator, namespace, NULL, NULL, NULL, 0, 256 | NULL, NULL, services); 257 | 258 | result = FAILED(hresult) ? FALSE : TRUE; 259 | 260 | SysFreeString(namespace); 261 | locator->lpVtbl->Release(locator); 262 | 263 | return result; 264 | } 265 | 266 | /** 267 | * Execute the suplied WMI query and call the row checking function for each row returned. 268 | */ 269 | int wmi_check_query(IWbemServices *services, const wchar_t *language, const wchar_t *query, 270 | wmi_check_row check_row) { 271 | int status = FALSE; 272 | IEnumWbemClassObject *queryrows = NULL; 273 | BSTR wmilang = SysAllocString(language); 274 | BSTR wmiquery = SysAllocString(query); 275 | 276 | // Execute the query. 277 | HRESULT result = services->lpVtbl->ExecQuery( 278 | services, wmilang, wmiquery, WBEM_FLAG_BIDIRECTIONAL, NULL, &queryrows); 279 | 280 | if (!FAILED(result) && (queryrows != NULL)) { 281 | IWbemClassObject * batchrows[10]; 282 | ULONG index, count = 0; 283 | result = WBEM_S_NO_ERROR; 284 | 285 | while (WBEM_S_NO_ERROR == result && status == FALSE) { 286 | // Retrieve 10 rows (instances) each time. 287 | // WBEM_INFINITE = 0xFFFFFFFF 288 | result = queryrows->lpVtbl->Next(queryrows, 0xFFFFFFFF, 10, 289 | batchrows, &count); 290 | 291 | if (!SUCCEEDED(result)) { 292 | continue; 293 | } 294 | 295 | for (index = 0; index < count && status == FALSE; index++) { 296 | status = check_row(batchrows[index]); 297 | 298 | batchrows[index]->lpVtbl->Release(batchrows[index]); 299 | } 300 | } 301 | 302 | queryrows->lpVtbl->Release(queryrows); 303 | } 304 | 305 | SysFreeString(wmiquery); 306 | SysFreeString(wmilang); 307 | 308 | return status; 309 | } 310 | 311 | /** 312 | * Cleanup WMI. 313 | */ 314 | void wmi_cleanup(IWbemServices *services) { 315 | if (services != NULL) { 316 | services->lpVtbl->Release(services); 317 | } 318 | 319 | CoUninitialize(); 320 | } 321 | -------------------------------------------------------------------------------- /pafish/rtt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "types.h" 5 | #include "rtt.h" 6 | 7 | /* Dialog's constants */ 8 | #define ID_OK 1 9 | #define ID_QUIT 2 10 | #define TEXT_OFF 20 11 | 12 | /* Custom message indicating timer's end */ 13 | #define WM_CUSTOM (WM_USER + 0x0001) 14 | 15 | /* Duration of each check */ 16 | #define MAX_DURATION 3000 17 | 18 | /* Some RTT global variables */ 19 | HHOOK rtt_hook; 20 | BOOL rtt_is_success = FALSE; 21 | BOOL rtt_is_timeout = FALSE; 22 | BOOL rtt_is_within_rect = FALSE; 23 | /* Tracks the point in time of last click */ 24 | u_int64 rtt_last = 0; 25 | /* Default double click time in milliseconds */ 26 | u_int rtt_double_click_time = 500; 27 | 28 | /* 29 | * Checks, for the presence of a mouse device. 30 | * 31 | * Found in similar form in maldoc used by ColdRiver 32 | * MD5: 48320f502811645fa1f2f614bd8a385a 33 | */ 34 | int rtt_mouse_presence() { 35 | int res; 36 | res = GetSystemMetrics(SM_MOUSEPRESENT); 37 | return res > 0 ? FALSE : TRUE; 38 | } 39 | 40 | /* 41 | * Checks, if the mouse cursor moves. 42 | * 43 | * Found in similar form in IFSB/Gozi in version 2.13.24.1 leaked by vx-undeground.org 44 | * See: https://github.com/vxunderground/MalwareSourceCode/blob/main/Leaks/Win32/Win32.Gozi.rar 45 | */ 46 | int rtt_mouse_move() { 47 | POINT cur = { 0 }, prev = { 0 }; 48 | u_int movement = 0; 49 | int interval = 100; 50 | int period = MAX_DURATION; 51 | 52 | do { 53 | GetCursorPos(&cur); 54 | 55 | if (prev.x && prev.y) 56 | movement = abs(cur.x - prev.x) + (abs(cur.y - prev.y) << 16); 57 | 58 | /* Cursor moved */ 59 | if (movement) { 60 | return FALSE; 61 | } 62 | 63 | prev = cur; 64 | Sleep(interval); 65 | period -= interval; 66 | } while (period); 67 | 68 | return TRUE; 69 | } 70 | 71 | /* 72 | * Checks, for supernatural cursor speeds. 73 | * 74 | * Referenced in Fireeye Blogpost from 2014 75 | * https://www.fireeye.com/blog/threat-research/2014/06/turing-test-in-reverse-new-sandbox-evasion-techniques-seek-human-interaction.html 76 | */ 77 | int rtt_mouse_speed_limit() { 78 | POINT prev, cur; 79 | int mx, my, dx, dy; 80 | 81 | int period = MAX_DURATION; 82 | int interval = 10; 83 | int cursor_updates = 0; 84 | 85 | mx = GetSystemMetrics(SM_CXFULLSCREEN) / 5; 86 | my = GetSystemMetrics(SM_CYFULLSCREEN) / 5; 87 | 88 | GetCursorPos(&prev); 89 | 90 | while (period) { 91 | Sleep(interval); /* Sleep time */ 92 | 93 | GetCursorPos(&cur); 94 | dx = prev.x - cur.x; 95 | dy = prev.y - cur.y; 96 | 97 | if ((dx != 0) || (dy != 0)) { 98 | /* Cursor moved */ 99 | cursor_updates++; 100 | 101 | if (abs(dx) > mx && abs(dy) > my) { 102 | /* Cursor moved too fast */ 103 | return TRUE; 104 | } 105 | } 106 | prev = cur; 107 | period -= interval; 108 | } 109 | 110 | /* Mouse actually moved, but never moved too fast, therefore pass check */ 111 | if (cursor_updates) { 112 | return FALSE; 113 | } 114 | 115 | /* No mouse activity, fail check as well */ 116 | return TRUE; 117 | } 118 | 119 | /* 120 | * Timer callback, which sends a custom message to the message loop, in order 121 | * to signal that the time is up. 122 | */ 123 | VOID CALLBACK timer_proc() { 124 | PostMessageA(NULL, WM_CUSTOM, 0, 0); 125 | } 126 | 127 | /* 128 | * Callback for a low-level mouse hook, which checks, if a single click occurs. 129 | */ 130 | LRESULT CALLBACK single_click_proc(int nCode, WPARAM wParam, LPARAM lp) { 131 | if (nCode >= 0) { 132 | if (wParam == WM_LBUTTONUP) { 133 | rtt_is_success = TRUE; 134 | PostMessageA(NULL, WM_CUSTOM, 0 , 0); 135 | } 136 | } 137 | return CallNextHookEx(rtt_hook, nCode, wParam, lp); 138 | } 139 | 140 | /* 141 | * Calculates the current time in milliseconds by querying system time as 142 | * FILETIME and converting it to Unix epoch format. 143 | * 144 | * Taken from https://gist.github.com/e-yes/278302 145 | */ 146 | u_int64 get_current_time_in_millis(){ 147 | FILETIME ft; 148 | LARGE_INTEGER li; 149 | 150 | /* 151 | * Gets the amount of 100 nano seconds intervals elapsed since January 1, 152 | * 1601 (UTC) and copy it * to a LARGE_INTEGER structure. 153 | */ 154 | GetSystemTimeAsFileTime(&ft); 155 | li.LowPart = ft.dwLowDateTime; 156 | li.HighPart = ft.dwHighDateTime; 157 | 158 | u_int64 ms = li.QuadPart; 159 | ms -= 116444736000000000LL; /* Converts from file time to UNIX epoch time. */ 160 | ms /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */ 161 | 162 | return ms; 163 | } 164 | 165 | /* 166 | * Callback for a low-level mouse hook, which checks, if a double click occurs. 167 | * The presence of a double click is assumed if two clicks are observed within 168 | * the time frame rtt_double_click_time. 169 | */ 170 | LRESULT CALLBACK double_click_proc(int code, WPARAM wp, LPARAM lp) { 171 | if (code >= 0) { 172 | if (wp == WM_LBUTTONDOWN) { 173 | u_int64 now = get_current_time_in_millis(); 174 | if((now - rtt_last) < rtt_double_click_time){ 175 | rtt_is_success = TRUE; 176 | PostMessageA(NULL, WM_CUSTOM, 0 , 0); 177 | } 178 | rtt_last = now; 179 | } 180 | } 181 | return CallNextHookEx(rtt_hook, code, wp, lp); 182 | } 183 | 184 | /* 185 | * Installs a low-level mouse hook with the specified callback. 186 | */ 187 | int install_hook(LRESULT CALLBACK (*callback)(int code, WPARAM wp, LPARAM lp)){ 188 | SetTimer(NULL, 0, MAX_DURATION, (TIMERPROC) &timer_proc); 189 | rtt_hook = SetWindowsHookEx(WH_MOUSE_LL, callback, NULL, 0); 190 | MSG msg; 191 | 192 | while (GetMessage(&msg, NULL, 0, 0) > 0) { 193 | if (msg.message == WM_CUSTOM) { 194 | /* Timer ended, exit message loop*/ 195 | break; 196 | } 197 | 198 | TranslateMessage(&msg); 199 | DispatchMessage(&msg); 200 | } 201 | 202 | /* Clean up */ 203 | KillTimer(NULL, 0); 204 | UnhookWindowsHookEx(rtt_hook); 205 | 206 | if (rtt_is_success) 207 | return FALSE; 208 | 209 | return TRUE; 210 | } 211 | 212 | /* 213 | * Checks for a single click with a technique used in the UpClicker trojan. 214 | * See https://webcache.googleusercontent.com/search?q=cache:NeVZ4J1Y-cQJ:https://www.fireeye.com/blog/threat-research/2012/12/dont-click-the-left-mouse-button-trojan-upclicker.html+&cd=1&hl=en&ct=clnk&gl=de 215 | */ 216 | int rtt_mouse_click() { 217 | return install_hook(&single_click_proc); 218 | } 219 | 220 | /* 221 | * Checks for dobule clicks. 222 | * 223 | * In the past several malware samples waited for a certain amount of clicks 224 | * (not necessarily double clicks) with different techniques, see for example: 225 | * 226 | * https://www.ptsecurity.com/ww-en/analytics/antisandbox-techniques/ mentioning 227 | * MyWeb backdoor used by APT15 in 2010, where three left clicks were required 228 | * 229 | * https://www.fireeye.com/blog/threat-research/2014/06/turing-test-in-reverse-new-sandbox-evasion-techniques-seek-human-interaction.html 230 | * referencing the use of GetAsyncKeyState() 231 | */ 232 | int rtt_mouse_double_click() { 233 | /* Determines double click time set on system */ 234 | rtt_double_click_time = GetDoubleClickTime(); 235 | /* Checks, if a double click occurs */ 236 | return install_hook(&double_click_proc); 237 | } 238 | 239 | LRESULT CALLBACK timed_dialog_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { 240 | 241 | RECT rect; 242 | int btn_w, btn_h; 243 | 244 | switch (msg) { 245 | case WM_CREATE: 246 | SetTimer(hwnd, 1, MAX_DURATION, NULL); 247 | 248 | /* Determines "usable" size inside of the current window */ 249 | GetClientRect(hwnd, &rect); 250 | 251 | /* Calculates button size */ 252 | btn_w = (rect.right - rect.left) / 2; 253 | btn_h = (rect.bottom - rect.top) / 2; 254 | 255 | /* Create two buttons - randomly chosen and "Quit" */ 256 | CreateWindowW(L"Button", L"OK", WS_VISIBLE | WS_CHILD, 0, TEXT_OFF, 257 | btn_w, btn_h, hwnd, (HMENU) ID_OK, NULL, NULL); 258 | 259 | CreateWindowW(L"Button", L"Quit", WS_VISIBLE | WS_CHILD, 0 + btn_w, 260 | TEXT_OFF, btn_w, btn_h, hwnd, (HMENU) ID_QUIT, NULL, NULL); 261 | /* Ensure dialog is displayed at the very top */ 262 | //SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 263 | break; 264 | 265 | case WM_TIMER: 266 | rtt_is_timeout = TRUE; 267 | DestroyWindow(hwnd); 268 | break; 269 | 270 | case WM_COMMAND: 271 | 272 | { 273 | /* 274 | * Plausibility check, whether cursor is still within rect. 275 | * Buttons are not focusable, therefore pressing return is not in this case possible 276 | */ 277 | POINT p; 278 | GetCursorPos(&p); 279 | GetWindowRect(hwnd, &rect); 280 | 281 | if (p.x >= rect.left && p.x <= rect.right && p.y >= rect.top 282 | && p.y <= rect.bottom) 283 | rtt_is_within_rect = TRUE; 284 | } 285 | 286 | /* Destroys and recreates a new window on "Ok" */ 287 | if (LOWORD(wp) == ID_OK) { 288 | MessageBeep(MB_OK); 289 | DestroyWindow(hwnd); 290 | } 291 | 292 | /* Sets stop condition, if "Quit" was clicked */ 293 | if (LOWORD(wp) == ID_QUIT) { 294 | DestroyWindow(hwnd); 295 | } 296 | break; 297 | 298 | case WM_DESTROY: 299 | PostQuitMessage(0); 300 | break; 301 | } 302 | 303 | return DefWindowProcW(hwnd, msg, wp, lp); 304 | } 305 | 306 | /* 307 | * Displays a dialog and waits for interaction 308 | */ 309 | int confirm_dialog(BOOL is_plausibility_check) { 310 | 311 | MSG msg; 312 | int mx, my, rx, ry, mw, mh; 313 | 314 | /* Defines class and window's attributes*/ 315 | WNDCLASSW wc = { 0 }; 316 | wc.lpszClassName = L"RTT window"; 317 | wc.hInstance = NULL; 318 | wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); 319 | wc.lpfnWndProc = timed_dialog_proc; 320 | wc.hCursor = LoadCursor(0, IDC_ARROW); 321 | srand(GetTickCount()); 322 | 323 | /* Size of screen without taskbar */ 324 | mx = GetSystemMetrics(SM_CXFULLSCREEN); 325 | my = GetSystemMetrics(SM_CYFULLSCREEN); 326 | 327 | /* Limits for window size */ 328 | mw = GetSystemMetrics(SM_CXMIN) * 3; 329 | mh = GetSystemMetrics(SM_CYMIN) * 3; 330 | 331 | /* Randomize window position */ 332 | rx = ((double) rand() / RAND_MAX) * (mx - (4 * mw)) + mw; 333 | ry = ((double) rand() / RAND_MAX) * (my - (4 * mh)) + mh; 334 | 335 | RegisterClassW(&wc); 336 | CreateWindowW(wc.lpszClassName, L"Pafish RTT window", 337 | WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CAPTION, rx, ry, mw, 338 | mh, 0, 0, NULL, 0); 339 | 340 | while (GetMessage(&msg, NULL, 0, 0)) { 341 | TranslateMessage(&msg); 342 | DispatchMessage(&msg); 343 | } 344 | 345 | if (!rtt_is_timeout) { 346 | if (is_plausibility_check) 347 | return !rtt_is_within_rect; 348 | else 349 | return FALSE; 350 | } 351 | 352 | return TRUE; 353 | } 354 | 355 | /* 356 | * Wrapper function for displaying a dialog and checking if interaction occurs. 357 | * 358 | * Found in similar form in XLM-macro with MD5: 50d518246c2b61f5b427948f87a0aa24 359 | * See also: https://www.lastline.com/labsblog/evolution-of-excel-4-0-macro-weaponization/ 360 | */ 361 | int rtt_confirm_dialog() { 362 | return confirm_dialog(FALSE); 363 | } 364 | 365 | /* 366 | * Wrapper function like rtt_confirm_dialog(), but performs an additional check 367 | * for plausibility by determining, whehter the cursor resides inside the 368 | * bounding box of the displayed dialog add the time of confirmation. 369 | * Thereby, machine-triggered SendMessageW-interactions can be identified. 370 | */ 371 | int rtt_plausible_confirm_dialog() { 372 | return confirm_dialog(TRUE); 373 | } 374 | -------------------------------------------------------------------------------- /pafish/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "config.h" 8 | #include "common.h" 9 | #include "utils.h" 10 | 11 | #if __i386__ 12 | #include "hooks.h" 13 | #include "cuckoo.h" 14 | #endif 15 | #include "debuggers.h" 16 | #include "sandboxie.h" 17 | #include "gensandbox.h" 18 | #include "vbox.h" 19 | #include "wine.h" 20 | #include "vmware.h" 21 | #include "qemu.h" 22 | #include "cpu.h" 23 | #include "bochs.h" 24 | #include "rtt.h" 25 | /* 26 | Pafish (Paranoid fish) 27 | 28 | All code from this project, including 29 | functions, procedures and the main program 30 | is licensed under GNU/GPL version 3. 31 | 32 | So, if you are going to use functions or 33 | procedures from this project to develop 34 | your malware, you have to release the 35 | source code as well :) 36 | 37 | - Alberto Ortega 38 | 39 | Blue fish icon thanks to http://www.fasticon.com/ 40 | 41 | */ 42 | 43 | int main(void) 44 | { 45 | char winverstr[64], aux[1024]; 46 | char cpu_vendor[13], cpu_hv_vendor[13], cpu_brand[49]; 47 | OSVERSIONINFO winver; 48 | unsigned short original_colors = 0; 49 | 50 | /* Minimize window at first to not interefere with human behaviour simulators */ 51 | ShowWindow(GetConsoleWindow(), SW_MINIMIZE); 52 | 53 | write_log("Start"); 54 | #if ENABLE_DNS_TRACE 55 | write_trace_dns("analysis-start"); 56 | #endif 57 | #if ENABLE_PE_IMG_TRACE 58 | write_trace_pe_img("analysis-start ", FALSE); 59 | #endif 60 | 61 | original_colors = init_cmd_colors(); 62 | print_header(); 63 | 64 | winver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 65 | GetVersionEx(&winver); 66 | snprintf(winverstr, sizeof(winverstr) - sizeof(winverstr[0]), 67 | "%lu.%lu build %lu", winver.dwMajorVersion, 68 | winver.dwMinorVersion, winver.dwBuildNumber); 69 | 70 | /* Get CPU vendor */ 71 | cpu_write_vendor(cpu_vendor); 72 | cpu_write_hv_vendor(cpu_hv_vendor); 73 | cpu_write_brand(cpu_brand); 74 | 75 | printf("[-] Windows version: %s\n", winverstr); 76 | printf("[-] Running in WoW64: "); 77 | if (pafish_iswow64()) { 78 | printf("True\n"); 79 | strncat(winverstr, " (WoW64)", 10); 80 | } 81 | else { 82 | printf("False\n"); 83 | strncat(winverstr, " (native)", 10); 84 | } 85 | printf("[-] CPU: %s\n", cpu_vendor); 86 | if (strlen(cpu_hv_vendor)) 87 | printf(" Hypervisor: %s\n", cpu_hv_vendor); 88 | printf(" CPU brand: %s\n", cpu_brand); 89 | snprintf(aux, sizeof(aux) - sizeof(aux[0]), "Windows version: %s", 90 | winverstr); 91 | write_log(aux); 92 | if (strlen(cpu_hv_vendor)) 93 | snprintf(aux, sizeof(aux) - sizeof(aux[0]), "CPU: %s (HV: %s) %s", cpu_vendor, 94 | cpu_hv_vendor, cpu_brand); 95 | else 96 | snprintf(aux, sizeof(aux) - sizeof(aux[0]), "CPU: %s %s", cpu_vendor, 97 | cpu_brand); 98 | write_log(aux); 99 | 100 | /* Debuggers detection tricks */ 101 | print_check_group("Debuggers detection"); 102 | exec_check("Using IsDebuggerPresent()", &debug_isdebuggerpresent, 103 | "Debugger traced using IsDebuggerPresent()", 104 | "hi_debugger_isdebuggerpresent"); 105 | exec_check("Using BeingDebugged via PEB access", &debug_beingdebugged_peb, 106 | "Debugger traced using PEB BeingDebugged", 107 | "hi_debugger_beingdebugged_PEB"); 108 | /* This is only working on MS Windows systems prior to Vista */ 109 | if (winver.dwMajorVersion < 6) { 110 | exec_check("Using OutputDebugString()", 111 | &debug_outputdebugstring, 112 | "Debugger traced using OutputDebugString()", 113 | "hi_debugger_outputdebugstring"); 114 | } 115 | 116 | /* CPU information based detection tricks */ 117 | print_check_group("CPU information based detections"); 118 | exec_check 119 | ("Checking the difference between CPU timestamp counters (rdtsc)", 120 | &cpu_rdtsc, 121 | "CPU VM traced by checking the difference between CPU timestamp counters (rdtsc)", 122 | "hi_CPU_VM_rdtsc"); 123 | exec_check 124 | ("Checking the difference between CPU timestamp counters (rdtsc) forcing VM exit", 125 | &cpu_rdtsc_force_vmexit, 126 | "CPU VM traced by checking the difference between CPU timestamp counters (rdtsc) forcing VM exit", 127 | "hi_CPU_VM_rdtsc_force_vm_exit"); 128 | exec_check("Checking hypervisor bit in cpuid feature bits", &cpu_hv, 129 | "CPU VM traced by checking hypervisor bit in cpuid feature bits", 130 | "hi_CPU_VM_hypervisor_bit"); 131 | exec_check("Checking cpuid hypervisor vendor for known VM vendors", 132 | &cpu_known_vm_vendors, 133 | "CPU VM traced by checking cpuid hypervisor vendor for known VM vendors", 134 | "hi_CPU_VM_hv_vendor_name"); 135 | 136 | /* Generic reverse turing tests */ 137 | print_check_group("Generic reverse turing tests"); 138 | exec_check("Checking mouse presence", &rtt_mouse_presence, 139 | "Sandbox traced by absence of mouse device", 140 | "hi_sandbox_mouse_presence"); 141 | exec_check("Checking mouse movement", &rtt_mouse_move, 142 | "Sandbox traced by missing mouse movement", 143 | "hi_sandbox_rtt_mouse_movement"); 144 | exec_check("Checking mouse speed", &rtt_mouse_speed_limit, 145 | "Sandbox traced by missing mouse movement or supernatural speed", 146 | "hi_sandbox_rtt_mouse_speed_limit"); 147 | exec_check("Checking mouse click activity", &rtt_mouse_click, 148 | "Sandbox traced by missing mouse click activity", 149 | "hi_sandbox_rtt_mouse_click"); 150 | exec_check("Checking mouse double click activity", &rtt_mouse_double_click, 151 | "Sandbox traced by missing double click activity", 152 | "hi_sandbox_rtt_mouse_double_click"); 153 | exec_check("Checking dialog confirmation", &rtt_confirm_dialog, 154 | "Sandbox traced by missing dialog confirmation", 155 | "hi_sandbox_rtt_confirm_dialog"); 156 | exec_check("Checking plausible dialog confirmation", &rtt_plausible_confirm_dialog, 157 | "Sandbox traced by missing or implausible dialog confirmation", 158 | "hi_sandbox_rtt_implausible_confirm_dialog"); 159 | 160 | /* Generic sandbox detection tricks */ 161 | print_check_group("Generic sandbox detection"); 162 | exec_check("Checking username", &gensandbox_username, 163 | "Sandbox traced by checking username", 164 | "hi_sandbox_username"); 165 | exec_check("Checking file path", &gensandbox_path, 166 | "Sandbox traced by checking file path", "hi_sandbox_path"); 167 | exec_check("Checking common sample names in drives root", 168 | &gensandbox_common_names, 169 | "Sandbox traced by checking common sample names in drives root", 170 | "hi_sandbox_common_names"); 171 | exec_check("Checking if disk size <= 60GB via DeviceIoControl()", 172 | &gensandbox_drive_size, 173 | "Sandbox traced by checking disk size <= 60GB via DeviceIoControl()", 174 | "hi_sandbox_drive_size"); 175 | exec_check("Checking if disk size <= 60GB via GetDiskFreeSpaceExA()", 176 | &gensandbox_drive_size2, 177 | "Sandbox traced by checking disk size <= 60GB via GetDiskFreeSpaceExA()", 178 | "hi_sandbox_drive_size2"); 179 | exec_check("Checking if Sleep() is patched using GetTickCount()", 180 | &gensandbox_sleep_patched, 181 | "Sandbox traced by checking if Sleep() was patched using GetTickCount()", 182 | "hi_sandbox_sleep_gettickcount"); 183 | exec_check("Checking if NumberOfProcessors is < 2 via PEB access", 184 | &gensandbox_one_cpu, 185 | "Sandbox traced by checking if NumberOfProcessors is less than 2 via PEB access", 186 | "hi_sandbox_NumberOfProcessors_less_2_PEB"); 187 | exec_check("Checking if NumberOfProcessors is < 2 via GetSystemInfo()", 188 | &gensandbox_one_cpu_GetSystemInfo, 189 | "Sandbox traced by checking if NumberOfProcessors is less than 2 via GetSystemInfo()", 190 | "hi_sandbox_NumberOfProcessors_less_2_GetSystemInfo"); 191 | exec_check("Checking if pysical memory is < 1Gb", 192 | &gensandbox_less_than_onegb, 193 | "Sandbox traced by checking if pysical memory is less than 1Gb", 194 | "hi_sandbox_pysicalmemory_less_1Gb"); 195 | exec_check("Checking operating system uptime using GetTickCount()", 196 | &gensandbox_uptime, 197 | "Sandbox traced by checking operating system uptime using GetTickCount()", 198 | "hi_sandbox_uptime"); 199 | exec_check("Checking if operating system IsNativeVhdBoot()", 200 | &gensandbox_IsNativeVhdBoot, 201 | "Sandbox traced by checking IsNativeVhdBoot()", 202 | "hi_sandbox_IsNativeVhdBoot"); 203 | 204 | #if __i386__ 205 | /* Hooks detection tricks */ 206 | print_check_group("Hooks detection"); 207 | exec_check("Checking function ShellExecuteExW method 1", 208 | &check_hook_ShellExecuteExW_m1, 209 | "Hooks traced using ShellExecuteExW method 1", 210 | "hi_hooks_shellexecuteexw_m1"); 211 | exec_check("Checking function CreateProcessA method 1", 212 | &check_hook_CreateProcessA_m1, 213 | "Hooks traced using CreateProcessA method 1", 214 | "hi_hooks_createprocessa_m1"); 215 | #endif 216 | 217 | /* Sandboxie detection tricks */ 218 | print_check_group("Sandboxie detection"); 219 | exec_check("Using GetModuleHandle(sbiedll.dll)", &sboxie_detect_sbiedll, 220 | "Sandboxie traced using GetModuleHandle(sbiedll.dll)", 221 | "hi_sandboxie"); 222 | 223 | /* Wine detection tricks */ 224 | print_check_group("Wine detection"); 225 | exec_check 226 | ("Using GetProcAddress(wine_get_unix_file_name) from kernel32.dll", 227 | &wine_detect_get_unix_file_name, 228 | "Wine traced using GetProcAddress(wine_get_unix_file_name) from kernel32.dll", 229 | "hi_wine"); 230 | exec_check("Reg key (HKCU\\SOFTWARE\\Wine)", &wine_reg_key1, 231 | "Wine traced using Reg key HKCU\\SOFTWARE\\Wine", "hi_wine"); 232 | 233 | /* VirtualBox detection tricks */ 234 | print_check_group("VirtualBox detection"); 235 | exec_check("Scsi port->bus->target id->logical unit id-> 0 identifier", 236 | &vbox_reg_key1, 237 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0 \"Identifier\"", 238 | "hi_virtualbox"); 239 | exec_check 240 | ("Reg key (HKLM\\HARDWARE\\Description\\System \"SystemBiosVersion\")", 241 | &vbox_reg_key2, 242 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\Description\\System \"SystemBiosVersion\"", 243 | "hi_virtualbox"); 244 | exec_check 245 | ("Reg key (HKLM\\SOFTWARE\\Oracle\\VirtualBox Guest Additions)", 246 | &vbox_reg_key3, 247 | "VirtualBox traced using Reg key HKLM\\SOFTWARE\\Oracle\\VirtualBox Guest Additions", 248 | "hi_virtualbox"); 249 | exec_check 250 | ("Reg key (HKLM\\HARDWARE\\Description\\System \"VideoBiosVersion\")", 251 | &vbox_reg_key4, 252 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\Description\\System \"VideoBiosVersion\"", 253 | "hi_virtualbox"); 254 | exec_check("Reg key (HKLM\\HARDWARE\\ACPI\\DSDT\\VBOX__)", 255 | &vbox_reg_key5, 256 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\ACPI\\DSDT\\VBOX__", 257 | "hi_virtualbox"); 258 | exec_check("Reg key (HKLM\\HARDWARE\\ACPI\\FADT\\VBOX__)", 259 | &vbox_reg_key7, 260 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\ACPI\\FADT\\VBOX__", 261 | "hi_virtualbox"); 262 | exec_check("Reg key (HKLM\\HARDWARE\\ACPI\\RSDT\\VBOX__)", 263 | &vbox_reg_key8, 264 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\ACPI\\RSDT\\VBOX__", 265 | "hi_virtualbox"); 266 | exec_check("Reg key (HKLM\\SYSTEM\\ControlSet001\\Services\\VBox*)", 267 | &vbox_reg_key9, NULL, "hi_virtualbox"); 268 | exec_check 269 | ("Reg key (HKLM\\HARDWARE\\DESCRIPTION\\System \"SystemBiosDate\")", 270 | &vbox_reg_key10, 271 | "VirtualBox traced using Reg key HKLM\\HARDWARE\\DESCRIPTION\\System \"SystemBiosDate\"", 272 | "hi_virtualbox"); 273 | exec_check("Driver files in C:\\WINDOWS\\system32\\drivers\\VBox*", 274 | &vbox_sysfile1, NULL, "hi_virtualbox"); 275 | exec_check("Additional system files", &vbox_sysfile2, NULL, 276 | "hi_virtualbox"); 277 | exec_check("Looking for a MAC address starting with 08:00:27", 278 | &vbox_mac, 279 | "VirtualBox traced using MAC address starting with 08:00:27", 280 | "hi_virtualbox"); 281 | exec_check("Looking for pseudo devices", &vbox_devices, NULL, 282 | "hi_virtualbox"); 283 | exec_check("Looking for VBoxTray windows", &vbox_traywindow, 284 | "VirtualBox traced using VBoxTray windows", "hi_virtualbox"); 285 | exec_check("Looking for VBox network share", &vbox_network_share, 286 | "VirtualBox traced using its network share", 287 | "hi_virtualbox"); 288 | exec_check("Looking for VBox processes (vboxservice.exe, vboxtray.exe)", 289 | &vbox_processes, NULL, "hi_virtualbox"); 290 | exec_check("Looking for VBox devices using WMI", &vbox_wmi_devices, 291 | "VirtualBox device identifiers traced using WMI", 292 | "hi_virtualbox"); 293 | 294 | /* VMware detection tricks */ 295 | print_check_group("VMware detection"); 296 | exec_check 297 | ("Scsi port 0,1,2 ->bus->target id->logical unit id-> 0 identifier", 298 | &vmware_reg_key1, 299 | "VMWare traced using Reg key HKLM\\HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0,1,2\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0 \"Identifier\"", 300 | "hi_vmware"); 301 | exec_check("Reg key (HKLM\\SOFTWARE\\VMware, Inc.\\VMware Tools)", 302 | &vmware_reg_key2, 303 | "VMware traced using Reg key HKLM\\SOFTWARE\\VMware, Inc.\\VMware Tools", 304 | "hi_vmware"); 305 | exec_check("Looking for C:\\WINDOWS\\system32\\drivers\\vmmouse.sys", 306 | &vmware_sysfile1, 307 | "VMware traced using file C:\\WINDOWS\\system32\\drivers\\vmmouse.sys", 308 | "hi_vmware"); 309 | exec_check("Looking for C:\\WINDOWS\\system32\\drivers\\vmhgfs.sys", 310 | &vmware_sysfile2, 311 | "VMware traced using file C:\\WINDOWS\\system32\\drivers\\vmhgfs.sys", 312 | "hi_vmware"); 313 | exec_check 314 | ("Looking for a MAC address starting with 00:05:69, 00:0C:29, 00:1C:14 or 00:50:56", 315 | &vmware_mac, 316 | "VMware traced using MAC address starting with 00:05:69, 00:0C:29, 00:1C:14 or 00:50:56", 317 | "hi_vmware"); 318 | exec_check("Looking for network adapter name", &vmware_adapter_name, 319 | "VMware traced using network adapter name", "hi_vmware"); 320 | exec_check("Looking for pseudo devices", &vmware_devices, NULL, 321 | "hi_vmware"); 322 | exec_check("Looking for VMware serial number", &vmware_wmi_serial, 323 | "VMware serial number traced using WMI", "hi_vmware"); 324 | 325 | /* Qemu detection tricks */ 326 | print_check_group("Qemu detection"); 327 | exec_check("Scsi port->bus->target id->logical unit id-> 0 identifier", 328 | &qemu_reg_key1, 329 | "Qemu traced using Reg key HKLM\\HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0 \"Identifier\"", 330 | "hi_qemu"); 331 | exec_check 332 | ("Reg key (HKLM\\HARDWARE\\Description\\System \"SystemBiosVersion\")", 333 | &qemu_reg_key2, 334 | "Qemu traced using Reg key HKLM\\HARDWARE\\Description\\System \"SystemBiosVersion\"", 335 | "hi_qemu"); 336 | exec_check("cpuid CPU brand string 'QEMU Virtual CPU'", &qemu_cpu_name, 337 | "Qemu traced using CPU brand string 'QEMU Virtual CPU'", 338 | "hi_qemu"); 339 | 340 | /* Bochs detection tricks */ 341 | print_check_group("Bochs detection"); 342 | exec_check 343 | ("Reg key (HKLM\\HARDWARE\\Description\\System \"SystemBiosVersion\")", 344 | &bochs_reg_key1, 345 | "Bochs traced using Reg key HKLM\\HARDWARE\\Description\\System \"SystemBiosVersion\"", 346 | "hi_bochs"); 347 | exec_check("cpuid AMD wrong value for processor name", &bochs_cpu_amd1, 348 | "Bochs traced using CPU AMD wrong value for processor name", 349 | "hi_bochs"); 350 | /* 351 | exec_check("cpuid AMD wrong value for Easter egg", &bochs_cpu_amd2, 352 | "Bochs traced using CPU AMD wrong value for Easter egg", 353 | "hi_bochs"); 354 | */ 355 | exec_check("cpuid Intel wrong value for processor name", 356 | &bochs_cpu_intel1, 357 | "Bochs traced using CPU Intel wrong value for processor name", 358 | "hi_bochs"); 359 | 360 | #if __i386__ 361 | /* Cuckoo detection tricks */ 362 | print_check_group("Cuckoo detection"); 363 | exec_check("Looking in the TLS for the hooks information structure", 364 | &cuckoo_check_tls, 365 | "Cuckoo hooks information structure traced in the TLS", 366 | "hi_cuckoo"); 367 | #endif 368 | 369 | printf("\n"); 370 | printf("[-] Pafish has finished analyzing the system, check the log file for more information\n"); 371 | printf(" and visit the project's site:\n\n"); 372 | printf(" https://github.com/a0rtega/pafish\n"); 373 | 374 | write_log("End"); 375 | #if ENABLE_DNS_TRACE 376 | write_trace_dns("analysis-end"); 377 | #endif 378 | #if ENABLE_PE_IMG_TRACE 379 | write_trace_pe_img(" analysis-end", FALSE); 380 | #endif 381 | 382 | /* Restore window */ 383 | ShowWindow(GetConsoleWindow(), SW_RESTORE); 384 | 385 | getchar(); 386 | 387 | /* Restore Original Console Colors */ 388 | restore_cmd_colors(original_colors); 389 | 390 | return 0; 391 | } 392 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------