-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
327 lines (190 loc) · 11.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>BlackHole开发日志--防止DNS污染 - 代码工匠</title>
<meta name="author" content="code4craft">
<meta name="description" content="DNS污染原理 DNS污染是比DNS劫持更加难以防御的一种攻击,受攻击者访问网站时可被导向其他域名,例如某“不存在的网站”被导向了一个“不存在的IP地址”。 DNS污染的原理如下: DNS查询也是一个经典的请求-回答模式。首先,客户端发起DNS查询,这是一个UDP包。路由器在转发IP包时, …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://code4craft.github.com/blog/2013/02/25/blackhole-anti-dns-poison/">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="/atom.xml" rel="alternate" title="代码工匠" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-41279861-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">代码工匠</a></h1>
<h2>Walking The Long Road.</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:code4craft.github.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">BlackHole开发日志--防止DNS污染</h1>
<p class="meta">
<time datetime="2013-02-25T21:13:00+08:00" pubdate data-updated="true">Feb 25<span>th</span>, 2013</time>
</p>
</header>
<div class="entry-content"><h3></h3>
<hr />
<h3>DNS污染原理</h3>
<p>DNS污染是比DNS劫持更加难以防御的一种攻击,受攻击者访问网站时可被导向其他域名,例如某“不存在的网站”被导向了一个“不存在的IP地址”。</p>
<p>DNS污染的原理如下:</p>
<p>DNS查询也是一个经典的请求-回答模式。首先,客户端发起DNS查询,这是一个UDP包。路由器在转发IP包时,对其内容做解析,若发现其是使用53端口的UDP包,并且其内容符合某些特征(普通的DNS请求都是明文),则从旁路直接返回一个伪造的应答,将其应答指向某个特定IP。因为这个返回速度非常快,所以先于正常请求到达客户端。而客户端收到一个返回包,就认为得到了答案,不再继续接收,而正确的请求结果就被忽略了!</p>
<p><img src="/images/posts/dns-poison.png" alt="image" /></p>
<!-- more -->
<p>一般防止DNS污染有几种方法:</p>
<ul>
<li><p>修改系统hosts文件</p>
<p> 系统的hosts文件可以配置某个域名对于的IP地址,并且会优先于DNS服务器的响应,所以此方法稳定高效,缺点是host地址需要不断更新。</p></li>
<li><p>改用TCP协议而不是DNS协议发送DNS请求</p>
<p> DNS也支持TCP协议传输,而TCP协议没有收到污染,所以可以改用TCP作为DNS下层协议。缺点是TCP速度慢,并且DNS服务器支持度有限。代表工具:Tcp-DNS-proxy <a href="https://github.com/henices/Tcp-DNS-proxy">https://github.com/henices/Tcp-DNS-proxy</a></p></li>
<li><p>使用IPv6地址发送DNS请求</p>
<p> 某些站点可以通过IPv6地址访问。代表工具:dnsproxycn <a href="http://code.google.com/p/dnsproxycn/">http://code.google.com/p/dnsproxycn/</a></p></li>
<li><p>根据污染特征过滤伪造DNS答案</p>
<p> 先截获DNS污染结果,然后分析其特征,然后将判断为污染的DNS包过滤掉。代表工具:AntiDnsPollution <a href="http://www.williamlong.info/archives/2184.html">http://www.williamlong.info/archives/2184.html</a></p></li>
</ul>
<h3>BlackHole解决方案</h3>
<p>BlackHole解决方案是第4种:向一个不存在的地址发送DNS查询,正常情况下不会有应答;若触发DNS污染,则只会有伪造包返回。记录这个伪造包的特征(一般是A记录的IP地址),加入黑名单,下次如果收到这些包,则直接过滤。</p>
<p>其实开发BlackHole时不知道有AntiDnsPollution这款工具,完成了才知道,采取的方法不谋而合。只不过BlackHole做的更复杂一点,增加了一些功能:</p>
<ul>
<li><p>DNS污染黑名单持久化</p>
<p> 所有污染IP都会存入”安装路径/blacklist”文件,每次重启可继续读入,也支持手工修改。</p></li>
<li><p>可用IP导出host</p>
<p> BlackHole会对IP地址做可达性判断(根据ICMP协议请求),存在DNS污染的域名,若正确DNS地址中,同时有可达IP,则会产生一条”IP domain”的DNS记录到”安装路径/safebox”文件中,与hosts文件格式一致,可以粘贴进去,从而无须再启动BlackHole。</p></li>
<li><p>支持多DNS服务器请求</p>
<p> BlackHole可以同时向多个DNS服务器请求,并采用最先返回的正确结果作为答案返回;同时后台会继续接收响应,并根据最终答案中IP地址的可用性进行判断,去掉不可用的IP。你可以将BlackHole的转发DNS配置为:一个ISP提供的服务器,速度较快;另一个权威的DNS服务器,结果较可信。对于大多数请求,ISP提供的DNS可以满足需要,从而降低查找时间。同时如果在公司内网中使用,还可以将公司内部DNS服务器地址配置进去,这样可以保证内部配置的某些DNS的有效性。</p></li>
<li><p>支持缓存</p>
<p> BlackHole使用ehcache作为缓存,并且可以持久化,下次启动时可直接载入上次缓存结果。</p></li>
<li><p>可配置</p>
<p> BlackHole还是修改hosts文件的替代方案。通过修改”config/zones”可以自定义DNS拦截规则,支持通配符”*“。</p></li>
</ul>
<p>BlackHole的源码地址:<a href="https://github.com/code4craft/blackhole">https://github.com/code4craft/blackhole</a></p>
</div>
<footer>
<p class="meta">
<span class="byline author vcard">Posted by <span class="fn">code4craft</span></span>
<time datetime="2013-02-25T21:13:00+08:00" pubdate data-updated="true">Feb 25<span>th</span>, 2013</time>
<span class="categories">
<a class='category' href='/blog/categories/blackhole/'>BlackHole</a>, <a class='category' href='/blog/categories/gfw/'>gfw</a>
</span>
</p>
<div class="sharing">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://code4craft.github.com/blog/2013/02/25/blackhole-anti-dns-poison/" data-via="" data-counturl="http://code4craft.github.com/blog/2013/02/25/blackhole-anti-dns-poison/" >Tweet</a>
</div>
<p class="meta">
<a class="basic-alignment left" href="/blog/2013/02/17/fenng-career/" title="Previous Post: 十年莽撞IT路">« 十年莽撞IT路</a>
<a class="basic-alignment right" href="/blog/2013/02/25/2012-summary/" title="Next Post: 2012年总结">2012年总结 »</a>
</p>
</footer>
</article>
<section imagesd="comment">
<h1>Add a comment</h1>
<!-- Duoshuo Comment BEGIN -->
<div class="ds-thread"></div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"code4craft"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = 'http://static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<!-- Duoshuo Comment END -->
</section>
</div>
<aside class="sidebar">
<section>
<h1>新浪微博</h1>
<ul id="weibo">
<li>
<iframe
width="100%"
height="550"
class="share_self"
frameborder="0"
scrolling="no"
src="http://widget.weibo.com/weiboshow/index.php?width=0&height=550&ptype=1&speed=0&skin=&isTitle=0&noborder=1&isWeibo=1&isFans=&uid=1487828712&verifier=a3843d95">
</iframe>
</li>
</ul>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/blog/2016/11/26/chuang-ye-gong-si-zhi-nan-zhi-ban-gong-shi-wang-luo-checklist/">创业公司指南之办公室网络checklist</a>
</li>
<li class="post">
<a href="/blog/2016/11/07/chuang-ye-ri-zhi-%28si-%29-man-xia-lai-de-tuan-dui/">创业日志(四)——慢下来的技术团队</a>
</li>
<li class="post">
<a href="/blog/2016/10/30/chuang-ye-ri-zhi-%28san-%29%5Byi%5D-nian-hou-%5Byi%5D-xie-ji-zhu-shang-de-zong-jie/">创业日志(三)一年来一些技术上的总结</a>
</li>
<li class="post">
<a href="/blog/2016/06/27/yao-you-dian-wei-ji-gan/">要有点危机感</a>
</li>
<li class="post">
<a href="/blog/2016/03/31/xie-zai-webmagickuai-yao-san-nian-de-shi-hou/">写在WebMagic快要三岁的时候</a>
</li>
</ul>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2016 - code4craft -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>