首页
社区
课程
招聘
[原创]R3 Hook CPUID指令
发表于: 2017-9-22 21:28 10736

[原创]R3 Hook CPUID指令

2017-9-22 21:28
10736
很多厂商对E3 E5 甚至整个志强系列做了特殊照顾,因此通过返回值可以伪造型号 序列号
下面是游戏中的代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
004D9FA0    53              push ebx
004D9FA1    57              push edi
004D9FA2    89D7            mov edi,edx
004D9FA4    31DB            xor ebx,ebx
004D9FA6    31C9            xor ecx,ecx
004D9FA8    31D2            xor edx,edx
004D9FAA    0FA2            cpuid
004D9FAC    8907            mov dword ptr ds:[edi],eax
004D9FAE    895F 04         mov dword ptr ds:[edi+0x4],ebx
004D9FB1    894F 08         mov dword ptr ds:[edi+0x8],ecx
004D9FB4    8957 0C         mov dword ptr ds:[edi+0xC],edx
004D9FB7    5F              pop edi
004D9FB8    5B              pop ebx
004D9FB9    C3              retn

利用调试器HOOK修改型号 序列号
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#define  CPUID地址 0x004D9FA0<br>
 
DebugClass::DebugClass()
{
     
    srand(time(NULL));//整个程序最调用一次
    memset(m_int3, 0, sizeof(Int3Info) * 20);
    int suijishu = 随机数2(1, 4);
    if (suijishu == 1)
    {
        sprintf(CPU型号, "      Intel(R) Core i7-7700K @4.20Hz");//前面6个空格
    }
    else if (suijishu ==2)
    {
        sprintf(CPU型号, "      Intel(R) Core i7-3615QN @2.30Hz");//前面6个空格
    }
    else if (suijishu == 3)
    {
        sprintf(CPU型号, "      Intel(R) Core i5-7440HQ @3.300Hz");//前面6个空格
    }
    else if (suijishu == 4)
    {
        sprintf(CPU型号, "      Intel(R) Core i7-3632QM @2.20Hz");//前面6个空格
    }
 
}<br>
<br>
void DebugClass::loop(DWORD Targpid)
{
    this->pid = Targpid;
    EndDebug = false;
    CWinThread* th= AfxBeginThread(AFX_THREADPROC(debugThread), this);
    ::WaitForSingleObject(th->m_hThread, INFINITE);
 
}
<br>
<br>
 
static DWORD  debugThread(LPVOID lp)
{
 
 
    DebugClass* dbg = (DebugClass*)lp;
     
    if (!DebugActiveProcess(dbg->pid))
    {
        AfxMessageBox("无法附加");
        return 0;
    }
    DebugSetProcessKillOnExit(FALSE);
    CString  jj;
    DEBUG_EVENT  event;
    DWORD  dwContinuesStatus = DBG_EXCEPTION_NOT_HANDLED;//默认不处理异常
    while (WaitForDebugEvent(&event, INFINITE))
    {
 
        switch (event.dwDebugEventCode)
        {
        case  CREATE_PROCESS_DEBUG_EVENT:
            //AfxMessageBox("CREATE_PROCESS_DEBUG_EVENT");
            dbg->Createint3(&event);
            dwContinuesStatus = DBG_CONTINUE;
              
            break;
 
        case EXCEPTION_DEBUG_EVENT:
            dwContinuesStatus = dbg->Int3Code(&event);
            ::CloseHandle(event.u.CreateProcessInfo.hThread);
            ::CloseHandle(event.u.CreateProcessInfo.hProcess);
            ::CloseHandle(event.u.CreateProcessInfo.hFile);
 
            break;
        case EXIT_PROCESS_DEBUG_EVENT:
            //AfxMessageBox("EXIT_PROCESS_DEBUG_EVENT");
            DebugActiveProcessStop(dbg->pid);
            return 0;
 
 
        }
          
         
        ContinueDebugEvent(event.dwProcessId, event.dwThreadId, dwContinuesStatus);
  
     
     
    }
 
}
<br>
<br>
 
DWORD DebugClass::Int3Code(LPDEBUG_EVENT lpDebugEvent)
{
    PEXCEPTION_RECORD per = &lpDebugEvent->u.Exception.ExceptionRecord;
     
    BYTE bInt3 = 0xCC;
    if (per->ExceptionCode == EXCEPTION_BREAKPOINT)
    {
        for (int i = 0; i < 20; i++)
        {
            if (m_int3[i].adr == 0)
            {
                continue;
            }
            if (per->ExceptionAddress == (LPVOID)m_int3[i].adr)
            {
                //AfxMessageBox("地址触发");
                if (m_int3[i].adr == CPUID地址)
                {
                    伪造CPUID(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == 查看修改后的CPU地址)
                {
                    查看CPU修改结果(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == 查看修改后的序列号地址)
                {
                    查看序列号修改结果(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == Game_NtCreateThread)
                {
                    线程直接返回(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == Game_CreateDC)
                {
                    线程直接返回(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == this->修改网站内存地址)
                {
                    //  AfxMessageBox("ADR");
                    改网站(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == this->发包地址)
                {
                    //  AfxMessageBox("ADR");
                    处理发包(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == this->喊话地址)
                {
                    //  AfxMessageBox("ADR");
                    记录喊话(lpDebugEvent, i);
                }
                else if (m_int3[i].adr == 登录信息地址)
                {
                    //  AfxMessageBox("ADR");
                    处理登录信息(lpDebugEvent, i);
                }
 
                return DBG_CONTINUE;
            }
             
 
        }
 
    }
    else if (per->ExceptionCode == EXCEPTION_SINGLE_STEP)
    {
        //AfxMessageBox("单步");
        BYTE bInt3 = 0xCC;
        for (int x = 0; x < 20; x++)
        {
            if (m_int3[x].adr != 0)
            {
                WriteProcessMemory(m_process, (LPVOID)m_int3[x].adr, &bInt3, sizeof(BYTE), NULL);
            }
        }
        return DBG_CONTINUE;
    }
    return  DBG_EXCEPTION_NOT_HANDLED;
}
<br>
<br>
<br>
 
 
void  DebugClass::伪造CPUID(LPDEBUG_EVENT lpDebugEvent, DWORD myindex)
{
    CONTEXT cText;
    HANDLE  m_thread = ::OpenThread(THREAD_ALL_ACCESS, FALSE, lpDebugEvent->dwThreadId);
    cText.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
    if (!GetThreadContext(m_thread, &cText))
    {
        return;
    }
 
    if (cText.Eax == 0x80000002)
    {
        ::WriteProcessMemory(m_process, (LPVOID)cText.Edx, CPU型号, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 4), CPU型号 + 4, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 0X8), CPU型号 + 8, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 0XC), CPU型号 + 0xC, 4, NULL);
    }
    else if (cText.Eax == 0x80000003)
    {
        ::WriteProcessMemory(m_process, (LPVOID)cText.Edx, CPU型号 + 16, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 4), CPU型号 + 16 + 4, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 0X8), CPU型号 + 16 + 8, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 0XC), CPU型号 + 16 + 0xC, 4, NULL);
    }
    else if (cText.Eax == 0x80000004)
    {
        ::WriteProcessMemory(m_process, (LPVOID)cText.Edx, CPU型号 + 16 * 2, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 4), CPU型号 + 16 * 2 + 4, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 0X8), CPU型号 + 16 * 2 + 8, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx + 0XC), CPU型号 + 16 * 2 + 0xC, 4, NULL);
      
    }
    else if (cText.Eax == 1)//获取CPU序列号
    {
 
        DWORD  meax = 随机数2(0x11111, 0xfffff);
        *((byte*)((DWORD)&meax) + 1) = 0X06;
        char eax_str[256] = { 0 };
        sprintf(eax_str, "%x", meax);
 
 
 
        //2
        DWORD  mebx_1 = 随机数2(0x1, 0xf);
        DWORD mebx = mebx_1 * 0x100000 + 0x800;
        sprintf(eax_str, "%x", mebx);
 
        //3 xfxxxxxf
        DWORD  m_ecx = 随机数2(0x11111111, 0xffffffff);
        sprintf(eax_str, "%0.8x", m_ecx);
        eax_str[1] = 'f';
        eax_str[7] = 'f';
          
        char* p = NULL;
        m_ecx = strtol(eax_str, &p, 16);
 
        DWORD  m_edx = 0xBFEBFBFF;
         
        ::WriteProcessMemory(m_process, (LPVOID)cText.Edx, &meax, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx+4), &mebx, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx+8), &m_ecx, 4, NULL);
        ::WriteProcessMemory(m_process, (LPVOID)(cText.Edx+0xc), &m_edx, 4, NULL);
          
         
 
    }
 
 
    WriteProcessMemory(m_process, (LPVOID)m_int3[myindex].adr, &m_int3[myindex].oldByte, sizeof(BYTE), NULL);
    cText.Eip = m_int3[myindex].eipAdr /*目标地址*/;
    cText.EFlags |= 0x100;
    SetThreadContext(m_thread, &cText);
    CloseHandle(m_thread);
}
 
<br>

[注意]看雪招聘,专注安全领域的专业人才平台!

收藏
免费
支持
分享
最新回复 (6)
雪    币: 2473
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
<br>  是什么鬼

想法很好      请问      EXCEPTION_DEBUG_EVENT    是谁抛的
如果是cpuid抛的    那要vt有何用
2017-9-23 03:26
0
雪    币: 12876
活跃值: (9332)
能力值: ( LV9,RANK:280 )
在线值:
发帖
回帖
粉丝
3
我用的可能是假E3
2017-9-24 08:54
0
雪    币: 75
活跃值: (150)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
中文C++?简直了!!
2017-12-26 11:03
0
雪    币: 172
活跃值: (81)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
VS支持中文变量
2017-12-26 11:14
0
雪    币: 1176
活跃值: (1284)
能力值: ( LV12,RANK:380 )
在线值:
发帖
回帖
粉丝
6
我擦  还真支持....
2017-12-26 12:00
0
雪    币: 42
活跃值: (208)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
itiansin 中文C++?简直了!![em_4]
不奇怪,我也喜欢用中文
2018-10-26 14:23
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册