一个通用的简单反远控技术

2023-10-04 0 1,844

序言:首先,我不能保证全部拦住,只能保证拦住简单的那种,没经过特殊处理的
我们都知道,远程控制木马病毒,一直是杀毒软件困扰的
但是我们通过观察他们的表面特征,都能发现几个共同点
1.没有窗口
2.一般来说没有签名
3.Mutex互斥体(防止重复上线)
4.联网
特征显而易见
但是有些远控不加Mutex 所以我们不判断这个
那么剩下的就是 没有窗口 没有签名 和联网了
有些木马是有签名的,我们暂时不提

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <windows.h>
#include <softpub.h>
#include <wintrust.h>
#include <tchar.h>
#include <psapi.h>
#include <tlhelp32.h>
#include <Iphlpapi.h>
#include <vector>
#pragma comment (lib, "wintrust")
#pragma comment(lib, "Iphlpapi.lib")
using namespace std;

我们要用到的头文件和namespace这些
好,我们可以开始编写主体部分了
1.判断是否有窗口,代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bool DoesProcessHaveWindow(DWORD processId) {
    HWND hwnd = FindWindow(nullptr, nullptr);
    while (hwnd) {
        DWORD windowProcessId;
        GetWindowThreadProcessId(hwnd, &windowProcessId);
        if (windowProcessId == processId) {
            return true;
        }
        hwnd = GetWindow(hwnd, GW_HWNDNEXT);
    }
    return false;
}
 
int Is_Has_Window(DWORD targetProcessId) {
    if (DoesProcessHaveWindow(targetProcessId)) {
        std::cout << "The specified process has a window." << std::endl;
        return 1;
    }
    else {
        std::cout << "The specified process does not have a window." << std::endl;
        return 0;
    }
}

Is_Has_Window(进程PID) 如果返回1 就有窗口 如果返回0 就没窗口

2.判断签名是否合法

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
int VerifyEmbeddedSignature(LPCWSTR pwszSourceFile)
{
    LONG lStatus;
    DWORD dwLastError;
 
    // Initialize the WINTRUST_FILE_INFO structure.
 
    // 待验证文件的完整路径
    WINTRUST_FILE_INFO FileData;
    memset(&FileData, 0, sizeof(FileData));
    FileData.cbStruct = sizeof(WINTRUST_FILE_INFO);
    FileData.pcwszFilePath = pwszSourceFile;
    FileData.hFile = NULL;
    FileData.pgKnownSubject = NULL;
 
    /*
    WVTPolicyGUID specifies the policy to apply on the file
    WINTRUST_ACTION_GENERIC_VERIFY_V2 policy checks:
    1) The certificate used to sign the file chains up to a root
    certificate located in the trusted root certificate store. This
    implies that the identity of the publisher has been verified by
    a certification authority.
    2) In cases where user interface is displayed (which this example
    does not do), WinVerifyTrust will check for whether the
    end entity certificate is stored in the trusted publisher store,
    implying that the user trusts content from this publisher.
    3) The end entity certificate has sufficient permission to sign
    code, as indicated by the presence of a code signing EKU or no
    EKU.
    */
 
    GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
    WINTRUST_DATA WinTrustData;
 
    // Initialize the WinVerifyTrust input data structure.
 
    // Default all fields to 0.
    memset(&WinTrustData, 0, sizeof(WinTrustData));
 
    WinTrustData.cbStruct = sizeof(WinTrustData);
 
    // Use default code signing EKU.
    WinTrustData.pPolicyCallbackData = NULL;
 
    // No data to pass to SIP.
    WinTrustData.pSIPClientData = NULL;
 
    // Disable WVT UI.
    WinTrustData.dwUIChoice = WTD_UI_NONE;
 
    // No revocation checking.
    WinTrustData.fdwRevocationChecks = WTD_REVOKE_NONE;
 
    // 采用文件方式验证, 其他还有内存等
    // Verify an embedded signature on a file.
    WinTrustData.dwUnionChoice = WTD_CHOICE_FILE;
 
    // Verify action.
    WinTrustData.dwStateAction = WTD_STATEACTION_VERIFY;
 
    // Verification sets this value.
    WinTrustData.hWVTStateData = NULL;
 
    // Not used.
    WinTrustData.pwszURLReference = NULL;
 
    // This is not applicable if there is no UI because it changes
    // the UI to accommodate running applications instead of
    // installing applications.
    WinTrustData.dwUIContext = 0;
 
    // Set pFile.
    WinTrustData.pFile = &FileData;
 
    // 当前操作是要验证签名,后面还需要调用一次关闭去释放从此次验证操作中得到的放在trustData中的数据
    // PS: 微软为啥老喜欢同一个接口换个flag就变成完全不同的功能,感觉用个FreeWinVerifyTrustedData之类的不好嘛。。(微软:你在教我做事?) -_-
    // WinVerifyTrust verifies signatures as specified by the GUID
    // and Wintrust_Data.
    lStatus = WinVerifyTrust(
        NULL,
        &WVTPolicyGUID,
        &WinTrustData);
 
    switch (lStatus)
    {
    case ERROR_SUCCESS:
        /*
        Signed file:
            - Hash that represents the subject is trusted.
            - Trusted publisher without any verification errors.
            - UI was disabled in dwUIChoice. No publisher or
                time stamp chain errors.
            - UI was enabled in dwUIChoice and the user clicked
                "Yes" when asked to install and run the signed
                subject.
        */
        // 只是验证了签名有效,但是到底是不是预期的签名者进行的签名还不确定, 可以进一步验证
        wprintf_s(L"The file "%s" is signed and the signature "
            L"was verified.n",
            pwszSourceFile);
        return 1;
        break;
 
    case TRUST_E_NOSIGNATURE:
        // The file was not signed or had a signature
        // that was not valid.
 
        // Get the reason for no signature.
        dwLastError = GetLastError();
        if (TRUST_E_NOSIGNATURE == dwLastError ||
            TRUST_E_SUBJECT_FORM_UNKNOWN == dwLastError ||
            TRUST_E_PROVIDER_UNKNOWN == dwLastError)
        {
            // The file was not signed.
            wprintf_s(L"The file "%s" is not signed.n",
                pwszSourceFile);
            return 0;
        }
        else
        {
            // The signature was not valid or there was an error
            // opening the file.
            wprintf_s(L"An unknown error occurred trying to "
                L"verify the signature of the "%s" file.n",
                pwszSourceFile);
            return 0;//无签名
        }
 
        break;
 
    case TRUST_E_EXPLICIT_DISTRUST:
        // The hash that represents the subject or the publisher
        // is not allowed by the admin or user.
        wprintf_s(L"The signature is present, but specifically "
            L"disallowed.n");
        return 0;//无效签名
        break;
 
    case TRUST_E_SUBJECT_NOT_TRUSTED:
        // The user clicked "No" when asked to install and run.
        wprintf_s(L"The signature is present, but not "
            L"trusted.n");
        return -1;
        break;
 
    case CRYPT_E_SECURITY_SETTINGS:
        /*
        The hash that represents the subject or the publisher
        was not explicitly trusted by the admin and the
        admin policy has disabled user trust. No signature,
        publisher or time stamp errors.
        */
        wprintf_s(L"CRYPT_E_SECURITY_SETTINGS - The hash "
            L"representing the subject or the publisher wasn't "
            L"explicitly trusted by the admin and admin policy "
            L"has disabled user trust. No signature, publisher "
            L"or timestamp errors.n");
        return -1;
        break;
 
    default:
        // The UI was disabled in dwUIChoice or the admin policy
        // has disabled user trust. lStatus contains the
        // publisher or time stamp chain error.
        wprintf_s(L"Error is: 0x%x.n",
            lStatus);
        return -1;
        break;
    }
 
    // 设置flag为CLOSE, 然后释放掉上面申请出来的内存。。
    // Any hWVTStateData must be released by a call with close.
    WinTrustData.dwStateAction = WTD_STATEACTION_CLOSE;
 
    lStatus = WinVerifyTrust(
        NULL,
        &WVTPolicyGUID,
        &WinTrustData);
 
    //return true;
}

VerifyEmbeddedSignature(文件路径) 如果返回1 则合法 如果其他 则不合法

3.是否联网

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
bool IsProcessCommunicating(DWORD processId) {
    MIB_TCPTABLE_OWNER_PID* pTcpTable;
    DWORD dwSize = 0;
    DWORD dwRetVal = 0;
 
    pTcpTable = (MIB_TCPTABLE_OWNER_PID*)malloc(sizeof(MIB_TCPTABLE_OWNER_PID));
    if (pTcpTable == NULL) {
        std::cout << "Error allocating memory." << std::endl;
        return false;
    }
 
    dwRetVal = GetExtendedTcpTable(pTcpTable, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0);
    if (dwRetVal != ERROR_INSUFFICIENT_BUFFER) {
        free(pTcpTable);
        std::cout << "Error getting extended TCP table." << std::endl;
        return false;
    }
 
    pTcpTable = (MIB_TCPTABLE_OWNER_PID*)malloc(dwSize);
    if (pTcpTable == NULL) {
        std::cout << "Error allocating memory." << std::endl;
        return false;
    }
 
    dwRetVal = GetExtendedTcpTable(pTcpTable, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0);
    if (dwRetVal == NO_ERROR) {
        for (DWORD i = 0; i < pTcpTable->dwNumEntries; i++) {
            if (pTcpTable->table[i].dwOwningPid == processId) {
                free(pTcpTable);
                return true;
            }
        }
    }
    else {
        std::cout << "Error getting extended TCP table." << std::endl;
    }
 
    free(pTcpTable);
    return false;
}

IsProcessCommunicating(进程PID)
如果返回True 则联网
如果为False 则没联网
仅仅是判断了TCP(如果是纯UDP或者纯HTTP可能检测不到)

接下来是一个简单的Method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
LPCWSTR GetProcessPath(DWORD processId) {
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
    static wchar_t szProcessPath[MAX_PATH];
 
    if (hProcess != nullptr) {
        DWORD size = sizeof(szProcessPath) / sizeof(szProcessPath[0]);
 
        if (GetModuleFileNameEx(hProcess, nullptr, szProcessPath, size) != 0) {
            CloseHandle(hProcess);
            return szProcessPath;
        }
        else {
            std::wcerr << L"无法获取进程路径。错误码: " << GetLastError() << std::endl;
        }
 
        CloseHandle(hProcess);
    }
    else {
        std::wcerr << L"无法打开指定进程。错误码: " << GetLastError() << std::endl;
    }
 
    return nullptr;
}

接下来的工作就很简单了
遍历进程然后判断就好
也可以用Event Trace For Windows(ProcessMon判断新进程是否为远控木马)

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
void test(DWORD PID, std::vector<DWORD>& abnormalProcesses) {
    bool = false; bool = false; bool = false;
 
    if (Is_Has_Window(PID) == 1) {//窗口
        = true;
        = true;
        = true;
    }
    if (VerifyEmbeddedSignature(GetProcessPath(PID)) != 0) {//签名
        = true;
        = true;
        = true;
    }
    if (IsProcessCommunicating(PID) == 0) {//联网
        = true;
    }
    cout << a << b << c << endl;
    if (!(a && b && c)) {
        abnormalProcesses.push_back(PID);
 
    }
}
 
 
int main() {
    DWORD processes[1024], cbNeeded, cProcesses;
    std::vector<DWORD> abnormalProcesses;
    if (EnumProcesses(processes, sizeof(processes), &cbNeeded)) {
        cProcesses = cbNeeded / sizeof(DWORD);
        for (DWORD i = 0; i < cProcesses; i++) {
            test(processes[i], abnormalProcesses);
        }
        system("cls");
        std::cout << "不正常的进程:" << std::endl;
        for (DWORD PID : abnormalProcesses) {
            std::cout << PID;
            std::wcout << "    " << GetProcessPath(PID) << endl;
        }
    }
    else {
        std::cout << "无法枚举进程。错误码: " << GetLastError() << std::endl;
    }
 
    system("pause");
    return 0;
}

一个通用的简单反远控技术

这个方法误报是有点高的
但是确实有效
可以接入ViursTotal来判断是否为白文件
或者直接过滤System目录

要Anti这个技术也很简单
任意断一项(签名 窗口 联网)

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

注:在使用本系统时,使用方必须在国家相关法律法规范围内并经过国家相关部门的授权许可,禁止用于一切非法行为。使用用途仅限于测试、实验、研究为目的,禁止用于一切商业运营,本团队不承担使用者在使用过程中的任何违法行为负责。

83源码 技术教程 一个通用的简单反远控技术 https://www.83ym.com/172.html

认准唯一TG:@ym830

常见问题
  • 站内所有资源,针对不同等级VIP会员可直接下载,特殊资源商品会注明是否免费,指会员所享有根据选择购买的会员选项所享有的特殊服务,具体以本站公布的服务内容为准。
查看详情
  • 按照我国的法律规定,运营网络棋牌首先需要成立一个注册正规备案的公司,然后申请网站备案、文网文、ICP等等,这些证件缺一不可。 一.注册公司 在当地工商进行注册,公司名称以“XX科技有限公司”为名,如:富裕棋牌经营范围填写“计算机软硬件、网络设备的设计开发与购销”。 二.域名及网站备案 在国内从事网站经营活动就必须经过相关部门的备案,因此棋牌运营商在购买了域名后,就要到当地网监局办理网站备案,或者请服务器提供商代为备案。 三.申请文网文 文网文全称为网络文化经营许可证,是从事经营性互联网文化活动所必需的资质。一般是需要到当地省一级(省、直辖市、自治区)的文化行政部门提出申请,并经由当地的文化行政部门合法批准。次资质要求申请公司注册资金必需达到1000万,并提供游戏版权证明文件。 四.申请ICP ICP又称为增值电信业务许可证,所有网络游戏运营商均需要办理ICP许可证,此证件要求公司注册资金1000万,需到当地市级通讯管理局办理。 五.申请文网游——游戏备案 根据《网络游戏管理暂行办法》(文化部第49号)的规定,国产网络游戏在上网运营之日起30日内应当按规定向国务院文化行政部门履行备案手续。 以上就是网络棋牌游戏正规运营所必需的资质证明。一般作为正规有实力的棋牌游戏开发公司,不光要具备所有的正规资质,而且会对投资者、代理商等合作伙伴给予相关指导和协助,与合作伙伴携手共赢!
查看详情

相关文章

猜你喜欢
官方客服团队

为您解决烦忧 - 24小时在线 专业服务