{"id":343694,"date":"2023-01-09T15:02:18","date_gmt":"2023-01-09T15:02:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343694"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343694","title":{"rendered":"<span>\u041f\u043e\u0432\u044b\u0448\u0430\u0439\u0442\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FORTIFY_SOURCE<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u0430\u043a\u0440\u043e\u0441 FORTIFY_SOURCE \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0444\u0435\u0440\u0430 (buffer overflows) \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438. \u041d\u0435 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0444\u0435\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043a\u0440\u043e\u0441\u0430, \u043d\u043e \u043e\u043d \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 buffer overflow. \u041e\u043d \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043a\u0430\u043a C, \u0442\u0430\u043a \u0438 C++ \u043a\u043e\u0434\u0430. FORTIFY_SOURCE \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0432 \u043c\u0435\u0441\u0442\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u0443\u0444\u0435\u0440, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>*** buffer overflow detected ***: .\/foobar terminated ======= Backtrace: ========= \/lib64\/libc.so.6[0x382d875cff] \/lib64\/libc.so.6(__fortify_fail+0x37)[0x382d906b17] ...<\/code><\/pre>\n<p>FORTIFY_SOURCE \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code>memcpy, mempcpy, memmove, memset, strcpy, stpcpy, strncpy, strcat,  strncat, sprintf, vsprintf, snprintf, vsnprintf, gets.<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 Feature Test Macros (man feature_test_macros) \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f:<\/p>\n<p>\u0415\u0441\u043b\u0438 _FORTIFY_SOURCE \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 1, \u0442\u043e \u043f\u0440\u0438 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 1 (gcc -O1) \u0438 \u0432\u044b\u0448\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.\u00a0 \u041f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 _FORTIFY_SOURCE \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 2 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0434\u0430\u0442\u044c \u0441\u0431\u043e\u0439.\u00a0 \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430; \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0430, \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430.\u00a0 \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u043a\u0440\u043e\u0441, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430\u044f \u0432 gcc(1) \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 4.0.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code>\/\/ fortify_test.c #include&lt;stdio.h>  \/* Commenting out or not using the string.h header will cause this  * program to use the unprotected strcpy function.  *\/ \/\/#include&lt;string.h>  int main(int argc, char **argv) { char buffer[5]; printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); strcpy(buffer,argv[1]); printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); }<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f FORTIFY_SOURCE (-D_FORTIFY_SOURCE) \u0438 \u0444\u043b\u0430\u0433\u043e\u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 (-g -02) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code>~]$ gcc -D_FORTIFY_SOURCE=1 -Wall -g -O2 fortify_test.c \\     -o fortify_test<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0444\u0435\u0440\u0430 \u043d\u0438\u043a\u0430\u043a\u0430\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code>~]$ objdump -d .\/fortify_test 0000000000400440 : 400440:  48 83 ec 18             sub $0x18,%rsp 400444:  ba 05 00 00 00          mov $0x5,%edx 400449:  bf 10 06 40 00          mov $0x400610,%edi 40044e:  48 89 e6                mov %rsp,%rsi 400451:  31 c0                   xor %eax,%eax 400453:  e8 b8 ff ff ff          callq 400410 400458:  48 b8 64 65 61 64 62    movabs $0x6665656264616564,%rax 40045f:  65 65 66 400462:  48 89 e6                mov %rsp,%rsi 400465:  ba 05 00 00 00          mov $0x5,%edx 40046a:  48 89 04 24             mov %rax,(%rsp) 40046e:  bf 10 06 40 00          mov $0x400610,%edi 400473:  31 c0                   xor %eax,%eax 400475:  c6 44 24 08 00          movb $0x0,0x8(%rsp) 40047a:  e8 91 ff ff ff          callq 400410 40047f:  31 c0                   xor %eax,%eax 400481:  48 83 c4 18             add $0x18,%rsp 400485:  c3                      retq 400486:  66 90                   xchg %ax,%ax<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u0437\u044a\u044f\u043d \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435. \u041f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0438\u043c\u0432\u043e\u043b &#8216;A&#8217;, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 &#8216;\\x41&#8217;) \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 RAX:<\/p>\n<pre><code>$ gdb -q .\/fortify_test Reading symbols from \/home\/sid\/security\/fortify\/fortify_test...done.  (gdb) br 8 Breakpoint 1 at 0x4004b8: file fortify_test.c, line 8.  (gdb) r $(python -c 'print \"\\x41\" * 360') Starting program: \/home\/sid\/security\/fortify\/fortify_test \\  $(python -c 'print \"\\x41\" * 360')  Buffer Contains: \ufffd\ufffd\ufffd\ufffd\ufffd , Size Of Buffer is 5 Breakpoint 1, main (argc=, argv=0x7fffffffd788) at fortify_test.c:8 8 printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",buffer, sizeof(buffer));  (gdb) i r rax 0x7fffffffd690 140737488344720 rbx 0x7fffffffd788 140737488344968 rcx 0x4141414141414141 4702111234474983745 rdx 0x41 65 rsi 0x7fffffffdd40 140737488346432 rdi 0x7fffffffd7ef 140737488345071 rbp 0x0 0x0 rsp 0x7fffffffd690 0x7fffffffd690 r8 0x2d 45 r9 0x0 0 r10 0x7fffffffd450 140737488344144 r11 0x382d974c60 241283058784 r12 0x4004d4 4195540 r13 0x7fffffffd780 140737488344960 r14 0x0 0 r15 0x0 0 rip 0x4004b8 0x4004b8 eflags 0x206 [ PF IF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0  (gdb) x \/100x $rax 0x7fffffffd690: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd6a0: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd6b0: 0x41414141 0x41414141 0x41414141 0x41414141 ... 0x7fffffffd7d0: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd7e0: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd7f0: 0x41414141 0x41414141 0xffffde00 0x00007fff 0x7fffffffd800: 0xffffde6a 0x00007fff 0xffffde85 0x00007fff 0x7fffffffd810: 0xffffde93 0x00007fff 0xffffdeae 0x00007fff<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 string.h \u0432 \u043d\u0430\u0448\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e strcpy \u0441\u0442\u0440\u043e\u043a\u0443, \u0434\u043b\u0438\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430:<\/p>\n<pre><code>\/\/ fortify_test.c #include&lt;stdio.h> #include&lt;string.h>  int main(int argc, char **argv) { char buffer[5]; printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); \/\/ Here the compiler the length of string to be copied strcpy(buffer,\"deadbeef\"); printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f FORTIFY_SOURCE \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u043b\u0430\u0433 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0441\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0431\u0435\u0437\u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 buffer:<\/p>\n<pre><code>~]$ gcc -D_FORTIFY_SOURCE=1 -Wall -g -O2 fortify_test.c \\  -o fortify_test  In file included from \/usr\/include\/string.h:636:0, from fortify_test.c:2: In function \u2018strcpy\u2019, inlined from \u2018main\u2019 at fortify_test.c:7:8: \/usr\/include\/bits\/string3.h:104:3: warning: call to  __builtin___memcpy_chk will always overflow destination buffer  [enabled by default] return __builtin___strcpy_chk (__dest, __src, __bos (__dest)); ^<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u044b\u0437\u043e\u0432 <code>&lt;__memcpy_chk@plt><\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430:<\/p>\n<pre><code>~]$ objdump -d .\/fortify_test ... 00000000004004b0 : 4004b0:       48 83 ec 18             sub    $0x18,%rsp 4004b4:       ba 05 00 00 00          mov    $0x5,%edx 4004b9:       bf 80 06 40 00          mov    $0x400680,%edi 4004be:       48 89 e6                mov    %rsp,%rsi 4004c1:       31 c0                   xor    %eax,%eax 4004c3:       e8 a8 ff ff ff          callq  400470 &lt;printf@plt> 4004c8:       48 89 e7                mov    %rsp,%rdi 4004cb:       b9 05 00 00 00          mov    $0x5,%ecx 4004d0:       ba 09 00 00 00          mov    $0x9,%edx 4004d5:       be b0 06 40 00          mov    $0x4006b0,%esi 4004da:       e8 b1 ff ff ff          callq  400490&lt;__memcpy_chk@plt>  4004df:       48 89 e6                mov    %rsp,%rsi 4004e2:       ba 05 00 00 00          mov    $0x5,%edx 4004e7:       bf 80 06 40 00          mov    $0x400680,%edi 4004ec:       31 c0                   xor    %eax,%eax 4004ee:       e8 7d ff ff ff          callq  400470 &lt;printf@plt> 4004f3:       31 c0                   xor    %eax,%eax 4004f5:       48 83 c4 18             add    $0x18,%rsp 4004f9:       c3                      retq    4004fa:       66 90                   xchg   %ax,%ax ... <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f strcpy \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u0442\u043e \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439:<\/p>\n<pre><code>\/\/ fortify_test.c #include&lt;stdio.h> #include&lt;string.h>  int main(int argc, char **argv) { char buffer[5]; printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer));  \/\/ String length is determined at runtime strcpy(buffer,argv[1]); printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); }<\/code><\/pre>\n<pre><code>~]$ gcc -D_FORTIFY_SOURCE=1 -Wall -g -O2 fortify_test.c \\      -o fortify_test ~]$<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 FORTIFY_SOURCE \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0438\u0437 argv[1], \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0432\u044b\u0434\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u043e \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0431\u0443\u0444\u0435\u0440\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0440\u0432\u0430\u043d\u0430:<\/p>\n<pre><code>~]$ .\/fortify_test $(python -c 'print \"\\x41\" * 360') Buffer Contains: \ufffdQ\ufffd\ufffd\ufffd , Size Of Buffer is 5 *** buffer overflow detected ***: .\/fortify_test terminated ======= Backtrace: ========= \/lib64\/libc.so.6[0x382d875cff] \/lib64\/libc.so.6(__fortify_fail+0x37)[0x382d906b17] \/lib64\/libc.so.6[0x382d904d00] .\/fortify_test[0x4004dd] \/lib64\/libc.so.6(__libc_start_main+0xf5)[0x382d821d65] .\/fortify_test[0x400525] ======= Memory map: ======== 00400000-00401000 r-xp 00000000 fd:05 9967292 \/home\/sid\/security\/ \\ fortify\/fortify_test 00600000-00601000 r--p 00000000 fd:05 9967292 \/home\/sid\/security\/ \\ fortify\/fortify_test 00601000-00602000 rw-p 00001000 fd:05 9967292 \/home\/sid\/security\/ \\ fortify\/fortify_test 013ee000-0140f000 rw-p 00000000 00:00 0 [heap] 382d400000-382d420000 r-xp 00000000 fd:03 922951 \/usr\/lib64\/ld-2.18.so 382d61f000-382d620000 r--p 0001f000 fd:03 922951 \/usr\/lib64\/ld-2.18.so 382d620000-382d621000 rw-p 00020000 fd:03 922951 \/usr\/lib64\/ld-2.18.so 382d621000-382d622000 rw-p 00000000 00:00 0 382d800000-382d9b4000 r-xp 00000000 fd:03 928040 \/usr\/lib64\/ \\ libc-2.18.so 382d9b4000-382dbb4000 ---p 001b4000 fd:03 928040 \/usr\/lib64\/ \\ libc-2.18.so 382dbb4000-382dbb8000 r--p 001b4000 fd:03 928040 \/usr\/lib64\/ \\ libc-2.18.so 382dbb8000-382dbba000 rw-p 001b8000 fd:03 928040 \/usr\/lib64\/ \\ libc-2.18.so 382dbba000-382dbbf000 rw-p 00000000 00:00 0 382f800000-382f815000 r-xp 00000000 fd:03 928048 \/usr\/lib64\/ \\ libgcc_s-4.8.2-20131212.so.1 382f815000-382fa14000 ---p 00015000 fd:03 928048 \/usr\/lib64\/ \\ libgcc_s-4.8.2-20131212.so.1 382fa14000-382fa15000 r--p 00014000 fd:03 928048 \/usr\/lib64\/ \\ libgcc_s-4.8.2-20131212.so.1 382fa15000-382fa16000 rw-p 00015000 fd:03 928048 \/usr\/lib64\/ \\ libgcc_s-4.8.2-20131212.so.1 7ffb727a5000-7ffb727a8000 rw-p 00000000 00:00 0 7ffb727cc000-7ffb727cf000 rw-p 00000000 00:00 0 7fffa1945000-7fffa1967000 rw-p 00000000 00:00 0 [stack] 7fffa19fe000-7fffa1a00000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Aborted<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435: \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FORTIFY_SOURCE. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0438\u0445 \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0438\u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043e\u043f\u0446\u0438\u044e -D_FORTIFY_SOURCE \u0438 \u0444\u043b\u0430\u0433\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0440\u0430\u0432\u043d\u044b\u0435 1 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435. \u0422\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043b\u043e\u0433 \u0444\u0430\u0439\u043b\u044b \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0438, \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 FORTIFY_SOURCE.<\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e FORTIFY_SOURCE \u0441\u043c. <a href=\"http:\/\/gcc.gnu.org\/ml\/gcc-patches\/2004-09\/msg02055.html\">\u043d\u0430 \u0441\u0430\u0439\u0442\u0435<\/a>.<\/p>\n<hr\/>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a &#171;GTK+: \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 C \u0441 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f&#187;. \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0435\u0431\u0438\u043d\u0430\u0440\u0435 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0448\u0438\u0440\u043e\u043a\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2014 GTK+ \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0430 <a href=\"https:\/\/otus.pw\/c1Q0\/\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/709660\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/709660\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u0430\u043a\u0440\u043e\u0441 FORTIFY_SOURCE \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0444\u0435\u0440\u0430 (buffer overflows) \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438. \u041d\u0435 \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0444\u0435\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043a\u0440\u043e\u0441\u0430, \u043d\u043e \u043e\u043d \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 buffer overflow. \u041e\u043d \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043a\u0430\u043a C, \u0442\u0430\u043a \u0438 C++ \u043a\u043e\u0434\u0430. FORTIFY_SOURCE \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0432 \u043c\u0435\u0441\u0442\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u0443\u0444\u0435\u0440, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>*** buffer overflow detected ***: .\/foobar terminated ======= Backtrace: ========= \/lib64\/libc.so.6[0x382d875cff] \/lib64\/libc.so.6(__fortify_fail+0x37)[0x382d906b17] ...<\/code><\/pre>\n<p>FORTIFY_SOURCE \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code>memcpy, mempcpy, memmove, memset, strcpy, stpcpy, strncpy, strcat,  strncat, sprintf, vsprintf, snprintf, vsnprintf, gets.<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 Feature Test Macros (man feature_test_macros) \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f:<\/p>\n<p>\u0415\u0441\u043b\u0438 _FORTIFY_SOURCE \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 1, \u0442\u043e \u043f\u0440\u0438 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 1 (gcc -O1) \u0438 \u0432\u044b\u0448\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.\u00a0 \u041f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 _FORTIFY_SOURCE \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 2 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0434\u0430\u0442\u044c \u0441\u0431\u043e\u0439.\u00a0 \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430; \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0430, \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430.\u00a0 \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u043a\u0440\u043e\u0441, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430\u044f \u0432 gcc(1) \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 4.0.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code>\/\/ fortify_test.c #include&lt;stdio.h>  \/* Commenting out or not using the string.h header will cause this  * program to use the unprotected strcpy function.  *\/ \/\/#include&lt;string.h>  int main(int argc, char **argv) { char buffer[5]; printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); strcpy(buffer,argv[1]); printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); }<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f FORTIFY_SOURCE (-D_FORTIFY_SOURCE) \u0438 \u0444\u043b\u0430\u0433\u043e\u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 (-g -02) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code>~]$ gcc -D_FORTIFY_SOURCE=1 -Wall -g -O2 fortify_test.c \\     -o fortify_test<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0444\u0435\u0440\u0430 \u043d\u0438\u043a\u0430\u043a\u0430\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code>~]$ objdump -d .\/fortify_test 0000000000400440 : 400440:  48 83 ec 18             sub $0x18,%rsp 400444:  ba 05 00 00 00          mov $0x5,%edx 400449:  bf 10 06 40 00          mov $0x400610,%edi 40044e:  48 89 e6                mov %rsp,%rsi 400451:  31 c0                   xor %eax,%eax 400453:  e8 b8 ff ff ff          callq 400410 400458:  48 b8 64 65 61 64 62    movabs $0x6665656264616564,%rax 40045f:  65 65 66 400462:  48 89 e6                mov %rsp,%rsi 400465:  ba 05 00 00 00          mov $0x5,%edx 40046a:  48 89 04 24             mov %rax,(%rsp) 40046e:  bf 10 06 40 00          mov $0x400610,%edi 400473:  31 c0                   xor %eax,%eax 400475:  c6 44 24 08 00          movb $0x0,0x8(%rsp) 40047a:  e8 91 ff ff ff          callq 400410 40047f:  31 c0                   xor %eax,%eax 400481:  48 83 c4 18             add $0x18,%rsp 400485:  c3                      retq 400486:  66 90                   xchg %ax,%ax<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u0437\u044a\u044f\u043d \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435. \u041f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0438\u043c\u0432\u043e\u043b &#8216;A&#8217;, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 &#8216;\\x41&#8217;) \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 RAX:<\/p>\n<pre><code>$ gdb -q .\/fortify_test Reading symbols from \/home\/sid\/security\/fortify\/fortify_test...done.  (gdb) br 8 Breakpoint 1 at 0x4004b8: file fortify_test.c, line 8.  (gdb) r $(python -c 'print \"\\x41\" * 360') Starting program: \/home\/sid\/security\/fortify\/fortify_test \\  $(python -c 'print \"\\x41\" * 360')  Buffer Contains: \ufffd\ufffd\ufffd\ufffd\ufffd , Size Of Buffer is 5 Breakpoint 1, main (argc=, argv=0x7fffffffd788) at fortify_test.c:8 8 printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",buffer, sizeof(buffer));  (gdb) i r rax 0x7fffffffd690 140737488344720 rbx 0x7fffffffd788 140737488344968 rcx 0x4141414141414141 4702111234474983745 rdx 0x41 65 rsi 0x7fffffffdd40 140737488346432 rdi 0x7fffffffd7ef 140737488345071 rbp 0x0 0x0 rsp 0x7fffffffd690 0x7fffffffd690 r8 0x2d 45 r9 0x0 0 r10 0x7fffffffd450 140737488344144 r11 0x382d974c60 241283058784 r12 0x4004d4 4195540 r13 0x7fffffffd780 140737488344960 r14 0x0 0 r15 0x0 0 rip 0x4004b8 0x4004b8 eflags 0x206 [ PF IF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0  (gdb) x \/100x $rax 0x7fffffffd690: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd6a0: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd6b0: 0x41414141 0x41414141 0x41414141 0x41414141 ... 0x7fffffffd7d0: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd7e0: 0x41414141 0x41414141 0x41414141 0x41414141 0x7fffffffd7f0: 0x41414141 0x41414141 0xffffde00 0x00007fff 0x7fffffffd800: 0xffffde6a 0x00007fff 0xffffde85 0x00007fff 0x7fffffffd810: 0xffffde93 0x00007fff 0xffffdeae 0x00007fff<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 string.h \u0432 \u043d\u0430\u0448\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e strcpy \u0441\u0442\u0440\u043e\u043a\u0443, \u0434\u043b\u0438\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430:<\/p>\n<pre><code>\/\/ fortify_test.c #include&lt;stdio.h> #include&lt;string.h>  int main(int argc, char **argv) { char buffer[5]; printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); \/\/ Here the compiler the length of string to be copied strcpy(buffer,\"deadbeef\"); printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f FORTIFY_SOURCE \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u043b\u0430\u0433 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0441\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0431\u0435\u0437\u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 buffer:<\/p>\n<pre><code>~]$ gcc -D_FORTIFY_SOURCE=1 -Wall -g -O2 fortify_test.c \\  -o fortify_test  In file included from \/usr\/include\/string.h:636:0, from fortify_test.c:2: In function \u2018strcpy\u2019, inlined from \u2018main\u2019 at fortify_test.c:7:8: \/usr\/include\/bits\/string3.h:104:3: warning: call to  __builtin___memcpy_chk will always overflow destination buffer  [enabled by default] return __builtin___strcpy_chk (__dest, __src, __bos (__dest)); ^<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u044b\u0437\u043e\u0432 <code>&lt;__memcpy_chk@plt><\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430:<\/p>\n<pre><code>~]$ objdump -d .\/fortify_test ... 00000000004004b0 : 4004b0:       48 83 ec 18             sub    $0x18,%rsp 4004b4:       ba 05 00 00 00          mov    $0x5,%edx 4004b9:       bf 80 06 40 00          mov    $0x400680,%edi 4004be:       48 89 e6                mov    %rsp,%rsi 4004c1:       31 c0                   xor    %eax,%eax 4004c3:       e8 a8 ff ff ff          callq  400470 &lt;printf@plt> 4004c8:       48 89 e7                mov    %rsp,%rdi 4004cb:       b9 05 00 00 00          mov    $0x5,%ecx 4004d0:       ba 09 00 00 00          mov    $0x9,%edx 4004d5:       be b0 06 40 00          mov    $0x4006b0,%esi 4004da:       e8 b1 ff ff ff          callq  400490&lt;__memcpy_chk@plt>  4004df:       48 89 e6                mov    %rsp,%rsi 4004e2:       ba 05 00 00 00          mov    $0x5,%edx 4004e7:       bf 80 06 40 00          mov    $0x400680,%edi 4004ec:       31 c0                   xor    %eax,%eax 4004ee:       e8 7d ff ff ff          callq  400470 &lt;printf@plt> 4004f3:       31 c0                   xor    %eax,%eax 4004f5:       48 83 c4 18             add    $0x18,%rsp 4004f9:       c3                      retq    4004fa:       66 90                   xchg   %ax,%ax ... <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f strcpy \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u0442\u043e \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439:<\/p>\n<pre><code>\/\/ fortify_test.c #include&lt;stdio.h> #include&lt;string.h>  int main(int argc, char **argv) { char buffer[5]; printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer));  \/\/ String length is determined at runtime strcpy(buffer,argv[1]); printf (\"Buffer Contains: %s , Size Of Buffer is %d\\n\",                                buffer,sizeof(buffer)); }<\/code><\/pre>\n<pre><code>~]$ gcc -D_FORTIFY_SOURCE=1 -Wall -g -O2 fortify_test.c \\      -o fortify_test ~]$<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 FORTIFY_SOURCE \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0438\u0437 argv[1], \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0432\u044b\u0434\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u043e \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0431\u0443\u0444\u0435\u0440\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0440\u0432\u0430\u043d\u0430:<\/p>\n<pre><code>~]$ .\/fortify_test $(python -c 'print \"\\x41\" * 360') Buffer Contains: \ufffdQ\ufffd\ufffd\ufffd , Size Of Buffer is 5 *** buffer overflow detected ***: .\/fortify_test terminated ======= Backtrace: ========= \/lib64\/libc.so.6[0x382d875cff] \/lib64\/libc.so.6(__fortify_fail+0x37)[0x382d906b17] \/lib64\/libc.so.6[0x382d904d00] .\/fortify_test[0x4004dd] \/lib64\/libc.so.6(__libc_start_main+0xf5)[0x382d821d65] .\/fortify_test[0x400525] ======= Memory map: ======== 00400000-00401000 r-xp 00000000 fd:05 9967292 \/home\/sid\/security\/ \\ fortify\/fortify_test 00600000-00601000 r--p 00000000 fd:05 9967292 \/home\/sid\/security\/ \\ fortify\/fortify_test 00601000-00602000 rw-p 00001000 fd:05 9967292 \/home\/sid\/security\/ \\ fortify\/fortify_test 013ee000-0140f000 rw-p 00000000 00:00 0 [heap] 382d400000-382d420000 r-xp 00000000 fd:03 922951 \/usr\/lib64\/ld-2.18.so 382d61f000-382d620000 r--p 0001f000 fd:03<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343694","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343694"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343694\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}