{"id":590,"date":"2018-09-14T20:40:49","date_gmt":"2018-09-14T20:40:49","guid":{"rendered":"https:\/\/d1m0.com\/?p=590"},"modified":"2018-09-15T15:14:47","modified_gmt":"2018-09-15T15:14:47","slug":"%d0%b7%d0%b0%d1%89%d0%b8%d1%82%d0%b0-%d0%bd%d0%b0-%d1%81%d1%8a%d1%80%d0%b2%d1%8a%d1%80-%d1%87%d1%80%d0%b5%d0%b7-geoip-%d0%b7%d0%b0%d0%b1%d1%80%d0%b0%d0%bd%d1%8f%d0%b2%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0","status":"publish","type":"post","link":"https:\/\/d1m0.com\/?p=590","title":{"rendered":"\u0417\u0430\u0449\u0438\u0442\u0430 \u043d\u0430 \u0441\u044a\u0440\u0432\u044a\u0440 \u0447\u0440\u0435\u0437 Geoip &#8211; \u0411\u043b\u043e\u043a\u0438\u0440\u0430\u043d\u0435 \u043d\u0430 SSH \u0432\u0440\u044a\u0437\u043a\u0438 \u0438\u0437\u0432\u044a\u043d \u0411\u044a\u043b\u0433\u0430\u0440\u0438\u044f"},"content":{"rendered":"<p>\u0418\u043d\u0441\u0442\u0430\u043b\u0438\u0440\u0430\u0439\u0442\u0435 geoip<\/p>\n<blockquote><p>sudo apt-get install geoip-bin geoip-database<\/p><\/blockquote>\n<p>\u041f\u043e\u0434\u0441\u0438\u0433\u0443\u0440\u0435\u0442\u0435 \u0441\u0435, \u0447\u0435 \u0440\u0430\u0431\u043e\u0442\u0438:<\/p>\n<blockquote><p>\nboyanweb@boyanweb:\/Files150G$ geoiplookup boyan.website<br \/>\nGeoIP Country Edition: <strong>BG<\/strong>, Bulgaria<\/p><\/blockquote>\n<p>\u0422\u043e\u0437\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u0431\u0440\u0430\u043d\u044f\u0432\u0430 ssh \u043e\u0442 <strong>\u043d\u0435\u0431\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438<\/strong> ip \u0430\u0434\u0440\u0435\u0441\u0438, \u0441\u043b\u043e\u0436\u0435\u0442\u0435 \u0433\u043e \u0432 \/usr\/local\/bin\/.<\/p>\n<blockquote><p>#!\/bin\/bash<br \/>\nALLOW_COUNTRIES=&#8221;<strong>BG<\/strong>&#8221;<\/p>\n<p>if [ $# -ne 1 ]; then<br \/>\n  echo &#8220;Usage:  `basename $0` &#8221; 1&gt;&amp;2<br \/>\n  exit 0 # return true in case of config issue<br \/>\nfi<\/p>\n<p>COUNTRY=`\/usr\/bin\/geoiplookup $1 | awk -F &#8220;: &#8221; &#8216;{ print $2 }&#8217; | awk -F &#8220;,&#8221; &#8216;{ print $1 }&#8217; | head -n 1`<\/p>\n<p>[[ $COUNTRY = &#8220;IP Address not found&#8221; || $ALLOW_COUNTRIES =~ $COUNTRY ]] &amp;&amp; RESPONSE=&#8221;ALLOW&#8221; || RESPONSE=&#8221;DENY&#8221;<\/p>\n<p>if [ $RESPONSE = &#8220;ALLOW&#8221; ]<br \/>\nthen<br \/>\n  exit 0<br \/>\nelse<br \/>\n  logger &#8220;$RESPONSE sshd connection from $1 ($COUNTRY)&#8221;<br \/>\n<strong>  echo &#8220;$RESPONSE sshd connection frem $1($COUNTRY)&#8221; &gt;&gt; \/home\/<strong>\u041f\u041e\u0422\u0420\u0415\u0411\u0418\u0422\u0415\u041b<\/strong>\/sshLOG<\/strong><\/p>\n<p>  exit 1<br \/>\nfi<\/p><\/blockquote>\n<p>\u0412\u044a\u0432 \u0444\u0430\u0439\u043b\u0430 \/etc\/hosts.deny \u0434\u043e\u0431\u0430\u0432\u0435\u0442\u0435 \u0440\u0435\u0434\u0430:<\/p>\n<blockquote><p>sshd: ALL<\/p><\/blockquote>\n<p>\u0412\u044a\u0432 \u0444\u0430\u0439\u043b\u0430 \/etc\/hosts.allow \u0434\u043e\u0431\u0430\u0432\u0435\u0442\u0435 \u0440\u0435\u0434\u0430:<\/p>\n<blockquote><p>sshd: ALL: aclexec \/usr\/local\/bin\/sshfilter.sh %a<\/p><\/blockquote>\n<p>\u041d\u0435 \u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0430 \u0440\u0435\u0441\u0442\u0430\u0440\u0438\u0440\u0430\u0442\u0435 sshd \u043f\u0440\u043e\u0446\u0435\u0441\u0430, \u0434\u0438\u0440\u0435\u043a\u0442\u043d\u043e \u043c\u043e\u0436\u0435 \u0434\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u0435 \u0442\u0435\u0441\u0442:<\/p>\n<blockquote><p>boyanweb@boyanweb:~$ \/usr\/local\/bin\/sshfilter.sh 8.4.8.4<br \/>\nboyanweb@boyanweb:~$ cat sshLOG<br \/>\nDENY sshd connection from 8.4.8.4(US)<br \/>\nboyanweb@boyanweb:~$ \/usr\/local\/bin\/sshfilter.sh 8.4.8.8<br \/>\nboyanweb@boyanweb:~$ cat sshLOG<br \/>\nDENY sshd connection from 8.4.8.4(US)<br \/>\nDENY sshd connection from 8.4.8.8(US)<\/p><\/blockquote>\n<p>\u0417\u0430 \u044a\u043f\u0434\u0435\u0439\u0442 \u043d\u0430 geoip \u043c\u043e\u0436\u0435 \u0434\u0430 \u0438\u0437\u043f\u043e\u043b\u0437\u0432\u0430\u0442\u0435 \u0441\u043b\u0435\u0434\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442. \u0414\u043e\u0440\u0438 \u0438 \u0442\u043e\u043a\u0443 \u0449\u043e \u0434\u0430 \u0441\u0442\u0435 \u0433\u043e \u0438\u0437\u0442\u0435\u0433\u043b\u0438\u043b\u0438 \u0435 \u0434\u043e\u0431\u0440\u0435 \u0434\u0430 \u0441\u0435 \u043f\u043e\u0434\u0441\u0438\u0433\u0443\u0440\u0438\u0442\u0435, \u0447\u0435 \u0441\u0442\u0435 \u043d\u0430 \u043d\u0430\u0439-\u043d\u043e\u0432\u0430\u0442\u0430 \u0432\u044a\u0437\u043c\u043e\u0436\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f.<\/p>\n<blockquote><p>!\/bin\/bash<br \/>\ncd \/tmp<br \/>\nwget -q https:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLiteCountry\/GeoIP.dat.gz<br \/>\nif [ -f GeoIP.dat.gz ]<br \/>\nthen<br \/>\n    gzip -d GeoIP.dat.gz<br \/>\n    rm -f \/usr\/share\/GeoIP\/GeoIP.dat<br \/>\n    mv -f GeoIP.dat \/usr\/share\/GeoIP\/GeoIP.dat<br \/>\nelse<br \/>\n    echo &#8220;The GeoIP library could not be downloaded and updated&#8221;<br \/>\nfi<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u0418\u043d\u0441\u0442\u0430\u043b\u0438\u0440\u0430\u0439\u0442\u0435 geoip sudo apt-get install geoip-bin geoip-database \u041f\u043e\u0434\u0441\u0438\u0433\u0443\u0440\u0435\u0442\u0435 \u0441\u0435, \u0447\u0435 \u0440\u0430\u0431\u043e\u0442\u0438: boyanweb@boyanweb:\/Files150G$ geoiplookup boyan.website GeoIP Country Edition: BG, Bulgaria \u0422\u043e\u0437\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u0431\u0440\u0430\u043d\u044f\u0432\u0430 ssh \u043e\u0442 \u043d\u0435\u0431\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438 ip \u0430\u0434\u0440\u0435\u0441\u0438, \u0441\u043b\u043e\u0436\u0435\u0442\u0435 \u0433\u043e \u0432 \/usr\/local\/bin\/. #!\/bin\/bash ALLOW_COUNTRIES=&#8221;BG&#8221; if [ $# -ne 1 ]; then echo &#8220;Usage: `basename $0` &#8221; 1&gt;&amp;2 exit 0 # return true in case of config &#8230;<\/p>\n<p><a href=\"https:\/\/d1m0.com\/?p=590\" class=\"more-link\">Continue reading &lsquo;\u0417\u0430\u0449\u0438\u0442\u0430 \u043d\u0430 \u0441\u044a\u0440\u0432\u044a\u0440 \u0447\u0440\u0435\u0437 Geoip &#8211; \u0411\u043b\u043e\u043a\u0438\u0440\u0430\u043d\u0435 \u043d\u0430 SSH \u0432\u0440\u044a\u0437\u043a\u0438 \u0438\u0437\u0432\u044a\u043d \u0411\u044a\u043b\u0433\u0430\u0440\u0438\u044f&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-590","post","type-post","status-publish","format-standard","hentry","category-no-category"],"_links":{"self":[{"href":"https:\/\/d1m0.com\/index.php?rest_route=\/wp\/v2\/posts\/590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/d1m0.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/d1m0.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/d1m0.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/d1m0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=590"}],"version-history":[{"count":8,"href":"https:\/\/d1m0.com\/index.php?rest_route=\/wp\/v2\/posts\/590\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/d1m0.com\/index.php?rest_route=\/wp\/v2\/posts\/590\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/d1m0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/d1m0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/d1m0.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}