<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mr. 21 &#187; Security</title>
	<atom:link href="http://mr21.in/tag/security/feed" rel="self" type="application/rss+xml" />
	<link>http://mr21.in</link>
	<description>KunMing &#124; SysAdmin &#124; Blogger &#124; G Fans</description>
	<lastBuildDate>Thu, 06 Oct 2011 09:23:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://mr21.in/?pushpress=hub'/>
		<item>
		<title>SSH和谐主机的iptables设置参考</title>
		<link>http://mr21.in/network-technology/a-iptables-configure-example-for-ssh-host.html</link>
		<comments>http://mr21.in/network-technology/a-iptables-configure-example-for-ssh-host.html#comments</comments>
		<pubDate>Thu, 13 Jan 2011 16:49:55 +0000</pubDate>
		<dc:creator>贰壹</dc:creator>
				<category><![CDATA[網際網路]]></category>
		<category><![CDATA[denyhosts]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[LNMP]]></category>
		<category><![CDATA[Ping]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[VPS]]></category>

		<guid isPermaLink="false">http://mr21.in/?p=383</guid>
		<description><![CDATA[这是一个关于SSH番羽土啬的话题，标题及文中的“和谐”=“番羽土啬”，感叹一下我们的文字。 因为21现在手上的VPS数量比较乐观（不是壮观……），因此其中有专司VPN和谐的、SSH和谐的、第... ]]></description>
			<content:encoded><![CDATA[<p>这是一个关于SSH番羽土啬的话题，标题及文中的“和谐”=“番羽土啬”，感叹一下我们的文字。</p>
<p>因为21现在手上的VPS数量比较乐观（不是壮观……），因此其中有专司VPN和谐的、SSH和谐的、第三方推和谐的等用途，当然，Mr. 21博客也在其中一个VPS上，用的LNMP包。</p>
<p>写这个话题的起因是这样的，在<a href="http://www.beishan.info">北山老卫</a>大神的Q群里面，有人提到了想以SSH和谐帐号来换取一些东西，因此引发了21对此的讨论。我的主要观点是不支持这么做，因为不安全（可以参考《<a href="http://mr21.in/linux-kernel-root-level-exploit-leveraging-multiple-previous-vulnerabilities.html">利用Linux内核的多个安全漏洞提权</a>》，不过本文内容与此关系不大），加上之前帮番茄童鞋配置iptables，因此引发了21对SSH和谐主机安全方面的思考，其中的一方面就是用iptables来过滤不和谐的东西。</p>
<p>是这样的，因为做实验的这个VPS我只用于SSH和谐，并且一般和谐仅限于Web浏览及各种基于Web的应用，所以，以下策略仅开放SSH的22端口并对其它的东西做了相应的限制。</p>
<h3>初始化防火墙</h3>
<p>第一步，我们总是要把一些知道的和不知道的先通通打倒了再说，于是，请如此：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="shell" style="font-family:monospace;">#清除现有的规则
~#: iptables -F
~#: iptables -X
~#: iptables -Z
&nbsp;
#设定默认策略为丢弃包
~#: iptables -P FORWARD DROP
~#: iptables -P OUTPUT DROP
~#: iptables -P INPUT DROP</pre></td></tr></table></div>

<p>以上是一些初始化的动作，以下是具有具体功能的策略。</p>
<h3>防火墙规则参考一</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="shell" style="font-family:monospace;">#允许本地回环
~#: iptables -A INPUT -i lo -p all -j ACCEPT
&nbsp;
#允许22端口接受连接
~#: iptables -A INPUT -p tcp --dport 22 -j ACCEPT
&nbsp;
#允许传入的数据包状态
~#: iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
&nbsp;
#允许传出的数据包状态
~#: iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
&nbsp;
#允许传入PING的ICMP包
~#: iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT</pre></td></tr></table></div>

<p>这几条规则实现的效果是：</p>
<ol>
<li>22端口允许用户主动发起TCP连接，一般用于提供SSH服务，如果你的SSH端口不是22，请修改；</li>
<li>其它端口需要ESTABLISHED、RELATED两种状态的数据包才能通过，而通常这两种状态的数据包在TCP协议上的定义是已经建立了连接的后续数据包，也就说，别人无法对你的任何端口主动发起连接，但是由你主动发起连接的数据包可以通过，比如说看网页的数据；</li>
<li>包状态NEW允许SSH用户对外的主动发起连接；</li>
<li>允许外部用户PING本机，这个嘛，方便自己测试，要不挂了都不知道。</li>
<li>关于数据包状态，我是参考这里 <a href="http://liubin.blog.51cto.com/282313/110394">http://liubin.blog.51cto.com/282313/110394</a> 。</li>
</ol>
<p>这样，虽然防住了外面进来的问题，但一定程度上来说，用户通过SSH登录以后就可以干他想干的事情了，对于应用的范围不能达到一个控制的目的，比如说，我前面提到的“一般和谐仅限于Web浏览及各种基于Web的应用”，是的，和谐嘛，也就是用这些了，顶天了再来个FTP或者跳板另外的SSH，于是，21便想到了稍微BT一点的限制，请看参考二。<br />
<span id="more-383"></span></p>
<h3>防火墙规则参考二</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="shell" style="font-family:monospace;">#允许本地回环
~#: iptables -A INPUT -i lo -p all -j ACCEPT
&nbsp;
#允许22端口的数据进出
~#: iptables -A INPUT -p tcp --dport 22 -j ACCEPT
~#: iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
&nbsp;
#允许状态正常的数据包进入
~#: iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
&nbsp;
#允许访问外部的80、81、8080、443等端口
~#: iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
~#: iptables -A OUTPUT -p tcp --dport 81 -j ACCEPT
~#: iptables -A OUTPUT -p tcp --dport 8080 -j ACCEPT
~#: iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
&nbsp;
#允许UDP数据包外发，由于浏览器发起的是1024~65536之间的随机端口，无法限制为具体端口
~#: iptables -A OUTPUT -p udp -j ACCEPT
&nbsp;
#允许PING测试的数据包进出
~#: iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
~#: iptables -A OUTPUT -p icmp --icmp-type 8 -j ACCEPT</pre></td></tr></table></div>

<p>好吧，规则二实际上能实现跟规则一差不多的效果，就是让SSH和谐用户能正常浏览Web内容及使用Web应用，那区别在哪里呢？之前提到了规则一的SSH用户只要登录进系统，就可以对外发起任何连接了，而规则二只允许用户发起目标端口为80、81、8080、443(https)的TCP连接和任意UDP连接，这样就能有效的限制用户对于SSH的应用范围。</p>
<h3>小结</h3>
<p>基本上，两个规则都实现了主机仅提供SSH服务（参考一）用于浏览网页（参考二）的目的，并且使用iptables对服务器的其它端口都进行了一些屏蔽，同时提供两种规则方式来实现不同的需求，实际上仅仅这样还是不够的，因为让用户登录到shell里面毕竟还是有一定风险的，特别是一些弱密码的用户也有被暴力猜解的风险，我个人是使用fail2ban的方案来解决暴力猜解的问题，请参考《<a href="http://mr21.in/fail2ban-and-lnmp-configration-for-little-memory-vps.html">小内存优化VPS的LNMP及fail2ban配置</a>》，同时还有denyhosts也是用于防止暴力猜解的，可以参考：《<a href="http://www.vpser.net/security/denyhosts.html">Linux VPS上DenyHosts阻止SSH暴力攻击</a>》。</p>
<p>以上内容是21这两天闲来无事的个人研究成果，才疏学浅难免存在一些不合理或不够精简的地方，如果你有任何意见，请留言指教，谢谢。</p>
<p>-EOF-</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
参考引用：<br />
1. Google: <a href="http://www.google.com/ncr">http://www.google.com/ncr</a><br />
2. iptables 状态机制的描述：<a href="http://liubin.blog.51cto.com/282313/110394">http://liubin.blog.51cto.com/282313/110394</a><br />
3. 定制iptables防火墙策略：<a href="http://ailixing.blog.51cto.com/188828/37309">http://ailixing.blog.51cto.com/188828/37309</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mr21.in/network-technology/a-iptables-configure-example-for-ssh-host.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>解决Linux VNC Viewer无法连接Win</title>
		<link>http://mr21.in/software/vnc-connect-to-windows-with-linux.html</link>
		<comments>http://mr21.in/software/vnc-connect-to-windows-with-linux.html#comments</comments>
		<pubDate>Fri, 28 Nov 2008 19:03:39 +0000</pubDate>
		<dc:creator>贰壹</dc:creator>
				<category><![CDATA[软言软语]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[RFB]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VNC]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://mr21.in/?p=216</guid>
		<description><![CDATA[新近安装了Ubuntu 8.10，并且升级各种更新包到最新。 由于工作需要， 需要访问布置了RealVNC的一堆Windows服务器进行日常维护管理， 其中，服务器安装了RealVNC Enterprise Edition v4.3.2, 客户端为Ubuntu 8... ]]></description>
			<content:encoded><![CDATA[<p>新近安装了Ubuntu 8.10，并且升级各种更新包到最新。</p>
<p>由于工作需要，<br />
需要访问布置了<a href="http://www.realvnc.com">RealVNC</a>的一堆Windows服务器进行日常维护管理，<br />
其中，服务器安装了<a href="http://www.realvnc.com/products/enterprise/index.html">RealVNC Enterprise Edition v4.3.2</a>, 客户端为<a href="http://www.ubuntulinux.com">Ubuntu</a> 8.10，</p>
<p>关于安装的VNC viewer，<br />
可以说<strong>新立得</strong>里面有的，我全部都安装测试了，没有一个能用！</p>
<p>不论是直接执行还是通过“终端伺服器用户端”调用，<br />
统统报告“<strong>No match security type</strong>”（没有匹配的安全类型），<br />
头大了，<br />
虽然可以通过RDP连接到终端桌面，但那是虚拟桌面，且服务器只布置了VNC，</p>
<p>经过翻阅新立得的程序说明和各类资料，<br />
发现主要是协议问题，<strong>RFB</strong>的版本过低，新立得里的Viewer最高只能支持<strong>RFB 3.8</strong>，<br />
但是RealVNC Enterprise Edition v4.3.2使用的是<strong>RFB 4.0</strong>，<br />
问题知道了，但是哪里去找支持RFB 4.0的Viewer呢？又折腾了半天~</p>
<p>最终，在RealVNC网站找到<strong>二进制(bin)</strong>的客户端，<br />
有各个OS的Viewer，包括Solaris, Windows, Linux etc, 就是不提供Source，</p>
<p>不过，好在问题解决了，<br />
下载了对应的4.3.2的Viewer，并同时测试了最新的4.4.2的Viewer，<br />
都支持RFB 4.0，OK，问题解决。</p>
<p>后来发现，<br />
新立得里面提供的几个Viewer似乎是RealVNC释出的免费版本（Free edition）使用的源码，<br />
而官方提供的最高版本为：VNC Free Edition 4.1。</p>
<p>结论：以后遇到高版本RFB的VNC Server，试试RealVNC最新的Viewer吧~</p>
<p>下载： http://www.realvnc.com/cgi-bin/download.cgi （填写表单后就出来了）</p>
]]></content:encoded>
			<wfw:commentRss>http://mr21.in/software/vnc-connect-to-windows-with-linux.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress 1.5.2</title>
		<link>http://mr21.in/blog-tips/wordpress/wordpress-152.html</link>
		<comments>http://mr21.in/blog-tips/wordpress/wordpress-152.html#comments</comments>
		<pubDate>Mon, 15 Aug 2005 04:29:43 +0000</pubDate>
		<dc:creator>贰壹</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Upgrade]]></category>

		<guid isPermaLink="false">http://mr21.in/2005/08/15/wordpress-152/</guid>
		<description><![CDATA[We’re happy to announce that a new version of WordPress is now available for download. This set of improvements and security fixes is in line with our commitment to maintaining an extremely stable 1.5 series. In addition to fixing a number of bugs and ... ]]></description>
			<content:encoded><![CDATA[<blockquote><p>We’re happy to announce that a new version of WordPress is now available for download. This set of improvements and security fixes is in line with our commitment to maintaining an extremely stable 1.5 series. In addition to <a href="http://trac.wordpress.org/milestone/1.5.2">fixing a number of bugs</a> and adding requested enhancements for plugin authors, this release also addresses all of the security issues that have been circulating the past few days.</p>
<p>This is a very straight-forward upgrade, you just need to upload the new files over the old, but as always the Codex is the best resource on upgrading. </p></blockquote>
<p>哎，又见安全问题，不过，修了就好。<br />
咱这小Blog也不会有人来黑着玩的，不像<a href="http://yanfeng.org/blog/634/">桑林志那么危险</a>……<br />
中午就给Upgrade了吧~~</p>
<p>顺带给WP的Newcomer说一下怎么升级，<br />
一般人都害怕把制作的模板，插件什么的给弄丢了，关键还有数据库上的问题。</p>
<ol>
<li>下载1.5.2的包，解压了</li>
<li>进入1.5.2的目录，删除wp-content目录</li>
<li>进入wp-admin，删除install.php、install-helper.php、setup-config.php（import-*.php也可以选择删除，那些是用来导入其它Blog程序数据的）</li>
<li>上传完以后，访问readme.html，执行Upgrade，升级完毕后，进入服务器FTP里面的wp-admin目录删除upgrade.php、upgrade-functions.php、upgrade-schema.php</li>
<li>升级完毕（删除那些php文件属于安全范畴，也可以选择不删）</li>
</ol>
<p>相关：<br />
WordPress 1.5.2: http://wordpress.org/latest.tar.gz</p>
]]></content:encoded>
			<wfw:commentRss>http://mr21.in/blog-tips/wordpress/wordpress-152.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Security on Blog</title>
		<link>http://mr21.in/jokes/security-on-blog.html</link>
		<comments>http://mr21.in/jokes/security-on-blog.html#comments</comments>
		<pubDate>Sun, 19 Jun 2005 01:27:10 +0000</pubDate>
		<dc:creator>贰壹</dc:creator>
				<category><![CDATA[二一视点]]></category>
		<category><![CDATA[開懷一笑]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://mr21.in/2005/06/19/security-on-blog/</guid>
		<description><![CDATA[在CCW看到这么一篇报道：《博客网站暴出三大漏洞 网络安全存巨大隐患》， 觉得他们纯粹就是吃饱了撑的，提这种问题讨论。 文中提到： 分析认为，现在的“博客网站”主要有以下安全漏洞... ]]></description>
			<content:encoded><![CDATA[<p>在CCW看到这么一篇报道：<a href="http://www.ccw.com.cn/news2/secure/htm2005/20050617_10QBD.htm">《博客网站暴出三大漏洞 网络安全存巨大隐患》</a>，<br />
觉得他们纯粹就是吃饱了撑的，提这种问题讨论。</p>
<p>文中提到：</p>
<blockquote><p>分析认为，现在的“博客网站”主要有以下安全漏洞：<br />
　　一是内容发布系统管理，基于博客倡导的自由化、个性化，只要用户进行身份认证便可以发放信息，以至于任何人都可利用内容发布嵌入恶意代码；<br />
　　二是回帖，不少博客网站的个人博客不需要登录即可直接回复，且回帖内容也几乎没有任何审核，这比BBS更让黑客得心应手，黑客很有可能通过匿名回复将病毒链接在一个高访问量的个人博客后；<br />
　　三是附加功能，追求与众不同是人的天性，不少博客为了吸引用户，在个人博客设置上增加了背景音乐等功能，这些高级功能一方面使博客变得更加丰富多彩，但另一方面无疑给了黑客另一个工具，黑客可以将这些功能作为病毒代码的替代品，植入木马也可做得更加隐蔽。
</p></blockquote>
<p>我认为：</p>
<blockquote>
<ol>
<li>本来BLOG就是基于HTML的，只要HTML能做的事，在BLOG上自然也没问题。但是为什么你的浏览器就害怕恶意代码呢？<br />
因为你的浏览器不够安全，你的升级不够勤快，你的系统不够坚固，你的安全不够水平.. .. ..<br />
那能怪谁？只能怪你丫水平/运气都不好才会中招，我的系统用了半年，什么问题都没有.. .. ..</li>
<li>我打赌这家伙肯定不懂“SNS”是个什么概念。<br />
作为一种开放/交流模式的BLOG，如果你需要验证、需要注册，那谁还光顾BLOG？BBS不就够用了吗？！<br />
至于所谓的“病毒连接”，如果单纯做一个LINKS，那只有笨蛋才会乱点，就算点进去了，也只有第一条描述的人才会中毒，而且回复是可以限制的，谁说用回复就可以使用全部HTML代码的？<br />
而且，个人主页就没这问题了吗？就算有，就算很严重，现在不也蓬勃发展么！</li>
<li>说到这里了，发现这段就纯粹废话了，还是在重复第一条。所谓的什么背景音乐，一样是个人主页可以做到的，为什么不也提一下？再说了，还是那句话，能中毒的都是“因为你的浏览器不够安全，你的升级不够勤快，你的系统不够坚固，你的安全不够水平.. .. ..”<br />
更何况，如果一个站点有问题，那还有谁光顾？如果BLOG作得精彩，那谁舍得放木马？如果放了木马丢了用户，那那丫还开BLOG做什么？</li>
</ol>
</blockquote>
<p>所以，结论就是：文章的作者吃饱了撑的.. .. ..</p>
]]></content:encoded>
			<wfw:commentRss>http://mr21.in/jokes/security-on-blog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security</title>
		<link>http://mr21.in/view-points/security.html</link>
		<comments>http://mr21.in/view-points/security.html#comments</comments>
		<pubDate>Fri, 08 Apr 2005 10:42:10 +0000</pubDate>
		<dc:creator>贰壹</dc:creator>
				<category><![CDATA[二一视点]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://live21.makemyblog.info/?p=24</guid>
		<description><![CDATA[今天回去S4T看了一下，发现已经被除名了，不过也是预料中的事情，因为事前已经托晓风帮忙说一声要脱离组织了，毕竟回去的我已经不如以前了，斗志都削减了不少，对安全方面也疏忽了不... ]]></description>
			<content:encoded><![CDATA[<p>今天回去<a href="http://www.4ngel.net">S4T</a>看了一下，发现已经被除名了，不过也是预料中的事情，因为事前已经托晓风帮忙说一声要脱离组织了，毕竟回去的我已经不如以前了，斗志都削减了不少，对安全方面也疏忽了不少，也没什么资格留在S4T了，留着也是浪费，不过还是有一点伤感的，<a href="http://www.4ngel.net/blog/angel">angel</a>倒是很久没见了，不过从blog上看，他的技术一直在提升……我倒是在后退，学习也不见好，哎，<br />
实在浪费~不过，我跟angel早就不是一个级别上的了~~</p>
<p>最近云南这边据说要举办一个比赛，据说还有照顾的那种，不知道是不是欺骗学生感情，这次泼水节游7天假期，说是给我们这点时间，有点兴趣的弄点东西，获奖了高考就不愁了~<br />
看了一下说明，说是叫“2005年中学生电脑制作比赛”，参赛的东西包括了一大堆，大家还是自己看吧~~嘿嘿~<br />
<a href='http://live21.makemyblog.info/images/2005.doc' title=''>参赛说明（DOC格式）</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mr21.in/view-points/security.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

