首页
社区
课程
招聘
[原创]去除花指令的代码
2008-8-8 17:52 14716

[原创]去除花指令的代码

2008-8-8 17:52
14716
奥运开幕前夕,发个帖子留作纪念。

#define WIN32_LEAN_AND_MEAN       
#include "windows.h"

BYTE flowCode1[] = {......}; // ......表示你的花指令组合,这个需要你自己替换了。

BYTE flowCode2[] = { ........};

BYTE flowCode3[] = { .........};
char szFileName[] = "combojiang.exe";

//找出花指令的位置并去掉花指令
void FindFlowerCodeAndRemove(LPVOID src, LPVOID flw, int nSrcLen,int nflwLen)
{
        __asm
        {
                xor eax,eax
                push esi
                push edi
                push ecx

                cld
                mov esi,flw
                mov edi,src
                mov ecx,nSrcLen
                lod**
               
Start:
                repnz sca**
                or ecx,ecx
                jz NotFindFlower
                push eax
                push ecx
                push esi
                push edi

                lea edi,[edi - 1]
                mov ecx,nflwLen
                mov esi,flw
        repz cmp**

                or ecx,ecx
                jnz MYLOOP
                       
                mov ecx,nflwLen
                sub edi,nflwLen
                mov al,0x90
                rep sto**

MYLOOP:
               pop edi
                pop esi
                pop ecx
                pop eax
                jmp Start

NotFindFlower:
                pop ecx
                pop edi
                pop esi
        }
}

int main(int argc, char* argv[])
{
    DWORD dwHigh;
        HANDLE hFile = CreateFile(szFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);       
        HANDLE hMap = CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,0,0);
        LPVOID lpMem = MapViewOfFile(hMap,FILE_MAP_ALL_ACCESS,0,0,0);
        int nFileLen  = GetFileSize(hFile,&dwHigh);

   FindFlowerCodeAndRemove(lpMem, flowCode1, nFileLen,23);       
   FindFlowerCodeAndRemove(lpMem, flowCode2, nFileLen,12);
        FindFlowerCodeAndRemove(lpMem, flowCode3, nFileLen,8);
       
        UnmapViewOfFile(lpMem);
        CloseHandle(hMap);
        CloseHandle(hFile);
        return 0;
}

注: 由于论坛屏蔽了s和b的连写,代码中看到的**表示这两个字母。

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

收藏
点赞7
打赏
分享
最新回复 (23)
雪    币: 83382
活跃值: (198465)
能力值: (RANK:10 )
在线值:
发帖
回帖
粉丝
linhanshi 2008-8-8 17:57
2
0
support.
雪    币: 271
活跃值: (18)
能力值: ( LV12,RANK:370 )
在线值:
发帖
回帖
粉丝
CCDeath 9 2008-8-8 18:12
3
0
支持 大叔新作...
雪    币: 612
活跃值: (315)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
峰回路转 3 2008-8-8 18:16
4
0
谁写一个支持脚本或特定格式的通用去花程序,把花做成sign进行收集不错,每次写都很麻烦
雪    币: 7651
活跃值: (493)
能力值: ( LV9,RANK:610 )
在线值:
发帖
回帖
粉丝
achillis 15 2008-8-8 19:06
5
0
花指令那么多种啊~
雪    币: 372
活跃值: (31)
能力值: ( LV12,RANK:410 )
在线值:
发帖
回帖
粉丝
vxin 10 2008-8-8 19:16
6
0
学习学习。。。
雪    币: 709
活跃值: (2230)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
sudami 25 2008-8-8 19:29
7
0
good job
雪    币: 846
活跃值: (221)
能力值: (RANK:570 )
在线值:
发帖
回帖
粉丝
笨笨雄 14 2008-8-8 20:15
8
0
dejunk不行?
雪    币: 7300
活跃值: (3758)
能力值: (RANK:1130 )
在线值:
发帖
回帖
粉丝
海风月影 22 2008-8-8 21:27
9
0
好像是某个驱动里面的花指令啊
雪    币: 207
活跃值: (10)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
embedlinux 1 2008-8-8 22:55
10
0
好好学习!。。。。。
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
lOOp 2008-8-8 23:41
11
0
support
雪    币: 612
活跃值: (315)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
峰回路转 3 2008-8-9 12:17
12
0
用OD时有用dejunk,有的时候不能用OD载入调试都要手动去花,再IDA静态分析
雪    币: 7115
活跃值: (644)
能力值: (RANK:1290 )
在线值:
发帖
回帖
粉丝
玩命 31 2008-8-10 00:17
13
0
收藏起来慢慢学习。
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
炉子 3 2008-8-10 08:49
14
0
支持  顶一个

要是fc知道他被人 find and remove他会很郁闷 哈哈

btw: 论坛的敏感字符过滤真不错 哈哈
雪    币: 1829
活跃值: (1293)
能力值: (RANK:50 )
在线值:
发帖
回帖
粉丝
backer 1 2008-8-10 21:39
15
0
如果有的花指令和流程相关,怎么办?
好在这样的花指令也难以设计得稳定而通用,插多了作者也难受。
雪    币: 101
活跃值: (12)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
jjnet 5 2008-8-11 09:31
16
0
BYTE flowCode1[] = {......};

BYTE flowCode2[] = { ........};

BYTE flowCode3[] = { .........};

f:\src\wg\src\common\dbginfo\dbginfo.cpp(17) : error C2466: cannot allocate an array of constant size 0
f:\src\wg\src\common\dbginfo\dbginfo.cpp(17) : error C2143: syntax error : missing '}' before '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(17) : error C2143: syntax error : missing ';' before '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(17) : error C2059: syntax error : '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(17) : error C2143: syntax error : missing ';' before '}'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(17) : error C2059: syntax error : '}'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(19) : error C2466: cannot allocate an array of constant size 0
f:\src\wg\src\common\dbginfo\dbginfo.cpp(19) : error C2143: syntax error : missing '}' before '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(19) : error C2143: syntax error : missing ';' before '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(19) : error C2059: syntax error : '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(19) : error C2143: syntax error : missing ';' before '}'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(19) : error C2059: syntax error : '}'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(21) : error C2466: cannot allocate an array of constant size 0
f:\src\wg\src\common\dbginfo\dbginfo.cpp(21) : error C2143: syntax error : missing '}' before '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(21) : error C2143: syntax error : missing ';' before '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(21) : error C2059: syntax error : '...'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(21) : error C2143: syntax error : missing ';' before '}'
f:\src\wg\src\common\dbginfo\dbginfo.cpp(21) : error C2059: syntax error : '}'
雪    币: 1829
活跃值: (1293)
能力值: (RANK:50 )
在线值:
发帖
回帖
粉丝
backer 1 2008-8-11 09:36
17
0
LS, LZ的意思是那里定义花指令的字节码,
如果遇到流程相关的花指令,有些字节码不能nop的,倒是可以考虑定义屏蔽字节,遇到屏蔽字节就不填NOP了
雪    币: 101
活跃值: (12)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
jjnet 5 2008-8-11 09:48
18
0
其实我是来搞笑的...
雪    币: 224
活跃值: (147)
能力值: ( LV9,RANK:970 )
在线值:
发帖
回帖
粉丝
wynney 24 2008-8-11 09:54
19
0
,我是来做俯卧撑的
雪    币: 101
活跃值: (12)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
jjnet 5 2008-8-11 10:21
20
0
有个奇怪的问题:

    mov ecx,nflwLen
    mov esi,flw
        repz cmp**

    or ecx,ecx
    jnz MYLOOP

对于memcmp(src,  dest, size)的代码是这样的
xor eax, eax
mov ecx, size
mov esi, src
mov edi, dest
repz cmp**
jz   __equ
**b eax, eax
**b eax, 0xffffffff
__equ:

就是说这个or ecx, ecx是多余的吧, 而且影响到判断,
如果最后一个字节不等, 那么ecx还是0, 毕竟所有的字节都扫描过了,
但他们却不相等。
cmp** 会根据设置的条件  rep(z) 来结束循环, 所以只需
在结束后判断flag就行。

一直对这个指令有迷糊, 刚参考了下intel, 感觉应该是这样的
Operation
temp ←SRC1 − SRC2;
SetStatusFlags(temp);
IF (byte comparison)
THEN IF DF = 0
THEN
(E)SI ← (E)SI + 1;
(E)DI ← (E)DI + 1;
ELSE
(E)SI ← (E)SI – 1;
(E)DI ← (E)DI – 1;
FI;
ELSE IF (word comparison)
THEN IF DF = 0
(E)SI ← (E)SI + 2;
(E)DI ← (E)DI + 2;
ELSE
(E)SI ← (E)SI – 2;
(E)DI ← (E)DI – 2;
FI;
ELSE (* doubleword comparison*)
THEN IF DF = 0
(E)SI ← (E)SI + 4;
(E)DI ← (E)DI + 4;
ELSE
(E)SI ← (E)SI – 4;
(E)DI ← (E)DI – 4;
FI;
FI;
雪    币: 321
活跃值: (271)
能力值: ( LV13,RANK:1050 )
在线值:
发帖
回帖
粉丝
combojiang 26 2008-8-19 00:21
21
0
呵呵,这里主要是判断ecx是否为0. or ecx, ecx是必须的
雪    币: 206
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yamu 2008-9-23 14:17
22
0
收藏 学习  谢谢lz
雪    币: 101
活跃值: (12)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
jjnet 5 2008-10-3 05:46
23
0
// A Test Simple

#define WIN32_LEAN_AND_MEAN  
#include "windows.h"

//找出花指令的位置并去掉花指令
void FindFlowerCodeAndRemove2(LPVOID src, LPVOID flw, int nSrcLen,int nflwLen)
{
        __asm
        {
                xor eax,eax
                        push esi
                        push edi
                        push ecx

                        cld
                        mov esi,flw
                        mov edi,src
                        mov ecx,nSrcLen
                        lodsb

Start:
                repnz scasb
                        or ecx,ecx
                        jz NotFindFlower
                        push eax
                        push ecx
                        push esi
                        push edi

                        lea edi,[edi - 1]
                mov ecx,nflwLen
                        mov esi,flw
                        repz cmpsb

//                        or ecx,ecx      // comment this BUG line
                        jnz MYLOOP

                        mov ecx,nflwLen
                        sub edi,nflwLen
                        mov al,0x90
                        rep stosb

MYLOOP:
                pop edi
                        pop esi
                        pop ecx
                        pop eax
                        jmp Start

NotFindFlower:
                pop ecx
                        pop edi
                        pop esi
        }
}

void FindFlowerCodeAndRemove(LPVOID src, LPVOID flw, int nSrcLen,int nflwLen)
{
        __asm
        {
                xor eax,eax
                        push esi
                        push edi
                        push ecx

                        cld
                        mov esi,flw
                        mov edi,src
                        mov ecx,nSrcLen
                        lodsb

Start:
                repnz scasb
                        or ecx,ecx
                        jz NotFindFlower
                        push eax
                        push ecx
                        push esi
                        push edi

                        lea edi,[edi - 1]
                mov ecx,nflwLen
                        mov esi,flw
                        repz cmpsb

                        or ecx,ecx
                        jnz MYLOOP

                        mov ecx,nflwLen
                        sub edi,nflwLen
                        mov al,0x90
                        rep stosb

MYLOOP:
                pop edi
                        pop esi
                        pop ecx
                        pop eax
                        jmp Start

NotFindFlower:
                pop ecx
                        pop edi
                        pop esi
        }
}

BYTE flowCode1[] = {0x30, 0x31, 0x32}; // ......表示你的花指令组合,这个需要你自己替换了。
BYTE src[14] = {'a', 'b', 'c', '0', '1', 'd', 'e', 'f', '0', '1', '2', 'g', 'h', 'i' };
BYTE expect_result[14] = {'a', 'b', 'c', '0', '1', 'd', 'e', 'f', 0x90, 0x90, 0x90, 'g', 'h', 'i' };

void hex_print(BYTE *buf, size_t size)
{
        while(size --)
                printf("%.2x ", *buf++);
        printf("\n");
}

void check_it(BYTE *result)
{
        if (0 == memcmp(result, expect_result, 14))
                printf("Right!\n");
        else
                printf("Wrong!\n");
}

int main(int argc, char* argv[])
{
        BYTE buf[14];

        // method 1: test ecx
        memcpy(buf, src, sizeof(buf));
        printf("src is :");
        hex_print(buf, sizeof(buf));
        printf("flower is:");
        hex_print(flowCode1, sizeof(flowCode1));
        printf("FindFlowerCodeAndRemove with test ecx>>>>>>\n");
        FindFlowerCodeAndRemove(buf, flowCode1, sizeof(buf),sizeof(flowCode1));  
        printf("now src is:");
        hex_print(buf, sizeof(buf));
        check_it(buf);

        // again
        printf("\n\nAnother test\n\n\n");

        // method 2: test flag
        memcpy(buf, src, sizeof(buf));
        printf("src is :");
        hex_print(buf, sizeof(buf));
        printf("flower is:");
        hex_print(flowCode1, sizeof(flowCode1));
        printf("FindFlowerCodeAndRemove with test flag>>>>>>\n");
        FindFlowerCodeAndRemove2(buf, flowCode1, sizeof(buf),sizeof(flowCode1));  
        printf("now src is:");
        hex_print(buf, sizeof(buf));
        check_it(buf);

        return 0;
}
雪    币: 202
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
FlowerCode 2008-10-7 16:31
24
0
汗,路过一下。
我记得驱动改了标志以后也是可以用 OD 载入的。
游客
登录 | 注册 方可回帖
返回