Thursday, December 4, 2014

Programming Montorring 001- Let's make a program that can list up handles of system!

Today, it has brought Manticore ...

Says the following sources:
http://forum.sysinternals.com/uploads/Napalm/2006-04-20_211055_HandleList.zip

Well ...

Manticore: Well ... the source to find out the handle from the system inter-day pecking

Then I go to the source.

NtQuerySystemInformation ()
NtDuplicateHandle ()
NtQueryObject ()

Manticore: Use this function to find out the handle, the handle deoraguyo find out information ~~

Oh I see ....

So good ...
So using that function ........
Try to find out the handles information .....

It's a real game ...
This is a real game ....

Game room or game room games are going jinkka not games ...

That function is plotting a monster.
That monster eats ~~

The   SP index (Sysmtem Power) index would go up .... okay?

We're in a real game of our lives ....

Imjaehae revelation in Jesus as the Lord of the power of the Holy of Holies in the ark
Plotting to defeat this guy is the real thing ... ~~
Okay ...?

And they're coming along very well ~~ !!!

Today yigijago ~~ from the devil ....
What we are fighting, not the flesh and blood
I fight the devil are you ~~!

Now ....

Well ... uh ... Today

I'll explain how NtDuplicateHandle () and why ...

It's not that the moment the process of creating a program called Click a.exe ~~
So, what did I say?

The environment in which the process can be executed jindago did you make?

In that environment, es ...
There is ~~ table dining table dining table (Table) ~~ !! What's dining table?
Folks handle ~~
Handle table
The handle table is given for each process
Who? ~~~ Side someone kernel

That's why the handle value in the handle table of another process, as it will never be used ...

Damn copy him -

Calling NtDuplicateHandle () function,
Side of the kernel ...
I teach object handles Please enable ~~~
So (I do not know who ~~~) kernel side someone for pointing objects that handle
Assigning a handle to be used again and stored in the handle table haejugo
Geojwi passing the index value of the handle table ~~
Do you understand?

Well ....
In addition, the function of NTDLL.DLL I can not be invoked directly by the compiler ...
Slow in order to use the functions in the program of NTDLL.DLL
Tell the compiler to the shape of the function, the function must be loaded ~~ that yourself!
Then, there can figure out the address of a function
~~ That by using this function to store a pointer to a function address!

Yet, I explained the LoadLibrary () function and GetProcAddress () function.

LoadLibrary () receives the path to the input (Input), were that receives the memory address to the output (Output).
The memory address is called the address for the module is loaded.
And, the function using the address


ntdll.dll is loaded addresses 0x77a1000
Then LoadLibrary () also eonaen address this guy he gets?



0x77a10000
Well ....
In other words ... LoardLibrary () that he is a perfect idea to return the memory address to which the module is loaded!

And, GetProcAddress () returns the address of the function is haejugo ~~ !!

FARPROC WINAPI GetProcAddress ( 
  _In_ HMODULE hModule, 
  _In_ LPCSTR lpProcName 
); 
And that if you use the function takes a function pointer address ~~
How do you create a function pointer?

The parameters for each function address, name, type, close, open landscape horizontal return type ~~
Just Do It by.
Says it this way.

DWORD (* pMyFun) (INT nData);

pMyFun =   GetProcAddress (hModule,   "Test");



So that you can use it any dll when ~~ !!

멘토링~~


오늘은 맨티가...이것 가져왔다...

다음 소스를 말이다.
http://forum.sysinternals.com/uploads/Napalm/2006-04-20_211055_HandleList.zip

음...

맨티 : 음...시스인터날에서 핸들을 알아내는 소스가 있더라구요~

그래서 소스를 보니까..

NtQuerySystemInformation()
NtDuplicateHandle()
NtQueryObject()

맨티 : 이 함수를 이용해서 핸들을 알아내고, 핸들 정보를 알아내더라구요~~

오 그렇구나....

그래 좋았어...
그럼 저 함수를 이용해서........
핸들 정보를 알아내보도록.....

이건 진짜 게임이야...
이게 진짜 게임....

게임방이나 오락실 게임이 진까게임이 아닌거야...

저 함수는 괴물인거야..
저 괴물을 잡아 먹어~~

그러면 SP지수(Sysmtem Power)지수가 올라갈거야....오케?

우리의 진짜 게임은 우리의 삶이야....

예수님안에서 지성소의 법궤안에 임재해 계시는 야훼의 파워로
저 괴물을 다 물리치는 것이 진짜 게임인거야~~
오케~?

지금 아주 잘 따라오고 있어~~!!!

오늘도 이기자고~~마귀에게서....
우리들이 싸우는 것은 혈과 육이 아니고
마귀랑 싸우는 거야~~!

자....

자...오늘은 말이야...

NtDuplicateHandle()을 왜하는지를 설명해줄께…

a.exe라는 프로그램을 클릭하는 순간 프로세스라는 것이 만들어지잖아~~
그럼.. 내가 뭐라고 했지?

프로세스가 실행될 수 있는 환경이 만들어진다고 했지?

그 환경에는 말이지…
밥상이 있어 밥상~~테이블(Table)~~!!무슨 밥상이냐?
핸들밥상~~
핸들 테이블
이 핸들 테이블은 프로세스마다 주어지지
누가 ? 커널 쪽에서 누군가가~~~

그래서 다른 프로세스의 핸들테이블에 있는 핸들값을 그대로 절대로 사용할 수 없는 거야…

그놈을 복사해야되는거야~

NtDuplicateHandle()함수를 호출하면,
커널쪽에…
이 핸들이 가르치는 개체 저도 사용할 수 있게 해주세요~~~
그럼 커널쪽 누군가가(누군지 모르겠어~~~) 그 핸들이 가르키는 개체에 대해서
사용할 수 있도록 핸들을 다시 할당해서 핸들 테이블에 저장해주고
그 핸들테이블의 인덱스 값을 넘겨주는 거쥐~~
알겠어?


음….
그리고, NTDLL.DLL의 함수를 컴파일러가 직접 호출할 수 가 없어….
NTDLL.DLL의 함수를 내 프로그램에서 사용하기 위해선느
컴파일러에게 함수의 모양을 알려줘야하고, 그 함수를 직접 로드해야 한다고~~!
그러면, 함수의 주소를 알아낼 수 있는데
이 함수를 함수주소포인터에 저장해서 사용하면 된다고~~!

그러면서, 나는 LoadLibrary()함수와 GetProcAddress()함수를 설명했다.

LoadLibrary()는 입력(Input)으로 경로를 받고, 출력(Output)으로 메모리 주소를 받는다고 했다.
이 메모리 주소는 로드한 모듈이 위한한 주소라고..
그리고 , 그 주소를 이용해서 함수를


ntdll.dll이 로드된 주소는 0x77a1000
그렇다면 LoadLibrary() 이놈이 뱄어낸 주소도?



0x77a10000
음….
즉… LoardLibrary()라는 녀석은 해당 모듈이 로드되어 있는 메모리 주소를 리턴해주는 것이 맞습니다!!!

그리고, GetProcAddress()는 함수의 주소를 리턴해주고~~!!


FARPROC WINAPI GetProcAddress(
 _In_  HMODULE hModule,
 _In_  LPCSTR lpProcName
);
그리고, 함수포인터로 해당 함수주소를 받아서 사용하면 된다는 점~~
함수 포인터는 어떻게 만드느냐?

리턴타입 가로열고 별 함수주소이름 가로닫고 인자값형태~~
로 하면 된다.
이런 식으로 말이다.


DWORD (*pMyFun)(INT nData);

pMyFun = GetProcAddress(hModule, "test");

이렇게 하면 어떤 dll이든 다 사용할 수 있다는 점~~!!