עבריינים שהתחברו למחשב מסויים גילו תוכנה בעלת הרשאות (s+). root התוכנה כתובה ב- והשיגו גישה לחלק מקוד המקור המופיע כאן. ידוע כי התוכנה רצה על מחשב linux שמכיל מעבד אינטל )ליטל אנדיאן - ביט(. במחשב מופעל :P אנא הימנעו מתשובות ארוכות עם מידע שאינו קריטי לתשובה לשאלה. הקפידו על מינימליות וכתב ברור. נא לקרוא ביסודיות כדי להימנע מטעויות שיגררו חוסר הבנה - קראו את כל השאלה ואז ענו. שימו לב כי יש פונקציות חסרות בקוד המודפס, אפשר לשער מה הן עושות אבל אין לכם מידע מדוייק. #define MX () typedef struct item_s int len; unsigned short data[mx ]; int (*numerical_value) (unsigned short *data); // This is a function pointer! item_t; item_t items[]; int n_items = -; void set_item_value(int index, unsigned short *_in_data, int _in_len) register int i = ; if (_in_len <= _in_len > MX ) return; items[index]->len = _in_len; for (i = ; i <= items[index]->len; i++) items[index]->data[i] = _in_data[i]; int default_numerical_evaluation(item_t *s) int i, sum = ; for (i = ; i <= s->len; i++) sum += s->data[i]; return sum; int create_new_item() register int index = get_unused_item(); if (index < ) return -; memset(&items[i],, sizeof(item_t)); items[i].numerical_value = (void *) default_numerical_evaluation; return i; void print_item_values(item_t *all, int n) register int i; for (i = ; i <= n; i++) register int tmp = all[i].numerical_value(all[i].data); printf("%d\n", tmp); void main_handler() int len = ; unsigned short *data = get_user_data(&len); int it = create_new_item(); set_item_value(it, data, len); print_item_values(items, n_items);
א. ב. ג. ד. ה. ו. וודאית זהו חולשה באחת הפונ', באיזה פונק' מדובר? ] נק' ] מנו את כל הקטגוריות שבהן אפשר לקטלג את החולשה: ] מילים לקטגוריה[? ] נק'[ off-by-one/privilege escalation/information leak/information disclosure/ set_item_value הציעו תיקון בשורה אחת, ציין אופציה אחת בלבד ] נק'[: ;[ + data[mx unsigned short בהנחה שהרצנו את החולשה עם ערכים שגויים בלבד, באיזו שורת קוד תקרוס התוכנה ] נק'[: ביכולתכם לשלוט ב- get_user_data. תנו דוגמאת קלט מקריס )ציינו את שמות המשתנים והערכים שלהם( ] נק'[: register int tmp = all[i].numerical_value(all[i].data); x ז. רשמו את מבנה המחסנית של הפונ' הקורסת בנק' הקריסה. בהנחה נאיבית ביותר שאין הגנות מכל סוג שהוא למעט P ומתוך הידע כפי שנראה בקוד. השתמשו בנוסח מינימלי ביותר )מהכתובות הגבוהות לנמוכות( ] נק' ] *תזכורת: הגדרת register על נותנת הנחיה לקומפיילר לא להקצות מקום על המחסנית ל הזה אלא לעבוד עם אוגר במקום שאינו מצריך שמירה. מלאו את הטור הימני בטבלה בלבד הטור השמאלי הוא רק דוגמא לצורה בה יש למלא את הטבלה Name: example_func HIGH R ret() Something(size) sample_buf() LOW R print_item_values HIGH R Ret() bp() Len() har *data() int it() n_items() items *[]() ret() bp() har *data () Ret() crash point. LOW R
לסעיפים הבאים יש להשתמש בטבלת כתובות הפונ' המצורפת בסוף השאלה. בנוסף יש להניח כי כל הפונ' רצות במהלך ריצה לאחר השמת הקלט הרלוונטי ח. ט. כמה שלבים נדרש על מנת לממש חולשה שמבצעת ] chmod s+ /tmp/a נק'[? רמז:( a,b printf( %$d, ידפיס את הערך של b )מסוג )int תאר את השלבים הנדרשים ] נק'[ תאר את השלב ה- x * c u n i q % $ x % $ x h m o d + s / t m p / a (addr To printf) תאר את השלב ה- )אם קיים(: x (addr To wcscpy) (addr to Item ) תאר את השלב ה- )אם קיים(:
תאר את השלב ה- )אם קיים(: י. רשום פסאודו קוד המשמיש את החולשה בהינתן השלבים, רשום באנגלית בפורמט פייתון [ נק'[, להלן, דוגמא: import os a = set_vuln_function_input(param,param) print a wait_for_shell(b) import subprocess process = subprocess.popen( vuln_app ) set_vuln_func_input(process, inpu_as_above, x) b= get_output_from_stdout (process) c = b[b.find( *uniq. ):].b.split(. )[]+(b.split(. )[]*sizeof_item) str_location = c.split(. )[]+(c.split(. )[]*sizeof_item)+x #location + _bytes_ set_vuln_func_input(input_as_above % (str_location_unpacked), x)
תיאור פונ' int printf(const char *format,...); The functions in the printf() family produce output according to a format as described below. The functions printf() and vprintf() write output to stdout, the standard output stream; fprintf() and vfprintf() write output to the given output stream; sprintf(), snprintf(), vsprintf() and vsnprintf() write to the character string str. void *malloc(size_t size); The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). void *memset(void *s, int c, size_t n); The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c. wchar_t *wcscpy(wchar_t *src, const wchar_t *dest); The wcscpy() function is the wide-character equivalent of the strcpy() function. It copies the wide-character string pointed to by src, including the terminating null wide character (L'\'), to the array pointed to by dest. void *memcpy(void *dest, const void *src, size_t n); default_numerical_evaluation create_new_item print_item_values set_item_value int system(const char *command); system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. uring execution of the command, SIGHL will be blocked, and SIGINT and SIGQUIT will be ignored. כתובת