{"id":26,"date":"2010-12-27T08:21:57","date_gmt":"2010-12-27T07:21:57","guid":{"rendered":"http:\/\/debnar.ath.cx\/?p=26"},"modified":"2016-02-29T21:55:38","modified_gmt":"2016-02-29T20:55:38","slug":"bash-trap","status":"publish","type":"post","link":"https:\/\/debnar.org\/wp\/?p=26","title":{"rendered":"bash trap"},"content":{"rendered":"<p>Itt az \u00fcnnepek alatt, iptables \u00e1ll\u00edtgat\u00e1s k\u00f6zben, eszembe jutott, hogy nem lenne jo ha kiz\u00e1rn\u00e1m magam valami el\u00edr\u00e1s miatt. Akkor leltem r\u00e1 a bash trap-re. Ez azt eredm\u00e9nyezi, hogy a ^C-re nem fogja megszak\u00edtani a scriptet, hanem tetsz\u0151leges parancsokat tudunk futtatni a hat\u00e1s\u00e1ra.<!--more--><\/p>\n<p>L\u00e9nyeg\u00e9ben err\u0151l van sz\u00f3:<\/p>\n<blockquote><p><code><br \/>\n trap bashtrap INT<br \/>\n    bashtrap()<br \/>\n    {<br \/>\n      echo -n \"\\n^C Detected! Problem?\\n\"<br \/>\n     }<br \/>\n    for a in `seq 1 15`; do<br \/>\n       if [ \"$a\" -gt \"3\" ]; then<br \/>\n          echo -n \"\\rProbably you can press ^C ($a\/15)\"<br \/>\n          sleep 1<br \/>\n        fi<br \/>\n        if [ \"$a\" -lt \"3\" ]; then<br \/>\n          echo \"$a\/15\"<br \/>\n          sleep 1;<br \/>\n        fi<br \/>\n    done<br \/>\n         echo -n \"\\nThe end of the BASH trap example\\n\"<\/code>\n<\/p><\/blockquote>\n<p>Ha lenyomjuk a ^C-t akkor lefut az<\/p>\n<blockquote><p>echo -n &#8220;\\n^C Detected! Problem?\\n&#8221;<\/p><\/blockquote>\n<p>15 m\u00e1sodperc m\u00falva pedig az<\/p>\n<blockquote><p>echo -n &#8220;\\nThe end of the BASH trap example\\n&#8221;.<\/p><\/blockquote>\n<p>Ezt f\u00f6lhaszn\u00e1lva pedig egyszer\u0171en elk\u00e9sz\u00fclhet a script (csak \u00fagy \u00f6sszedobva a teljess\u00e9g ig\u00e9nye n\u00e9lk\u00fcl):<\/p>\n<blockquote><p>drestart)<br \/>\necho &#8220;Delayed restart&#8230;&#8221;<br \/>\niptables -F<br \/>\ndo_start<\/p>\n<p>trap bashtrap INT<br \/>\nbashtrap()<br \/>\n{<br \/>\necho -n &#8220;\\n^C Detected !&#8230;applying new rule\\n&#8221;<br \/>\nexit<br \/>\n}<\/p>\n<p>for a in `seq 1 15`; do<br \/>\nif [ &#8220;$a&#8221; -gt &#8220;3&#8221; ]; then<br \/>\necho -n &#8220;\\rProbably you can press ^C ($a\/15)&#8221;<br \/>\nsleep 1<br \/>\nfi<br \/>\nif [ &#8220;$a&#8221; -lt &#8220;3&#8221; ]; then<br \/>\necho &#8220;$a\/15 secs to default rule.&#8221;<br \/>\nsleep 1;<br \/>\nfi<\/p>\n<p>done<br \/>\ndo_ssh<br \/>\necho -n &#8220;\\nAre you still there?\\n&#8221;<br \/>\necho &#8220;Default rule has been applied.&#8221;<br \/>\n;;<\/p><\/blockquote>\n<p>A do_start() fv. futtatja az iptables szab\u00e1lyokat a do_ssh() pedig egy biztosan m\u0171k\u00f6d\u0151 minimal konfig (ssh). Ezt sosem v\u00e1ltoztatjuk.<br \/>\n!!!Fontos!!!<br \/>\nN\u00e9zz\u00fck meg, hogy a t\u0171zfalon az ESTABLISHED, RELATED kapcsolatok ha ACCEPT-eli azonnal, az INPUT l\u00e1ncon, akkor hi\u00e1ba rontjuk el, mondjuk, az SSH portot a kapcsolat \u00e9lni fog. Ergo: a drestart kapcsol\u00f3 olyan eredm\u00e9nnyel fog lefutni, mintha minden rendben lenne, de \u00faj kapcsolatot m\u00e1r nem tudunk l\u00e9trehozni.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Itt az \u00fcnnepek alatt, iptables \u00e1ll\u00edtgat\u00e1s k\u00f6zben, eszembe jutott, hogy nem lenne jo ha kiz\u00e1rn\u00e1m magam valami el\u00edr\u00e1s miatt. Akkor leltem r\u00e1 a bash trap-re. Ez azt eredm\u00e9nyezi, hogy a ^C-re nem fogja megszak\u00edtani a scriptet, hanem tetsz\u0151leges parancsokat tudunk &hellip; <a href=\"https:\/\/debnar.org\/wp\/?p=26\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":6,"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":28,"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions\/28"}],"wp:attachment":[{"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debnar.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}