Hacking - The Art of Exploitation, 2nd Edition
Programming 87 0x282 File Permissions If the O_CREAT flag is used in access mode for the open() function, an additional argument ...
88 0x200 reader@hacking:~/booksrc $ chmod 731 simplenote.c reader@hacking:~/booksrc $ ls -l simplenote.c -rwx-wx--x 1 reader rea ...
Programming 89 reader@hacking:~/booksrc $ sudo su jose jose@hacking:/home/reader/booksrc $ id uid=501(jose) gid=501(jose) groups ...
90 0x200 uid_demo.c #include <stdio.h> int main() { printf("real uid: %d\n", getuid()); printf("effective uid: %d\n", gete ...
Programming 91 This same technique can be used in a multiuser note-taking program. The next program will be a modification of th ...
92 0x200 } void fatal(char *); // A function for fatal errors void *ec_malloc(unsigned int); // An error-checked malloc() wrappe ...
Programming 93 reader@hacking:~/booksrc $ gcc -o notetaker notetaker.c reader@hacking:~/booksrc $ sudo chown root:root ./notetak ...
94 0x200 #define FILENAME "/var/notes" int print_notes(int, int, char *); // Note printing function. int find_user_note(int, int ...
Programming 95 if(read(fd, ¬e_uid, 4) != 4) // Read the uid data. return -1; // If 4 bytes aren't read, return end of fil ...
96 0x200 [DEBUG] found a 34 byte note for user id 999 this is a test of multiuser notes -------[ end of note data ]------- reade ...
Programming 97 A simple example will suffice for now. When dealing with many time functions, these functions use a time struct c ...
98 0x200 of current_time, an empty tm struct. The address-of operator is used to provide a pointer to seconds_since_epoch for th ...
Programming 99 printf("bytes of struct located at 0x%08x\n", time_ptr); raw_ptr = (unsigned char *) time_ptr; for(i=0; i < si ...
100 0x200 While struct memory can be accessed this way, assumptions are made about the type of variables in the struct and the l ...
Programming 101 function_ptr is 0x0804838d This is function two value returned was 2 reader@hacking:~/booksrc $ 0x286 Pseudo-ran ...
102 0x200 815015288 1315541117 2080969327 450538726 710528035 907694519 1525415338 1843056422 random values from 1 to 20 2 3 8 5 ...
Programming 103 game_of_chance.c include <stdio.h> include <string.h> include <fcntl.h> include <sys/stat.h ...
104 0x200 printf("6 - Reset your account at 100 credits\n"); printf("7 - Quit\n"); printf("[Name: %s]\n", player.name); printf(" ...
Programming 105 return -1; else player = entry; // Copy the read entry into the player struct. return 1; // Return a success. } ...
106 0x200 int fd; printf("\n====================| HIGH SCORE |====================\n"); fd = open(DATAFILE, O_RDONLY); if(fd == ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf