-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
82 lines (63 loc) · 1.68 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
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
void print_date();
/*
Message format in bytes:
0 1 2 3 n
+----+----+----+-- ... --+
| ps | payload |
+----+----+----+-- ... --+
ps = payload size
*/
void parse_message(int socketfd)
{
char payload[32] = {0};
unsigned char ps;
read(socketfd, &ps, 1);
read(socketfd, payload, ps); // <-- buffer overflow if ps > 32
print_date();
printf("%s\n\n", payload);
}
void print_date()
{
system("date");
}
void start()
{
int listenfd = 0, connfd = 0;
struct sockaddr_in serv_addr;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(1337);
if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
perror("Could not bind socket");
exit(EXIT_FAILURE);
}
listen(listenfd, 10);
while (1)
{
connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
parse_message(connfd);
close(connfd);
}
}
int main(int argc, char *argv[])
{
printf("\nWelcome to the ROP playground!\n\n");
printf("Process ID: %i\n", getpid());
extern uintptr_t __stack_chk_guard;
printf("__stack_chk_guard: 0x%lx\n", __stack_chk_guard);
uintptr_t print_date_no_aslr = 0x100000ce0;
printf("ASLR binary offset: +%p\n", &print_date - print_date_no_aslr);
printf("- print_date is at %p\n", &print_date);
printf("- system is at %p\n\n", &system);
start();
return 0;
}