CriticalSection 의 CPU 점유율을 어떻게 구해야할까.
일단, 생각할 수 있는 가장 간단한 코드로 구해본 CPU 점유율
CRITICAL_SECTION cs;
InitializeCriticalSection(&cs);
DWORD prvTick=GetTickCount();
for(int i = 0; i<1000000; i++)
{
EnterCriticalSection(&cs);
Sleep(0);
LeaveCriticalSection(&cs);
}
DWORD curTick = GetTickCount() - prvTick;
위의 코드에서
CS를 썼을 때에는 0.78초
CS를 안썼을 때에는 0.81초의 TickCount가 반환
즉, CS의 점유율이 100만번 호출에 0.03 초라는 계산.
위의 코드에서도,
사실 정확히 하려면 쓰레드의 KernelTime과 UserTime 을 구해 더해야하겠지만,
ns로 반환되는 KernelTime/UserTime 의 오차율이 ms를 상회하는 약 0.06초 이므로 의미가 없다.
멀티 쓰레드 환경에서의 점유율도 구해야하겠지만 귀찮으므로 pass.
WinDbg // ServiceDescriptorTable 내용 확인하기
우선, 커널 변수를 이용하여, 테이블 위치 확인
8055c700 80504450 00000000 0000011c 805048c4
8055c710 00000000 00000000 00000000 00000000
8055c720 00000000 00000000 00000000 00000000
8055c730 00000000 00000000 00000000 00000000
8055c740 00000002 00002710 bf80c0b6 00000000
8055c750 f719ba80 f6b89b60 86d74950 806f60c0
8055c760 00000000 00000000 ffea8ad6 ffffffff
8055c770 ee4ae396 01c90284 00000000 00000000
8055c6c0 80504450 00000000 0000011c 805048c4
8055c6d0 bf999b80 00000000 0000029b bf99a890
8055c6e0 00000000 00000000 00000000 00000000
8055c6f0 00000000 00000000 00000000 00000000
8055c700 80504450 00000000 0000011c 805048c4
8055c710 00000000 00000000 00000000 00000000
8055c720 00000000 00000000 00000000 00000000
8055c730 00000000 00000000 00000000 00000000
KeServiceDescriptorTable 에서, NtOsKrnl 에 연결된 서비스.
KeServiceDescriptorTableShadow 에서, Win32K 에 연결된 서비스 를 확인 할 수 있다.
{
PULONG ServiceTable; // array of entry-points
PULONG puCounterTable; // array of counters
ULONG uTableSize; // number of table entries
PUCHAR pbArgumentTable; // array of byte counts
} SERVICE_DESCRIPTOR_TABLE, *PSERVICE_DESCRIPTOR_TABLE;
ServiceDescriptorTable의 구조가 위와 같으므로,
앞의 SDT에서는
ServiceTable Array of Entry 가 80504450
Entry의 개수는 0000011c 개 임을 알 수 있다.
출력하여 보면
80504450 805a4614 nt!NtAcceptConnectPort
80504454 805f0adc nt!NtAccessCheck
80504458 805f4312 nt!NtAccessCheckAndAuditAlarm
8050445c 805f0b0e nt!NtAccessCheckByType
80504460 805f434c nt!NtAccessCheckByTypeAndAuditAlarm
80504464 805f0b44 nt!NtAccessCheckByTypeResultList
80504468 805f4390 nt!NtAccessCheckByTypeResultListAndAuditAlarm
8050446c 805f43d4 nt!NtAccessCheckByTypeResultListAndAuditAlarmByHandle
80504470 806153a2 nt!NtAddAtom
...
위와 같이 List를 확인할 수 있다.
덧붙혀, 위의 순서가 바로 서비스 Index가 된다.
Detecting & Defeating the Debuggers
원문 : http://nagareshwar.securityxploded.com/2007/07/15/detecting-defeating-the-debuggers/
Debuggers are the main tool used in reverse engineering. It is used by serial crackers to break the software protection or to uncover the algorithm used in the proprietary applications. On the other hand it is also used by researchers to analyze the malwares.
Detecting the presence of debuggers is an important step in this direction. Here I will discuss about both user land and kernel level debugger detection techniques. Also I will throw some light on how one can defeat these techniques. Its always good to know both sides of the coin even though you always sit on one side.
In user land
Detecting debuggers in user land (ring 3) is simple. Windows provides API IsDebuggerPresent() which indicates if the application is being debugged. In such a case application may decide to terminate or may take different path just to evade the crackers.
There is a better method than one mentioned above. This involves directly reading ‘beingDebugged’ flag of PEB of the process. It is more stealthier than directly using the function since the function entry is clearly visible in the import table. In fact the IsDebuggerPresent() function internally does the same thing of reading the flag from PEB.
Here is the disassembly of IsDebuggerPresent Function
mov eax, dword ptr fs:[18]
mov eax, dword ptr ds:[eax+30] ; eax now points to PEB
movzx eax, byte ptr ds:[eax+2] ; retrieves PEB->beingDebugged value
Bypassing the above detection is simple as well.You can just attach debugger and modify the return value of IsDebuggerPresent(). You can also directly modify the ‘beingDebugged’ value in PEB. OllyDbg has several plugins which does this automatically.
This technique of detecting debuggers is pretty old, but it still helps in evading casual crackers. Now there are most customized methods specific to debuggers such as OllyDbg, IDAPro, Softice etc.
You can find some very good techniques at OpenRCE.
Inside the Kernel
There are very less resouces available online when it comes to kernel as very few people have dared to enter ring 0. However windows provides support for detecting and defeating the debuggers inside kernel. You can use exported variable KdDebuggerEnabled of ntoskrnl to detect if the machine is being debugged by kernel debugger. The good place to perform this check in the DriverEntry routine of your driver.
Once the debugger is detected, you can either terminate execution of your driver or disable the debugger itself. To stop the debugger, you can use another exported function KdDisableDebugger on NT based machines.
This same trick is used by IceSword (anti rootkit tool) to prevent reversers from knowing its internals.Here is the code snippet from IceSword driver Isdrv120.sys which does this check and then disables the debugger.
loc_disable_debugger: | |
mov eax, ds:KdDebuggerEnabled | ; check if debugger running |
cmp byte ptr [eax], 0 | |
jz short loc_next | ; no debugger found |
call KdDisableDebugger | ; disable debugger |
jmp short loc_disable_debugger | ; check again, until it is disabled |
loc_next: |
However inside the ring 0 also its not rare to find debugger specific checks. For example, you can test for the presence of SoftIce by checking if its driver is loaded or not.
- Nagareshwar
(APM + ITS + SVN 설치 따라하기) 6. Zeroboard XE 설치하기
문서 내용 :
a. MySQL 을 이용한 DB설정
b. ZBXE 설치 및, DB 연동
기본 준비물 :
공식 홈페이지 : http://www.zeroboard.com/
Download Url : http://www.zeroboard.com/zbxe_download/
설치는 다음 파일을 기준으로 합니다
zbxe.1.0.2.zip
우선 제로보드에서 사용하기 위한 DB를 설정합니다.
이븐텀 설치시와 마찬가지로 Schemata에서 사용할 DB를 추가합니다.
DB 설정이 끝나면, 사용 계정을 설정합니다.
User Administration 메뉴 화면입니다.
제로보드 DB에 대하여, 제로보드 유저의 SQL 명령 권한을 모두 Assign 해주고,
다운받은 ZBXE 파일을
아파치의 DOC 폴더에 풀고
익스플로러를 통해 다음 PHP 파일을 열어줍니다
설치가 진행되는 화면입니다.
DB & 관리자 정보 입력 부분은 앞서 설정한 DB부분을 연동합니다.
설치 완료 후 관리자 페이지를 연 모습입니다.
끝.