{"id":455598,"date":"2025-04-11T09:19:20","date_gmt":"2025-04-11T09:19:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=455598"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=455598","title":{"rendered":"<span>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 ptrace \u0432 Linux \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u0442\u0435\u0431\u0435<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0441\u0442\u043e\u043b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u043c\u0430\u043b\u043e \u043a\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u2014 ptrace. <\/p>\n<p>\u0421 ptrace \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u0447\u0443\u0436\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c, \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u043f\u0430\u043c\u044f\u0442\u044c, \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u2014 \u0438 \u0434\u0430\u0436\u0435 \u0432\u0435\u0436\u043b\u0438\u0432\u043e \u0443\u0432\u043e\u043b\u0438\u0442\u044c sleep 9999.  <\/p>\n<h3>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ptrace \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d <\/h3>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f ptrace(PTRACE_ATTACH, pid, &#8230;), \u043c\u044b \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443\u00bb, \u0430 \u0434\u0430\u0435\u043c \u044f\u0434\u0440\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 <strong>\u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438<\/strong> \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.13.7\/C\/ident\/task_struct\">task_struct<\/a> \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d: \u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f ptrace-\u0444\u043b\u0430\u0433, \u0443 \u0440\u0435\u0431\u0451\u043d\u043a\u0430 \u2014 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430.<\/p>\n<p>\u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0435\u0431\u0430\u0436\u0435\u043d\u043d\u044b\u043c, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c <strong>\u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u2014 \u043e\u043d \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c (\u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441) \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>waitpid()<\/code>. \u0421\u0430\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b <code>SIGSTOP<\/code>, \u043d\u043e \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>PTRACE_SYSCALL<\/code>, <code>PTRACE_SINGLESTEP<\/code> \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0432\u043a\u0443\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h4>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u043b\u044b<\/h4>\n<p>ptrace \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043e\u043a\u0440\u0443\u0433 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0422.\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u00ab\u0434\u0438\u0442\u044f\u00bb \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u044f\u0434\u0440\u043e \u043b\u043e\u0432\u0438\u0442 \u044d\u0442\u043e \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 <code>SIGTRAP<\/code>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>PTRACE_SYSCALL<\/code>, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <strong>\u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u042f\u0434\u0440\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434 \u0432 <code>syscall <\/code>\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<\/li>\n<li>\n<p>\u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 waitpid \u043b\u043e\u0432\u0438\u0442 <code>WIFSTOPPED<\/code>, \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442: \u0430\u0433\u0430, \u043c\u044b \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0432 syscall.<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0447\u0435\u0448\u044c \u2014 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0448\u044c <code>PTRACE_SYSCALL<\/code>, \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0434\u0451\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 <strong>\u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 syscall<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043b\u043e\u0432\u0438\u0448\u044c <code>SIGTRAP <\/code>\u2014 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c syscall \u043f\u0440\u044f\u043c\u043e \u0432 orig_rax (x86_64) \u2014 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u044b\u0437\u043e\u0432. \u0418\u043b\u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b <code>rdi<\/code>, <code>rsi<\/code>, <code>rdx<\/code>, \u0435\u0441\u043b\u0438 \u0442\u044b \u0437\u043d\u0430\u0435\u0442\u0435 ABI. <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0446\u0435\u043f\u043b\u044f\u0435\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443, \u044f\u0434\u0440\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u043e\u0440\u0430\u0436\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c <code>PTRACE_ATTACH<\/code>, \u043d\u0443\u0436\u043d\u043d\u043e <strong>\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e<\/strong> \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>waitpid(pid, ...)<\/code> \u2014 \u0438\u043d\u0430\u0447\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432 \u043f\u043e\u0434\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0438 \u043e\u043d \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h4>ptrace \u2014 \u043e\u043f\u0430\u0441\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0446\u0438\u043a\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 <code>PTRACE_CONT<\/code> \u0438\u043b\u0438 <code>PTRACE_SYSCALL<\/code> \u2014 \u0442\u043e \u0442\u043e\u0442 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 <code>stopped<\/code> \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e. \u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0430\u0443\u0437\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441: \u043e\u043d \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043c\u043e\u0436\u0435\u0442 \u0432\u0438\u0441\u0435\u0442\u044c \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0437\u043e\u043c\u0431\u0438 \u0438\u043b\u0438 \u0432 T \u0441\u0442\u0430\u0442\u0443\u0441\u0435 \u0432 <code>ps<\/code>, \u043f\u043e\u043a\u0430 \u0437\u0430 \u043d\u0438\u043c \u043a\u0442\u043e-\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442 \u0438 \u043d\u0435 \u0434\u043e\u0434\u0435\u043b\u0430\u0435\u0442 \u0446\u0438\u043a\u043b \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043d\u0430\u0438\u0432\u043d\u044b\u0445 ptrace-\u0442\u0440\u0435\u0439\u0441\u0435\u0440\u043e\u0432: \u043f\u043e\u0432\u0435\u0441\u0438\u043b\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u2014 \u0438 \u0431\u0440\u043e\u0441\u0438\u043b, \u0437\u0430\u0431\u044b\u0432, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u044b \u0437\u0430 \u043d\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0448\u044c.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0433\u0440\u0430\u043d\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u0435\u0441\u043b\u0438 \u0442\u044b \u043b\u0435\u0437\u0435\u0448\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u0442\u0438\u0440\u0430\u0435\u0448\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, .text \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u043b\u0438 .got.plt), \u0442\u043e \u0442\u044b \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u0448\u044c <code>SIGSEGV <\/code>\u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438. \u0418\u043b\u0438 \u0445\u0443\u0436\u0435 \u2014 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0448\u044c return address \u043d\u0430 \u0441\u0442\u0435\u043a\u0435, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0448\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0440\u0430\u0448, \u0430 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0442\u044b \u043a\u0440\u0438\u0432\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0448\u044c waitpid() \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0448\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b (\u0432 \u0442.\u0447 <code>WSTOPPED<\/code>, <code>WIFEXITED<\/code>, <code>WIFSIGNALED<\/code>) \u2014 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442 \u0438\u043b\u0438 \u0442\u0432\u043e\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a: \u0442\u044b \u043d\u0435 root \u2014 \u0442\u044b \u043d\u0435 \u043b\u0435\u0437\u0435\u0448\u044c \u0432 \u0447\u0443\u0436\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b. \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 <code>UID\/GID<\/code>, \u0430 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 setuid-\u0431\u0438\u043d\u0430\u0440\u0435\u0439 \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 setuid-\u0431\u0438\u0442. <\/p>\n<h4>ptrace vs seccomp vs capabilities<\/h4>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u0445) \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442 ptrace \u0447\u0435\u0440\u0435\u0437:<\/p>\n<ul>\n<li>\n<p><code>yama\/ptrace_scope=1<\/code>: \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 <code>PTRACE_ATTACH<\/code> \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 (\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u0440\u043e\u0434\u0441\u0442\u0432\u043e);<\/p>\n<\/li>\n<li>\n<p><code>seccomp<\/code>: \u043c\u043e\u0436\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0442\u044b \u0438\u0445 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0448\u044c;<\/p>\n<\/li>\n<li>\n<p><code>capabilities<\/code>: \u043d\u0443\u0436\u043d\u044b <code>CAP_SYS_PTRACE<\/code>, \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0448\u044c \u0446\u0435\u043f\u043b\u044f\u0442\u044c\u0441\u044f \u043a \u0447\u0443\u0436\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0432\u043d\u0435 user&#8217;\u0430.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u043e\u0439<\/h3>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0442\u044b \u0445\u043e\u0447\u0435\u0448\u044c \u043d\u0435 \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0443\u0436\u0435 \u0438\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0430 \u0441\u0430\u043c \u0432\u0441\u0451 \u0441\u043e\u0437\u0434\u0430\u0442\u044c, \u043e\u0431\u0432\u044f\u0437\u0430\u0442\u044c, \u043f\u043e\u0434\u0446\u0435\u043f\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439: \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u044f\u0434\u0440\u0443: \u00ab\u044f \u0441\u043e\u0433\u043b\u0430\u0441\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u00bb. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>PTRACE_TRACEME<\/code>, \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f exec \u043d\u0443\u0436\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442, \u0430 <strong>\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432<\/strong> \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<pre><code class=\"dart\">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys\/ptrace.h&gt; #include &lt;sys\/types.h&gt; #include &lt;sys\/wait.h&gt; #include &lt;sys\/user.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt;  int main() {     pid_t child = fork();      if (child == 0) {         \/\/ \u0414\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441: \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u0435\u043c\u044b\u043c         ptrace(PTRACE_TRACEME, 0, NULL, NULL);         execl(\"\/bin\/ls\", \"ls\", NULL);         perror(\"execl\");         exit(1);     } else {         \/\/ \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c: \u0441\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c         int status;         waitpid(child, &amp;status, 0);          ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACESYSGOOD);          while (1) {             ptrace(PTRACE_SYSCALL, child, NULL, NULL);             waitpid(child, &amp;status, 0);             if (WIFEXITED(status)) break;              if (WIFSTOPPED(status) &amp;&amp; WSTOPSIG(status) &amp; 0x80) {                 struct user_regs_struct regs;                 ptrace(PTRACE_GETREGS, child, NULL, &amp;regs);                 printf(\"Syscall: %llu\\n\", regs.orig_rax);             }         }     }      return 0; }<\/code><\/pre>\n<p>fork() \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 PTRACE_TRACEME, \u0438 \u044f\u0434\u0440\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435. \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0441\u043b\u0443\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432.<\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0443\u0436\u0435 \u0436\u0438\u0432\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443<\/h4>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u044b \u043d\u0435 \u0445\u043e\u0447\u0435\u0448\u044c \u0435\u0433\u043e \u0443\u0431\u0438\u0432\u0430\u0442\u044c, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0435\u0448\u044c \u043f\u043e\u0434\u0433\u043b\u044f\u0434\u0435\u0442\u044c. \u0422\u043e\u0433\u0434\u0430 \u0442\u0435\u0431\u0435 \u043d\u0443\u0436\u0435\u043d PTRACE_ATTACH:<\/p>\n<pre><code class=\"cs\">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys\/ptrace.h&gt; #include &lt;sys\/wait.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt;  int main(int argc, char *argv[]) {     if (argc != 2) {         fprintf(stderr, \"Usage: %s &lt;pid&gt;\\n\", argv[0]);         return 1;     }      pid_t pid = atoi(argv[1]);      if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) {         perror(\"ptrace attach\");         return 1;     }      waitpid(pid, NULL, 0);     printf(\"Attached to process %d\\n\", pid);      \/\/ \u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c\u2026      ptrace(PTRACE_DETACH, pid, NULL, NULL);     printf(\"Detached\\n\");      return 0; }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 PTRACE_ATTACH \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041f\u043e\u043a\u0430 \u0442\u044b \u0441 \u043d\u0438\u043c \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0448\u044c, \u043e\u043d \u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c PTRACE_DETACH \u0438\u043b\u0438 PTRACE_CONT \u2014 \u0438\u043d\u0430\u0447\u0435 \u043e\u043d \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442.<\/p>\n<h4>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0430\u043c\u044f\u0442\u0438<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\">long word = ptrace(PTRACE_PEEKTEXT, pid, (void *)addr, NULL); printf(\"Data at %p: 0x%lx\\n\", addr, word);<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043f\u0438\u0448\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u0432\u043e\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"cs\">long new_word = 0x64636261; \/\/ 'abcd' \u0432 ASCII (LE) ptrace(PTRACE_POKETEXT, pid, (void *)addr, (void *)new_word);<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0437\u043d\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f <code>gdb<\/code>, <code>maps<\/code>, <code>nm<\/code>, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e <code>ltrace<\/code>.<\/p>\n<h4>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438<\/h4>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0448\u044c \u043d\u0430 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435? \u0421\u043d\u0438\u043c\u0430\u0435\u043c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0443 \u0447\u0443\u0436\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\">#include &lt;sys\/user.h&gt;  struct user_regs_struct regs; ptrace(PTRACE_GETREGS, pid, NULL, &amp;regs); printf(\"RIP: %llx, RAX: %llx\\n\", regs.rip, regs.rax);<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c <code>rip<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0441\u043a\u043e\u0447\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"cs\">regs.rip += 2; ptrace(PTRACE_SETREGS, pid, NULL, &amp;regs);<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 <code>gdb<\/code>, \u043d\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<h3>\u0423\u0431\u0438\u0432\u0430\u0435\u043c sleep 9999 \u0431\u0435\u0437 kill<\/h3>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c:<\/p>\n<pre><code class=\"bash\">sleep 9999 &amp;<\/code><\/pre>\n<p>\u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0434\u0451\u0442. \u041c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0441\u043b\u0430\u0442\u044c SIGKILL, \u0430 \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c <strong>\u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u0437\u0432\u0430\u0442\u044c exit(0)<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c <code>rax<\/code> (\u043d\u043e\u043c\u0435\u0440 syscall) \u043d\u0430 60 (\u044d\u0442\u043e exit).<\/p>\n<\/li>\n<li>\n<p>\u0412 <code>rdi <\/code>\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c 0 (\u043a\u043e\u0434 \u0432\u044b\u0445\u043e\u0434\u0430).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cs\">#include &lt;stdio.h&gt; #include &lt;sys\/ptrace.h&gt; #include &lt;sys\/wait.h&gt; #include &lt;sys\/user.h&gt; #include &lt;unistd.h&gt;  int main() {     pid_t pid = 4242; \/\/ \u041f\u043e\u0434\u0441\u0442\u0430\u0432\u044c \u0441\u0432\u043e\u0439 PID      ptrace(PTRACE_ATTACH, pid, NULL, NULL);     waitpid(pid, NULL, 0);      struct user_regs_struct regs;     ptrace(PTRACE_GETREGS, pid, NULL, &amp;regs);      regs.rax = 60;    \/\/ syscall exit     regs.rdi = 0;     \/\/ exit code 0     ptrace(PTRACE_SETREGS, pid, NULL, &amp;regs);      ptrace(PTRACE_CONT, pid, NULL, NULL);     return 0; }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0430\u043c \u0441\u0435\u0431\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 <code>exit(0)<\/code>, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0434\u043e\u0448\u0451\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 <code>main<\/code>. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 <code>kill<\/code>, \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0432 \u0441\u0438\u0433\u043d\u0430\u043b\u044b. <\/p>\n<hr\/>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435! \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 ptrace \u0432 \u0441\u0432\u043e\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.   <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0431\u043b\u0438\u0437\u043a\u0430 \u0438\u0434\u0435\u044f \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043d\u0430\u0434 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438, \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u2014 \u0432\u0430\u043c \u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0440\u0435\u0434\u044b. <a href=\"https:\/\/otus.pw\/DdFG\/\"><strong>\u041d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u00ab\u0418\u0437 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u00bb<\/strong><\/a> \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a Ansible, Vagrant \u0438 Terraform \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442 \u0442\u043e\u0447\u0435\u0447\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435. \u0411\u0435\u0437 \u043c\u0430\u0433\u0438\u0438 \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434.<\/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\/articles\/898448\/\"> https:\/\/habr.com\/ru\/articles\/898448\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0441\u0442\u043e\u043b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u043c\u0430\u043b\u043e \u043a\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u2014 ptrace. <\/p>\n<p>\u0421 ptrace \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u0447\u0443\u0436\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c, \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u043f\u0430\u043c\u044f\u0442\u044c, \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u2014 \u0438 \u0434\u0430\u0436\u0435 \u0432\u0435\u0436\u043b\u0438\u0432\u043e \u0443\u0432\u043e\u043b\u0438\u0442\u044c sleep 9999.  <\/p>\n<h3>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ptrace \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d \u043d\u0443\u0436\u0435\u043d <\/h3>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f ptrace(PTRACE_ATTACH, pid, &#8230;), \u043c\u044b \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443\u00bb, \u0430 \u0434\u0430\u0435\u043c \u044f\u0434\u0440\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 <strong>\u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438<\/strong> \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.13.7\/C\/ident\/task_struct\">task_struct<\/a> \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d: \u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f ptrace-\u0444\u043b\u0430\u0433, \u0443 \u0440\u0435\u0431\u0451\u043d\u043a\u0430 \u2014 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430.<\/p>\n<p>\u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0435\u0431\u0430\u0436\u0435\u043d\u043d\u044b\u043c, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c <strong>\u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u2014 \u043e\u043d \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c (\u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441) \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>waitpid()<\/code>. \u0421\u0430\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b <code>SIGSTOP<\/code>, \u043d\u043e \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>PTRACE_SYSCALL<\/code>, <code>PTRACE_SINGLESTEP<\/code> \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0432\u043a\u0443\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h4>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0447\u0435\u0440\u0435\u0437 \u0441\u0438\u0433\u043d\u0430\u043b\u044b<\/h4>\n<p>ptrace \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043e\u043a\u0440\u0443\u0433 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0422.\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u00ab\u0434\u0438\u0442\u044f\u00bb \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u044f\u0434\u0440\u043e \u043b\u043e\u0432\u0438\u0442 \u044d\u0442\u043e \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 <code>SIGTRAP<\/code>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>PTRACE_SYSCALL<\/code>, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <strong>\u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u042f\u0434\u0440\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434 \u0432 <code>syscall <\/code>\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<\/li>\n<li>\n<p>\u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0447\u0435\u0440\u0435\u0437 waitpid \u043b\u043e\u0432\u0438\u0442 <code>WIFSTOPPED<\/code>, \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442: \u0430\u0433\u0430, \u043c\u044b \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0432 syscall.<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0447\u0435\u0448\u044c \u2014 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0448\u044c <code>PTRACE_SYSCALL<\/code>, \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0434\u0451\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 <strong>\u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 syscall<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043b\u043e\u0432\u0438\u0448\u044c <code>SIGTRAP <\/code>\u2014 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c syscall \u043f\u0440\u044f\u043c\u043e \u0432 orig_rax (x86_64) \u2014 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u044b\u0437\u043e\u0432. \u0418\u043b\u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b <code>rdi<\/code>, <code>rsi<\/code>, <code>rdx<\/code>, \u0435\u0441\u043b\u0438 \u0442\u044b \u0437\u043d\u0430\u0435\u0442\u0435 ABI. <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0446\u0435\u043f\u043b\u044f\u0435\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443, \u044f\u0434\u0440\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u043e\u0440\u0430\u0436\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c <code>PTRACE_ATTACH<\/code>, \u043d\u0443\u0436\u043d\u043d\u043e <strong>\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e<\/strong> \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>waitpid(pid, ...)<\/code> \u2014 \u0438\u043d\u0430\u0447\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432 \u043f\u043e\u0434\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0438 \u043e\u043d \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h4>ptrace \u2014 \u043e\u043f\u0430\u0441\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0446\u0438\u043a\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 <code>PTRACE_CONT<\/code> \u0438\u043b\u0438 <code>PTRACE_SYSCALL<\/code> \u2014 \u0442\u043e \u0442\u043e\u0442 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 <code>stopped<\/code> \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e. \u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0430\u0443\u0437\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441: \u043e\u043d \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043c\u043e\u0436\u0435\u0442 \u0432\u0438\u0441\u0435\u0442\u044c \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0437\u043e\u043c\u0431\u0438 \u0438\u043b\u0438 \u0432 T \u0441\u0442\u0430\u0442\u0443\u0441\u0435 \u0432 <code>ps<\/code>, \u043f\u043e\u043a\u0430 \u0437\u0430 \u043d\u0438\u043c \u043a\u0442\u043e-\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442 \u0438 \u043d\u0435 \u0434\u043e\u0434\u0435\u043b\u0430\u0435\u0442 \u0446\u0438\u043a\u043b \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043d\u0430\u0438\u0432\u043d\u044b\u0445 ptrace-\u0442\u0440\u0435\u0439\u0441\u0435\u0440\u043e\u0432: \u043f\u043e\u0432\u0435\u0441\u0438\u043b\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u2014 \u0438 \u0431\u0440\u043e\u0441\u0438\u043b, \u0437\u0430\u0431\u044b\u0432, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u044b \u0437\u0430 \u043d\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0448\u044c.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0433\u0440\u0430\u043d\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u0435\u0441\u043b\u0438 \u0442\u044b \u043b\u0435\u0437\u0435\u0448\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u0442\u0438\u0440\u0430\u0435\u0448\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, .text \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u043b\u0438 .got.plt), \u0442\u043e \u0442\u044b \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u0448\u044c <code>SIGSEGV <\/code>\u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438. \u0418\u043b\u0438 \u0445\u0443\u0436\u0435 \u2014 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0448\u044c return address \u043d\u0430 \u0441\u0442\u0435\u043a\u0435, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0448\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0440\u0430\u0448, \u0430 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0442\u044b \u043a\u0440\u0438\u0432\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0448\u044c waitpid() \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0448\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b (\u0432 \u0442.\u0447 <code>WSTOPPED<\/code>, <code>WIFEXITED<\/code>, <code>WIFSIGNALED<\/code>) \u2014 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442 \u0438\u043b\u0438 \u0442\u0432\u043e\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a: \u0442\u044b \u043d\u0435 root \u2014 \u0442\u044b \u043d\u0435 \u043b\u0435\u0437\u0435\u0448\u044c \u0432 \u0447\u0443\u0436\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b. \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 <code>UID\/GID<\/code>, \u0430 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 setuid-\u0431\u0438\u043d\u0430\u0440\u0435\u0439 \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 setuid-\u0431\u0438\u0442. <\/p>\n<h4>ptrace vs seccomp vs capabilities<\/h4>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u0445) \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442 ptrace \u0447\u0435\u0440\u0435\u0437:<\/p>\n<ul>\n<li>\n<p><code>yama\/ptrace_scope=1<\/code>: \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 <code>PTRACE_ATTACH<\/code> \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 (\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u0440\u043e\u0434\u0441\u0442\u0432\u043e);<\/p>\n<\/li>\n<li>\n<p><code>seccomp<\/code>: \u043c\u043e\u0436\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0442\u044b \u0438\u0445 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0448\u044c;<\/p>\n<\/li>\n<li>\n<p><code>capabilities<\/code>: \u043d\u0443\u0436\u043d\u044b <code>CAP_SYS_PTRACE<\/code>, \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0448\u044c \u0446\u0435\u043f\u043b\u044f\u0442\u044c\u0441\u044f \u043a \u0447\u0443\u0436\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0432\u043d\u0435 user&#8217;\u0430.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u043e\u0439<\/h3>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0442\u044b \u0445\u043e\u0447\u0435\u0448\u044c \u043d\u0435 \u0432\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0443\u0436\u0435 \u0438\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0430 \u0441\u0430\u043c \u0432\u0441\u0451 \u0441\u043e\u0437\u0434\u0430\u0442\u044c, \u043e\u0431\u0432\u044f\u0437\u0430\u0442\u044c, \u043f\u043e\u0434\u0446\u0435\u043f\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439: \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u044f\u0434\u0440\u0443: \u00ab\u044f \u0441\u043e\u0433\u043b\u0430\u0441\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u00bb. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>PTRACE_TRACEME<\/code>, \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f exec \u043d\u0443\u0436\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442, \u0430 <strong>\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432<\/strong> \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<pre><code class=\"dart\">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys\/ptrace.h&gt; #include &lt;sys\/types.h&gt; #include &lt;sys\/wait.h&gt; #include &lt;sys\/user.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt;  int main() {     pid_t child = fork();      if (child == 0) {         \/\/ \u0414\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441: \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u0435\u043c\u044b\u043c         ptrace(PTRACE_TRACEME, 0, NULL, NULL);         execl(\"\/bin\/ls\", \"ls\", NULL);         perror(\"execl\");         exit(1);     } else {         \/\/ \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c: \u0441\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c         int status;         waitpid(child, &amp;status, 0);          ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACESYSGOOD);          while (1) {             ptrace(PTRACE_SYSCALL, child, NULL, NULL);             waitpid(child, &amp;status, 0);             if (WIFEXITED(status)) break;              if (WIFSTOPPED(status) &amp;&amp; WSTOPSIG(status) &amp; 0x80) {                 struct user_regs_struct regs;                 ptrace(PTRACE_GETREGS, child, NULL, &amp;regs);                 printf(\"Syscall: %llu\\n\", regs.orig_rax);             }         }     }      return 0; }<\/code><\/pre>\n<p>fork() \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 PTRACE_TRACEME, \u0438 \u044f\u0434\u0440\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435. \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0441\u043b\u0443\u0448\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432.<\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0443\u0436\u0435 \u0436\u0438\u0432\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443<\/h4>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431: \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u044b \u043d\u0435 \u0445\u043e\u0447\u0435\u0448\u044c \u0435\u0433\u043e \u0443\u0431\u0438\u0432\u0430\u0442\u044c, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0435\u0448\u044c \u043f\u043e\u0434\u0433\u043b\u044f\u0434\u0435\u0442\u044c. \u0422\u043e\u0433\u0434\u0430 \u0442\u0435\u0431\u0435 \u043d\u0443\u0436\u0435\u043d PTRACE_ATTACH:<\/p>\n<pre><code class=\"cs\">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys\/ptrace.h&gt; #include &lt;sys\/wait.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt;  int main(int argc, char *argv[]) {     if (argc != 2) {         fprintf(stderr, \"Usage: %s &lt;pid&gt;\\n\", argv[0]);         return 1;     }      pid_t pid = atoi(argv[1]);      if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) {         perror(\"ptrace attach\");         return 1;     }      waitpid(pid, NULL, 0);     printf(\"Attached to process %d\\n\", pid);      \/\/ \u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c\u2026      ptrace(PTRACE_DETACH, pid, NULL, NULL);     printf(\"Detached\\n\");      return 0; }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 PTRACE_ATTACH \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041f\u043e\u043a\u0430 \u0442\u044b \u0441 \u043d\u0438\u043c \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0448\u044c, \u043e\u043d \u043d\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c PTRACE_DETACH \u0438\u043b\u0438 PTRACE_CONT \u2014 \u0438\u043d\u0430\u0447\u0435 \u043e\u043d \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442.<\/p>\n<h4>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0430\u043c\u044f\u0442\u0438<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\">long word = ptrace(PTRACE_PEEKTEXT, pid, (void *)addr, NULL); printf(\"Data at %p: 0x%lx\\n\", addr, word);<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043f\u0438\u0448\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u0432\u043e\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"cs\">long new_word = 0x64636261; \/\/ 'abcd' \u0432 ASCII (LE) ptrace(PTRACE_POKETEXT, pid, (void *)addr, (void *)new_word);<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0437\u043d\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f <code>gdb<\/code>, <code>maps<\/code>, <code>nm<\/code>, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e <code>ltrace<\/code>.<\/p>\n<h4>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438<\/h4>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0448\u044c \u043d\u0430 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435? \u0421\u043d\u0438\u043c\u0430\u0435\u043c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0443 \u0447\u0443\u0436\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<pre><code class=\"cs\">#include &lt;sys\/user.h&gt;  struct user_regs_struct regs; ptrace(PTRACE_GETREGS, pid, NULL, &amp;regs); printf(\"RIP: %llx, RAX: %llx\\n\", regs.rip, regs.rax);<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c <code>rip<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0441\u043a\u043e\u0447\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"cs\">regs.rip += 2; ptrace(PTRACE_SETREGS, pid, NULL, &amp;regs);<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 <code>gdb<\/code>, \u043d\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<h3>\u0423\u0431\u0438\u0432\u0430\u0435\u043c sleep 9999 \u0431\u0435\u0437 kill<\/h3>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c:<\/p>\n<pre><code class=\"bash\">sleep 9999 &amp;<\/code><\/pre>\n<p>\u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0434\u0451\u0442. \u041c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0441\u043b\u0430\u0442\u044c SIGKILL, \u0430 \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c <strong>\u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u0437\u0432\u0430\u0442\u044c exit(0)<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c <code>rax<\/code> (\u043d\u043e\u043c\u0435\u0440 syscall) \u043d\u0430 60 (\u044d\u0442\u043e exit).<\/p>\n<\/li>\n<li>\n<p>\u0412 <code>rdi <\/code>\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c 0 (\u043a\u043e\u0434 \u0432\u044b\u0445\u043e\u0434\u0430).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cs\">#include &lt;stdio.h&gt; #include &lt;sys\/ptrace.h&gt; #include &lt;sys\/wait.h&gt; #include &lt;sys\/user.h&gt; #include &lt;unistd.h&gt;  int main() {     pid_t pid = 4242; \/\/ \u041f\u043e\u0434\u0441\u0442\u0430\u0432\u044c \u0441\u0432\u043e\u0439 PID      ptrace(PTRACE_ATTACH, pid, NULL, NULL);     waitpid(pid, NULL, 0);      struct user_regs_struct regs;     ptrace(PTRACE_GETREGS, pid, NULL, &amp;regs);      regs.rax = 60;    \/\/ syscall exit     regs.rdi = 0;     \/\/ exit code 0     ptrace(PTRACE_SETREGS, pid, NULL, &amp;regs);      ptrace(PTRACE_CONT, pid, NULL, NULL);     return 0; }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0430\u043c \u0441\u0435\u0431\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 <code>exit(0)<\/code>, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0434\u043e\u0448\u0451\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 <code>main<\/code>. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 <code>kill<\/code>, \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0432 \u0441\u0438\u0433\u043d\u0430\u043b\u044b. <\/p>\n<hr\/>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435! \u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 ptrace \u0432 \u0441\u0432\u043e\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.   <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0431\u043b\u0438\u0437\u043a\u0430 \u0438\u0434\u0435\u044f \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043d\u0430\u0434 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438, \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u2014 \u0432\u0430\u043c \u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0440\u0435\u0434\u044b. <a href=\"https:\/\/otus.pw\/DdFG\/\"><strong>\u041d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u00ab\u0418\u0437 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u00bb<\/strong><\/a> \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a Ansible, Vagrant \u0438 Terraform \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442 \u0442\u043e\u0447\u0435\u0447\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435. \u0411\u0435\u0437 \u043c\u0430\u0433\u0438\u0438 \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434.<\/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\/articles\/898448\/\"> https:\/\/habr.com\/ru\/articles\/898448\/<\/a><br \/><\/br><\/br><\/p>\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-455598","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/455598","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=455598"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/455598\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}