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 83 84 85 86 87
| // gcc cred.c -o cred
// ./cred 30029089570
//
// rappels sur les pointeurs :
// &truc est l'adresse de truc
// ptruc = &truc, l'adresse en question.
// ptruc prend la même place qu'un entier, quel que soit
// le type de l'objet sur lequel il pointe.
// int *ptruc; // ici, il pointera sur un entier.
// int n=10; // n est un entier initialisé à 10.
// ptruc=&n; // ptruc pointe sur n.
// *ptruc+=5; // l'objet sur lequel pointe ptruc est augémenté de cinq.
// à partir d'ici, n vaut quinze.
//
// ps -o user,pid,addr,args -p $$
// (si $$ est le PID de la shell en cours)
//
// $ more /local/patch/Solaris/8_Recommended/108528-29/SUNWhea/reloc/usr/include/sys/proc.h
// [...]
// typedef struct proc {
// /*
// * Fields requiring no explicit locking
// */
// struct vnode *p_exec; /* pointer to a.out vnode */
// struct as *p_as; /* process adr_process space pointer */
// struct plock *p_lockp; /* ptr to proc struct's mutex lock */
// kmutex_t p_crlock; /* lock for p_cred */
// struct cred *p_cred; /* process credentials */
// [...]
//
// find / -name cred.h -print -exec echo {} \;
// $ more /usr/include/sys/cred.h
// [...]
// typedef struct cred {
// uint_t cr_ref; /* reference count */
// uid_t cr_uid; /* effective user id */
// gid_t cr_gid; /* effective group id */
// uid_t cr_ruid; /* real user id */
// gid_t cr_rgid; /* real group id */
// uid_t cr_suid; /* "saved" user id (from exec) */
// [...]
//
// From this it is apparent that the pointer to the credential structure is
// located 24 bytes into the proc struct. In the above example that means the
// pointer is at 0xf5e09000 + 0x18 = 0xf5e09018. The credential struct is
// listed in /usr/include/sys/cred.h. From this we note that the effective user
// id is 4 bytes into the cred structure.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "/local/patch/Solaris/8_Recommended/108528-29/SUNWhea/reloc/usr/include/sys/proc.h"
#include "/usr/include/sys/cred.h"
//
main(int argc, char *argv[])
{
int uid, adr_uid, *p_uid;
long long adr_sproc;
long long adr_scred;
struct proc st_proc;
struct cred st_cred;
printf("\n\tHello, cred !\n\n");
// $ ps -o user,pid,addr,args -p $$
printf("adr_sproc=%s (s)\n", argv[1]); // ceci est la chaine d'adresse de la stucture proc.
//
adr_sproc=strtoll(argv[1], &argv[1], 0);
printf("adr_sproc=%lld (lld)\n", adr_sproc); // ceci est l'adresse décimale la stucture proc.
printf("adr_sproc= %llx (llx)\n\n", adr_sproc); // ceci est l'adresse hexa de la stucture proc.
//
printf("&st_proc =%x\n\n", &st_proc); // ceci est l'adresse de st_proc. mais ???
printf("st_proc->*p_exec =%x\n", st_proc.p_exec);
printf("st_proc->*p_as =%x\n", st_proc.p_as);
printf("st_proc->*p_lockp=%x\n", st_proc.p_lockp);
printf("st_proc.p_crlock =%x\n", st_proc.p_crlock);
printf("st_proc->p_cred =%x\n\n", st_proc.p_cred); // ceci est le pointeur vers st_cred.
//
printf("&st_cred =%x\n\n", &st_cred); // ceci est l'adresse de st_cred. mais ???
printf("st_cred.cr_ref =%d\n", st_cred.cr_ref);
printf("st_cred.cr_uid =%d\n", st_cred.cr_uid);
printf("st_cred.cr_gid =%d\n", st_cred.cr_gid);
printf("st_cred.cr_ruid =%d\n", st_cred.cr_ruid);
printf("st_cred.cr_rgid =%d\n", st_cred.cr_rgid);
printf("st_cred.cr_suid =%d\n\n", st_cred.cr_suid);
}
//
// gcc cred.c -o cred
/* |
Partager