Hlavné menuUser loginSearch |
Reply to comment
Tuesday, 05.08.2008 16:49
WARNING: FOLLOWING DOCUMENT IS INTENDED FOR STUDY PURPOSES ONLY. AUTHOR HAS NO RESPONSIBILITY FOR ANY ABUSE OF THIS DOCUMENT OR ITS PARTS INCLUDING SOURCE CODE. IT IS NOT ALLOWED TO COPY THIS DOCUMENT WITHOUT AUTHORS PERSMISSION. if you do not agree, please close your eyes and try to close your browser ;) First I want to apologize for my little strange English. This document describes how to write a program, that starts automatically at system start, has unlimited run time and is not visible in Hijackthis as a process or even as a startup entry - altough it is normal exe file. Samely, the program is not visible in Combofixs log (warning for Combofix users - i do not deal with Snapshot section, which is based on previous Combofix scan). This proof of concept is not based on any rootkit technology, it is based only on mistakes and very naive assumptions used in these two applications. Succesfully tested on Windows 2000, Windows XP. Exploiting HijackThisHijackThis' log information value is based on two sections. Process list and list of startup entries + some other informations. First task will be to remove our process from process list, the second one to remove it from the startup list. Hijackthis - ProcessHijackthis uses standard high level API functions to work with processes: CreateToolHelp32Snapshot, Process32First, Process32Next. In the process list is displayed the whole path to executable file which is obtained by psapi.dll function - GetModuleFileNameExA. GetModuleFileNameEx works very simply, by calling of NtQueryInformationProcess obtains address of PEB structure in the process from which is then readed list of loaded modules by ReadProcessMemory. It is nescessary to remind that the PEB structure is in read-write memory, so this whole structure, even the list of loaded modules, can be easily changed and rewrote to anything we want. PEB -> (ptr PEB +0x00c Ldr) PEB_LDR_DATA PEB_LDR_DATA: All of these lists, InLoadOrder, InMemoryOrder, InInitializationOrder are structures of LIST_ENTRY type, that means blink & flink to strutures LDR_DATA_TABLE_ENTRY. This structure contains members such as UNICODE_STRING FullDllName, UINCODE_STRING BaseDllName and PVOID DllBase. GetModuleFileNameEx browses InLoadOrded list - it is important to change its first entry - executable file is loaded by PE loader as a first module. ;:: HIDE PROCESS :::::::::::::::::::::::::::::::::::::
assume fs: nothing push fs: [30h] pop edi ;edi = ptr to PEB mov edi, dword ptr [edi+0Ch] ;ptr to LDR ReDoPath function rewrites original path and creates new path - in this example i will use same path as svchost.exe. The soltuion is, the GetModuleFileNameEx function returns the same path as system file svchost.exe. Hijackthis - StartupThe second task is to hide our startup entry from Hjackthis. Hijackthis checkcs probably all keys and folders used for automatical startup, but contains very naive assumption that we can misuse. Services are filtered by simple filter, which is based on InStr function and CompanyName of executable file. What does it mean? If the file has a CompanyName which contains "Microsoft" string (eg. "IamNotMicrosoftFile"), the service will be filtered out. This part is the easiest, because you need only to change resource or modify compile settings in IDE. Hijackthis - SummaryIn this time we have program that is not visible in Hijackthis log. There is only another svchost or whatever name we desire. Exploiting ComboFixCombofix threat our invisibility by many checks, we can't allow even one check to see us. First problem is a list of files created in last X days. Next problem is a startup list including list of all services on which base we are running. The last problem is check of newly created services. Combofix - list of filesThe way how to hide from this check is very trivial as everything in this document. We only need is to change our file times to the same values as any system file (e. g. kernel32.dll) has. This is possible via standard kernel32.dll API functions (CreateFile, GetFileTime, SetFileTime). Combofix does not test TimeDateStamp in NT Header, so we don't need to add next 12 lines of code. Combofix - services listAs we saw service listing filter in Hijackthis, Combofix is not that much different. Combofix contains its own whitelist based on service names. Whitelist - the list of all names of services which have to be filtered out from the log is saved in blank text file. There are no hashes, no catalogs, no digital sign checks and nothing else what would detect that we are trying to fake any whitelisted service. It is very easy to take this list and just try to bruteforce every name throught CreateService till we get an unused service. In this example i have choosen a static one. Combofix - list of newly created servicesWithout no further study i started to write function for changing creation time of service register key. After failing to hide this log entry i noticed that Windows creates a value *NewlyCreated* in Services\enum\root\LEGACY_service_name which Combofix surprisingly checks. After our program start, it is necessary to delete this value. We haven't got write access into this key, but we can set it with no problems. Detection summarryIf we do everything mentioned above, we get program with startup entry, which Hjackthis displays as another svchost process and Combofix see nothing, actually. Proof of conceptNow i should describe behaviour of this PoC program. We have few states, the first one is, when user gets the program into his hands - it is necessary to install it - create service, change file times, etc. The second status is, when the program is started as a service. As a service, we have a bit harder life - working with windows, user interface, etc. From this and many other reasons i have decided, that it is better to run new instance with parameter under token of logged user and stop the service. The third status, when we are started with parameter is the last status, it is not installation, and even not a service... It is time to hide and show to the user, that we are still here! # Obtain path, where we currently are #Are we started with "go" param? 3) We are in final state Source codeInstallation ;-- PATH CHECK -------------------------------------------
invoke GetSystemDirectory, addr dbPath, sizeof dbPath invoke lstrcat, addr dbPath, addr szMY_NAME invoke GetModuleFileName, 0, addr dbBuffer, sizeof dbBuffer ; 2. modify file times invoke GetModuleFileName, eax, ecx, sizeof dbBuffer ;- set creation date, ... - ; 3. create service ; 4. run new file Service / action? ;-- TO BE A SERVICE OR NOT TO BE A SERVICE... -------------
Invoke GetCommandLine mov esi, EAX Invoke lstrlen, esi Add esi, EAX .IF word ptr[esi-2] != "og" lea esi, tSTE assume esi: ptr SERVICE_TABLE_ENTRY invoke RtlZeroMemory, esi, sizeof SERVICE_TABLE_ENTRY * 2 mov [esi].lpServiceName, offset szSVC_NAME mov [esi].lpServiceProc, offset ServiceMain Invoke StartServiceCtrlDispatcher, esi assume esi: nothing Invoke ExitProcess, 0 .ENDIF We are service ServiceMain proc uses esi edi argA:DWORD, argB:DWORD
local hProc: HANDLE local hToken: HANDLE local hDupToken: HANDLE ;-- SERVICE STUFF ---------------------------------------- lea esi, tServiceStatus mov [esi].dwCurrentState, SERVICE_RUNNING ;-- RELOAD US TO NORMAL PROC. & STOP -------------------- invoke GetModuleFileName, 0, addr dbBuffer, sizeof dbBuffer Invoke CloseHandle, hDupToken mov tServiceStatus.dwCurrentState, SERVICE_STOP_PENDING We are not service - hide! ;-- NOT A SERVICE =)) LETS HIDE! --------------------------
invoke SetNamedSecurityInfo, addr szSVC_CFX, 4, DACL_SECURITY_INFORMATION, 0, 0, 0, 0 .IF !EAX lea esi, szSVC_CFX Add esi, 8 invoke RegOpenKey, HKEY_LOCAL_MACHINE, esi, addr hKey ;:: INIT ::::::::::::::::::::::::::::::::::::: mov sNEW_NAMEA.dwLength, ax push 1 ;:: HIDE PROCESS ::::::::::::::::::::::::::::::::::::: mov edi, dword ptr [edi+0Ch] ;ptr to LDR invoke MessageBox, 0, addr szRUNNING, addr szCAPTION,MB_ICONQUESTION or MB_SERVICE_NOTIFICATION DownloadBinary for testing: Complete source code in MASM: Reply |
LinksIRC kanál: #secit Štatistika fóraNové témy na fóre |
Recent comments
1 week 6 days ago
2 weeks 22 hours ago
2 weeks 1 day ago
2 weeks 1 day ago
3 weeks 2 days ago
16 weeks 1 day ago
29 weeks 4 days ago
29 weeks 6 days ago
30 weeks 4 days ago
30 weeks 4 days ago