principles for secure implementation
play

Principles for secure implementation Some of the slides and - PowerPoint PPT Presentation

Principles for secure implementation Some of the slides and content are from Mike Hicks Coursera course Trusted computing bases Every system has a TCB Your reference monitor Compiler OS CPU Memory Keyboard..


  1. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) -

  2. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) - • Possible attack goals

  3. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) - • Possible attack goals Steal or corrupt resources (e.g., files, malware) -

  4. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) - • Possible attack goals Steal or corrupt resources (e.g., files, malware) - Remote code injection -

  5. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) - • Possible attack goals Steal or corrupt resources (e.g., files, malware) - Remote code injection - • Circumstances:

  6. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) - • Possible attack goals Steal or corrupt resources (e.g., files, malware) - Remote code injection - • Circumstances: Client attacks server -

  7. VSFTPD Threat model Clients untrusted, until authenticated • • Once authenticated, limited trust: According to user’s file access control policy - For the files being served FTP (and not others) - • Possible attack goals Steal or corrupt resources (e.g., files, malware) - Remote code injection - • Circumstances: Client attacks server - Client attacks another client -

  8. Defense: Secure Strings struct mystr { char* PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; };

  9. Defense: Secure Strings struct mystr { char* PRIVATE_HANDS_OFF_p_buf; char* PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; }; Normal (zero-terminated) C string

  10. Defense: Secure Strings struct mystr { char* PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; }; Normal (zero-terminated) C string The actual length (i.e., strlen(PRIVATE_HANDS_OFF_p_buf) )

  11. Defense: Secure Strings struct mystr { char* PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; }; Normal (zero-terminated) C string The actual length (i.e., strlen(PRIVATE_HANDS_OFF_p_buf) ) Size of buffer returned by malloc

  12. Defense: Secure Strings struct mystr { char* PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; }; Normal (zero-terminated) C string The actual length (i.e., strlen(PRIVATE_HANDS_OFF_p_buf) ) Size of buffer returned by malloc

  13. void private_str_alloc_memchunk( struct mystr* p_str, const char* p_src, unsigned int len) { struct mystr … { } char* p_buf; unsigned int len; unsigned int alloc_bytes; }; void str_copy( struct mystr* p_dest, const struct mystr* p_src) { private_str_alloc_memchunk(p_dest, p_src->p_buf, p_src->len); } replace uses of char* with struct mystr* and uses of strcpy with str_copy

  14. void private_str_alloc_memchunk( struct mystr* p_str, const char* p_src, unsigned int len) { struct mystr /* Make sure this will fit in the buffer */ { unsigned int buf_needed; char* p_buf; if (len + 1 < len) unsigned int len; { unsigned int alloc_bytes; bug("integer overflow"); }; } Copy in at most len buf_needed = len + 1; if (buf_needed > p_str->alloc_bytes) bytes from p_src { into p_str str_free(p_str); s_setbuf(p_str, vsf_sysutil_malloc(buf_needed)); p_str->alloc_bytes = buf_needed; } vsf_sysutil_memcpy(p_str->p_buf, p_src, len); p_str->p_buf[len] = '\0'; p_str->len = len; }

  15. void private_str_alloc_memchunk( struct mystr* p_str, const char* p_src, unsigned int len) { struct mystr /* Make sure this will fit in the buffer */ { unsigned int buf_needed; char* p_buf; if (len + 1 < len) consider NUL unsigned int len; { terminator when unsigned int alloc_bytes; bug("integer overflow"); computing space }; } Copy in at most len buf_needed = len + 1; if (buf_needed > p_str->alloc_bytes) bytes from p_src { into p_str str_free(p_str); s_setbuf(p_str, vsf_sysutil_malloc(buf_needed)); p_str->alloc_bytes = buf_needed; } vsf_sysutil_memcpy(p_str->p_buf, p_src, len); p_str->p_buf[len] = '\0'; p_str->len = len; }

  16. void private_str_alloc_memchunk( struct mystr* p_str, const char* p_src, unsigned int len) { struct mystr /* Make sure this will fit in the buffer */ { unsigned int buf_needed; char* p_buf; if (len + 1 < len) consider NUL unsigned int len; { terminator when unsigned int alloc_bytes; bug("integer overflow"); computing space }; } Copy in at most len buf_needed = len + 1; if (buf_needed > p_str->alloc_bytes) allocate space, bytes from p_src { if needed into p_str str_free(p_str); s_setbuf(p_str, vsf_sysutil_malloc(buf_needed)); p_str->alloc_bytes = buf_needed; } vsf_sysutil_memcpy(p_str->p_buf, p_src, len); p_str->p_buf[len] = '\0'; p_str->len = len; }

  17. void private_str_alloc_memchunk( struct mystr* p_str, const char* p_src, unsigned int len) { struct mystr /* Make sure this will fit in the buffer */ { unsigned int buf_needed; char* p_buf; if (len + 1 < len) consider NUL unsigned int len; { terminator when unsigned int alloc_bytes; bug("integer overflow"); computing space }; } Copy in at most len buf_needed = len + 1; if (buf_needed > p_str->alloc_bytes) allocate space, bytes from p_src { if needed into p_str str_free(p_str); s_setbuf(p_str, vsf_sysutil_malloc(buf_needed)); p_str->alloc_bytes = buf_needed; } vsf_sysutil_memcpy(p_str->p_buf, p_src, len); copy in p_src p_str->p_buf[len] = '\0'; contents p_str->len = len; }

  18. Defense: Secure Stdcalls • Common problem: error handling

  19. Defense: Secure Stdcalls • Common problem: error handling • Libraries assume that arguments are well-formed

  20. Defense: Secure Stdcalls • Common problem: error handling • Libraries assume that arguments are well-formed • Clients assume that library calls always succeed

  21. Defense: Secure Stdcalls • Common problem: error handling • Libraries assume that arguments are well-formed • Clients assume that library calls always succeed • Example: malloc()

  22. Defense: Secure Stdcalls • Common problem: error handling • Libraries assume that arguments are well-formed • Clients assume that library calls always succeed • Example: malloc() • What if argument is non-positive? We saw earlier that integer overflows can induce this behavior - Leads to buffer overruns -

  23. Defense: Secure Stdcalls • Common problem: error handling • Libraries assume that arguments are well-formed • Clients assume that library calls always succeed • Example: malloc() • What if argument is non-positive? We saw earlier that integer overflows can induce this behavior - Leads to buffer overruns - • What if returned value is NULL? Oftentimes, a deference means a crash - On platforms without memory protection, a dereference can cause - corruption

  24. void* vsf_sysutil_malloc(unsigned int size) { void* p_ret; /* Paranoia - what if we got an integer overflow/underflow? */ if (size == 0 || size > INT_MAX) { bug("zero or big size in vsf_sysutil_malloc"); } p_ret = malloc(size); if (p_ret == NULL) { die("malloc"); } return p_ret; }

  25. fails if it receives malformed void* argument or runs vsf_sysutil_malloc(unsigned int size) out of memory { void* p_ret; /* Paranoia - what if we got an integer overflow/underflow? */ if (size == 0 || size > INT_MAX) { bug("zero or big size in vsf_sysutil_malloc"); } p_ret = malloc(size); if (p_ret == NULL) { die("malloc"); } return p_ret; }

  26. Defense: Minimal Privilege

  27. Defense: Minimal Privilege • Untrusted input always handled by non- root process • Uses IPC to delegate high-privilege actions Very little code runs as root -

  28. Defense: Minimal Privilege • Untrusted input always handled by non- root process • Uses IPC to delegate high-privilege actions Very little code runs as root - • Reduce privileges as much as possible • Run as particular (unprivileged) user File system access control enforced by OS - • Use capabilities and/or SecComp on Linux Reduces the system calls a process can make -

  29. Defense: Minimal Privilege • Untrusted input always handled by non- root process • Uses IPC to delegate high-privilege actions Very little code runs as root - • Reduce privileges as much as possible • Run as particular (unprivileged) user File system access control enforced by OS - • Use capabilities and/or SecComp on Linux Reduces the system calls a process can make - • chroot to hide all directories but the current one • Keeps visible only those files served by FTP

  30. Defense: Minimal Privilege • Untrusted input always handled by non- root process • Uses IPC to delegate high-privilege actions Very little code runs as root - • Reduce privileges as much as possible principle • Run as particular (unprivileged) user of File system access control enforced by OS - least • Use capabilities and/or SecComp on Linux privilege Reduces the system calls a process can make - • chroot to hide all directories but the current one • Keeps visible only those files served by FTP

  31. Defense: Minimal Privilege • Untrusted input always handled by non- root process • Uses IPC to delegate high-privilege actions Very little code runs as root small - trusted computing • Reduce privileges as much as possible principle base • Run as particular (unprivileged) user of File system access control enforced by OS - least • Use capabilities and/or SecComp on Linux privilege Reduces the system calls a process can make - • chroot to hide all directories but the current one • Keeps visible only those files served by FTP

  32. Connection Establishment connection server client

  33. Connection Establishment connection server T C P c o n n r e q u e s t client

  34. Connection Establishment command connection processor server client

  35. Connection Establishment command connection processor server login client reader

  36. Connection Establishment command connection processor server U+P OK OK login client reader USER, PASS

  37. Connection Establishment command connection processor server command client reader/ executor

  38. Performing Commands connection command server processor command client reader/ executor

  39. Performing Commands connection command server processor OK command client reader/ CHDIR executor

  40. Performing Commands connection command server processor CHOWN OK OK command client reader/ CHOWN executor

  41. Logging out connection command server processor command client reader/ executor

  42. Logging out connection server client

  43. Attack: Login connection command server processor login client reader

  44. Attack: Login connection command server processor login client reader ATTACK

  45. Attack: Login • Login reader white-lists input • And allowed input very limited • Limits attack surface connection command server processor login client reader ATTACK

  46. Attack: Login • Login reader white-lists input • And allowed input very limited • Limits attack surface connection command • Login reader has limited privilege server processor • Not root; authentication in separate process • Mutes capabilities of injected code login client reader ATTACK

  47. Attack: Login • Login reader white-lists input • And allowed input very limited • Limits attack surface connection command • Login reader has limited privilege server processor • Not root; authentication in separate process • Mutes capabilities of injected code • Comm. proc. only talks to reader • And, again, white-lists its limited input X login client reader ATTACK

  48. Attack: Commands connection command server processor command client reader/ executor

  49. Attack: Commands connection command server processor command client reader/ ATTACK executor

  50. Attack: Commands • Command reader sandboxed • Not root • Handles most commands connection command • Except few requiring privilege server processor command client reader/ ATTACK executor

  51. Attack: Commands • Command reader sandboxed • Not root • Handles most commands connection command • Except few requiring privilege server processor • Comm. proc. only talks to reader • And, again, white-lists its limited input CHOWN OK X command client reader/ ATTACK executor

  52. Attack: Cross-session connection server client 1 client 2

  53. Attack: Cross-session connection command command server processor client 1 reader/ executor client 2

  54. Attack: Cross-session connection command command server processor client 1 reader/ executor command command processor client 2 reader/ executor

  55. Attack: Cross-session connection command command server processor client 1 reader/ executor command command processor client 2 reader/ executor

  56. Attack: Cross-session connection command command server processor client 1 reader/ CMD executor command command processor client 2 reader/ CMD executor

  57. Attack: Cross-session connection command command server processor client 1 reader/ CMD executor ATTACK • Each session isolated X • Only can talk to one client command command processor client 2 reader/ CMD executor

  58. Separation of responsibilities

  59. Separation of responsibilities

  60. Separation of responsibilities

  61. Separation of responsibilities TCB: KISS

  62. Separation of responsibilities TCB: KISS

  63. Separation of responsibilities TCB: KISS

Recommend


More recommend