talked by CI/CD Conference 2021 by CloudNative Days https://event.cloudnativedays.jp/cicd2021
re-upload: https://speakerdeck.com/whywaita/cyberagent-oss-cicd-myshoes-cicd2021
talked by CI/CD Conference 2021 by CloudNative Days https://event.cloudnativedays.jp/cicd2021
re-upload: https://speakerdeck.com/whywaita/cyberagent-oss-cicd-myshoes-cicd2021
8. 1. DLLRegisterServer / DLLUnregisterServer
동작 원리
1. OleInitialize
2. LoadLibrary to load the DLL
GetProcAddress를 호출해서, DllRegisterServer or
DllUnregisterServer의 주소를 알아 낸 후,
3. DllRegisterServer or DllUnregisterServer 호출
4. FreeLibrary
5. OleUninitialize
9. 1. DLLRegisterServer / DLLUnregisterServer
유의 사항
3. DllRegisterServer or DllUnregisterServer 호출후
해당 함수에서 또 다른 Export 함수를 호출할
수 있음
10. 1. DLLRegisterServer / DLLUnregisterServer
호출 방법
3. DllRegisterServer or DllUnregisterServer 호출
regsvr32.exe 파일에 의해서 실행시 호출됨
Ex> regsvr32.exe sample.dll (DllRegisterServer호출)
regsvr32.exe /u sample.dll (DllUnregisterServer호출)
11. 1. DLLRegisterServer / DLLUnregisterServer
분석 방법
1. OllyDbg를 이용해서 %system%regsvr32.exe를
연다.
12. 1. DLLRegisterServer / DLLUnregisterServer
분석 방법
2. OllyDbg의 Debug -> Arguments
에서 분석 대상 DLL 파일을 연다.
13. 1. DLLRegisterServer / DLLUnregisterServer
분석 방법
3. OleInitialize에 BreakPoint를 설정한다. 그런 다음 LoadLibrary로
분석 대상 DLL파일을 메모리에 맵핑후 GetProcAddress로 DLLRegisterServer
주소를 가져오는 코드를 볼 수 있다.
그리고 나서 해당 함수를 호출하는 CALL문에 진입하면 된다.
14. 2. Export Function Names … etc
동작 원리
1. GetCommandLineW
Export 함수명을 파싱
2. LoadLibrary to load the DLL
GetProcAddress를 호출해서, Export 함수의 주소를 알아 낸 후,
3. Export 함수 호출
4. FreeLibrary
15. 2. Export Function Names … etc
유의 사항
3. Export 함수 분석시
파일 하나에 Export 함수가 다수 존재할 수 있어서 어떤 함수를 가장 먼저 실행해
야하는지 알려면 관련 DLL 파일을 실행하는 파일
을 분석해야 알 수 있음
관련 Dll 파일이 없을 경우에는 각 Export 함수를 분석하여 어떤 함수가 가장 먼
저 실행해야하는지 유추할 수 있음
16. 2. Export Function Names … etc
호출 방법
3. Export 함수 호출
rundll32.exe 파일에 의해서 실행시 호출됨
Ex> rundll32.exe sample.dll, ALSTS_ExecuteAction
(ALSTS_ExecuteAction Export 함수 호출)
17. 2. Export Function Names … etc
분석 방법
1. OllyDbg를 이용해
서 %system%rundll32.exe를 연다.
18. 2. Export Function Names … etc
분석 방법
2. OllyDbg의 Debug -> Arguments
에서 분석 대상 DLL 파일을 연다.
regsvr32.exe 와 다르게 Export 함수명을 인자로 추가해야함
19. 2. Export Function Names … etc
분석 방법
3. LoadLibrary로 분석 대상 DLL파일을 메모리에 맵핑후 GetProcAddress로
Export 함수 주소를 가져오는 코드를 볼 수 있다.
그리고 나서 해당 함수를 호출하는 CALL문에 진입하면 된다.
20. 3. ServiceMain
동작 원리
1. StartService
SCM(ServiceControlManager)에 의해 하기 레지스트리에 등록된 서비스 실행 파일을
실행
경로 : HKEY_LOCAL_MACHINESystemCurrentControlSetService
2. ServiceMain 호출
SCM의 Dispatcher에 의해 ServiceMain 함수 호출
3. RegisterServiceCtrlHandler
서비스의 제어 신호를 처리하기 위해 핸들러를 SCM의 Dispatcher에 등록
4. SetServiceStatus
서비스 제어 신호를 SCM의 Dispatcher에 전달
21. 3. ServiceMain
유의 사항
2. ServiceMain 함수 분석시
서비스로 등록하여 동작하기 때문에 rundll32.exe 파일로 ServiceMain 호출하
여 분석시 서비스를 열고 상태 정보를 얻는 과정에서 Exception 발생함.
따라서 서비스 등록하여 실행하는 또 다른 파일이 필요함.
해당 파일이 없을 경우에는 sc 명령을 이용하여 서비스 등록하여 실행하여야 함.
Ex> sc create 서비스명 binPath= 서비스 DLL 파일 경로 설정
실행 조건에 인자가 필요하면 설정해주어야함.
22. 3. ServiceMain
호출 방법
2. ServiceMain 호출
svchost.exe 파일에 의해서 실행시 호출됨
Ex> svchost.exe -k 서비스명
서비스 Dcomlunch, netsvcs 등에 의해 관련 DLL 파일의
ServiceMain함수를 호출함
24. 3. ServiceMain
분석 방법
2. OllyDbg에서 Options -> Just-in-time debugging 로 가서 Make
allyDbg just-in-time debugger 기능을 활성화한다. 그런 다음 Done을
클릭하고 OllyDbg를 종료한다.
25. 3. ServiceMain
분석 방법
3. 분석 대상 DLL파일 ServiceMain 의 첫번째 1 Byte를 0xCC로 변경한다.
그렇게 하는 이유는 서비스를 시작하면 INT 3h 인터럽트가 발생하여 OllyDbg
가 자동으로 디버깅 가능하도록 Attach할 수 있기 때문이다. 먼저
ServiceMain의 주소를 확인하고 해당 주소는 RVA임으로 File
Offset를 확인한다.
26. 3. ServiceMain
분석 방법
4. 분석 대상 DLL 파일의 ServiceMain의 첫번째 1 Byte를
0xCC로 변경한다. 원본 1 Byte에 해당하는 바이너리는 기억한다.
OllyDbg에 의해 Attach 한 후 원본 바이너리로 복원해야 하기 때문이다.
27. 3. ServiceMain
분석 방법
5. 서비스를 시작하면, OllyDbg가 해당 서비스를 Attach하여 보여준다.
그런 다음 첫번째 1 Byte를 원본 바이너리로 복원한다.