<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Information Security</title>
    <link>https://leeeeye321.tistory.com/</link>
    <description></description>
    <language>ko</language>
    <pubDate>Tue, 11 Aug 2026 01:09:18 +0900</pubDate>
    <generator>TISTORY</generator>
    <ttl>100</ttl>
    <managingEditor>leeeeye321</managingEditor>
    <item>
      <title>Debug 방식의 API 후킹</title>
      <link>https://leeeeye321.tistory.com/267</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;&lt;u&gt;[ Debug&amp;nbsp;방식의&amp;nbsp;API 후킹 ]&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;디버거(Debugger):&amp;nbsp;디버깅/후킹 프로그램(hookdbg.exe)&lt;/p&gt;&lt;p&gt;디버기(Debuggee):&amp;nbsp;디버깅 당하는 프로그램(notepad.exe)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이번에는 디버그 방식으로 API 후킹을 할 것이다. 위의&amp;nbsp;두 프로세스로 실습을 진행한다.&lt;/p&gt;&lt;p&gt;디버거는 디버깅을 당하는 디버기에 대한 모든 권한을 가지므로 후킹 함수를 쉽게 설치할 수 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;float: none; text-align: left; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 820px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99182D475D369CA014&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99182D475D369CA014&quot; width=&quot;820&quot; height=&quot;236&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; text-align: left; clear: none;&quot;&gt;&lt;span style=&quot;text-align: left;&quot;&gt;notepad는 파일에 내용을 입력하고 저장할&amp;nbsp;때 WriteFile() API를 사용한다. 이 API를 후킹하여 저장되는 문자열 중&amp;nbsp;소문자를 대문자로 덮어쓸&lt;/span&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&amp;nbsp;것이다.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;먼저 notepad의 WriteFile()&amp;nbsp;시작 주소에 Break Point를 설치하고 메모장에서 문자열을 저장한다. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;그리고 스택에서 파라미터를 확인한다. 두 번째 파라미터(ESP+8 : AEE18)가&amp;nbsp;버퍼의 주소이고, 그 버퍼에는 메모장에서 저장한 문자열이 있다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;이 버퍼를 덮어쓰면 원하는 대로 내용을 변경할 수 있다.&lt;/p&gt;
&lt;p&gt;* 버퍼의 주소, PID는 반복된 실습으로 인해 변경됩니다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 818px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E0EC335D26CF592A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E0EC335D26CF592A&quot; width=&quot;818&quot; height=&quot;360&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;디버거(hookdbg.exe)의 코드이다. 메인 함수에서 DebugLoop()를 호출하고 있다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;디버깅을 하면서 후킹의 과정을 확인할 것이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 665px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99083F4C5D23581E39&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99083F4C5D23581E39&quot; width=&quot;665&quot; height=&quot;523&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[ DebugLoop()의 작업 단계 ]&lt;/p&gt;&lt;p&gt;1)&amp;nbsp;WriteFile() API의 시작에 BP(INT3 명령어, 0xCC)를 설치 == &lt;b&gt;Hook 설치&lt;/b&gt;&lt;/p&gt;&lt;p&gt;2)&amp;nbsp;디버깅 중 INT3 명령어를&amp;nbsp;만나면 CPU는 디버기 실행을&amp;nbsp;멈추고 EXCEPTION_BREAKPOINT 예외를 디버거에게 전달&lt;/p&gt;&lt;p&gt;3) 디버거에게 제어를 넘김&lt;/p&gt;&lt;p&gt;4) 작업 수행(여기서는 소문자를 대문자로 바꾸기)&lt;/p&gt;&lt;p&gt;5) WriteFile() API의 시작 첫 번째 바이트 원상 복구 == &lt;b&gt;Unhook&lt;/b&gt;&lt;/p&gt;&lt;p&gt;6) 수행한&amp;nbsp;작업 저장을 위해 한 번 더 WriteFile() 실행&lt;/p&gt;&lt;p&gt;7) 다음의 후킹을 위해 다시 Hook 설치&lt;/p&gt;&lt;p&gt;8) 디버기에게 제어 돌려줌&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 432px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99F9CE415D26D7D62B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99F9CE415D26D7D62B&quot; width=&quot;432&quot; height=&quot;307&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Ollydbg에서 [F3]을 누르면 파라미터를 주면서 실행할 수 있다. &amp;nbsp;&lt;/p&gt;&lt;p&gt;디버거의 실행 파라미터는 후킹할 프로세스의 PID이므로, notepad를 실행하고 [Process Explorer]에서&amp;nbsp;PID를 확인한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 719px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99D612415D26D53428&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99D612415D26D53428&quot; width=&quot;719&quot; height=&quot;256&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;실행 후 메인 함수부터 찾고, 그로부터 DebugLoop()의 시작(4011D0)을&amp;nbsp;알아냈다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span style=&quot;text-align: start;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 352px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99D209345D26D9A001&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99D209345D26D9A001&quot; width=&quot;352&quot; height=&quot;110&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;WaitForDebugEvent(): 디버기에서 디버그 이벤트가 발생할 때까지 대기하는 API&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[4011EE]까지 진행하면 스택에서 WaitForDebugEvent()의 파라미터를 확인할 수 있다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;[코드 84] 이벤트가 발생하면 첫번째 파라미터 DEBUG_EVENT 구조체 변수 de(pDebugEvent)에 이벤트 정보를 설정한 후&amp;nbsp;1을 리턴한다. 이로 인해 while 문에 참이 되어 안으로 들어간다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 553px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990C68365D26D1A91D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990C68365D26D1A91D&quot; width=&quot;553&quot; height=&quot;306&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;DEBUG_EVENT 구조체는 이렇게 생겼고, 발생한 이벤트의 종류에 맞춰서 유니온 멤버(u)가 설정된다.&lt;/div&gt;&lt;div&gt;유니온 멤버는 9개의 구조체로 구성된다.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&amp;nbsp;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 347px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A44A415D26D7D637&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A44A415D26D7D637&quot; width=&quot;347&quot; height=&quot;75&quot; filename=&quot;이미지 013.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;[88-91] WaitForDebugEvent()를 호출한 후 EVENT_DEBUG 구조체 de 변수(12FF00)에 가보면&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;dwDebugEventCode의 값이 3으로 설정되어 있다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;결과적으로 첫 번째&amp;nbsp;if 문은 참이 되어&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;b&gt;CREATE_PROCESS_DEBUG_EVENT 이벤트 핸들러 OnCreateProcessDebugEvent()&lt;/b&gt;를&amp;nbsp;호출한다.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 710px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/997A4D4A5D2429002D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F997A4D4A5D2429002D&quot; width=&quot;710&quot; height=&quot;376&quot; filename=&quot;이미지 001.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;OnCreateProcessDebugEvent() 함수이다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;디버기의 프로세스가 시작될 때 호출되는 함수이다. 파라미터로 DEBUG_EVENT 구조체 변수 de를 pde로 전달한다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 820px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99F029485D26E9691A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99F029485D26E9691A&quot; width=&quot;820&quot; height=&quot;143&quot; filename=&quot;이미지 014.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;[10] GetModuleHandleA(), GetProcAddress()를 호출하여 결과적으로 WriteFile()의 주소를 리턴한다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 758px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99CD33455D26F94801&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99CD33455D26F94801&quot; width=&quot;758&quot; height=&quot;83&quot; filename=&quot;이미지 016.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;[11] memcpy() 함수로 ESI를 EDI에 복사한다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 342px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99226F425D26F9AD01&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99226F425D26F9AD01&quot; width=&quot;342&quot; height=&quot;88&quot; filename=&quot;이미지 018.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;ESI(Source)는 12FF0C를 가리킨다. u.CreateProcessInfo 구조체 변수이다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 346px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/998308455D26F9492A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F998308455D26F9492A&quot; width=&quot;346&quot; height=&quot;68&quot; filename=&quot;이미지 015.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;EDI(Destination)은 5라인에서&amp;nbsp;정의한 CREATE_PROCESS_DEBUG_INFO 구조체 변수 g_cpdi이다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;이 구조체에는 디버기 프로세스 핸들 hProcess 멤버가 존재한다. 이를 통해 디버기의 메모리에 읽기/쓰기 작업을 수행할 수 있다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 820px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99CBDA365D27006F30&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99CBDA365D27006F30&quot; width=&quot;820&quot; height=&quot;296&quot; filename=&quot;이미지 019.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;[13-14]&amp;nbsp;일단&amp;nbsp;ReadProcessMemory() API로 WriteFile()의 첫 번째 바이트(0x6A)를 g_ch0rgByte에 저장한다. BP 설치 후 원상 복구할 때를 위한 것이다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 342px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/991953365D27007004&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F991953365D27007004&quot; width=&quot;342&quot; height=&quot;52&quot; filename=&quot;이미지 020.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;g_ch0rgByte(40DA64)에 0x6A가 저장되었다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: center;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 820px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996BF0365D27007001&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996BF0365D27007001&quot; width=&quot;820&quot; height=&quot;234&quot; filename=&quot;이미지 021.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none; text-align: left;&quot;&gt;[16-17] WriteProcessMemory() API를 이용하여 notepad의 WriteFile() 첫 번째 바이트를&amp;nbsp;0xCC(g_chINT3)로 덮어쓴다.&lt;/p&gt;&lt;p&gt;[19] 여기까지 하면 이제 TRUE를 리턴하고&amp;nbsp;&lt;/p&gt;&lt;p&gt;[108] ContiueDebugEvent() 함수를 만난다. 이 함수는 디버기의 실행을 재개한다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 456px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99684D395D31B34811&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99684D395D31B34811&quot; width=&quot;456&quot; height=&quot;162&quot; filename=&quot;이미지 001.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;WriteFile()의 호출을 위해 메모장에 ReverseCore이라고 쓰고 저장했다.&lt;/p&gt;&lt;p&gt;while 문에 의해 다시 WaitForDebugEvent()를 만나게 되고, BP가 설치된 WriteFile()이 호출되었으니 dwDebugEventCode의 값이 1(EXCEPTION_DEBUG_INFO)로 설정된다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;else if 문에 참이 되어 &lt;b&gt;EXCEPTION_DEBUG_EVENT 이벤트 핸들러OnExceptionDebugEvent()&lt;/b&gt; 함수가 호출된다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 656px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99F82E3F5D37E91E10&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99F82E3F5D37E91E10&quot; width=&quot;656&quot; height=&quot;380&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;OnExceptionDebugEvent() 함수이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;★ WriteFile()의 INT 3 명령어를 만나면 EIP는 WriteFile() 주소 + 1(0xCC, 1바이트)이 되고&amp;nbsp;제어권이 디버거에게 넘어간다.&lt;/p&gt;&lt;p&gt;원하는 대로 내용을 덮어쓰고 저장하기 위해&amp;nbsp;EIP를 정상적인 WriteFile() 주소로 변경해야 한다.&lt;/p&gt;&lt;p&gt;그리고 정상적인 WriteFile() 시작 주소로 가서 다시 BP를 만나 버리면 안되므로&amp;nbsp;BP도 제거해 준다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;[27-30] 발생한 이벤트가 BP인지, WriteFile()에서 발생한 것이 맞는지 if 문 두 개로 확인한다.&lt;/p&gt;&lt;p&gt;[31-32] WriteProcessMemory()를 이용하여 미리 저장해 놓은 0x6A로 첫 번째 바이트를 원상 복구(Unhook)한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 771px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9905703F5D37E91F18&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9905703F5D37E91F18&quot; width=&quot;771&quot; height=&quot;68&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[36-37] GetThreadContext() API는 ctx에 스레드(g_cpdi.hThread: 디버기의 메인 스레드 핸들)의 CONTEXT를 저장한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Windows OS는 멀티 스레드 기반이다.&amp;nbsp;CPU가 모든 스레드를 일정시간 실행하고 넘어가고를 반복하기 때문에 작업의 내용을 백업하는 것이 중요하다. CPU 레지스터 값이 유지되어야 다음 실행이 제대로 이루어지는데, 스레드의 CPU 레지스터 정보를 저장하는 구조체가 CONTEXT 구조체이다. 스레드 하나 당 CONTEXT 구조체 하나를 가진다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 704px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/993651365D31C23123&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F993651365D31C23123&quot; width=&quot;704&quot; height=&quot;356&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[39-42] 덮어 쓸 버퍼의 주소와 크기가 필요하므로 Context.Esp 멤버를 이용해서 디버기 스택의 파라미터&amp;nbsp;값을 각각 dwAddrOfBuffer[12FC10], dwNumOfBytesToWrite[12FC14]에 저장한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 623px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/998C64505D37EB6312&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F998C64505D37EB6312&quot; width=&quot;623&quot; height=&quot;359&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&amp;nbsp;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 456px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/998BCA4D5D31C4A624&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F998BCA4D5D31C4A624&quot; width=&quot;456&quot; height=&quot;178&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;[44]&amp;nbsp;malloc() 함수로 임시 버퍼를 할당한다. 버퍼의 주소를 리턴하여 EAX에 저장(393F18)한다.&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 453px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A5914D5D31C4A724&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A5914D5D31C4A724&quot; width=&quot;453&quot; height=&quot;168&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[45]&amp;nbsp;임시 버퍼(393F18~393F23)를 memset() 함수로 0으로 초기화한다.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 591px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/998671485D31C5F530&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F998671485D31C5F530&quot; width=&quot;591&quot; height=&quot;256&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[47-48] ReadProcessMemory() API로 WriteFile() 버퍼를 임시 버퍼에 읽어온다. 이전에 저장했던 ReverseCore 문자열이 임시 버퍼에 복사되었다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 591px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/997DE74D5D31C6871A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F997DE74D5D31C6871A&quot; width=&quot;591&quot; height=&quot;265&quot; filename=&quot;이미지 007.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[52-56]&amp;nbsp;버퍼의 문자열이 소문자이면 대문자로 변환(-0x20)하여 저장한다. 임시 버퍼를 보면 for 문을 통하여 한 글자씩 변환해가는 과정을 확인할 수 있다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 266px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99FF873D5D37EF0730&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99FF873D5D37EF0730&quot; width=&quot;266&quot; height=&quot;188&quot; filename=&quot;캡처.PNG&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;hookdbg.exe에서 다음과 같이 출력된다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 635px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99F1A53D5D37EF070D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99F1A53D5D37EF070D&quot; width=&quot;635&quot; height=&quot;135&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[60-61]&amp;nbsp;대문자로 변경된 문자열을 WriteFile() 버퍼에 복사&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[63]&amp;nbsp;임시 버퍼 해제&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 689px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/997E363B5D37EF9720&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F997E363B5D37EF9720&quot; width=&quot;689&quot; height=&quot;271&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 700px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A2DA405D31C96A01&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A2DA405D31C96A01&quot; width=&quot;700&quot; height=&quot;112&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[65-66]&amp;nbsp;CONTEXT.Eip 멤버를 WriteFile() 시작 주소(7C810E17)로 변경하고 SetThreadContext()를 호출하여 이를 셋팅한다.&lt;/p&gt;&lt;p&gt;[68]&amp;nbsp;ContinueDebugEvent() API를 호출하여 멈췄던 디버기의 실행을&amp;nbsp;재개한다. WriteFile()이 정상적으로 호출되어 변환한 내용을 저장한다.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 448px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A762415D31CA0530&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A762415D31CA0530&quot; width=&quot;448&quot; height=&quot;136&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[72]&amp;nbsp;마지막으로 다음의 후킹을 위해 다시 BP(g_chINT3)&amp;nbsp;WriteFile()의 첫 바이트에 써준다(훅 설치).&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 209px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99207C365D37F83038&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99207C365D37F83038&quot; width=&quot;209&quot; height=&quot;160&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;대문자로 변환되어 저장된 것을 확인한다. 이렇게 디버그 기법으로 API 후킹이 성공했다.&lt;br /&gt;&lt;/p&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/267</guid>
      <comments>https://leeeeye321.tistory.com/267#entry267comment</comments>
      <pubDate>Thu, 4 Jul 2019 17:56:34 +0900</pubDate>
    </item>
    <item>
      <title>Code Injection</title>
      <link>https://leeeeye321.tistory.com/265</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;[ Code Injection ]&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;-프로세스에 독립 실행 코드를 삽입한 후 실행하는 기법&lt;/p&gt;&lt;p&gt;-CreateRemoteThread() API를 이용하여 원격 스레드 형태로 실행하므로 Thread 인젝션이라고도 한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 253px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E3CD385D1D856807&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E3CD385D1D856807&quot; width=&quot;253&quot; height=&quot;250&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 543px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99472E4D5D15D9482E&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99472E4D5D15D9482E&quot; width=&quot;543&quot; height=&quot;109&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;Windows 메시지 박스를 출력하는 간단한 코드이다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 741px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99F80A345D15E4252B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99F80A345D15E4252B&quot; width=&quot;741&quot; height=&quot;182&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Ollydbg에서 ThreadProc()를 확인한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;PUSH 명령어로 MessageBox() API의 문자열&amp;nbsp;주소를 스택에 저장하고 있다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;1000781C, 10007828 주소는 DLL의 데이터(.rdata)&amp;nbsp;섹션 영역에 정의된 문자열을 가리킨다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 675px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99AFC2355D15E55232&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99AFC2355D15E55232&quot; width=&quot;675&quot; height=&quot;182&quot; filename=&quot;이미지 007.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;CALL 명령어의 100060E4 주소는 MessageBox() API의 IAT이다.&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;DLL 코드에서 사용되는 모든 데이터(파라미터, IAT 등)는&amp;nbsp;DLL의 데이터(.rdata) 섹션에 위치한다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이 코드를 DLL로 만들고 다른 프로세스에 삽입하면 코드와 데이터가 같이 메모리에 존재하여 정상적으로 실행이 된다.&lt;/p&gt;&lt;p&gt;하지만 DLL이 아닌 코드(10001000~10001016)만&amp;nbsp;다른 프로세스에 삽입한다면, 정상적으로 실행되지 않을 것이다.&lt;/p&gt;&lt;p&gt;다른 프로세스에는 1000781C, 10007828, 100060E4에 참조할 데이터가 없기 때문이다.&lt;/p&gt;&lt;p&gt;그래서 Code injection을 위해서는 &lt;b&gt;참조할 데이터까지 인젝션&lt;/b&gt;해야 한다.&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 411px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/991825405D19C7D124&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F991825405D19C7D124&quot; width=&quot;411&quot; height=&quot;331&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;실습은 간단하다. notepad를 실행시키고, CodeInjection.exe를 실행시키면 notepad에&amp;nbsp;코드가 인젝션되어 메시지 박스가 출력된다.&lt;/p&gt;&lt;p&gt;이제 Code 인젝션을 위해 구현된 CodeInjection.exe를 봅시다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 765px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99FB67475D19C0C122&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99FB67475D19C0C122&quot; width=&quot;765&quot; height=&quot;434&quot; filename=&quot;이미지 007.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;위의 코드는 메인 함수에서 호출되는 InjectCode() 함수의 일부분이다. ThreadProc() 스레드 함수에 파라미터로 전달될 값들을 THREAD_PARAM 구조체를 이용하여 셋팅하고 있다. &amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: center; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;그리고&amp;nbsp;API를&amp;nbsp;호출하여 상대방 프로세스에 메모리를 할당(VirtualAllocExec)하고 데이터(THREAD_PARAM)와 코드(ThreadProc)를 각각 인젝션(WriteProcessMemory)한다. 그리고&amp;nbsp;원격 스레드를 실행(CreateRemoteThread)시킨다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 700px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99BFAB385D19BAB214&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99BFAB385D19BAB214&quot; width=&quot;700&quot; height=&quot;308&quot; filename=&quot;이미지 001.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;이 코드가 인젝션할 코드 ThreadProc()이다.&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;모든 데이터를 직접 API를 호출하거나 문자열을 정의하지 않고(하드코딩된 주소의 데이터를 참조하지 않고) THREAD_PARM 구조체에 접근해서 사용하고 있다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 565px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996C983B5D19D09F1E&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996C983B5D19D09F1E&quot; width=&quot;565&quot; height=&quot;423&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;코드가 인젝션된 상태의 notepad를 Ollydbg로 보면, ThreadProc()을 확인할 수 있다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[EBP+8]는 ThreadProc()의 파라미터 lParam으로, InjectCode()에서 열심히 셋팅했던 THREAD_PARAM 구조체를 가리킨다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이를 ESI에 옮겨 놓고 함수들을 호출할 때 ESI를 기준으로 값에 접근하여 사용한다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 743px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9956C83B5D19D09F2B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9956C83B5D19D09F2B&quot; width=&quot;743&quot; height=&quot;409&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;[ESP+8]의 값&amp;nbsp;960000으로 찾아가보면, THREAD_PARAM 구조체가 나온다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이렇게 Code 인젝션이 어떻게 구현되는지 살펴 보았다.&lt;/p&gt;&lt;p&gt;Code 인젝션을 사용하는 이유는&amp;nbsp;DLL로 만들지 않고 코드만 인젝션하기 때문에 메모리를 조금만 차지하고, 흔적을 찾기도 어렵고, 쉽고 편리하게 구현할 수 있기 때문이다.&amp;nbsp;&lt;/p&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/265</guid>
      <comments>https://leeeeye321.tistory.com/265#entry265comment</comments>
      <pubDate>Wed, 26 Jun 2019 15:47:39 +0900</pubDate>
    </item>
    <item>
      <title>PE 패치를 이용한 DLL 로딩</title>
      <link>https://leeeeye321.tistory.com/264</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;[ PE 패치를 이용한 DLL 로딩 ]&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;실행 파일을 직접 수정하여 DLL을 로딩시켜 봅시다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 243px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/991E8A3E5D1304FD29&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F991E8A3E5D1304FD29&quot; width=&quot;243&quot; height=&quot;255&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;TextView.exe 파일을 직접 수정하여 실행 시에&amp;nbsp;myhack3.dll을 로딩하도록 실습을 진행한다.&lt;/p&gt;&lt;div&gt;myhack3.dll은 www.google.com에서 index.html을 다운 받아서 프로세스에 드롭(drop)시키는 기능을 가진다.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 397px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99BF0E3E5D0C9EDA2C&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99BF0E3E5D0C9EDA2C&quot; width=&quot;397&quot; height=&quot;198&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;PE 파일에서 어떤 DLL을 import한다는 것은 그 DLL이 코드 내에서 제공하는 export 함수를 호출한다는 의미이다.&lt;/div&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;myhack.dll도 이를 따라 아무런 기능이 없는 dummy라는 export 함수를 정의한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 645px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9957F23A5D1C42BD1B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9957F23A5D1C42BD1B&quot; width=&quot;645&quot; height=&quot;472&quot; filename=&quot;이미지 004 (1).png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;TextView.exe는 읽고 쓰는 기능을 가진&amp;nbsp;단순한 텍스트 뷰어이다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;PEview에서 이 프로세스의 IDT(IMPORT Directory Table)를 확인한다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;import하는 DLL이 각각 IID(IMAGE_IMPORT_DESCRIPTOR) 구조체로 정의되어 있다.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 607px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/992703485D10804D31&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F992703485D10804D31&quot; width=&quot;607&quot; height=&quot;181&quot; filename=&quot;이미지 007.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이를 HxD에서 확인하면 14바이트씩 4개의 IID 구조체, 마지막으로 NULL 구조체까지 총 64바이트를 차지하며 myhack3.dll의 구조체를&amp;nbsp;추가시킬 자리가&amp;nbsp;없다는 것을 알 수 있다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;IDT 전체를 더 크고&amp;nbsp;비어있는&amp;nbsp;영역으로&amp;nbsp;이동시키고 DLL을 추가해야 한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 600px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A2C4355D1C42FB21&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A2C4355D1C42FB21&quot; width=&quot;600&quot; height=&quot;287&quot; filename=&quot;이미지 008 (1).png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;.rdata 섹션의 끝 부분에 Null padding 영역이 있다. 이 부분을 사용하기 전,&amp;nbsp;메모리에 로딩되는 부분인지 확인해야 한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 642px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/992600415D1C440C1C&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F992600415D1C440C1C&quot; width=&quot;642&quot; height=&quot;289&quot; filename=&quot;이미지 009 (1).png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;메모리에 로딩되었을 때 섹션의 크기(VirtualSize)는&amp;nbsp;2C56이다. 파일 크기(Size of Raw Data)는 2E00이고&amp;nbsp;사용되지 않는 크기는 2E00-2C56=1AA로 기존의 IDT가 위치하기에 문제가 없다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이제 TextView.exe를 직접 수정해 봅시다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 728px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9996AB445D1C2A7D2D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9996AB445D1C2A7D2D&quot; width=&quot;728&quot; height=&quot;130&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;IMAGE_OPTIONAL_HEADER에서 IMPORT Table 구조체 멤버는 IDT의 위치와 크기를 알려준다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 462px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E901455D10896007&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E901455D10896007&quot; width=&quot;462&quot; height=&quot;55&quot; filename=&quot;이미지 012.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;HxD로 이 값(Offset:160)을&amp;nbsp;찾아가서 이제부터 IDT의 위치는&amp;nbsp;.rdata 섹션의 Null padding 영역 8C80이고, 사이즈는 78(64+14)라고 수정한다.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 773px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990CC3375D1CBA4E1C&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990CC3375D1CBA4E1C&quot; width=&quot;773&quot; height=&quot;129&quot; filename=&quot;이미지 001.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;DLL 로딩 속도를 향상시키는 기법인 BOUND IMPORT Table은 옵션이므로 편의상&amp;nbsp;값을 0으로 만든다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 465px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9993B54B5D108D2C01&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9993B54B5D108D2C01&quot; width=&quot;465&quot; height=&quot;135&quot; filename=&quot;이미지 014.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;기존 IDT를&amp;nbsp;모두 복사한 후&amp;nbsp;새로&amp;nbsp;정의한 IDT에 [Paste Write]로&amp;nbsp;덮어쓰기한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 651px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/992C463F5D1C43AB26&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F992C463F5D1C43AB26&quot; width=&quot;651&quot; height=&quot;465&quot; filename=&quot;이미지 007 (1).png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;IDT가 7E80~7EE3로 인식되었고, 이제 7ED0~7EE0에 myhack.dll의 IID를 구성하면 된다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 663px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9942C8475D10A90309&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9942C8475D10A90309&quot; width=&quot;663&quot; height=&quot;289&quot; filename=&quot;99E2154A5C9202E407 (1).png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;IID는 이렇게 생겼다.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 600px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99D74F4D5D1C38060D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99D74F4D5D1C38060D&quot; width=&quot;600&quot; height=&quot;113&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;table class=&quot;txc-table&quot; width=&quot;784&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; style=&quot;border:none;border-collapse:collapse;;font-family:&quot; 맑은=&quot;&quot; 고딕&quot;,=&quot;&quot; sans-serif;font-size:15px&quot;=&quot;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 24px; border-width: 1px; border-style: solid; border-color: rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7ED0(OriginalFirstThunk)&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style=&quot;width: 590px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-top: 1px solid rgb(204, 204, 204);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;INT의 RVA(8D00)&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-left: 1px solid rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7F00&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style=&quot;width: 590px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;INT(8D30)&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;INT의 각 원소가 가리키는 값은 IMAGE_IMPORT_BY_NAME 구조체 포인터이다.&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-left: 1px solid rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7F30&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style=&quot;width: 590px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;IMAGE_IMPORT_BY_NAME 구조체&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;Ordinal(0000) + function name string(dummy:임포트하려는 함수)&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-left: 1px solid rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7EDC(Name)&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style=&quot;width: 590px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;DLL Name의 RVA(8D10)&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-left: 1px solid rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7F10&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style=&quot;width: 590px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;DLL Name(myhack3.dll)&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 41px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-left: 1px solid rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7EE0(FirstThunk)&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style=&quot;width: 590px; height: 41px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204);&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;IAT의 RVA(8D20)&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;실행 시에 PE 로더에 의해 실제 함수의 주소로 덮어쓴다.&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;width: 193px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204); border-left: 1px solid rgb(204, 204, 204); background-color: rgb(234, 234, 234);&quot; rowspan=&quot;1&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;b&gt;7F20&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style=&quot;width: 590px; height: 24px; border-bottom: 1px solid rgb(204, 204, 204); border-right: 1px solid rgb(204, 204, 204);&quot; rowspan=&quot;1&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&amp;nbsp;IAT(8D30)&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 562px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990F84375D1303D216&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990F84375D1303D216&quot; width=&quot;562&quot; height=&quot;271&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;실행 시 IAT는 PE 로더에 의해서 실제 함수로 덮어쓰기 때문에 .rdata 섹션은 WRITE 속성을 가져야 한다.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;Characteristics 값에 IMAGE_SCN_MEM_WRITE(80000000) 속성 값을 추가해 준다. 40000040 | 80000000 = C0000040&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;★ .rdata 섹션에 쓰기 속성 없이 정상적으로 실행하려면?&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 766px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/991BEC3B5D1CBB5807&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F991BEC3B5D1CBB5807&quot; width=&quot;766&quot; height=&quot;128&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;IAT 영역(6000~6154)에 IAT가 존재하면 된다. 위에서는 임의로 정한 부분에 dummy()의 IAT를 정의했는데,&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;쓰기 속성을 원래대로 없애고 IAT 영역에 정의해&amp;nbsp;보겠다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 464px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9938173D5D1CBE9E20&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9938173D5D1CBE9E20&quot; width=&quot;464&quot; height=&quot;119&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;IAT 영역으로 가서 끝 부분(5354)에 dummy()의 IAT(8D30)를 추가한다.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 607px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9926FB4F5D1CBEFD08&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9926FB4F5D1CBEFD08&quot; width=&quot;607&quot; height=&quot;135&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;myhack3.dll의 IID에 가서 IAT의 RVA를 6154(Offset:5354)으로 변경한다. 이렇게 dummy()의 IAT가 IAT 영역에 위치하므로, 쓰기 속성이 없어도 정상적으로 실행될 것이다.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 431px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9941DB4C5D1CBFB823&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9941DB4C5D1CBFB823&quot; width=&quot;431&quot; height=&quot;110&quot; filename=&quot;이미지 007.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;myhack.dll의 IID 구조체 멤버의 값이 설정되었다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 604px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E86D4E5D1C3EC40F&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E86D4E5D1C3EC40F&quot; width=&quot;604&quot; height=&quot;163&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;INT를 확인하면&amp;nbsp;dummy() 함수가 추가되어&amp;nbsp;있다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 596px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9984CA3C5D0C964611&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9984CA3C5D0C964611&quot; width=&quot;596&quot; height=&quot;343&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이제 수정을 완료한 TextView.exe을 실행해 본다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;로딩되어 있는 myhack3.dll은 구글의 index.html을 다운받아서 TextView.exe에 드롭시킨다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 605px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/992C513C5D0C964716&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F992C513C5D0C964716&quot; width=&quot;605&quot; height=&quot;407&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;구글 사이트인 것을 확인한다. 이렇게 IDT를 수정하여 DLL 인젝션에 성공했다.&lt;/p&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/264</guid>
      <comments>https://leeeeye321.tistory.com/264#entry264comment</comments>
      <pubDate>Fri, 21 Jun 2019 18:16:31 +0900</pubDate>
    </item>
    <item>
      <title>DLL Ejection</title>
      <link>https://leeeeye321.tistory.com/263</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;[ DLL Ejection&amp;nbsp;]&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;프로세스에 강제로 삽입한 DLL을 빼내는 것&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 246px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E1C2365D0C826628&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E1C2365D0C826628&quot; width=&quot;246&quot; height=&quot;301&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;notepad.exe에 myhack.dll을 강제로 인젝션했다가 다시 이젝션해봅시다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 704px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A3EA4E5D0C851D29&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A3EA4E5D0C851D29&quot; width=&quot;704&quot; height=&quot;91&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;이젝션을 하기 위해서는&amp;nbsp;CreateRemoteThread()를 사용하여 대상 프로세스가&amp;nbsp;&lt;b&gt;FreeLibrary() API&lt;/b&gt;를 스스로 호출하도록 만들어야 한다.&lt;/p&gt;&lt;div&gt;pThreadProc은 FreeLibrary()의 주소이고, me.modBaseAddr은 이젝션할 myhack.dll의 로딩 주소이다.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 409px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990A47365D0C82671A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990A47365D0C82671A&quot; width=&quot;409&quot; height=&quot;180&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;일단 인젝션을 하고&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 567px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99D4F3365D0C82671C&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99D4F3365D0C82671C&quot; width=&quot;567&quot; height=&quot;345&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;확인을 한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 408px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99C6DF405D0C83C526&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99C6DF405D0C83C526&quot; width=&quot;408&quot; height=&quot;146&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;EjectDll.exe로 이젝션을 시도한다. success.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 508px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99B4C4365D0C82671D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99B4C4365D0C82671D&quot; width=&quot;508&quot; height=&quot;274&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;notepad.exe에서 myhack.dll이 빠져 나갔다. 이젝션은 우리가 강제로 삽입한 dll만 가능하고 일반적으로 로딩되어 있는 dll은 불가능하다.&lt;/p&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/263</guid>
      <comments>https://leeeeye321.tistory.com/263#entry263comment</comments>
      <pubDate>Fri, 21 Jun 2019 16:27:33 +0900</pubDate>
    </item>
    <item>
      <title>DLL Injection - Remote Thread 생성 &amp;amp; 레지스트리 이용</title>
      <link>https://leeeeye321.tistory.com/262</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;맑은 고딕&amp;quot;, sans-serif;&quot;&gt;[ DLL Injection ]&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;-실행 중인 프로세스에 LoadLibrary() API를 스스로 호출하도록 명령하여 원하는 DLL을 로딩시키는 것&lt;/p&gt;&lt;p&gt;-삽입된 DLL은 이미 프로세스에 로딩되어 있는&amp;nbsp;다른 DLL과 마찬가지로&amp;nbsp;프로세스 메모리에 대한 &lt;b&gt;권한&lt;/b&gt;을 가지게 된다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 610px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99E788395D0B4DC005&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99E788395D0B4DC005&quot; width=&quot;610&quot; height=&quot;326&quot; filename=&quot;이미지 036.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;DLL이 로딩되면 &lt;b&gt;DLLMain()&lt;/b&gt; 함수가 실행되는데, 이 switch 문에 기능을 개선하거나 버그를 패치하는 등의 사용자가 원하는 코드를&amp;nbsp;넣을 수 있다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;1. 원격 스레드 생성하여 DLL 인젝션 구현하기 -&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;맑은 고딕&amp;quot;, sans-serif;&quot;&gt;CreateRemoteThread()&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 243px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/995E95355D0B320905&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F995E95355D0B320905&quot; width=&quot;243&quot; height=&quot;251&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;(리버싱 핵심 원리&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://reversecore.com/104&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;https://reversecore.com/104&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;notepad.exe에 myhack.dll을 인젝션하는 실습을 할 것이다.&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 655px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99AB393D5D0B484A0D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99AB393D5D0B484A0D&quot; width=&quot;655&quot; height=&quot;307&quot; filename=&quot;이미지 021.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;myhack.dll이 로딩되면 OutputDebugString()에 의해 해당 문자열을 출력되어&amp;nbsp;dll이 인젝션되었음을 확인할 수 있고, CreateThread() 함수&amp;nbsp;호출로&amp;nbsp;TreadProc 스레드를 실행된다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 482px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9995C5465D0B491704&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9995C5465D0B491704&quot; width=&quot;482&quot; height=&quot;17&quot; filename=&quot;이미지 022.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;ThreadProc의 내용은,&amp;nbsp;URLDownloadToFile() API를 이용하여 DEF_URL(http://www.naver.com/index.html)을 다운받는 것이다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;InjectDll.exe는 DLL 인젝션 유틸리티이다. 코드가 생소하므로 자세히&amp;nbsp;공부합시다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 744px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99092B485D0B495533&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99092B485D0B495533&quot; width=&quot;744&quot; height=&quot;91&quot; filename=&quot;이미지 028.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;OpenProcess()를 이용하여 PROCESS_ALL_ACCESS 권한을 가진 notepad.exe 프로세스 핸들을 얻는다. 이제 이 핸들(hProcess)를 이용하여 해당 프로세스를 제어할 수 있다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 741px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996073345D0B49AA2E&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996073345D0B49AA2E&quot; width=&quot;741&quot; height=&quot;19&quot; filename=&quot;이미지 029.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;우리는 notepad.exe에게 인젝션 할 dll의 경로를 알려줘야 한다. 일단 VirtualAllocEx()로 해당 프로세스 메모리에&amp;nbsp;경로 길이만큼의 버퍼를 할당한다. 리턴 값(pRemoteBuf)은&amp;nbsp;notepad.exe에 할당된&amp;nbsp;버퍼 주소이다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 740px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99064E345D0B49AB31&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99064E345D0B49AB31&quot; width=&quot;740&quot; height=&quot;19&quot; filename=&quot;이미지 030.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;그리고&amp;nbsp;WriteProcessMemory()로 할당한 버퍼에 경로(szDllPath)를 써준다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 746px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A75E345D0B49AB34&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A75E345D0B49AB34&quot; width=&quot;746&quot; height=&quot;37&quot; filename=&quot;이미지 031.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;우리는 LoadLibraryW를 호출하기 위해 주소를 얻어야 한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;b&gt;kernel32.dll(그 외 Windows 핵심 DLL도)은 프로세스마다 같은 주소에 로딩&lt;/b&gt;되기 때문에 굳이 notepad.exe에 로딩된 임포트 주소를 구하지 않아도 된다. DLL Injection이 바로 이 취약점을 이용한 것이다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;InejctDll.exe에 로딩되어 있는 kernel32.dll가 소유한&amp;nbsp;LoadLibraryW()의 주소를&amp;nbsp;얻는다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 744px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9905FC345D0B49AB31&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9905FC345D0B49AB31&quot; width=&quot;744&quot; height=&quot;16&quot; filename=&quot;이미지 032.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이제 notepad.exe에 LoadLibrary() API를 스스로 호출하도록 명령해야 한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;우리는 이를 위해 다른 프로세스에게 스레드를 실행시켜주는 함수&amp;nbsp;&lt;b&gt;CreateRemoteThread()&lt;/b&gt;를 사용할&amp;nbsp;것이다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;* LoadLibrary() API를 호출하도록 해야 하는데 스레드를 실행시키는 함수를 사용하는 이유는,&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 284px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9989A0345D0B99D926&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9989A0345D0B99D926&quot; width=&quot;284&quot; height=&quot;127&quot; filename=&quot;99CA3E395D0B4DC133.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이렇게 ThreadProc()과 LoadLibrary()가 함수 형태가 똑같기 때문이라고 한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 444px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99BB72375D0B9B3D2F&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99BB72375D0B9B3D2F&quot; width=&quot;444&quot; height=&quot;165&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;CreateRemoteThread() API의 파라미터는 어떻게 설정할까?&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;lpStartAddress에는 스레드 함수 주소 -&amp;gt; LoadLibrary()의 주소 pThreadProc,&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;lpParameter에는 스레드 파라미터 주소 -&amp;gt; 인젝션할 DLL 경로의 주소&amp;nbsp;pRemoteBuf을 넣고 호출하면 된다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;이렇게 소스 코드들을 살펴 보았으니 실습을 해봅시다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&amp;nbsp;&lt;img id=&quot;tx_entry_76117_&quot; class=&quot;txc-image&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/99CEEE495D07562D08&quot; width=&quot;117&quot; height=&quot;57&quot;&gt;&lt;/p&gt;&lt;p&gt;* DebugView - 시스템에서 실행되는 프로세스들이 출력하는 모든 디버그 문자열을 가로채서 보여주는 유틸리티이다.&lt;/p&gt;&lt;p&gt;이것으로&amp;nbsp;인젝션의&amp;nbsp;성공을&amp;nbsp;확인할 수 있다.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 412px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9971F3355D0C73F839&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9971F3355D0C73F839&quot; width=&quot;412&quot; height=&quot;179&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;1900은 notepad.exe의 PID이다. Dbgview를 실행시켜 놓고, InjectDll.exe를 실행하여 notepad.exe로 DLL 인젝션을 시도한다.&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 434px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990AC1355D0C73F813&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990AC1355D0C73F813&quot; width=&quot;434&quot; height=&quot;177&quot; filename=&quot;이미지 012.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;DebugView을 확인해보면,&amp;nbsp;문자열이 출력되어 있다. 이는&amp;nbsp;myhack.dll&amp;nbsp;인젝션이 성공하여&amp;nbsp;DllMain() 함수의 OutputDebugString() API가 호출된 것이다.&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 562px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99C3C9355D0C73F943&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99C3C9355D0C73F943&quot; width=&quot;562&quot; height=&quot;344&quot; filename=&quot;이미지 014.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;Process Explorer에서 notepad.exe에 로딩된 dll 목록을 확인했다. 역시 myhack.dll을 확인할 수 있다.&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 241px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/994C4B4A5D0B9D9D0F&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F994C4B4A5D0B9D9D0F&quot; width=&quot;241&quot; height=&quot;303&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;notepad.exe에 인젝션된 myhack.dll이 제 기능을 수행하여 index.html이 다운로드되었다.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 605px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/993A5B365D0C746009&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F993A5B365D0C746009&quot; width=&quot;605&quot; height=&quot;410&quot; filename=&quot;이미지 016.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Naver 페이지 확인&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;&lt;b&gt;2. 레지스트리 이용하여&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;b style=&quot;font-size: 18.6667px;&quot;&gt;&amp;nbsp;DLL 인젝션 구현하기 - AppInit-DLLs&lt;/b&gt;&lt;/p&gt;&lt;p&gt;User32.dll은&amp;nbsp;프로세스에 로딩될 때 레지스트리 항목 AppInt_DLLs를 읽어서 값이 존재하면 LoadLibrary()를 이용하여 사용자 DLL을 로딩한다. 이를 이용하여&amp;nbsp;AppInt_DLLs에 인젝션을 원하는 DLL의 경로를 입력하고 재부팅을 하면, User32.dll이 로딩된 모든 프로세스에 해당 DLL이 인젝션된다. 그럼 이제 실습을 해봅시다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 239px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99615F495D0C6D172E&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99615F495D0C6D172E&quot; width=&quot;239&quot; height=&quot;196&quot; filename=&quot;이미지 007.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;myhack2.dll은 자신을 로딩한 프로세스가 notepad.exe이면 IE를 숨김 모드(SW_HIDE)로 실행한다.&lt;/p&gt;&lt;p&gt;실습 파일을 준비하고, cmd에서 레지스트리 에디터&amp;nbsp;regedit.exe를 실행한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 669px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9919B0355D0C6DCD32&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9919B0355D0C6DCD32&quot; width=&quot;669&quot; height=&quot;329&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;AppInit_DLLs가 있는 곳으로 찾아간다. 아래에 나온 긴 경로를 따라 가세요.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 388px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/993844395D0C716C07&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F993844395D0C716C07&quot; width=&quot;388&quot; height=&quot;175&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;값을 인젝션할 dll의 경로로 변경하고 변경 사항을 적용하기 위해서 시스템을 재부팅한다.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 506px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/995D63395D0C716D05&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F995D63395D0C716D05&quot; width=&quot;506&quot; height=&quot;277&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;재부팅이 되었으면 Process Explorer에서 모든 프로세스에 myhackk2.dll이 인젝션된 것을 확인한다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 566px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A94F355D0C73F90A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A94F355D0C73F90A&quot; width=&quot;566&quot; height=&quot;345&quot; filename=&quot;이미지 015.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;notepad를 실행하면 notepad에도 인젝션된다. iexplore.exe가 숨김 속성으로 실행된 것도 확인한다.&lt;/p&gt;&lt;p&gt;이렇게 DLL INJECTION을 두 가지 방법으로 구현해 보았다. 다음에는 DLL EJECTION을 알아 봅시다.&lt;/p&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/262</guid>
      <comments>https://leeeeye321.tistory.com/262#entry262comment</comments>
      <pubDate>Thu, 20 Jun 2019 14:17:23 +0900</pubDate>
    </item>
    <item>
      <title>Windows Message Hooking</title>
      <link>https://leeeeye321.tistory.com/261</link>
      <description>&lt;p&gt;&lt;span style=&quot;font-size: 14pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;맑은 고딕&amp;quot;, sans-serif;&quot;&gt;[ DLL Injection - Windows Message Hooking ]&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Windows는 Event Driven&lt;strong&gt; &lt;/strong&gt;방식으로 동작한다. 이벤트가 발생하면 OS는&amp;nbsp;응용프로그램에게 메시지를 보낸다.&lt;/p&gt;
&lt;p&gt;이 메시지가 이동하는 중간에&amp;nbsp;엿보거나 가로채가는&amp;nbsp;것을 Message Hook이라고 한다.&lt;/p&gt;&lt;p&gt;메시지 후킹은 DLL 인젝션 기법의 하나로 사용된다.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;아래의 파일을 이용하여 후킹 실습을 진행한다.&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 120px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996931375D085EFA28&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996931375D085EFA28&quot; width=&quot;120&quot; height=&quot;115&quot; filename=&quot;이미지 015.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;(리버싱 핵심 원리&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://reversecore.com/104&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;https://reversecore.com/104&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;HookMain.exe은 KeyHook.dll을 최초로 로딩한 후, SetWindowsHookEx()을 이용하여&amp;nbsp;훅을 설치하는 프로그램이다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 192px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9973394A5D09C93318&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9973394A5D09C93318&quot; width=&quot;192&quot; height=&quot;119&quot; filename=&quot;이미지 025.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;SetWindowsHookEX()는 훅을 설치하는 API이고, 정의는 위와 같다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;float: none; clear: none; text-align: left;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 671px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9996453B5D0B967318&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9996453B5D0B967318&quot; width=&quot;671&quot; height=&quot;73&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;KeyHook.dll에서 확인한 SetWindowsHookEx() API의 호출이다.&amp;nbsp;첫 번째 파라미터&amp;nbsp;idHook(훅 타입)의 값은 WH_KEYBOARD로, 키 입력 메시지를 모니터하여 훅을 설치한다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 606px; text-align: center;; height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/997A193B5D0B967419&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F997A193B5D0B967419&quot; width=&quot;606&quot; height=&quot;342&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot; style=&quot;text-align: center;&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;KeyHook.dll은 내부에 훅 프로시저가 존재한다. 이&amp;nbsp;dll의 프로시저는, notepad.exe의 메시지를 가로채도록 프로그래밍되어 있다. 키보드 입력이 발생하면&amp;nbsp;프로세스 이름을 확인하고, notepad.exe(DEF_PROCESS_NAME)과 같다면 1을 리턴하여 KeyboardProc() 함수를&amp;nbsp;종료시킨다. 결과적으로&amp;nbsp;키보드 메시지는 notepad 프로세스에게 전달되지 못하여 화면에 아무것도 출력되지 않을 것이다.&lt;/p&gt;&lt;p&gt;이제 이 파일들로 실습을 해봅시다.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;float: none; text-align: left; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 410px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9967784A5D0B1AA323&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9967784A5D0B1AA323&quot; width=&quot;410&quot; height=&quot;176&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;HookMain.exe를 실행하면, 시스템에 훅이 설치된다.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;설치 후 메모장(notepad.exe)를 실행하고, 키보드를 입력해본다. 인터넷 익스플로러(iexplore.exe)도&amp;nbsp;실행하고 입력을 발생시켰다. 이제 OS가 이 프로세스들에게 Keyhook.dll을 강제로 로딩했을 것이다.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;float: none; text-align: left; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 507px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99C183475D09D2CA33&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99C183475D09D2CA33&quot; width=&quot;507&quot; height=&quot;272&quot; filename=&quot;이미지 027.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;Process Explorer에서 해당 프로세스에게 KeyHook.dll이 인젝션된 것을 확인할 수 있다.&lt;/p&gt;&lt;p style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;float: none; text-align: left; clear: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 287px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99ABEF4F5D0B199C17&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99ABEF4F5D0B199C17&quot; width=&quot;287&quot; height=&quot;164&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;float: none; text-align: left; clear: none;&quot;&gt;notepad.exe를 열어서 입력해보면, 메시지가 출력되지 않는다.&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 406px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9932484D5D0B1B1713&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9932484D5D0B1B1713&quot; width=&quot;406&quot; height=&quot;176&quot; filename=&quot;이미지 010.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;q를 눌러 후킹을 종료시킨다.&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 502px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99B5454F5D0B1C9D1D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99B5454F5D0B1C9D1D&quot; width=&quot;502&quot; height=&quot;270&quot; filename=&quot;이미지 013.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;후킹이 종료되며 dll이 언로딩된 것을 확인했다.&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left; clear: none; float: none;&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 288px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9967C34D5D0B1B171B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9967C34D5D0B1B171B&quot; width=&quot;288&quot; height=&quot;165&quot; filename=&quot;이미지 011.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/261</guid>
      <comments>https://leeeeye321.tistory.com/261#entry261comment</comments>
      <pubDate>Mon, 17 Jun 2019 20:02:44 +0900</pubDate>
    </item>
    <item>
      <title>EAT(Export Address Table)</title>
      <link>https://leeeeye321.tistory.com/260</link>
      <description>&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 18pt; FONT-FAMILY: Courier New&quot;&gt;&lt;STRONG&gt;EAT(Export Address Table)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;라이브러리 파일에서 제공하는 함수를 다른 프로그램에서 가져다 사용할 수 있게 해주는 핵심 메커니즘이다.&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;IMAGE_EXPORT_DIRECTORY 구조체에&amp;nbsp;Export 정보가&amp;nbsp;저장되어 있다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_10079_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99D987405C93390819&quot; width=686 height=235&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; WIDTH: 513px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=513 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 193px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;NumberOfFunctions&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 319px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;실제 Export 함수 개수&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 193px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;NumberOfNames&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 319px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;Export 함수 중에서 이름을 가지는 함수 개수 &lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 193px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;AddressOfFunctions&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 319px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;Export 함수 주소 배열&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 193px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;AddressOfNames&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 319px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;함수 이름 주소 배열&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 193px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;AddressOfNameOrdinals&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 319px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;Ordinal 배열&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EAT를 통해서만 해당 라이브러리에서 Export하는 함수의 시작 주소를 정확히 구할 수 있다.&lt;/P&gt;
&lt;P&gt;라이브러리에서 함수 주소를 얻는 API는 GetProcAddress()이다. 이 API가&amp;nbsp;EAT를 참조하여&amp;nbsp;원하는 API의 주소를 구한다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* &lt;STRONG&gt;GetProcAddress()&lt;/STRONG&gt;가 함수 이름으로 함수 주소를 얻는 과정&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. &lt;STRONG&gt;AddressOfNames&lt;/STRONG&gt;를 이용하여 함수 이름 주소 배열로 간다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. 문자열 비교(strcmp)를 통하여 원하는 함수의 이름을 찾는다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.&lt;STRONG&gt; AddressOfNameOrdinals &lt;/STRONG&gt;배열을 이용하여&amp;nbsp;Ordinal 배열로 간다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. 2번 배열의 인덱스로 해당 ordinal 값을 찾는다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5.&lt;STRONG&gt; AddressOfFunctions&lt;/STRONG&gt;를 통해 함수 주소 배열(EAT)로 간다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;6. 4번에서 찾은 ordinal을 배열 인덱스로 하여 원하는 함수의 시작 주소를 얻는다.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_82561_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/9972633A5C9334FE16&quot; width=752 height=126&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;kernel32.dll(C:\WINDOWS\system32\kernel32.dll)을 이용하여 GetProcAddress()가 EAT를 참조해서 AddConsoleAliasW의 실제 함수 주소를 찾는 과정을 실습할 것이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_92437_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/990ABB495C94879E14&quot; width=608 height=88&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;EXPORT 구조체의 시작 주소는 IMAGE_OPTIONAL_HEADER32.DataDirectory[0].VirtualAddress에 나와 있다.&lt;/P&gt;
&lt;P&gt;PEview를 통해 확인해보면 값은 262C(RVA)이고, 이를 RAW로 변환하면 262C-1000+400=1A2C이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; WIDTH: 689px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=689 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: #e6e6e6&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;Offset&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: #e6e6e6&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;Member&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: #e6e6e6&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;Value&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: #e6e6e6&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;RAW&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A38&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;Name&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;00004B98&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;4B98 - 1000 + 400 = 3F98&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A3C&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;Base&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;00000001&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A40&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;NumberOfFunctions&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;000003BA&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A44&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;NumberOfNames&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;000003BA&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A48&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;AddressOfFunctions&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;00002654&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;2654 - 1000 + 400 = 1A54&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A4C&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;AddressOfNames&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;0000353C&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;353C - 1000 + 400 = 293C&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 75px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;1A50&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 236px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;AddressOfNameOrdinals&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 126px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;00004424&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 251px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; rows=&quot;1&quot; cols=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;4424 - 1000 + 400 = 3824&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;EXPORT 구조체의 멤버들 정보를 정리했다. &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;다음은 AddConsoleAliasW 함수의 주소를 찾는 과정이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;1. AddressOfNames (함수 이름 배열) : 293C&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_57580_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/992267495C9488E815&quot; width=606 height=199&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;함수 이름 배열은 3BA(NumberOfNames)개의 원소가 있는 배열이고, 원소는 모두 문자열 주소(RVA)로 이루어져 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;첫번째 원소 4BA5를 RAW&amp;nbsp;3FA5로 변환하여 찾아가 본다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;2. 함수 이름 찾기 : 3F455&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_13429_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99FFAE505C9489F804&quot; width=610 height=214&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;엄청나게 많은 문자열들이 보인다. 우리가 찾아야 할 함수의 이름은&amp;nbsp;AddConsoleAliasW이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;ActivateActCtx가 제일 앞에 있어 인덱스의 값이 0이다. 그러므로 AddConsoleAliasW의 인덱스는 4이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;3. AddressOfNameOrdinals (Ordinal 배열) : 3824&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_65621_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/992C2D4D5C948A8910&quot; width=610 height=70&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;Ordinal 배열로 가서 위에서 알아낸&amp;nbsp;인덱스 4로 해당 ordinal을 찾는다. 똑같이 4이다. &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;4. AddressOfFunctions (함수 주소 배열 - EAT) : 1A54&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_46916_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/993BF8485C948BA321&quot; width=600 height=105&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;EAT로 가서 ordinal 4를 인덱스로 하여 함수 주소를 찾으면 00072B29 값을 얻는다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;kernel32.dll의 ImageBase는 7C800000이므로&amp;nbsp;00072B29(RVA) + 7C800000(ImageBase) = 7C872B29(VA)이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;Ollydbg에서 직접 찾아가 보면&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_49497_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99B7BE485C948CAC1F&quot; width=717 height=224&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;AddConsoleAliasW 함수를 만날 수 있다..&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;이렇게 IAT / EAT에 대해서 정리를 마칩니다.&lt;/P&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/260</guid>
      <comments>https://leeeeye321.tistory.com/260#entry260comment</comments>
      <pubDate>Wed, 12 Jun 2019 15:33:48 +0900</pubDate>
    </item>
    <item>
      <title>IAT(Import Address Table)</title>
      <link>https://leeeeye321.tistory.com/259</link>
      <description>&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 18pt; FONT-FAMILY: Courier New&quot;&gt;&lt;STRONG&gt;IAT(Import Address Table)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;프로그램이 어떤 라이브러리에서 어떤 함수를 사용하는지를 기술한 테이블이다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 18pt; FONT-FAMILY: Courier New&quot;&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt; FONT-FAMILY: 맑은 고딕,sans-serif&quot;&gt;&lt;STRONG&gt;DLL&lt;/STRONG&gt;(Dynamic Linked Library, &lt;/SPAN&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt; FONT-FAMILY: 맑은 고딕,sans-serif&quot;&gt;동적 연결 라이브러리&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt; FONT-FAMILY: 맑은 고딕,sans-serif&quot;&gt;)이란 &lt;/SPAN&gt;여러 프로그램에서 동시에 사용할 수 있는 코드와 데이터를 포함한 라이브러리이다. &lt;/P&gt;
&lt;P&gt;DLL의 로딩 방식은 두 가지인데, 그 중 하나가 &amp;nbsp;프로그램 시작할 때 같이 로딩되어 종료 시 메모리에서 해제되는 &lt;STRONG&gt;Implicit Linking&lt;/STRONG&gt; 방식이다. IAT는 Implicit Linking에 대한 메커니즘을 제공한다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_46301_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/994AF33C5C9325A130&quot; width=572 height=185&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CALL [1001104]&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;notepad.exe에서 kernel32.dll의 CreateFileW를 호출하는 명령어이다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;이 CALL&amp;nbsp;명령에서 호출하는&amp;nbsp;주소는&amp;nbsp;CreateFileW의 주소가 아니라 IAT 메모리 영역이다. &lt;/P&gt;
&lt;P&gt;1001104 주소에는 7C810CD9라는 값이 저장되어 있는데, 이 값이 CreateFileW의 주소이다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;이렇게 CALL 7C810CD9 명령을 사용하지 않고, IAT 영역을 사용하는 이유는 두 가지가 있다.&lt;/P&gt;
&lt;P&gt;1. 환경에 따라 kernel32.dll의 버전이 달라지고, 함수의 주소가 달라지기 때문이다.&lt;/P&gt;
&lt;P&gt;모든 환경에서 함수 호출을 보장하기 위하여 컴파일러는 실제 주소가 저장될 위치와 CALL [위치] 명령어를 준비한다. 파일이 실행되는 순간 PE 로더가 그 위치에 실제 함수의 주소를 입력한다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. DLL Relocation&lt;/P&gt;
&lt;P&gt;DLL이 ImageBase 값에 로딩되고, 또 다른 DLL도 같은 곳에 로딩을 시도하면 PE&amp;nbsp;로더는 다른 비어있는 공간에 로딩시켜 준다. 이렇게 재배치가 일어나기 때문에, 함수 주소로 하드코딩을 할 수가 없다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;이어서&amp;nbsp;PE로더가 어떤 방법으로 IAT에&amp;nbsp;함수 주소를 입력하는지&amp;nbsp;알아봐야 겠다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 18pt&quot;&gt;&lt;STRONG&gt;IMAGE_IMPORT_DESCRIPTOR(=Import Directory Table)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;PE 파일은 자신이 어떤 라이브러리를 Import하고 있는지를 IID 구조체에 명시한다.&lt;/P&gt;
&lt;P&gt;일반적 프로그램은 여러 라이브러리를 임포트하므로 라이브러리의 개수만큼 구조체 배열이 존재한다. (구조체 배열은 NULL 구조체로 끝난다.)&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;IMG id=tx_entry_12576_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99E2154A5C9202E407&quot; width=663 height=289&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; WIDTH: 423px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=423 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 148px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&lt;STRONG&gt;&amp;nbsp;OriginalFirstThunk&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 276px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;INT(Import Name Table)의 주소(RVA)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 148px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&lt;STRONG&gt;&amp;nbsp;Name&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 276px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;라이브러리 이름 문자열의 주소(RVA)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 148px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&lt;STRONG&gt;&amp;nbsp;FirstThunk&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 276px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;IAT의 주소(RVA)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* INT와 IAT는 long type(4바이트) 배열이고 NULL로 끝난다.&lt;/P&gt;
&lt;P&gt;* INT에서 각 원소의 값은 IMAGE_IMPORT_BY_NAME 구조체 포인터이다.&lt;/P&gt;
&lt;P&gt;* INT와 IAT의 크기는 같아야 한다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PE 로더가 임포트 함수 주소를 IAT에 입력하는 순서는 다음과 같다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;IID의&amp;nbsp;Name 멤버를 읽어들여서 라이브러리의 이름 문자열을 얻는다.&lt;/P&gt;
&lt;P&gt;2. 해당 라이브러리를 로딩한다.&lt;/P&gt;
&lt;P&gt;3. 이번에는 OriginalFirstThunk에서 INT의 주소를 얻는다.&lt;/P&gt;
&lt;P&gt;4. IMAGE_IMPORT_BT_NAME 구조체의 Hint 또는 Name 멤버를 이용하여 함수의 시작 주소를 얻는다.&lt;/P&gt;
&lt;P&gt;5. IID의 FirstThunk에서 IAT의 주소를 얻는다.&lt;/P&gt;
&lt;P&gt;6. IAT의 배열 값으로 INT에서 얻은 함수 주소를 입력한다.&lt;/P&gt;
&lt;P&gt;7. INT가 NULL을 만날 때까지 4~7번을 반복한다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_74430_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/9915B84C5C9209C72E&quot; width=749 height=126&gt;&lt;/P&gt;
&lt;P&gt;PEview로 IID를 직접 확인해 볼 것이다. IID 구조체의 위치는 OPTIONAL 헤더의 DataDirectory[1].VirtualAddress(RVA)에 저장되어 있다. PEview로 확인한 결과 위치가 7604인 것을 알 수 있다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;7604를 RAW로 변환하면 7604 - 1000 + 400 = 6A04이다. HxD로 이 위치를 찾아가면 IID 구조체를 확인할 수 있다.&lt;/P&gt;
&lt;P&gt;사이즈는 C8이기 때문에 6A04 ~ 6ACD까지 IID이다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_58970_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/997429445C920FFC01&quot; width=606 height=233&gt;&lt;/P&gt;
&lt;P&gt;화살표로&amp;nbsp;표시한 부분이 IID 구조체 배열의 첫 번째 원소이다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; WIDTH: 548px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=548 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 67px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: #e6e6e6&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;Offset&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 179px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: #e6e6e6&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;Member&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 91px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: #e6e6e6&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;RVA&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #000 1px solid; HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 208px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: #e6e6e6&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&lt;STRONG&gt;&amp;nbsp;RAW&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 22px; BORDER-RIGHT: #000 1px solid; WIDTH: 67px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;6A04&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 22px; BORDER-RIGHT: #000 1px solid; WIDTH: 179px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;OriginalFirstThunk (INT)&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 22px; BORDER-RIGHT: #000 1px solid; WIDTH: 91px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;00007990&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 22px; BORDER-RIGHT: #000 1px solid; WIDTH: 208px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;7990 - 1000 + 400 = 6D90&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 67px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;6A10&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 179px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;Name&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 91px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;00007AAC&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 208px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;7AAC - 1000 + 400 = 6EAC&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 67px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BORDER-LEFT: #000 1px solid; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;6A14&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 179px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;FirstThunk (IAT)&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 91px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;000012C4&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #000 1px solid; WIDTH: 208px; BORDER-BOTTOM: #000 1px solid; COLOR: #000; BACKGROUND-COLOR: transparent&quot; cols=&quot;1&quot; rows=&quot;1&quot;&gt;
&lt;P style=&quot;TEXT-ALIGN: center&quot;&gt;&amp;nbsp;12C4 - 1000 + 400 = 6C4&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;멤버들의 정보를 정리한 것이다.&amp;nbsp;RAW를 보고 각각 멤버들을 찾아간다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Name (라이브러리 이름)&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_48565_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/995E6C485C92138409&quot; width=607 height=56&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;IID 구조체 배열 첫 번째 원소의 라이브러리 이름은 comdlg32.dll으로 확인&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. OriginalFirstThunk - INT(Import Name Table)&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_83119_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99C70A4A5C9215352B&quot; width=607 height=71&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;INT는 임포트하는 함수의 정보가 담긴 구조체 포인터 배열이다. 이를 통해서 함수의 시작 주소를 정확히 구할 수 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;주소 값이 각각 IMAGE_IMPROT_BY_NAME 구조체를 가리킨다. &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;3. IMAGE_IMPROT_BY_NAME&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_18880_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99E2154A5C9215362A&quot; width=608 height=57&gt;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;배열의 첫 번째 값 7A7A(RAW: 6E70)으로 가면 임포트하는 API 함수 이름 문자열이 있다.&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;Ordinal: 000F&amp;nbsp;/ Name: PageSetupDlgW&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;4. FirstThunk - IAT(Import Address Table)&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_27391_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/992127375C93222F1D&quot; width=607 height=72&gt;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;comdlg32.dll&amp;nbsp;라이브러리에 해당하는 IAT 배열 영역이다. 파일이 로딩될 때 이 영역들이 정확한 함수 주소로 대체되는 것이다.&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;OllyDbg에서 IAT를 확인하기 위해&amp;nbsp;주소를 변환한다.&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;12C4(RVA) + 1000000(ImageBase) = 10012C4 &lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_97665_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/9910113D5C9325D118&quot; width=483 height=158&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;주소를 찾아가보니 763D4906을 가리키고 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_98171_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/997612335C9327AE2D&quot; width=741 height=212&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;이는 comdlg32 라이브러리의 PageSetupDlgW 함수의 정확한 주소이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;여기까지,&amp;nbsp;IAT가 무엇인지 알아보고 직접 값을 확인도 해보았다. 다음에는&amp;nbsp;EAT에 대해서&amp;nbsp;알아보겠다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/259</guid>
      <comments>https://leeeeye321.tistory.com/259#entry259comment</comments>
      <pubDate>Wed, 12 Jun 2019 15:31:43 +0900</pubDate>
    </item>
    <item>
      <title>PE File Format</title>
      <link>https://leeeeye321.tistory.com/258</link>
      <description>&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 36pt&quot;&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;FONT-FAMILY: Courier New&quot;&gt;PE File Format&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt&quot;&gt;PE(Portable Executable)&amp;nbsp;파일이란 Windows OS에서 사용하는 실행 파일 형식이다.&lt;/SPAN&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt&quot;&gt; &lt;/SPAN&gt;우리는 메모장(notepad.exe)으로 PE 파일의 기본&amp;nbsp;구조를 알아볼 것이다.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_49067_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99F9733F5C908A7709&quot; width=243 height=221&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt&quot;&gt;PE 파일은 PE 헤더(DOS&amp;nbsp;헤더 ~&amp;nbsp;섹션 헤더)와 PE&amp;nbsp;바디(섹션)로&amp;nbsp;이루어진다.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;PE 헤더에는&amp;nbsp;파일이 실행되기 위해 필요한 정보들이 구조체 형식으로 저장되어 있다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;IMAGE_DOS_HEADER&lt;/SPAN&gt;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_78946_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/994301335C908CEF10&quot; width=617 height=122&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;HxD로 확인한 DOS Header이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;e_magic&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DOS signature MZ(4D5A)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;e_lfanew&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;NT_header의 offset(000000E0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_28193_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99A62D4C5C8F72EF37&quot; width=216 height=73&gt;&lt;/P&gt;
&lt;P&gt;e_lfanew&amp;nbsp;멤버의 값을 따라서 000000E0에는&lt;STRONG&gt;&amp;nbsp;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;IMAGE_NT_HEADERS&lt;/SPAN&gt; &lt;/STRONG&gt;구조체가 위치한다.&lt;/P&gt;
&lt;P&gt;이 구조체는 signature와 두 개의 구조체 멤버로 구성된다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_32180_ class=txc-image alt=&quot;더블클릭을 하시면 이미지를 수정할 수 있습니다&quot; src=&quot;https://t1.daumcdn.net/cfile/tistory/998780335C9092B30E&quot; width=608 height=281&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #008299; BACKGROUND-COLOR: #ffffff&quot;&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;COLOR: #4174d9&quot;&gt;Signature&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;:&amp;nbsp;PE&amp;nbsp;signature&amp;nbsp;PE(50450000)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;COLOR: #3db7cc&quot;&gt;File Header&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=824 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 180px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #000000&quot;&gt;&lt;SPAN style=&quot;COLOR: #3db7cc; BACKGROUND-COLOR: #ffffff&quot;&gt;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;Machine&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 645px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;CPU별 고유한 값(14C: 32비트 Intel x86 호환 칩)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 180px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #3db7cc; BACKGROUND-COLOR: #ffffff&quot;&gt;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;NumberOfSections&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 645px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;섹션의 개수&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 180px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #0900ff; BACKGROUND-COLOR: #ffffff&quot;&gt;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;TimeDateStamp&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 645px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;해당 파일의 빌드 시간(파일의 실행에 영향을 미치지 않는 값)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 180px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #000000; BACKGROUND-COLOR: #ffffff&quot;&gt;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;SizeOfOptionalHeader&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 645px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;NT 구조체의 마지막 멤버&amp;nbsp;OPTIONAL 구조체의 크기&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 180px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #000000; BACKGROUND-COLOR: #ffffff&quot;&gt;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;Characteristic&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 645px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;파일의 속성들이 bit OR 형식으로 조합(0002h: File is executable. / 2000h: File is a DLL.)&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;COLOR: #ffbb00&quot;&gt;Optional header&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=824 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;&lt;STRONG&gt;Magic&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;IMAGE_OPTIONAL_HEADER32 구조체: 10B / IMAGE_OPTIONAL_HEADER64 구조체:&amp;nbsp;20B&lt;br /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;&lt;STRONG&gt;AddressOfEntryPoint&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;EP(Entry Point)의 RVA 값으로, 프로그램의 최초 실행 코드의 시작 주소(VERY IMPORTANT)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style=&quot;COLOR: #000000&quot;&gt;&lt;STRONG&gt;ImageBase&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;메모리에서 PE 파일이 로딩되는 시작 주소&lt;/P&gt;
&lt;P&gt;&amp;nbsp;*&amp;nbsp;PE&amp;nbsp;로더는&amp;nbsp;PE 파일을 실행시키기 위해 프로세스를 생성하고,&amp;nbsp;파일을 메모리에 로딩한 후&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; EIP의 값을&amp;nbsp;AddressOfEntryPoint&amp;nbsp;+ ImageBase의 결과로&amp;nbsp;세팅한다.&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;File/SectionAlignment&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;파일에서/메모리에서 섹션의 최소단위. 섹션크기는 각각&amp;nbsp;이 값의 배수여야 한다.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;SizeOfImage&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;파일이 메모리에 로딩되었을 때 가상 메모리에서 PE Image가 차지하는 크기&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;SizeOfHeader&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;PE 헤더의 전체 크기로 FileAlignment의 배수여야 한다.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;Subsystem&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;이 값(Driver: 1/ GUI: 2/ CUI: 3)을 보고 파일 구분&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 25px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;NumberOfRvaAndSizes&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 25px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;DataDirectory 배열의 개수&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 25px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 181px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;DataDirectory&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 25px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 644px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;IMAGE_DATA_DIRECTORY 구조체의 배열&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_94586_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/993B443C5C9099E731&quot; width=361 height=289&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* &lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;&lt;STRONG&gt;VA(Virtual Address)&lt;/STRONG&gt;&lt;/SPAN&gt;: 프로세스 가상 메모리의 절대주소&lt;/P&gt;
&lt;P&gt;* &lt;STRONG&gt;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;RVA(Relative Virtual Address)&lt;/SPAN&gt;&lt;/STRONG&gt;: 어느 기준 위치(ImageBase)에서부터의 상대주소&lt;br /&gt;=&amp;gt; VA와 RVA의 관계식: &lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;&lt;STRONG&gt;RVA + ImageBase = VA&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* Image: PE 파일은 섹션 헤더에 정의된 대로 맞춰서 메모리에 로딩된다. 메모리에&amp;nbsp;로딩된&amp;nbsp;상태를 이미지라고 한다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG id=tx_entry_63813_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99ABA93A5C90A70E0F&quot; width=776 height=274&gt;&lt;/P&gt;
&lt;P&gt;NT 헤더 다음에 등장하는 섹션 헤더는 각 섹션별 &lt;STRONG&gt;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;IMAGE_SECTION_HEADER&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style=&quot;FONT-SIZE: 18pt&quot;&gt; &lt;/SPAN&gt;구조체의 배열로 되어 있다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_98457_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/9915FE3A5C90A96905&quot; width=607 height=154&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;
&lt;TABLE class=txc-table style=&quot;FONT-SIZE: 15px; BORDER-TOP: medium none; FONT-FAMILY: '맑은 고딕',sans-serif; BORDER-RIGHT: medium none; WIDTH: 399px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none&quot; cellSpacing=0 cellPadding=0 width=399 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 145px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;VirtualSize&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;BORDER-TOP: #ccc 1px solid; HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 253px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;메모리에서 섹션이 차지하는 크기&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 145px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;VirtualAddress&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 253px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;메모리에서 섹션의 시작 주소(RVA)&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 145px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;SizeOfRawData&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 253px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;파일에서 섹션이 차지하는 크기&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 145px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;PointerToRawData&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 253px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;파일에서 섹션의 시작 위치&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 145px; BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid&quot;&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;Characteristic&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style=&quot;HEIGHT: 24px; BORDER-RIGHT: #ccc 1px solid; WIDTH: 253px; BORDER-BOTTOM: #ccc 1px solid&quot;&gt;
&lt;P&gt;&amp;nbsp;섹션의 속성(bit OR)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;FONT-SIZE: 18pt&quot;&gt;★&amp;nbsp;RVA&amp;nbsp;to RAW&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;PE&amp;nbsp;파일이 메모리에 로딩되었을 때, 각&amp;nbsp;섹션에서&amp;nbsp;메모리 주소와 파일 옵셋을 잘 매핑할 수 있어야 한다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_63071_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99D82A465C90BCF40E&quot; width=665 height=477&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;섹션 헤더를 참고하여&amp;nbsp;메모장 파일이 메모리에&amp;nbsp;적재되는&amp;nbsp;모습과 위치를 그림으로 표현한 것이다.&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;그러면 이제,&amp;nbsp;어떤 메모리 주소가 주어졌을&amp;nbsp;때 그에 매핑되는 오프셋을 구하는 방법을 알아보겠다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;Q. RVA가 7A60일 때,&amp;nbsp;RAW(File offset)의 값은 무엇일까요??&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;RVA(7A60) +&amp;nbsp;ImageBase(1000000) =&amp;nbsp;VA(1007A60) &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;VA의 공식을 통해, RVA 7A60 값이 첫번째&amp;nbsp;text 섹션에 속해있다는 것을 알 수 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;그리고 &lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;&lt;STRONG&gt;RAW = RVA - VirtualAddress(RVA) + PointerToRawData&lt;/STRONG&gt;&lt;/SPAN&gt; 비례식을 이용하면 끝!&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;7A60&amp;nbsp;- 메모리에서 text 섹션의 시작 주소(RVA:&amp;nbsp;1000) +&amp;nbsp;파일에서&amp;nbsp;text&amp;nbsp;섹션의 시작 위치(400) =&amp;nbsp;6E60&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;A. RVA가 7A60일 때 RAW의 값은 6E60이다.&lt;/P&gt;</description>
      <category>Reverse Engineering</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/258</guid>
      <comments>https://leeeeye321.tistory.com/258#entry258comment</comments>
      <pubDate>Wed, 12 Jun 2019 15:29:31 +0900</pubDate>
    </item>
    <item>
      <title>스택 버퍼 오버플로우 공격 실습</title>
      <link>https://leeeeye321.tistory.com/226</link>
      <description>&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;SPAN style=&quot;FONT-SIZE: 14pt&quot;&gt;&lt;STRONG&gt;&lt;SPAN style=&quot;FONT-SIZE: 11pt; COLOR: #ffffff; BACKGROUND-COLOR: #4673ff&quot;&gt;Shell Code&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;-버퍼 오버플로우 공격의 핵심은 오버플로우가 발생하는 버퍼에 저장되는 공격자의 코드로 실행 제어를 이동시키는 것이다.&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;-사용자 명령어 라인의 해석기 Shell로 제어를 넘기고 공격당한 프로그램의 권한으로 시스템의 다른 프로그램에 접근하기 때문에 Shell code라고 부른다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 264px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990828385A73491709&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990828385A73491709&quot; width=&quot;264&quot; height=&quot;135&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 383px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/997ACA365A734B3103&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F997ACA365A734B3103&quot; width=&quot;383&quot; height=&quot;53&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;일단 /bin/sh 명령어를 실행하는 소스 코드를 작성했다.&lt;/P&gt;
&lt;P&gt;메모리에 실행할 명령어만 올려야 하므로 data 세그먼트는 사용하지 않고 기계어로 변환해야 한다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 495px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/994429405A734C1A1A&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F994429405A734C1A1A&quot; width=&quot;495&quot; height=&quot;69&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 238px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99682D425A747E3715&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99682D425A747E3715&quot; width=&quot;238&quot; height=&quot;271&quot; filename=&quot;이미지 002.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;text 세그먼트만 사용해서 어셈블리어로 작성했다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 543px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99B792425A747E370C&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99B792425A747E370C&quot; width=&quot;543&quot; height=&quot;273&quot; filename=&quot;이미지 005.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;실행 파일을 disassemble해서 기계어를 획득했다.&lt;/P&gt;
&lt;P&gt;그런데&amp;nbsp;여기서&amp;nbsp;보이는 null 값(00)은 입력할 수 없는 값(bad character)이다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. 4바이트 레지스터 eax에 1바이트 값을 넣으면 나머지 3바이트에 0이 들어간다.&lt;/P&gt;
&lt;P&gt;-&amp;gt; eax 레지스터 대신에 al 레지스터를 사용한다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. push 0&lt;/P&gt;
&lt;P&gt;-&amp;gt; 0을 push 하지말고 xor 연산으로 초기화한 레지스터를 사용한다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 236px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/990F90445A747DD924&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F990F90445A747DD924&quot; width=&quot;236&quot; height=&quot;320&quot; filename=&quot;이미지 003.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 545px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/999D3E445A747DD934&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F999D3E445A747DD934&quot; width=&quot;545&quot; height=&quot;242&quot; filename=&quot;이미지 004.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #000000&quot;&gt;31 d2 31 c0 52 68 2f 2f 73 68 68 2f 62 69 6e b0 0b 89 e3 52 53 8d 0c 24 52 cd 80&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;다시 작성하여 기계어를 확인한 결과 null 문자는 하나도 없다.&lt;/P&gt;
&lt;P&gt;이제 이 숫자들 앞에 \x를 붙여서&amp;nbsp;입력 가능한 문자열 형태로 만들어 주면 된다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #000000&quot;&gt;\x31\xd2\x31\xc0\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\xb0\x0b\x89\xe3\x52\x53\x8d\x0c\x24\x52\xcd\x80&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;여기까지 하면 쉘 코드가 완성된다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 542px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/999D0F485A75D81921&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F999D0F485A75D81921&quot; width=&quot;542&quot; height=&quot;212&quot; filename=&quot;이미지 006.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 246px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A4364A5A75D8BE07&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A4364A5A75D8BE07&quot; width=&quot;246&quot; height=&quot;48&quot; filename=&quot;이미지 008.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;함수 포인터를 이용해서 검증해 본 결과&amp;nbsp;쉘 코드가 정상적으로 동작한다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;이제 진짜 버퍼 오버플로우 공격을 해볼 것이다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR class=tx-hr-border-3 style=&quot;BORDER-TOP: black 1px dotted; HEIGHT: 1px; BORDER-RIGHT: black 0px; BORDER-BOTTOM: black 0px; BORDER-LEFT: black 0px; DISPLAY: block&quot;&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #4673ff&quot;&gt;&lt;STRONG&gt;Stack Buffer Overflow Attack1 !!&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&lt;STRONG&gt;공격 시나리오&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;①&amp;nbsp;공격&amp;nbsp;쉘 코드를 버퍼에 저장한다.&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;②&amp;nbsp;root 권한으로 실행되는 프로그램의 버퍼를 오버플로우 시켜서 공격&amp;nbsp;쉘 코드가 저장되어 있는 버퍼의 주소로 덮어씌운다.&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;③&amp;nbsp;특정 함수의 호출이 완료되면 조작된 반환 주소로&amp;nbsp;쉘 코드의 주소가 반환되어&amp;nbsp;쉘 코드가 실행되고,&amp;nbsp;root 권한을 획득하게 된다.&lt;/P&gt;
&lt;P style=&quot;TEXT-ALIGN: left&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 312px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99C602395A75DFAB16&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99C602395A75DFAB16&quot; width=&quot;312&quot; height=&quot;195&quot; filename=&quot;이미지 011.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;타겟 프로세스를 생성한다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;타겟 프로세스는&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;버퍼 오버플로우 취약점이 존재하고, &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;SetUID 권한이 설정되어 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 570px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/9997E8395A75DFAB1D&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F9997E8395A75DFAB1D&quot; width=&quot;570&quot; height=&quot;80&quot; filename=&quot;이미지 012.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;target1 프로세스에 SetUID를 설정하고 /tmp 디렉터리에 위치시킨다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 316px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99F9BE375A75E03513&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99F9BE375A75E03513&quot; width=&quot;316&quot; height=&quot;18&quot; filename=&quot;이미지 013.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 280px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99EE813B5A75E0A52B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99EE813B5A75E0A52B&quot; width=&quot;280&quot; height=&quot;33&quot; filename=&quot;이미지 014.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;공격을 시도할&amp;nbsp;attacker&amp;nbsp;계정을 생성한 후&amp;nbsp;접속한다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 596px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99DD983B5A75E0A50B&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99DD983B5A75E0A50B&quot; width=&quot;596&quot; height=&quot;80&quot; filename=&quot;이미지 015.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;gdb로 메모리를 분석해야 한다. root 권한의 프로세스로는 할 수 없기 때문에 복사본을 만들고 gdb를 실행한다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 498px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/999524435A75EAB219&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F999524435A75EAB219&quot; width=&quot;498&quot; height=&quot;129&quot; filename=&quot;이미지 021.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 227px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/992FD7505A75E6371E&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F992FD7505A75E6371E&quot; width=&quot;227&quot; height=&quot;32&quot; filename=&quot;이미지 016.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;버퍼 오버플로우 취약점은 strcpy 함수에서 발생한다. &lt;/P&gt;
&lt;P&gt;함수 호출 후 지점을&amp;nbsp;breakpoint로 설정해주고 쉘 코드를 인자로 전달하여 메모리를 확인한다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 759px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/99A09C4A5A7888E929&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F99A09C4A5A7888E929&quot; width=&quot;759&quot; height=&quot;255&quot; filename=&quot;이미지 023.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;인자로 전달한 쉘 코드는 버퍼에 저장된다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;버퍼 100 바이트&amp;nbsp;중 쉘 코드는 27 바이트를 차지한다. &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;나머지 73 바이트는 0으로 초기화되어 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #000000&quot;&gt;$(python -c 'print &quot;\x31\xd2\x31\xc0\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\xb0\x0b\x89\xe3\x52\x53\x8d\x0c\x24\x52\xcd\x80&quot; + &quot;a&quot; * 77 + &quot;\x44\xfa\xff\xbf&quot;')&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;EIP의 값을 쉘 코드가 위치한&amp;nbsp;버퍼의 주소로 덮어 씌워야 한다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;버퍼는 총 100 바이트이므로 100 - 27 = 73 바이트,&amp;nbsp;버퍼를 넘어서서 EBP까지 총 77 바이트를 A로 채우고 &lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;쉘 코드가 위치하는&amp;nbsp;버퍼의 주소(0xbffffa44)를 입력한다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 769px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/995275435A788A6108&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F995275435A788A6108&quot; width=&quot;769&quot; height=&quot;226&quot; filename=&quot;이미지 009.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;EIP 값이 해당 주소로 덮어졌다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;span class=&quot;imageblock&quot; style=&quot;display: inline-block; width: 798px;  height: auto; max-width: 100%;&quot;&gt;&lt;img src=&quot;https://t1.daumcdn.net/cfile/tistory/996CB3425A78533D10&quot; srcset=&quot;https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F996CB3425A78533D10&quot; width=&quot;798&quot; height=&quot;65&quot; filename=&quot;이미지 026.png&quot; filemime=&quot;image/jpeg&quot;/&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;16 바이트 단위로 실제 주소를 추측하다 보면 쉘 코드가 실행이 된다.&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;오버플로우 공격으로 인해 프로그램의 실행 흐름이 변경된 결과이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;우리가 원하던 대로 target1 프로세스의 SetUID에 의해&amp;nbsp;root 권한으로 실행된다. 권한 탈취(상승)에 성공했다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;HR class=tx-hr-border-3 style=&quot;BORDER-TOP: black 1px dotted; HEIGHT: 1px; BORDER-RIGHT: black 0px; BORDER-BOTTOM: black 0px; BORDER-LEFT: black 0px; DISPLAY: block&quot;&gt;
&lt;/DIV&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #4673ff&quot;&gt;&lt;STRONG&gt;Stack Buffer Overflow Attack2 !!&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #4673ff&quot;&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_67470_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99CC903F5A7883B727&quot; width=311 height=177 exif=&quot;{}&quot; actualwidth=&quot;311&quot;&gt;&lt;/P&gt;
&lt;P&gt;이번에는&amp;nbsp;gets 함수로 인해 버퍼 오버플로우 취약점이 발생한다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;gets(char *str)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;표준 입력으로부터 str로 한 줄을 읽어들인다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_29315_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99A2EB485A788B6331&quot; width=555 height=32 exif=&quot;{}&quot; actualwidth=&quot;555&quot;&gt;&lt;/P&gt;
&lt;P&gt;표준 입력은 모든 입력을 문자열로 인식하여 숫자를 입력할&amp;nbsp;수 없다.&lt;/P&gt;
&lt;P&gt;쉘 코드를&amp;nbsp;입력하기 위해서는&amp;nbsp;파이프를 사용해야 한다.&lt;/P&gt;
&lt;P&gt;-&amp;gt; 파이프(|)는&amp;nbsp;&lt;STRONG&gt;한 명령어의 출력을 두 번째 명령어의 입력으로 사용&lt;/STRONG&gt;하고 싶을 때 사용할 수 있다.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_87568_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99BB784F5A78916809&quot; width=642 height=47 exif=&quot;{}&quot; actualwidth=&quot;642&quot;&gt;&lt;/P&gt;
&lt;P&gt;gdb에서 파이썬 명령어를 사용할 수 없다. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;버퍼 100바이트 + EBP 4바이트&amp;nbsp;-&amp;gt; A * 104&lt;/P&gt;
&lt;P&gt;EIP 4바이트&amp;nbsp;-&amp;gt; BBBB&lt;/P&gt;
&lt;P&gt;메모리에 값이 어떻게 들어가는지 확인하기 위해서&amp;nbsp;문자를 미리 출력해서 그대로 복사할 것이다.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_32414_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99A6E44B5A7891271B&quot; width=643 height=98 exif=&quot;{}&quot; actualwidth=&quot;643&quot;&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_91036_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99955D4B5A78912707&quot; width=669 height=149 exif=&quot;{}&quot; actualwidth=&quot;669&quot;&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;EIP에 BBBB가 들어간 것을 확인할 수 있다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;쉘 코드가 위치할 주소는&amp;nbsp;bffffa64이다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style=&quot;COLOR: #ffffff; BACKGROUND-COLOR: #000000&quot;&gt;(python -c 'print &quot;\x31\xd2\x31\xc0\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\xb0\x0b\x89\xe3\x52\x53\x8d\x0c\x24\x52\xcd\x80&quot; + &quot;A&quot; * 77 + &quot;\x64\xfa\xff\xbf&quot;';cat) | ./target2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;파이썬 명령과 cat 명령을 같이 실행하기 위해 묶고 이를 표준 입력으로 전달한다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;&lt;IMG id=tx_entry_58815_ class=txc-image src=&quot;https://t1.daumcdn.net/cfile/tistory/99A7F14B5A7891281B&quot; width=681 height=164 exif=&quot;{}&quot; actualwidth=&quot;681&quot;&gt;&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;오버플로우 공격에 의해 실행의 흐름이&amp;nbsp;공격 코드로 변경되었다.&lt;/P&gt;
&lt;P style=&quot;FLOAT: none; TEXT-ALIGN: left; CLEAR: none&quot;&gt;target2 프로세스의 SetUID에 의해&amp;nbsp;권한 상승도 성공했다.&lt;/P&gt;</description>
      <category>System Hacking</category>
      <author>leeeeye321</author>
      <guid isPermaLink="true">https://leeeeye321.tistory.com/226</guid>
      <comments>https://leeeeye321.tistory.com/226#entry226comment</comments>
      <pubDate>Thu, 1 Feb 2018 11:16:25 +0900</pubDate>
    </item>
  </channel>
</rss>