CreateMutex
까보면 다나와~
유용한 지식 자료들 (89)

리눅스 폴더별 용량 확인하기

디렉토리를 용량순으로 표시하는 방법

원래 du 명령을 사용하면 14K > 12M로 표시되는 걸 다음과 같이 표시하는 방법이다.


ex) 현재 디렉토리 내 A, B, C 폴더, a, b, c 파일을 용량순으로 표시(M, K 이런식으로..)

12M A

9M  C

1M  B

14K b

10K a

0     c


du -ks * | sort -nr | cut -f2 | xargs -d '\n' du -sh


이런식으로 하면 됩니다.

-ks (block-size 1K & total size 1 depth)

-nr (numeric-sort & reverse) : r 주면 역순으로 재배치, 숫자에 따라 내림차순 또는 오름차순

xargs -d (delimiter) '\n' du -sh : 이건 du -sh를 엔터를 허용해서 표시

-sh는 사이즈를 인간이 보기편하게 보는 옵션


관련 포스트

http://arisri.tistory.com/entry/%EB%A6%AC%EB%88%85%EC%8A%A4-du-%EB%AA%85%EB%A0%B9%EB%94%94%EB%A0%89%ED%86%A0%EB%A6%AC-%EC%9A%A9%EB%9F%89-%ED%99%95%EC%9D%B8-%EC%9D%91%EC%9A%A9

'유용한 지식 자료들 > 기타' 카테고리의 다른 글

EPM Sandbox (IE)에 대한 글  (0) 2015.01.13
리눅스 특정 사이즈 이상 폴더 삭제  (0) 2014.12.22
Indoor positioning system  (0) 2014.09.23
HashSet HashMap 차이 정리  (0) 2014.08.07
MFC 리버싱하기  (0) 2013.08.12
  Comments,     Trackbacks

Indoor positioning system

http://en.wikipedia.org/wiki/Indoor_positioning_system


실내 및 근거리 내 위치를 찾아내는 시스템들....


wifi 수신감도를 3차원으로 해석할 수 있으면 삼각측량법이 아니여도

위치의 정확도를 높일 수 있지 않을까

'유용한 지식 자료들 > 기타' 카테고리의 다른 글

리눅스 특정 사이즈 이상 폴더 삭제  (0) 2014.12.22
리눅스 폴더별 용량 확인하기  (0) 2014.12.22
HashSet HashMap 차이 정리  (0) 2014.08.07
MFC 리버싱하기  (0) 2013.08.12
Decompilers  (0) 2013.08.12
  Comments,     Trackbacks

HashSet HashMap 차이 정리

Set과 Map은 저장된 방식의 차이다. 둘다 순서는 없다.

 

HashSet : {1, 2, 3, 4, 5}

HashMap : {a->1, b->2, c->2, d, ->1}

 

HashMap은 중복 데이터 허용, HashSet는 불허용

 

HashSet은 키가 곧 데이터이고 HashMap은 키값이 지정됨(??). 둘다 인덱싱을 하지 않지만 데이터를 찾아가는 방식이 차이가 있음.

 

그리고 Set은 그냥 집합임(Set이 한글로 집합)

'유용한 지식 자료들 > 기타' 카테고리의 다른 글

리눅스 폴더별 용량 확인하기  (0) 2014.12.22
Indoor positioning system  (0) 2014.09.23
MFC 리버싱하기  (0) 2013.08.12
Decompilers  (0) 2013.08.12
virtualbox-host-only-network-cuckoo-sandbox-0-4-2/  (0) 2013.07.29
  Comments,     Trackbacks

320악성코드의 변종(?) - Thread Context 관련

이번 악성코드를 살펴보니 자식 프로세스에 메모리를 재할당하고 Thread Context 구조체를 활용, OEP를 원하는 지점으로 수정하는 방법을 사용하고 있었다.


찾아보니 이미 HOWTO가 많이 검색되었다.


아래는 320변종이라는 악성코드가 사용하는 코드





악성코드가 Thread Context 구조체를 접근하는 이유는 Eax, Ebx가 각각 특정 포인터 역할을 하기 때문이다.


Context.Eax =>Original Entiry Point(OEP)

Context.Ebx =>Process Environment Block(PEB)

(PEB + 8 offset은 Image Base Address이므로 PEB 주소를 알면 이를 수정할 수 있다.)



Eax를 보면 OEP가 수정되었다는 것을 알 수 있다.

  Comments,     Trackbacks

MFC 리버싱하기

MFC 리버싱하기


요약
AfxWinMain
- AfxGetModuleThreadState
- AfxGetModuleState
- AfxWinInit
- CWinApp::InitApplication (?InitApplication@CWinApp@@UAEHXZ)
 - call dword ptr [eax+58h], that is pThread->InitInstance (main code)
call    ?DoModal@CDialog@@UAEHXZ ; CDialog::DoModal(void)
DoModal 콜하기 바로 전에 mov [esi], eax 또는 mov [esi+20], eax 이런 어셈코드가 있는데 eax + 30  이것이 MessageMap entry를 호출하는 GetMessageMap Function

자세한 설명은 아래.

good~!!

http://quequero.org/2008/08/guidelines-to-mfc-reversing/

Guidelines to MFC Reversing

Software developed with MFC may import MFC80U.dll (MFC80U is the name of the last version of the dll, as I’m writing), it depends on the type of compilation: as a static library or as a shared DLL.
I’ll analyze a software which imports the dll and has debug infos, just to make the job easier.
Once you understand MFC in this way, you can analyze MFC software compiled statically just adding to IDA the signatures of MFC and VisualC.

 

Prologue: What is MFC?

The Microsoft Foundation Classes Library (also Microsoft Foundation Classes or MFC) is a library that wraps portions of the Windows API in C++ classes, including functionality that allows to use a default application framework. Classes are defined for many of the handle-managed Windows objects and also for predefined windows and common controls.

 

Tools – References

IDA
Reversing Microsoft Visual C++ Part II: Classes, Methods and RTTI
Crackme

 

Essay

This is a standard C source code for windows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
LRESULT CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
        switch(uMsg)
        {
        case WM_COMMAND:
                switch(LOWORD(wParam))
                {
 
                case IDC_ABOUT:
                        DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)MainDialogProc, 0);
                        break;
 
                        // ...
                }
        }
}

Instead this is source code that uses MFC:

class CAboutDlg : public CDialog
{
public:
        CAboutDlg();
 
// Dialog Data
        enum { IDD = IDD_ABOUTBOX };
 
protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 
// Implementation
protected:
        DECLARE_MESSAGE_MAP()
};
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)  //CAboutDlg::IDD is dialog ID         
{
}
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
}
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //Dialog Message Map: is like DialogProc
END_MESSAGE_MAP()
 
// App command to run the dialog
void CProvaRevApp::OnAppAbout()
{
        CAboutDlg aboutDlg;
        aboutDlg.DoModal();
}

How you can imagine the disasm of MFC software is harder to understand.

MFC Main

This is the Main disasm of our target:

.text:00401CBB                 public start
.text:00401CBB                 call    ___security_init_cookie
.text:00401CC0                 jmp     ___tmainCRTStartup
 
.text:004019FB ___tmainCRTStartup proc near           ; CODE XREF: start+5�j
.text:004019FB
.text:004019FB                 push    5Ch
.text:004019FD                 push    offset unk_403DD8
.text:00401A02                 call    __SEH_prolog4
;... other initialization code
.text:00401B3E                 push    ecx            ; nShowCmd
.text:00401B3F                 push    eax            ; lpCmdLine
.text:00401B40                 push    ebx            ; hPrevInstance
.text:00401B41                 push    400000h        ; hInstance
.text:00401B46                 call    _wWinMain@16   ; wWinMain(x,x,x,x)
 
; int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
_wWinMain@16 proc near
        jmp     ?AfxWinMain@@YGHPAUHINSTANCE__@@0PA_WH@Z ; AfxWinMain(HINSTANCE__ *,HINSTANCE__ *,wchar_t *,int)
_wWinMain@16 endp

As you can see WinMain calls AfxWinMain.
If you have VisualStudio you can see MFC source code, in this article I’ll report only the functions we’ll need.

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        _In_ LPTSTR lpCmdLine, int nCmdShow)
{
        ASSERT(hPrevInstance == NULL);
 
        int nReturnCode = -1;
        CWinThread* pThread = AfxGetThread();
        CWinApp* pApp = AfxGetApp();
 
        // AFX internal initialization
        if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
                goto InitFailure;
 
        // App global initializations (rare)
        if (pApp != NULL && !pApp->InitApplication())
                goto InitFailure;
 
        // Perform specific initializations
        if (!pThread->InitInstance())
        {
                if (pThread->m_pMainWnd != NULL)
                {
                        TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
                        pThread->m_pMainWnd->DestroyWindow();
                }
                nReturnCode = pThread->ExitInstance();
                goto InitFailure;
        }
        nReturnCode = pThread->Run();
 
InitFailure:
        AfxWinTerm();
        return nReturnCode;
}

This is the disasm of AfxWinMain:

.text:7831D2D2                 public AfxWinMain
.text:7831D2D2 AfxWinMain      proc near
.text:7831D2D2                 push    ebx
.text:7831D2D3                 push    esi
.text:7831D2D4                 push    edi
.text:7831D2D5                 or      ebx, 0FFFFFFFFh
.text:7831D2D8                 call    AfxGetModuleThreadState
.text:7831D2DD                 mov     esi, [eax+4] ;pThread
.text:7831D2E0                 call    AfxGetModuleState
.text:7831D2E5                 push    [esp+0Ch+arg_C]
.text:7831D2E9                 mov     edi, [eax+4] ;pApp
.text:7831D2EC                 push    [esp+10h+arg_8]
.text:7831D2F0                 push    [esp+14h+arg_4]
.text:7831D2F4                 push    [esp+18h+arg_0]
.text:7831D2F8                 call    AfxWinInit
.text:7831D2FD                 test    eax, eax
.text:7831D2FF                 jz      short loc_7831D33D
.text:7831D301                 test    edi, edi   
.text:7831D303                 jz      short loc_7831D313
.text:7831D305                 mov     eax, [edi]
.text:7831D307                 mov     ecx, edi
.text:7831D309                 call    dword ptr [eax+98h]
.text:7831D30F                 test    eax, eax
.text:7831D311                 jz      short loc_7831D33D
.text:7831D313
.text:7831D313 loc_7831D313:
.text:7831D313                 mov     eax, [esi]
.text:7831D315                 mov     ecx, esi
.text:7831D317                 call    dword ptr [eax+58h]
.text:7831D31A                 test    eax, eax
.text:7831D31C                 jnz     short loc_7831D334
.text:7831D31E                 cmp     [esi+20h], eax
.text:7831D321                 jz      short loc_7831D32B
.text:7831D323                 mov     ecx, [esi+20h]
.text:7831D326                 mov     eax, [ecx]
.text:7831D328                 call    dword ptr [eax+68h]
.text:7831D32B
.text:7831D32B loc_7831D32B:
.text:7831D32B                 mov     eax, [esi]
.text:7831D32D                 mov     ecx, esi
.text:7831D32F                 call    dword ptr [eax+70h]
.text:7831D332                 jmp     short loc_7831D33B
.text:7831D334
.text:7831D334 loc_7831D334:
.text:7831D334                 mov     eax, [esi]
.text:7831D336                 mov     ecx, esi
.text:7831D338                 call    dword ptr [eax+5Ch]
.text:7831D33B
.text:7831D33B loc_7831D33B
.text:7831D33B                 mov     ebx, eax
.text:7831D33D
.text:7831D33D loc_7831D33D:
.text:7831D33D                 call    AfxWinTerm
.text:7831D342                 pop     edi
.text:7831D343                 pop     esi
.text:7831D344                 mov     eax, ebx
.text:7831D346                 pop     ebx
.text:7831D347                 retn    10h
.text:7831D347 AfxWinMain      endp

In the code there are calls as call [eax+XXh]: actually the call to AfxGetApp (and AfxGetThread) gives back a pointer to a structure that has offsets of all functions used by MFC framework.
In this case edi (pApp) holds the offset of 405498, which value is 40349C VA, where the virtual functions table of CWinApp is stored:

.rdata:0040349C off_40349C      dd offset ?GetRuntimeClass@CWinApp@@UBEPAUCRuntimeClass@@XZ;CWinApp::GetRuntimeClass(void)
.rdata:004034A0                 dd offset sub_401010
.rdata:004034A4                 dd offset nullsub_1
.rdata:004034A8                 dd offset nullsub_2
.rdata:004034AC                 dd offset nullsub_1
.rdata:004034B0                 dd offset ?OnCmdMsg@CCmdTarget@@UAEHIHPAXPAUAFX_CMDHANDLERINFO@@@Z ; CCmdTarget::OnCmdMsg(uint,int,void *,AFX_CMDHANDLERINFO *)
.rdata:004034B4                 dd offset ?OnFinalRelease@CCmdTarget@@UAEXXZ ; CCmdTarget::OnFinalRelease(void)
.rdata:004034B8                 dd offset ?IsInvokeAllowed@CCmdTarget@@UAEHJ@Z ; CCmdTarget::IsInvokeAllowed(long)
.rdata:004034BC                 dd offset ?GetDispatchIID@CCmdTarget@@UAEHPAU_GUID@@@Z ; CCmdTarget::GetDispatchIID(_GUID *)
.rdata:004034C0                 dd offset ?GetTypeInfoCount@CCmdTarget@@UAEIXZ ; CCmdTarget::GetTypeInfoCount(void)
.rdata:004034C4                 dd offset ?GetTypeLibCache@CCmdTarget@@UAEPAVCTypeLibCache@@XZ ; CCmdTarget::GetTypeLibCache(void)
.rdata:004034C8                 dd offset ?GetTypeLib@CCmdTarget@@UAEJKPAPAUITypeLib@@@Z ; CCmdTarget::GetTypeLib(ulong,ITypeLib * *)
.rdata:004034CC                 dd offset sub_401000
;.......................................................

Now a question should pop up in your mind: where does MFC get the address? A quick glance at the reference with IDA…

.text:004023B0 sub_4023B0      proc near             
.text:004023B0                 push    0
.text:004023B2                 mov     ecx, offset dword_405498
.text:004023B7                 call    ??0CWinApp@@QAE@PB_W@Z ; CWinApp::CWinApp(wchar_t const *)
.text:004023BC                 push    offset sub_4023F0 ; void (__cdecl *)()
.text:004023C1                 mov     dword_405498, offset off_40349C ;<-- this is our offset
.text:004023CB                 call    _atexit
.text:004023D0                 pop     ecx
.text:004023D1                 retn
.text:004023D1 sub_4023B0      endp

This VA, 004023B0, is present in a structure

1
2
3
4
5
6
7
.rdata:00403304 unk_403304      db    0   
.rdata:00403305                 db    0
.rdata:00403306                 db    0
.rdata:00403307                 db    0
.rdata:00403308                 dd offset _pre_cpp_init
.rdata:0040330C                 dd offset ??__E_afxInitAppState@@YAXXZ ; `dynamic initializer for'_afxInitAppState''(void)
.rdata:00403310                 dd offset sub_4023B0

which is pushed to __initterm, called before WinMain

.text:00401AAC                 push    offset unk_403314
.text:00401AB1                 push    offset unk_403304
.text:00401AB6                 call    _initterm

After this excursus, let’s go back to AfxWinMain:
call dword ptr [eax+98h] (40349C + 98 = 00403534) calls…

.text:00403534                 dd offset ?InitApplication@CWinApp@@UAEHXZ ; CWinApp::InitApplication(void)

…while call dword ptr [eax+58h], that is pThread->InitInstance, calls the function:

1
.rdata:004034F4                 dd offset sub_401030

This function shows the dialog window, here is the main part of the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.text:00401030 sub_401030      proc near 
.text:00401030                 push    ebp
.text:00401031                 mov     ebp, esp
;..........................................................................
.text:0040109F                 call    sub_401130
;--------------------------------------------------------------------------
;entrato nella call
.text:00401155                 push    0              ; lpIconName
.text:00401157                 push    66h            ; Dialog ID
.text:00401159                 mov     ecx, esi
.text:0040115B                 call    ??0CDialog@@QAE@IPAVCWnd@@@Z ; CDialog::CDialog(uint,CWnd *)
.text:00401160                 mov     [esp+14h+var_4], 0
.text:00401168                 mov     dword ptr [esi], offset off_403744 ;virtual functions table offset which is store
; in CDialog.DoModal -> CDialog__PreModal -> AfxHookWindowCreate 
.text:0040116E                 call    ?AfxGetModuleState@@YGPAVAFX_MODULE_STATE@@XZ ; AfxGetModuleState(void)
;exit the call
;---------------------------------------------------------------------------
.text:004010A4                 lea     edx, [esp+8+arg_4]
.text:004010A8                 mov     [esp+8+arg_88], 0
.text:004010B3                 mov     ecx, edx
.text:004010B5                 mov     [esi+20h], edx
.text:004010B8                 call    ?DoModal@CDialog@@UAEHXZ ; CDialog::DoModal(void)
.text:004010BD                 lea     ecx, [esp+8+arg_4]
.text:004010C1                 mov     [esp+8+arg_88], 0FFFFFFFFh
.text:004010CC                 call    ??1CDialog@@UAE@XZ ; CDialog::~CDialog(void)
;..........................................................................
.text:004010E3                 mov     esp, ebp
.text:004010E5                 pop     ebp
.text:004010E6                 retn

 

Get MESSAGE_MAP

But where is MESSAGE_MAP?: Message Map can be get from

BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
     // ....
     const AFX_MSGMAP* pMessageMap;
     pMessageMap = GetMessageMap();
     // ....
          if ((lpEntry = AfxFindMessageEntry(pMessageMap->lpEntries, message, 0, 0)) != NULL)
     // ...
 
}

This is the disasm

.text:78312E91                 mov     eax, [edi] ; eax = 403744
.text:78312E93                 mov     ecx, edi
.text:78312E95                 call    dword ptr [eax+30h] ; eax+30h = 00403774 = GetMessageMap()
;.rdata:00403774                 dd offset sub_4011E0
;...................................................................
.text:78312F1B                 push    0
.text:78312F1D                 push    0
.text:78312F1F                 jnb     short loc_78312F67
.text:78312F21                 push    [ebp+arg_0] ;messagge
.text:78312F24                 push    dword ptr [esi+4] ; lpEntries (0040362C)
.text:78312F27                 call    AfxFindMessageEntry

The call in 78312E95 leads us to:

;GetMessageMap()
.text:004011E0                 mov     eax, offset off_403628 ;eax = pMessageMap
.text:004011E5                 retn
;----------------------------------------------------------------
;pMessageMap
.rdata:00403628 off_403628      dd offset ?GetThisMessageMap@CDialog@@KGPBUAFX_MSGMAP@@XZ
.rdata:00403628                                        ; CDialog::GetThisMessageMap(void)
.rdata:0040362C                 dd offset unk_403580 ;pMessageMap->lpEntries

At 403580 there’s the MESSAGE_MAP of this dialog.

So we can get the MessageMap quickly this way:

  1. Find before a call to CDialog:DoModal an istruction like this: mov dword ptr [esi], offset off_XXXXXX (it is used to load virtual functions table).
  2. Add 0×30 to that offset to get GetMessageMap function: into that function, look for the instruction mov eax, offset off_XXXXXX, where eax is pMessageMap
  3. Add 4 to pMessageMap to get Dialog MessageMap

Now an example. This is the software resource:

CONTROL "Register", 1006, BUTTON, //1006 = 0x3ee
CONTROL "About", 1007, BUTTON, //1007 = 0x3ef
CONTROL "Cancel", 1008, BUTTON, //1008 = 0x3f0

And this is its MESSAGE_MAP, which is an array of structures

struct AFX_MSGMAP_ENTRY
{
        UINT nMessage;   // windows message
        UINT nCode;      // control code or WM_NOTIFY code
        UINT nID;        // control ID (or 0 for windows messages)
        UINT nLastID;    // used for entries specifying a range of control id's
        UINT_PTR nSig;       // signature type (action) or pointer to message #
        AFX_PMSG pfn;    // routine to call (or special value)
};
.rdata:00403580 MESSAGE_MAP    dd 112h               
.rdata:00403584                 dd 0
.rdata:00403588                 dd 0
.rdata:0040358C                 dd 0
.rdata:00403590                 dd 1Eh
.rdata:00403594                 dd offset sub_4012D0
 
.rdata:00403598                 dd 0Fh
.rdata:0040359C                 dd 0
.rdata:004035A0                 dd 0
.rdata:004035A4                 dd 0
.rdata:004035A8                 dd 13h
.rdata:004035AC                 dd offset sub_401370
 
.rdata:004035B0                 dd 37h
.rdata:004035B4                 dd 0
.rdata:004035B8                 dd 0
.rdata:004035BC                 dd 0
.rdata:004035C0                 dd 28h
.rdata:004035C4                 dd offset sub_401450
 
.rdata:004035C8                 dd 111h
.rdata:004035CC                 dd 0
.rdata:004035D0                 dd 3EFh 
.rdata:004035D4                 dd 3EFh 
.rdata:004035D8                 dd 38h
.rdata:004035DC                 dd offset sub_401460
 
.rdata:004035E0                 dd 111h
.rdata:004035E4                 dd 0
.rdata:004035E8                 dd 3F0h 
.rdata:004035EC                 dd 3F0h
.rdata:004035F0                 dd 38h
.rdata:004035F4                 dd offset sub_4014F0
 
.rdata:004035F8                 dd 111h
.rdata:004035FC                 dd 0
.rdata:00403600                 dd 3EEh 
.rdata:00403604                 dd 3EEh
.rdata:00403608                 dd 38h
.rdata:0040360C                 dd offset sub_401510
 
.rdata:00403610                 dd 0
...

Every event has a structure where window ID and the function to use are stored.
 

IDC Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// mfc_message_map.idc version 0.2 by Pn 2008
#include <idc.idc>
 
//Only some WM_ command are recognized
static messageName(ptr, message) {
 
        if(message == 1) // WM_CREATE
                MakeComm(ptr, "WM_CREATE");
        else if(message == 2) // WM_DESTROY
                MakeComm(ptr, "WM_DESTROY");
        else if(message == 5) // WM_SIZE
                MakeComm(ptr, "WM_SIZE");
        else if(message == 0x10) // WM_CLOSE
                MakeComm(ptr, "WM_CLOSE");
        else if(message == 0x18) // WM_SHOWWINDOW
                MakeComm(ptr, "WM_SHOWWINDOW");
 
        else if(message == 0x0100) // WM_KEYDOWN
                MakeComm(ptr, "WM_KEYDOWN");
        else if(message == 0x0101) // WM_KEYUP
                MakeComm(ptr, "WM_KEYUP");
        else if(message == 0x0102) // WM_CHAR
                MakeComm(ptr, "WM_KEYCHAR");
 
        else if(message == 0x0110) // WM_INITDIALOG
                MakeComm(ptr, "WM_INITDIALOG");
        else if(message == 0x0111) // WM_COMMAND
                MakeComm(ptr, "WM_COMMAND");
        else if(message == 0x0112) // WM_SYSCOMMAND
                MakeComm(ptr, "WM_SYSCOMMAND");
        else if(message == 0x0113) // WM_TIMER
                MakeComm(ptr, "WM_TIMER");
        else if(message == 0x0116) // WM_INITMENU
                MakeComm(ptr, "WM_INITMENU");
        else if(message == 0x0117) // WM_INITMENUPOPUP
                MakeComm(ptr, "WM_INITMENUPOPUP");
        else if(message == 0x0126) // WM_MENUCOMMAND
                MakeComm(ptr, "WM_MENUCOMMAND");
 
}
static DefineStruct() {
        auto idStruct;
 
        idStruct = AddStrucEx(-1,"AFX_MSGMAP_ENTRY",0);
        if(idStruct == 0) return 0;
 
        if(AddStrucMember(idStruct, "nMessage", 0, FF_DWRD|FF_DATA, -1, 4) != 0) {
                Warning("\n1\n");
                DelStruc(idStruct);
                return 0;
        }
 
        if(AddStrucMember(idStruct, "nCode", 4, FF_DWRD|FF_DATA, -1, 4) != 0) {
                Warning("\n2\n");
                DelStruc(idStruct);
                return 0;
        }
 
        if(AddStrucMember(idStruct, "nID", 8, FF_DWRD|FF_DATA, -1, 4) != 0) {
                Warning("\n3\n");
                DelStruc(idStruct);
                return 0;
        }
 
        if(AddStrucMember(idStruct, "nLastID", 12, FF_DWRD|FF_DATA, -1, 4) != 0) {
                Warning("\n4\n");
                DelStruc(idStruct);
                return 0;
        }
 
        if(AddStrucMember(idStruct, "nSignature", 16, FF_DWRD|FF_DATA, -1, 4) != 0) {
                Warning("\n5\n");
                DelStruc(idStruct);
                return 0;
        }
 
        if(AddStrucMember(idStruct, "pFunction", 20, FF_DWRD|FF_0OFF, -1, 4) != 0) {
                Warning("\n6\n");
                DelStruc(idStruct);
                return 0;
        }
 
        return idStruct;
}
 
static GenerateMFCMap(addr) {
        auto idStruct, ptr, message, isOk;
 
        idStruct = GetStrucIdByName("AFX_MSGMAP_ENTRY");
        if( idStruct == -1) {
                idStruct = DefineStruct();
                if(idStruct == 0) {
                        Warning("\nCannot declare the structure\n"); 
                        return;
                }
        }
 
        ptr = addr;
        isOk = 1;
 
        while( Dword(ptr) != 0) {
                if(MakeStructEx(ptr, 24, "AFX_MSGMAP_ENTRY") == 0) {
                        isOk = 0;
                        break;
                }
                                messageName(ptr,Dword(ptr));
 
                ptr = ptr + 24;
        }
 
        if(isOk == 0) {
                Warning("\nCannot set the structure at %x\n", addr);
        } else {
                Message("Completed");
        }
 
        return;
}

This is the disasm after I used the script on it:

.rdata:00403580 stru_403580     AFX_MSGMAP_ENTRY <112h, 0, 0, 0, 1Eh, offset sub_4012D0> ; WM_SYSCOMMAND
.rdata:00403580                                        ; DATA XREF: .rdata:0040362C�o
.rdata:00403598                 AFX_MSGMAP_ENTRY <0Fh, 0, 0, 0, 13h, offset sub_401370>
.rdata:004035B0                 AFX_MSGMAP_ENTRY <37h, 0, 0, 0, 28h, offset sub_401450>
.rdata:004035C8                 AFX_MSGMAP_ENTRY <111h, 0, 3EFh, 3EFh, 38h, offset sub_401460> ; WM_COMMAND
.rdata:004035E0                 AFX_MSGMAP_ENTRY <111h, 0, 3F0h, 3F0h, 38h, offset sub_4014F0> ; WM_COMMAND
.rdata:004035F8                 AFX_MSGMAP_ENTRY <111h, 0, 3EEh, 3EEh, 38h, offset sub_401510> ; WM_COMMAND
.rdata:00403610                 db    0

 

Retrieve WM_COMMAND

The function BOOL CCmdTarget::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo), precisely the function _AfxDispatchCmdMsg, handles WM_COMMAND event.
Actually if you set a bp on it you can see that after a button or a menu is clicked on, the debugger halts the execution. By stepping you can enter the function called for that event, without having to retrieve the MESSAGE_MAP.


  Comments,     Trackbacks

Decompilers


  • Debuggers:
    • OllyDbg, free, a fine debugger, for which you can find numerous user-made plugins and scripts to make it all the more useful.
    • WinDbg, free, a quite capable debugger by Microsoft. WinDbg is especially useful for looking at the Windows internals, since it knows more about the data structures than other debuggers.
    • SoftICE, SICE to friends. Commercial and development stopped in 2006. SoftICE is kind of a hardcore tool that runs beneath the operating system (and halts the whole system when invoked). SoftICE is still used by many professionals, although might be hard to obtain and might not work on some hardware (or software - namely, it will not work on Vista or NVIDIA gfx cards).
  • Disassemblers:
    • IDA Pro, commercial, top of the line disassembler/debugger. Used by most professionals, like malware analysts etc. Costs quite a few bucks though.
    • W32Dasm, free, a bit dated but gets the job done. I believe W32Dasm is abandonware these days, and there are numerous user-created hacks to add some very useful functionality. You'll have to look around to find the best version.
  • Decompilers:
    • Visual Basic: VB Decompiler, commercial, produces somewhat identifiable bytecode.
    • Delphi: DeDe, free, produces good quality source code.
    • C: HexRays, commercial, a plugin for IDA Pro by the same company. Produces great results but costs a big buck, and won't be sold to just anyone (or so I hear).
    • .NET(C#): dotPeek, free, decompiles .NET 1.0-4.5 assemblies to C#. Support for .dll, .exe, .zip, .vsix, .nupkg, and .winmd files.

Some related tools that might come handy in whatever it is you're doing are resource editors such asResourceHacker (free) and a good hex editor such as Hex Workshop (commercial).

  Comments,     Trackbacks

스크린캡쳐

최근 악성코드가 사용한 캡쳐 코드

{

  i = 0;

  do

  {

    v5 = 1;

    v6 = 0;

    v7 = 0;

    v8 = 0;

    GdiplusStartup(&v4, &v5, &v13);

    v1 = CreateDCA("DISPLAY", 0, 0, 0);

    H_value = GetDeviceCaps(v1, 8);             // H(가로)

    V_value = GetDeviceCaps(v1, 10);            // V(세로)

    v10 = 0;

    v9 = 0;

    Sleep(0xBB8u);

    GetTempPathW(0xC8u, &Buffer);

    wsprintfW(&Buffer, L"%s%d.jpg", &Buffer, i);

    v2 = CREATE_BITMAP(&v9);

    Save_img(v2, &Buffer);

    DeleteDC(v1);

    GdiplusShutdown(v4);

    ++i;

  }

  while ( i < 5 );

  Sleep(0x2710u);

  return sub_10001C90(&unk_10004140);

}



CREATE_BITMAP(&v9){

  v1 = a1;

  if ( IsRectEmpty(a1) )

  {

    result = 0;

  }

  else

  {

    v8 = CreateDCA("DISPLAY", 0, 0, 0);

    hDCA = v8;

    v9 = CreateCompatibleDC(v8);

    v10 = v1->top;

    v5 = v1->right;

    v6 = v9;

    v11 = v1->left;

    v4 = v1->bottom;

    v19 = v11;

    v18 = v10;

    H_value = GetDeviceCaps(hDCA, 8);

    V_value = GetDeviceCaps(hDCA, 10);

    if ( v19 < 0 )

      v19 = 0;

    if ( v18 < 0 )

      v18 = 0;

    if ( v5 > H_value )

      v5 = H_value;

    if ( v4 > V_value )

      v4 = V_value;

    v12 = v4 - v18;

    v13 = v5 - v19;

    v14 = CreateCompatibleBitmap(hDCA, v13, v12);

    v15 = SelectObject(v6, v14);

    BitBlt(v6, 0, 0, v13, v12, hDCA, v19, v18, 0xCC0020u);

    v16 = SelectObject(v6, v15);

    (DeleteDC)(v17, hDCA);

    DeleteDC(v6);

    result = v16;

  }

  return result;

}


Save_img(v2, &Buffer){

  v4 = 0;

  GdipCreateBitmapFromHBITMAP(this, 0, &v4);

  v3 = v4;

  jpeg_encode(&v6);

  v8 = dword_1000317C;

  v9 = dword_10003180;

  v7 = 1;

  v10 = dword_10003184;

  v12 = 1;

  v11 = dword_10003188;

  v14 = &v5;

  v13 = 4;

  v5 = 30;

  GdipSaveImageToFile(v3, a2, &v6, &v7);

  return GdipDisposeImage(v3);

}

  Comments,     Trackbacks

virtualbox-host-only-network-cuckoo-sandbox-0-4-2/

http://precisionsec.com/virtualbox-host-only-network-cuckoo-sandbox-0-4-2/


virtualbox 설치 후 (cuckoo)agent.py와 xmlrpc로 연결되려면 host-only interface를 연결해야함

host-only 연결이지만 방화벽 설정 해주면 nat같이 사용가능. 아래 참조.


The purpose of this post is to guide you through setting up host-only networking using VirtualBox for Cuckoo Sandbox. Using this method you can have multiple analysis machines running on the same server concurrently while giving all of them access to the Internet. This method is preferred over bridged networking because you only need one external IP. This post assumes that you have Virtualbox and your guest VMs installed and Cuckoo extracted somewhere.

First create a host-only interface on host:

vboxmanage hostonlyif create
vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1

Now you should see vboxnet0 configured with that IP when running ifconfig:

vboxnet0  Link encap:Ethernet  HWaddr 0A:00:27:00:00:00  
          inet addr:192.168.56.1  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:273 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:31818 (31.0 KiB)

Next you need to set the NIC on the guest Virtual Machine as a host only interface. This can be done with the following commands:

vboxmanage modifyvm CuckooBox --hostonlyadapter1 vboxnet0
vboxmanage modifyvm CuckooBox --nic1 hostonly

Now you will have to set up networking on the guest to use the host as a gateway. I use the following settings:

Static IP - 192.168.56.101
DNS - any DNS server (8.8.8.8)
Default Gateway - 192.168.56.1

In order to have your Virtual Machines be able to access the internet you will have to add the followingiptables rules. This will forward packets through the host and on to the Internet:

iptables -A FORWARD -o eth0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE

You will also need to enable IP forwarding on the host by issuing the following command (as root):

echo 1 > /proc/sys/net/ipv4/ip_forward

If everything worked properly you should now have Internet connectivity from the guest to the Internet and you should be able to ping back and forth between the guest and the host.

Now you need to install the agent on the guest and edit the conf/virtualbox.conf file with the correct parameters as outlined in the Cuckoo documentation, set up your snapshot and you are in business.

'유용한 지식 자료들 > 기타' 카테고리의 다른 글

MFC 리버싱하기  (0) 2013.08.12
Decompilers  (0) 2013.08.12
리눅스 du 명령(디렉토리 용량 확인) 응용  (0) 2013.07.16
포렌직 자료  (0) 2013.07.16
Kernel32 Wow64관련 API에 대하여.  (0) 2013.07.09
  Comments,     Trackbacks

리눅스 du 명령(디렉토리 용량 확인) 응용

# du 2013-07-1* -h --max-depth=0 | sort -r -k 2

1.6G    2013-07-16

1.1G    2013-07-15

1.2G    2013-07-14

1.5G    2013-07-13

1.1G    2013-07-12

1.2G    2013-07-11

1.8G    2013-07-10

 

용량 순이 아닌 2번째 컬럼 순으로 정렬.

생각해둬야 할게 du 명령은 일단 실행된 뒤에 sort가 되므로 du 명령시 2013-07-1*과 같이 제한을 잘 걸어줘야 용량이 큰 디렉토리 결과를 잘 볼 수 있음. 그게 아니면 메모리상에 다 처리되고 sort가 되므로 상당한 시간이 흐른뒤에 결과를 볼 수 있음. sort 명령을 안하면 그나마 순차적으로 출력결과를 볼 수는 있음.

  Comments,     Trackbacks

포렌직 자료

점점 이분 블로그도 많이 보이네요..포렌직 좀 공부해야는데 ㅎ

http://forensic-proof.com/slides


FUNDAMENTALS
 [FP] 디지털 포렌식 개요 (Introduction to dForensics).pdf (Last updated: 2013-05-15)
 [FP] 컴퓨터 구성 요소와 인터페이스 (Computer Components and Interfaces) (Last updated: 2011-10-12)
 [FP] 저장매체 (Storage) (Last updated: 2011-10-12)
 [FP] 부팅과 데이터 저장,전송 (Booting and Data Recording,Transmission) (Last updated: 2013-02-18)
 [FP] 디지털 데이터 표현 (Digital Data Representation) (Last updated: 2011-10-12)
 [FP] 하드디스크 구조 (HDD Components) (Last updated: 2011-10-12)
 [FP] 부팅 절차 (Boot Process) (Last updated: 2011-10-12)
 [FP] 메모리 포렌식 (Memory Forensics) (Last updated: 2011-10-12)
 [FP] 증거 획득 (Evidence Acquisition) (Last updated: 2011-09-01)
 [FP] Small Computer System Interface (ATA vs. SCSI) (Last updated: 2010-05-31)

 

FILESYSTEM
 [FP] File System, MBR, GPT (Last updated: 2011-10-12)
 [FP] FAT(12,16,32) File System (Last updated: 2011-10-12)
 [FP] exFAT File System (Last updated: 2011-10-12)
 [FP] NTFS (Last updated: 2011-10-12)
 [FP] File System Forensics (Last updated: 2011-10-12)

 

WINDOWS
 [FP] 사고(실시간) 대응 (Live Response) (Last updated: 2011-10-12)
 [FP] 레지스트리 포렌식과 보안 (Registry Forensics & Security) (Last updated: 2011-04-17)
 [FP] 프리(슈퍼) 패치 포렌식 (Pre & Superfetch Forensics) (Last updated: 2011-10-12)
 [FP] 바로가기(링크파일) 포렌식 (LNK File Forensics) (Last updated: 2011-10-12)
 [FP] 휴지통 포렌식 (Recycle Bin Forensics) (Last updated: 2011-10-12)
 [FP] 썸네일 포렌식 (Thumbnail Forensics) (Last updated: 2011-10-12)
 [FP] 윈도우7 – 파일시스템 (Windows7 – File System) (Last updated: 2011-10-12)
 [FP] 윈도우7 – 폴더 구조 (Windows7 – Folder Structure) (Last updated: 2011-10-12)
 [FP] 윈도우 7 – 점프 목록 (Windows7 – Jump List) (Last updated: 2011-10-12)

 

*NIX
 [FP] LVM(Logical Volume Manager) (Last updated: 2010-03-30)

 

ADVANCED
 [FP] 데이터 복구의 거의 모든 것 (Almost Everything for Data Recovery) (Last updated: 2013-05-30)
 [FP] 윈도우8은 포렌식도 다르다 (What’s changed in Windows8) (Last updated: 2012-09-20)
 [FP] 악성코드 포렌식 (Malware Forensics) (Last updated: 2012-07-31)
 [FP] 디지털포렌식 현황과 전망 (The Status and Prospects for dForensics in Korea) (Last updated: 2013-05-06)

 

ENCASE
 [FP] EnCase Fundamental (Last updated: 2011-03-01)
 [FP] A brief Introduction to EnScript (Last updated: 2010-08-10)
 [FP] EnCase Windows Operating System Artifacts (Last updated: 2010-05-31)
 [FP] EnCase #1 (Hardware & File_System) (Last updated: 2009-03-01)
 [FP] EnCase #2 (Acquiring Digital Evidence) (Last updated: 2009-03-01)
 [FP] EnCase #3 (EnCase Concepts & Environment) (Last updated: 2009-03-01)
 [FP] EnCase #6 Windows Operating System Artifacts – Part I (Last updated: 2009-03-01)
 [FP] EnCase #7 Windows Operating System Artifacts – Part II (Last updated: 2009-03-01)


  Comments,     Trackbacks