<?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>NetworksAreMadeOfString &#187; Systems</title>
	<atom:link href="http://blog.networksaremadeofstring.co.uk/category/datacenter/systems/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.networksaremadeofstring.co.uk</link>
	<description>Cat5, Cat6, Fibre, or String.............</description>
	<lastBuildDate>Mon, 21 Jun 2010 19:37:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Utilising Read Only Domain Controllers to Leverage Hosted Active Directory</title>
		<link>http://blog.networksaremadeofstring.co.uk/2009/08/20/utilising-read-only-domain-controllers-to-leverage-hosted-active-directory/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2009/08/20/utilising-read-only-domain-controllers-to-leverage-hosted-active-directory/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 19:57:57 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Datacenter]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Networks]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/?p=533</guid>
		<description><![CDATA[One of the common issues that appears when integrating a hybrid vision of Hosted Exchange with someones existing infrastructure (so not really Hosted Exchange at all!) is synchronising credentials between the Exchange Server and the local machines or for the more tech savvy the &#8216;hackiness&#8217; of having disparate forests. Cross Forest trusts are a possibility [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common issues that appears when integrating a hybrid vision of Hosted Exchange with someones existing infrastructure <em>(so not really Hosted Exchange at all!)</em> is synchronising credentials between the Exchange Server and the local machines or for the more tech savvy the &#8216;hackiness&#8217; of having disparate forests. </p>
<p>Cross Forest trusts are a possibility and merging one with the other <em>(i.e having the Hosted Exchange solution bound to the existing domain)</em> is another but there are many issues with that <em>(mostly political)</em>. </p>
<p>What I intend to do is utilise the &#8216;Branch office&#8217; concept that Read Only Domain Controllers were designed for to mock up a solution for Hosting the entire AD infrastructure remotely and having R/O DC&#8217;s on the customer premises. </p>
<h2>What now?</h2>
<p>For no other reason than that of satisifying my curiosity I built an entire AD infrastructure hosted at the data center and then had a remote &#8216;office&#8217; running for a day without a local DC and then the following day with a Read Only Domain Controller sitting there. </p>
<p>There&#8217;s nothing new or crazy here other than maybe the fact that most people move bits of their AD infrastructure to the DC when its bandwidth requirements overwhelm their resources. What I&#8217;m playing with is the idea of having everything remote and only putting the stuff you need (NAS etc) in the office.</p>
<h2><strong>The Test</strong></h2>
<p>In the Red Corner we have a full Active Directory and Exchange infrastructure at the DC and then the &#8216;offices&#8217; were built using a few Terminal Services servers  running a respective amounts of users. The idea is to monitor traffic before dropping in a RO DC and then again afterwards. </p>
<h2><strong>The Infrastructure</strong></h2>
<h2>Hosted Infrastructure</h2>
<p><a href="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/08/hosted-infrastructure.png"><img src="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/08/hosted-infrastructure-101x300.png" alt="" title="hosted-infrastructure" width="101" height="300" class="alignnone size-medium wp-image-170" /></a> The Hosted infrastructure consists of a relatively standard Exchange 2007 deployment (if you follow the guidelines) visible to the world (selected ports only) is an Edge Transport server for handling the initial mail connections and the Client Access Server. Behind those is the Mailbox and Hub Transport (in reality these were on the same box but the diagram wasn&#8217;t as symmetrical then!).<br />
<br/><br />
The Domain controller is a special case because whilst we have no reason for the Internet at large to talk to it we need the read only Domain Controller at the client site to be able to communicate with it so an IPSEC LAN to LAN VPN was required.<br />
<br/><br/><br/><br/></p>
<h2><strong>The Results</strong></h2>
<p><br/></p>
<h2>AD Traffic From the TS to the Remote DC No Local DC</h2>
<p><a href="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/09/replication_traffic_no_local_dc.png"><img src="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/09/replication_traffic_no_local_dc.png" alt="" title="Active Directory Traffic From the TS to the Remote DC" width="500" height="166" class="aligncenter size-full wp-image-187" /></a><br />
<br/><br/></p>
<h2>AD Traffic to the Remote DC with Local RODC</h2>
<p><a href="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/09/replication_traffic_rodc.png"><img src="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/09/replication_traffic_rodc.png" alt="" title="Active Directory Traffic to the Remote DC with A Local RODC" width="500" height="166" class="aligncenter size-full wp-image-189" /></a><br />
<br/><br/><br/></p>
<h2>OWA Traffic During the Tests</h2>
<p><em>Scripted behavior &#8211; so it was the same(ish) on both days</em><br />
<a href="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/09/traffic-owa.png"><img src="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/09/traffic-owa.png" alt="" title="OWA Traffic" width="500" height="203" class="aligncenter size-full wp-image-195" /></a><br />
<br/><br/><br/></p>
<h2>Conclusion</h2>
<p>Well it did exactly what I expected it to do so nothing ground breaking there. It was interesting to see the spike just after I logged all the fake users off the Terminal Servers.</p>
<p>R/O DC&#8217;s were used because in an ideal world customers shouldn&#8217;t have write access to an AD infrastructure that a SysAdmin has an SLA to honor!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2009/08/20/utilising-read-only-domain-controllers-to-leverage-hosted-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing psFetch</title>
		<link>http://blog.networksaremadeofstring.co.uk/2008/09/25/introducing-psfetch/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2008/09/25/introducing-psfetch/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 23:08:23 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[NAMOS]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/?p=207</guid>
		<description><![CDATA[psFetch is my latest project and is a Powershell cmdlet that communicates with various Repositories on the Internet to find what you are looking for and easily download and install them to your machine. The cmdlet itself is written in C# and utilises a centralised LAMP backend as a repository and director. Upon install psFetch [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.psFetch.net">psFetch</a> is my latest project and is a Powershell cmdlet that communicates with various Repositories on the Internet to find what you are looking for and easily download and install them to your machine.</p>
<p>The cmdlet itself is written in C# and utilises a centralised LAMP backend as a repository and director. </p>
<p>Upon install psFetch will create a custom shortcut on your desktop which includes the psFetch cmdlet as one of the default set of commands available without having to use add-pssnapin each time.</p>
<p>Everytime you add a cmdlet or script they will be added to your console profile and will be available in any consoles you load from that point on. When you psFetch a custom script it&#8217;s alias will be added to your shell and any other shells launched from that point on to ensure a consistant experience.</p>
<p>In the next couple of months the PSFetch crawler will attempt to trawl CodePlex and various other sites to try and build up the initial repository. When the crawler goes live you will also be able to add your own cmdlets and scripts manually.</p>
<p>I am hoping to build up a Core team of Beta testers to ensure that when the initial release of psFetch is made available it will be as bug free as possible!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2008/09/25/introducing-psfetch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory Fun</title>
		<link>http://blog.networksaremadeofstring.co.uk/2008/08/29/active-directory-fun/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2008/08/29/active-directory-fun/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 19:17:55 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[NAMOS]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/?p=158</guid>
		<description><![CDATA[This post has no real merit its just that the Error message caused me to actually laugh out loud:]]></description>
			<content:encoded><![CDATA[<p>This post has no real merit its just that the Error message caused me to actually laugh out loud:<br />
<div id="attachment_159" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/08/active-directory.png"><img src="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/08/active-directory-300x224.png" alt="An error with no description occurred" title="Active Directory Error" width="300" height="224" class="size-medium wp-image-159" /></a><p class="wp-caption-text">An error with no description occured</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2008/08/29/active-directory-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last H.O.P.E and Tackling the Debian OpenSSL Issue</title>
		<link>http://blog.networksaremadeofstring.co.uk/2008/07/30/last-hope-and-tackling-the-debian-openssl-issue/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2008/07/30/last-hope-and-tackling-the-debian-openssl-issue/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 17:34:38 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Datacenter]]></category>
		<category><![CDATA[Networks]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2008/07/30/last-hope-and-tackling-the-debian-openssl-issue/</guid>
		<description><![CDATA[Well I&#8217;m back from my trip to New York and I&#8217;ve brought back a couple of things. With the most tracks HOPE has ever had I was truly spoilt for choice but I spent most of my time [when I wasn't showing our US friends how drinking should be done] visiting talks that had potential [...]]]></description>
			<content:encoded><![CDATA[<p>Well I&#8217;m back from my trip to New York and I&#8217;ve brought back a couple of things.</p>
<p>With the most tracks HOPE has ever had I was truly spoilt for choice but I spent most of my time [<em>when I wasn't showing our US friends how drinking should be done</em>] visiting talks that had potential datacenter impact.</p>
<p>Kevin Figueroa, Marco Figueroa and Anthony L. Williams reminded me that VLAN&#8217;s and other layer 2 stuff is still vulnerable to many attacks. Most are just Denial of Service stuff that would be detected almost instantly and very easily fixed (<em>although not easily preventable</em>) but the cross VLAN packet injection / snooping made me rethink some of my installations that packet injection / snooping would not be a critical issue but might not be desirable. Bare in mind though that in order to attack layer 2 someone needs to own a box on my layer 2 infrastructure which is much more of an issue! </p>
<p>The demonstration that stuck with me the most was Jacob Appelbaum, Dino Dai Zovi and Karsten Nohl&#8217;s talk regarding the Debian OpenSSL catastrophe. When I first heard about it there was much smugness (<em>being as I only use Red Hat Enterprise / CentOS and FreeBSD</em>) My fellow SysAdmins and I had many hours of fun reminding our collegues who had chosen Debian as their Distro of choice of this &#8216;little&#8217; bug.</p>
<p>Unfortunately our smugness was shortlived as these Debian keys can end up in a RedHat servers authorised_keys file which results in that server being vulnerable to <a href="http://www.metasploit.com/users/hdm/tools/debian-openssl/">Brute Forcing</a>. Knowing how lazy people are and how widespread the careless use of root is there was likely to be a few machines out there just waiting to get rooted. </p>
<p>The majority of tools (<em>asides from the <a href="http://security.debian.org/project/extra/dowkd/dowkd.pl.gz">official Debian tools</a></em>) are designed for discovering vulnerable servers that <strong>don&#8217;t</strong> belong to you! The Debian tool is great unless for one reason or another you don&#8217;t / can&#8217;t have Perl installed.</p>
<p>Therefore I present to you another hacked together bash script that anyone <em>could</em> have put together in 5 minutes but maybe this&#8217;ll save someone the hassle.</p>
<p><code><br />
#!/bin/bash<br />
#--------------------------------------<br />
# Looks for fscking debian client keys<br />
# Gareth#NetworksAreMadeOfString.co.uk<br />
#--------------------------------------<br />
<br />
for KeysFile in `locate authorized_keys`; do<br />
&nbsp;&nbsp;echo<br />
&nbsp;&nbsp;echo Testing $KeysFile for weak keys<br />
&nbsp;&nbsp;echo -------------------------------------------------<br />
<br />
&nbsp;&nbsp;cat $KeysFile | while read line; do<br />
<br />
&nbsp;&nbsp;&nbsp;echo $line > pubkey.tmp<br />
<br />
&nbsp;&nbsp;&nbsp;RawFP=`ssh-keygen -l -f pubkey.tmp | awk '{print $2}'`<br />
<br />
&nbsp;&nbsp;&nbsp;FP=${RawFP//:/}<br />
<br />
&nbsp;&nbsp;&nbsp;MatchCount=`grep -c $FP FingerPrints.db`<br />
<br />
&nbsp;&nbsp;&nbsp;if [ $MatchCount -gt 0 ]; then<br />
&nbsp;&nbsp;&nbsp;echo -e '\E[40;31m'"\033[1m!!!!! WEAK KEY FOUND!!!!!!\033[0m"<br />
&nbsp;&nbsp;&nbsp;echo $line<br />
&nbsp;&nbsp;&nbsp;fi<br />
&nbsp;&nbsp;&nbsp;done<br />
&nbsp;&nbsp;done<br />
&nbsp;echo<br />
&nbsp;echo ------------- DONE -------------<br />
</code></p>
<p>The FingerPrints.db file can be found <a href="http://blog.networksaremadeofstring.co.uk/wp-content/uploads/Directs/FingerPrints.db">here</a></p>
<p>Hopefully you&#8217;ll find vulnerable user accounts before someone else does!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2008/07/30/last-hope-and-tackling-the-debian-openssl-issue/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows Server 2008 With Exchange 2007 &#8211; In Production</title>
		<link>http://blog.networksaremadeofstring.co.uk/2008/05/29/windows-server-2008-with-exchange-2007-in-production/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2008/05/29/windows-server-2008-with-exchange-2007-in-production/#comments</comments>
		<pubDate>Thu, 29 May 2008 19:30:32 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Datacenter]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[NAMOS]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2008/05/29/windows-server-2008-with-exchange-2007-in-production/</guid>
		<description><![CDATA[Considering how bleeding edge the majority of my projects are I&#8217;m a little behind the curve on this one but I&#8217;ve finally managed to move all my Windows Servers across to Windows Server 2008. This includes the Domain Controllers, Web Servers and most critically the Exchange servers. This post is going to be cut into [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/windows_server_2008.png' style="border-style: none" alt='Windows Server 2008 With Exchange 2007 - In Production' />Considering how bleeding edge the majority of my projects are I&#8217;m a little behind the curve on this one but I&#8217;ve finally managed to move all my Windows Servers across to Windows Server 2008. This includes the Domain Controllers, Web Servers and most critically the Exchange servers.</p>
<p>This post is going to be cut into the following sections:</p>
<li>Exchange 2007 Prerequisites on Windows Server 2008</li>
<li>Cross Forest Migration of Exchange 2007 Mailboxes and User Accounts</li>
<li>Creating SSL Certificates for use with Exchange 2007 on Windows Server 2008</li>
<p><br/><br />
<strong>Exchange 2007 Prerequisites on Windows Server 2008</strong><br />
The first thing to do is to run a Windows update as there are already several patches available. Once thats done the prequisite componants of Server 2008 can be installed via the command line (not powershell!), simply load up a command prompt and paste / type each one of these:<br />
<code><br />
ServerManagerCmd -i RSAT-ADDS<br />
ServerManagerCmd -i PowerShell<br />
ServerManagerCmd -i Web-Server<br />
ServerManagerCmd -i Web-ISAPI-Ext<br />
ServerManagerCmd -i Web-Metabase<br />
ServerManagerCmd -i Web-Lgcy-Mgmt-Console<br />
ServerManagerCmd -i Web-Basic-Auth<br />
ServerManagerCmd -i Web-Digest-Auth<br />
ServerManagerCmd -i Web-Windows-Auth<br />
ServerManagerCmd -i Web-Dyn-Compression<br />
</code></p>
<p>Once those are installed (the server may have to reboot a couple of times) then Exchange 2007 SP1 can be installed. Be aware that Exchange 2007 RTM can <strong>not</strong> be installed on Windows Server 2008. </p>
<p>Exchange Server 2008 Service Pack 1 is available <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=44C66AD6-F185-4A1D-A9AB-473C1188954C&#038;displaylang=en">here</a> and is in effect a copy of Exchange with the service pack streamlined in <em>(the warez kiddies are gonna love this)</em>. Get this extracted and installed. During the install it will complain about not finding a send connector for &#8216;*&#8217; remember this for later.<br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/send-connector-error.png' title='Exchange 2007 Send Connector error'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/send-connector-error-TN.png' alt='Exchange 2007 Send Connector error' /></a></p>
<p><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></p>
<p>Once Exchange is installed and configured it&#8217;d be recommendable to do another Windows Update as even being SP1 there are a few more updates.</p>
<p>Once the server has restarted its time to add the Send Connector that setup complained about earlier. Within Organisation Configuration select Hub Transport and then click on the Send Connector tab and choose the &#8216;New Send Connector&#8217; option. Obviously whatever is required can be configured here but all I want to do at the moment is send email out to the world:</p>
<p><code>new-SendConnector -Name 'Default Connector' -Usage 'Internet' -AddressSpaces 'smtp:*;1' -DNSRoutingEnabled $true -UseExternalDNSServersEnabled $false -SourceTransportServers 'ServerName'</code></p>
<p>Now the Exchange 2007 server can send email out to the world, unfortunately there&#8217;s no-one on it yet!</p>
<p><br/><br />
<strong>Cross Forest Migration of Exchange 2007 Mailboxes and User Accounts</strong><br />
Whilst most people are unlikely to have come across this situation I decided to start my AD infrastructure completely from scratch. Unlike normal people I don&#8217;t have any Workstations bound to domain controllers I just have various forests in different parts of the world for Exchange, RADIUS and Kerberos based authentication.</p>
<p>Despite the lack of workstations asking people to start their mailboxes, calendars and contacts etc from scratch would just not have gone down well.</p>
<p>The Microsoft Press Exchange 2007 Pocket Handbook recommends the following PowerShell cmdlet to get the job done:<br />
<code><br />
Move-Mailbox -Identity 'domain\username' -TargetDatabase 'servername\First Storage Group\DBName' -SourceDomainController 'SourceDC'] [-DomainController 'DestinationDC'] -SourceGlobalCatalog 'SourceGC'] [-GlobalCatalog 'DestinationGC'] -BadItemLimit 50 -IgnorePolicyMatch $true<br />
</code></p>
<p>Unfortunately this results in the following error:<br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/move-mailbox-error.png' title='Exchange 2007 Move-Mailbox cmdlet error'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/move-mailbox-thumbnail.png' alt='Exchange 2007 Move-Mailbox cmdlet error' /></a></p>
<p><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br />
A bit of poking around later and I finally get a cmdlet string that does what I need it to do:</p>
<p><code><br />
$SourceCredential = Get-Credential<br />
$TargetCredential = Get-Credential<br />
Move-Mailbox -TargetDatabase "Target Server\First Storage Group\Mailbox Database" -Identity UserName -GlobalCatalog GCServerName -SourceForestGlobalCatalog GCServerName -NTAccountOU "OU=OUName,DC=DomainName,DC=com" -SourceForestCredential $SourceCredential -TargetForestCredential $TargetCredential -SourceMailboxCleanupOptions DeleteSourceNTAccount<br />
</code><br />
The use of get-credentials at the beginning is so there is a System.Security.SecureString object to pass to the Move-Mailbox cmdlet. I&#8217;ve set them as variables so I know exactly which popup dialog is for which server.</p>
<p>Unfortunately I hit another stumbling block; because of the -SourceMailboxCleanupOptions DeleteSourceNTAccount arguement the process insists on deleting all traces of the user from the source forest and replacing them with a Mail Contact so running that command will result in a nasty message:<br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/Delete-user.png' title='Exchange 2007 Cross Forest Move Error'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/Delete-user-TN.png' alt='Exchange 2007 Cross Forest Move Error' /></a><br />
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br />
Simply disable the user in the source Forest and run the command again.</p>
<p>Now the user is in the new forest along with their mailbox etc, unfortunately the user is still disabled and the users mailbox shows as a &#8216;linked mailbox&#8217; rather than a user mailbox. </p>
<p>Because Microsoft still haven&#8217;t provided any proper Active Directory cmdlets and I hadn&#8217;t installed the Quest cmdlets I re-enabled the user via the Active Directory Users and Computers MMC so no PowerShell example I&#8217;m afraid.</p>
<p>Even after enabling the account I still couldn&#8217;t login. In hindsight it makes perfect sense that a cross forest move means the user no longer has a valid UPN however I have to admit I was stuck for a moment or two! Within the account tab in Active Directory Users and Computers give the user an account name and choose a domain suffix.</p>
<p>The user can now login and has all their mail etc. Unfortunately the mailbox shows as a &#8216;linked mailbox&#8217;. I expect this is linked to the UPN / SID issues. If the loss of custom rules / forwarders etc isn&#8217;t an issue then simply disconnect and reconnect the mailbox to the corrected user account:</p>
<p><code><br />
Disable-Mailbox -Identity UserName<br />
Connect-Mailbox -Identity UserName -Database "Mailbox Database" -User UserName<br />
</code></p>
<p><br/><br />
<strong>Creating SSL Certificates for use with Exchange 2007 on Windows Server 2008</strong></p>
<p>The first thing to do is create the CSR but rather than using a single Common Name Exchange 2007 has some tricks up its sleeve with autodiscover etc so the CSR will need some Subject Alternative Names as well.</p>
<p><code><br />
New-ExchangeCertificate -GenerateRequest -SubjectName "<br />
DC=networksaremadeofstring, DC=co, DC=uk, O=NetworksAreMadeOfString, CN=<br />
exch07.networksaremadeofstring.co.uk"<br />
-DomainName mail.networksaremadeofstring.co.uk, smtp.networksaremadeofstring.co.uk, autodiscover.networksaremadeofstring.co.uk, networksaremadeofstring.co.uk, exchange.networksaremadeofstring.co.uk<br />
-FriendlyName "New Exchange"<br />
-Path c:\mail.networksaremadeofstring.co.uk.req<br />
</code><br />
When this is complete the script will output something similar to the following:<br />
<code><br />
Thumbprint                                                                Services   Subject<br />
----------                                                                 --------   -------<br />
DED40CE5BD344F7FA9C76081E5412A8AF17FB8F2  .....      DC=cadogan-house, DC=ne...<br />
</code></p>
<p>Take note of the thumbprint which will be needed later to import and enable the certificate.</p>
<p>Send this to a Certificate Authority of choice (I use <a href="http://www.cacert.org">CACert.org</a>).</p>
<p>Once the Authority returns the Certificate import it into the Certificate store:<br />
<code><br />
Import-ExchangeCertificate -path C:\certificate.cer<br />
</code></p>
<p>Once imported its time to enable it for various services:<br />
<code><br />
Enable-ExchangeCertificate -thumbprint 493C50CFFF8B65344F1FBEAF8BE6740044F1842B -services "IIS,SMTP"<br />
</code></p>
<p>At this point I got hit with another error message about the private key being missing:</p>
<p><a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/private-key-error.png' title='Exchange 2007 Missing Private Key'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/private-key-error-TN.png' alt='Exchange 2007 Missing Private Key' /></a></p>
<p><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></p>
<p>It turns out that Windows Server 2008 / Exchange 2007 doesn&#8217;t import / set the Private Key for generated certificates. In the Certificate MMC certificates are usually shown with an icon depicting a certificate and ones with a corresponding Private key also show a little key icon. The self generated certificate has a little key icon but the imported one does not.</p>
<p><a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/Certificate-Broken.png' title='Exchange 2007 Missing Private Key'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/Certificate-Broken-TN.png' alt='Exchange 2007 Missing Private Key' /></a><br />
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br />
To fix this do the following:</p>
<li>Load up the Certificates MMC Snap In and right-click the Personal folder, point to All Tasks, and then click Import.</li>
<li>Import your generated certifcate to the personal store</li>
<li>In the Certificates snap-in, double-click the imported certificate</li>
<li>In the Certificate dialog box, click the Details tab.</li>
<li>Get the Serial Number (i.e 00 45 67)</li>
<li>Load up a command prompt and type:</li>
<li><code>certutil -repairstore my 004567</code></li>
<p><br/><br />
Refreshing the Certificate store will now show both certificates with Private Keys. Run the Enable-Certificate cmdlet again to import the certificates and enable SSL.</p>
<p><a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/Certificate-Fixed.png' title='Exchange 2007 Missing Private Key'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2008/05/Certificate-Fixed-TN.png' alt='Exchange 2007 Missing Private Key' /></a><br />
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></p>
<p>So there it is, a fully working Exchange 2007 server installed on Windows Server 2008. Now the Service Packs are rolling in and more drivers are being released I&#8217;m looking forward to seeing more Server 2008 and Exchange 2007 deployments!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2008/05/29/windows-server-2008-with-exchange-2007-in-production/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Benefits of Virtualisation For Training</title>
		<link>http://blog.networksaremadeofstring.co.uk/2008/02/24/benefits-of-virtualisation-for-training/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2008/02/24/benefits-of-virtualisation-for-training/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 21:00:43 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Datacenter]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2008/02/24/benefits-of-virtualisation-for-training/</guid>
		<description><![CDATA[Working in a Data Center brings with it various challenges that you wouldn&#8217;t normally find in most other jobs; we come across demanding solutions, ingenious &#8216;hacks&#8216;, impressive software and outright weird errors. Once we&#8217;ve crossed a particular hurdle then we need to go about disseminating this new found information to the other SysAdmins. So far [...]]]></description>
			<content:encoded><![CDATA[<p>Working in a Data Center brings with it various challenges that you wouldn&#8217;t normally find in most other jobs; we come across demanding solutions, ingenious &#8216;<a href="http://northernmost.org/blog/hacked-webapps/">hacks</a>&#8216;, impressive software and outright weird errors. </p>
<p>Once we&#8217;ve crossed a particular hurdle then we need to go about disseminating this new found information to the other SysAdmins. </p>
<p>So far the best way I&#8217;ve found of doing this is to take a VM image, break it in the same way that we encountered and then make it available for deployment to the VM infrastructure <em>(minus of course the malicious payload if it was part of a botnet)</em>. These VM&#8217;s are then made available to the teams to deploy at their will or used as part of the weekly inter-team training sessions. The VM&#8217;s are &#8216;tagged&#8217; and a description of the issue with the fixes found to date are attached.</p>
<p>This allows people to either:</p>
<ol><strong>a)</strong> Simply follow what was done so they know how to go about it themselves.</ol>
<ol><strong>b)</strong> Find new ways of fixing the issue</ol>
<ol><strong>c)</strong> Use it as an example of a particular technologies issues and the diagnostic methods used to ascertain what is wrong and fix it in classroom style training.</ol>
<p><br/><br />
There is no additional hardware cost and with the use of snapshots people can experiment with various methodologies other than the ones that we initially used. If a quicker, cleaner or better way of fixing the issue is discovered this can be put on the wiki and tagged to the VM image. This practice really starts to pay off once you&#8217;ve got the ball rolling and people are experimenting, contributing or using it as teaching material and all without any further downtime or additional hardware cost.</p>
<p>At the recent IIS7 for Managed Hosting seminar in London we saw Microsoft make heavy use of &#8216;model&#8217; VM Machines in conjunction with projected slides and Step-by-Step walkthroughs to show us the features and improvements of IIS7 (<em>I still prefer apache if anyone is wondering</em>) which just goes to prove that this is an effective and cost-effective method of hands on training.</p>
<p>This might seem like common sense to some people and may already be in place for some companies, but if its not then why not try it out and let me know how it works out for you?</p>
<p>As always I use <a href="http://www.VMWare.com">VMWare</a> technology.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2008/02/24/benefits-of-virtualisation-for-training/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leveraging Virtualisation To Fight Spam</title>
		<link>http://blog.networksaremadeofstring.co.uk/2007/12/23/leveraging-virtualisation-to-fight-spam/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2007/12/23/leveraging-virtualisation-to-fight-spam/#comments</comments>
		<pubDate>Sat, 22 Dec 2007 23:00:01 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Datacenter]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2007/12/23/leveraging-virtualisation-to-fight-spam/</guid>
		<description><![CDATA[A few weeks ago I &#8216;inherited&#8217; a frontend anti-spam solution that was getting crushed under the weight of the Christmas run-up. Emails were taking up to a week to arrive at the back-end system and a lot of spam was getting through too. The solution consisted of two machines each with Dual Core 2.13Ghz Intel&#8217;s, [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I &#8216;inherited&#8217; a frontend anti-spam solution that was getting crushed under the weight of the Christmas run-up. Emails were taking up to a week to arrive at the back-end system and a lot of spam was getting through too.</p>
<p>The solution consisted of two machines each with Dual Core 2.13Ghz Intel&#8217;s, 2Gb of RAM &#038; SATA disks behind a hardware load balancer. Unfortunately the combination of having to use swap due to the volume of incoming mail coupled with BackScatter attacks <em>[the BackScatter attacks would of course require the original mail and the NDA to be written to disk for later delivery]</em> was killing the disks and the sheer volume of mail was overwhelming the I/O available to just two servers <em>(in terms of Hardware and Postfix postdrop etc)</em>.</p>
<p>Whilst scaling out was considered, space and power consumption would have been an issue. I made the decision to go with two machines but this time one would be a virtualisation power-house and virtualise the anti-spam &#8216;appliances&#8217;. </p>
<p><strong>The Machines:</strong><br />
<strong>Machine 1:</strong><br />
2x 2.4Ghz Quad Core XEON&#8217;s<br />
8Gb ECC RAM<br />
80Gb RAID5 SATA (Host OS)<br />
300Gb RAID1 15k SCSI (Guest Stores)<br />
Gigabit uplink to Load Balancer</p>
<p><strong>Machine 2:</strong><br />
2.13Ghz Core2 Duo<br />
2Gb RAM<br />
80Gb RAID1 SATA<br />
Gigabit uplink to Load Balancer</p>
<p>Machine 1 hosts 6 virtual servers which run the usual combination of Postfix, SpamAssassin &#038; Amavis. These are Load Balanced via a hardware load balancer. Machine 2 runs the same software but with an extremely strict set of rules, the idea is that if all 6 of the Virtual Machines fail the Load Balancers fail over to Machine 2 but this will only talk to the most well behaved clients and only let the cleanest of mail into the mail queue to be processed by the Anti-Spam processes. </p>
<p>To ensure that these servers aren&#8217;t the source of BackScatter attacks the servers only accept truly legitimate mail (i.e it doesn&#8217;t accept mail for any destination, attempt to deliver it to the backend server and then bounce an undeliverable to the [usually faked] from address.)</p>
<p><strong>Postfix Config:</strong><br />
<code><br />
#-------------------------------------------------------------<br />
# Additional non-standard bits<br />
#-------------------------------------------------------------<br />
#Max message of 15mb<br />
message_size_limit = 15728640<br />
#<br />
#Transport maps - i.e where are we sending this stuff<br />
transport_maps = hash:/etc/postfix/transport<br />
#<br />
#Stop people trying to farm addresses<br />
disable_vrfy_command = yes<br />
#<br />
#Stop people hammering the hell out of us<br />
smtpd_data_restrictions =  reject_unauth_pipelining<br />
#<br />
#Pass off content checking to amavis<br />
content_filter = smtp-amavis:[127.0.0.1]:10024<br />
#<br />
#Fed up of mailer-daemon fucking up my queue<br />
#fallback_relay = xx.xx.xx.xx<br />
#<br />
#If the above doesn't work we can always make sure the<br />
#mails don't live for more than one bounce<br />
bounce_queue_lifetime = 0<br />
#<br />
#Spam still went crazy - lets speed up delivery at the cost of resources<br />
maximal_backoff_time = 120s<br />
minimal_backoff_time = 10s<br />
#<br />
#This might adversely affect legitimate mail<br />
maximal_queue_lifetime = 900s<br />
#<br />
#-------------------------------------------------------------<br />
# These things are the bits that can really cause us some issues<br />
# with false positives etc etc<br />
#<br />
# Consult Pages 139 - 142 of postfix book for more info<br />
#-------------------------------------------------------------<br />
#<br />
#Start off with some blacklisting<br />
#                           														Check our black / white list                  		| RealtimeBlacklist                	| Realtime blacklist<br />
smtpd_client_restrictions = permit_sasl_authenticated, check_client_access hash:/etc/postfix/client_access, reject_rbl_client sbl.spamhaus.org, reject_rbl_client dul.dnsbl.sorbs.net<br />
#<br />
#Make clients use EHLO / HELO verbs<br />
smtpd_helo_required = yes<br />
#<br />
#If we are being REALLY strict make them conform to the RFC<br />
#strict_rfc821_envelopes = yes<br />
#<br />
#Now we make them say hello politely<br />
#                          Crap remote hostname     remote host not FQDN<br />
smtpd_helo_restrictions =  reject_invalid_hostname, reject_non_fqdn_hostname<br />
#<br />
#When a user says who they are we had better check what they are telling us<br />
#                           Sender address not FQ | Might want to remove this<br />
smtpd_sender_restrictions = reject_non_fqdn_sender, reject_unknown_sender_domain<br />
#<br />
#Rejects crap / faked / bad recipiants - This might be overkill<br />
#                              Non FQDN target email      Allow inside    						Only relay our domains<br />
smtpd_recipient_restrictions = permit_sasl_authenticated, reject_non_fqdn_recipient, permit_mynetworks, reject_unauth_destination<br />
</code></p>
<p><strong>The VM&#8217;s</strong><br />
With 8Gb of RAM and only 6 machines we can &#8216;scale out&#8217; if more machines are needed or leverage that &#8216;spare&#8217; RAM to improve I/O.</p>
<p>Anything that needs to be written to disk is written to a <a href="http://www.vanemery.com/Linux/Ramdisk/ramdisk.html">RAM disk</a> which will prevent the disk wear and will improve I/O. The VM&#8217;s are restricted to the Physical RAM of the Host machine so there will be no swapping to the Host disk which once again improves I/O and reduces mechanical wear and tear. </p>
<p><strong>The Results</strong><br />
As mentioned at the beginning the servers were seeing a massive spike in mail, mails were taking a week to arrive and many of them were spam. As soon as the Virtualised Solutuion went live the emails hitting the back-end servers dropped from almost 14,000 (per 5 minute MRTG interval) to around 800 and with <strong>zero</strong> false positives! Emails were making it through in less than 2 seconds despite the spam attacks becoming increasingly aggressive!</p>
<p><a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/12/before.png' title='Emails Before the Virtualisaton'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/12/before.png' alt='Emails Before the Virtualisaton' /></a><br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/12/after.png' title='After the Virtualisation'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/12/after.png' alt='After the Virtualisation' /></a></p>
<p><strong>Links:</strong><br />
<a href="http://www.DNSStuff.com">www.DNSStuff.com</a><br />
<a href="http://spamlinks.net/prevent-secure-backscatter.htm">http://spamlinks.net/prevent-secure-backscatter.htm</a><br />
<a href="http://www.postfix.org/docs.html">http://www.postfix.org/docs.html</a><br />
<a href="http://www.vmware.com/">http://www.vmware.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2007/12/23/leveraging-virtualisation-to-fight-spam/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fedora 8 Released</title>
		<link>http://blog.networksaremadeofstring.co.uk/2007/11/10/fedora-8-released/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2007/11/10/fedora-8-released/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 23:35:02 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Networks]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2007/11/10/fedora-8-released/</guid>
		<description><![CDATA[The new version of Fedora is upon us, Rejoice! Feature List Where to get it Update &#8211; 22/11/2007 In little under 2 weeks I&#8217;ve seeded nearly 40Gb! Ubuntu 7.10 has only seeded 33Gb and has been out for twice as long. Read into that what you will!]]></description>
			<content:encoded><![CDATA[<p>The new version of Fedora is upon us, Rejoice!</p>
<p><a href="http://fedoraproject.org/wiki/Releases/8/FeatureList">Feature List</a><br />
<a href="http://fedoraproject.org/get-fedora">Where to get it</a></p>
<p><strong>Update &#8211; 22/11/2007</strong><br />
In little under 2 weeks I&#8217;ve seeded nearly 40Gb! Ubuntu 7.10 has only seeded 33Gb and has been out for twice as long. <em>Read into that what you will!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2007/11/10/fedora-8-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMWare Virtual Center Errors</title>
		<link>http://blog.networksaremadeofstring.co.uk/2007/09/04/vmware-virtual-center-errors/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2007/09/04/vmware-virtual-center-errors/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 23:00:33 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[Datacenter]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2007/09/04/vmware-virtual-center-errors/</guid>
		<description><![CDATA[Yesterday I had a nasty case of Y-splitter failure (in future I&#8217;m just going to upgrade the PSU rather than go though this again) which caused all four of the 320Gb disks of a RAID5 array to suddenly disappear. Windows didn&#8217;t like that and hung, VMware Virtual Center disliked it even more. Once I recovered [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/09/vi_vc.png' alt='VMVC' />Yesterday I had a nasty case of Y-splitter failure (in future I&#8217;m just going to upgrade the PSU rather than go though this again) which caused all four of the 320Gb disks of a RAID5 array to suddenly disappear.</p>
<p>Windows didn&#8217;t like that and hung, VMware Virtual Center disliked it even more. Once I recovered the machine (ohhh AD was in a mess!) VMVC refused to launch and spewed some messages to the console. The sole purpose for this entry is to list the event log errors and list the solution so hopefully some one else out there won&#8217;t be in the dark.</p>
<p>The errors always happen in batches as follows:</p>
<p>[2376] [VpxdMutex] Locking InvtLock (5) conflicts with InvtHostBarrier (0)</p>
<p>[3372] (HY000) &#8211; [Microsoft][ODBC Microsoft Access Driver] Not a valid bookmark.</p>
<p>[3372] [ARCHIVER] Q: SELECT COUNT(*) FROM STATS_HOST_DATA WHERE HOST_ID=? AND HIST_ID=? AND COL_ID=? AND ROW_ID=?</p>
<p>[3372] [ARCHIVER] Failed to count stats. ODBC error=-1</p>
<p>[3372] [Vpxd] Initiating shutting down</p>
<p>[3352] [Vpxd] Shutting down&#8230;</p>
<p>[3352] [Vpxd] Shutting down now</p>
<p>The description for Event ID ( 1 ) in Source ( VMware Virtual Mount Service Extended ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: vmount2 service stopped 1.5.2 build-32167.<br />
Then the VMVC process hangs, it shows as &#8216;Started&#8217; in the Services MMC but any connection attempts are met with an active refusal.</p>
<p>Taking the hint that a database was corrupted I made a copy of the Template / Uploads directory and bit the bullet; initiated the dreaded MSI Repair mode.</p>
<p>Answering &#8216;Yes&#8217; to keeping the existing database followed by a swift reboot and all was working again.</p>
<p>One of the VMWare servers had hung (it was deploying from a template when this happened!) and had to be kill -9&#8242;d but after that all came up fine again.</p>
<p>Fun eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2007/09/04/vmware-virtual-center-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring WMI From Linux via a C# Daemon and PHP</title>
		<link>http://blog.networksaremadeofstring.co.uk/2007/07/01/monitoring-wmi-from-linux-via-a-c-daemon-and-php/</link>
		<comments>http://blog.networksaremadeofstring.co.uk/2007/07/01/monitoring-wmi-from-linux-via-a-c-daemon-and-php/#comments</comments>
		<pubDate>Sun, 01 Jul 2007 13:59:54 +0000</pubDate>
		<dc:creator>Gareth Llewellyn</dc:creator>
				<category><![CDATA[NAMOS]]></category>
		<category><![CDATA[Systems]]></category>

		<guid isPermaLink="false">http://blog.networksaremadeofstring.co.uk/2007/07/01/monitoring-wmi-from-linux-via-a-c-daemon-and-php/</guid>
		<description><![CDATA[WARNING: I am not a programmer, I don&#8217;t claim to be so it is quite likely that the code you will find here will horrify you! As part of my drive to monitor as much as possible of my systems I realised that creating an intermediate daemon for WMI would allow me to access some [...]]]></description>
			<content:encoded><![CDATA[<p><strong>WARNING:</strong> I am not a programmer, I don&#8217;t claim to be so it is quite likely that the code you will find here will horrify you!</p>
<p>As part of my drive to monitor as much as possible of my systems I realised that creating an intermediate daemon for WMI would allow me to access some of the WMI properties that wouldn&#8217;t normally be exposed via SNMP and graph them with MRTG. </p>
<p>I&#8217;m not going to cover WMI in any great detail so if you&#8217;d like to do a bit more reading I would recommend reading through the Microsoft <a href="http://msdn2.microsoft.com/en-us/library/aa394582.aspx">Knowledge Base article on WMI</a>.</p>
<p>As the title suggests the Windows Daemon has been written in C# and the basic idea behind it is that it will sit on the server listening on an specified UDP port waiting for a particular type of packet to arrive. That packet will contain the originating IP, the UDP port it will be waiting for a reply on, the WMI Class from which we will be extracting a property and the property itself.</p>
<p><code><br />
//Receive DataGram<br />
byte[] recData = server.Receive(ref ServerReceivePoint);<br />
System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding();<br />
//Split it up [IP/Port/WMIClass/WMIQueryItem]<br />
string[] temp = encode.GetString(recData).Split(new Char[] { '/' });<br />
string Class = temp[2].ToString();<br />
string Query = temp[3].ToString();<br />
string WMIResult = "";<br />
WMIResult = DoWMIQuery(Class, Query);<br />
</code></p>
<p>So far the code just sits waiting to receive some data, when it does it writes a nice little entry to a log and then throws the packet data into a string array named temp split on the / character (this shouldn&#8217;t appear in either a WMI Class or a Method / Property). The 3rd entry is the WMI Class and the 4th entry is the property we are asking for. These values are then passed to a function named DoWMIQuery (can you guess what that does?).</p>
<p>First we have to set up the options for connecting to WMI:<br />
<code><br />
ConnectionOptions ConOpt = new ConnectionOptions();<br />
string strNameSpace = @"\\";<br />
strNameSpace += ".";<br />
strNameSpace += @"\root\cimv2";<br />
</code></p>
<p>With that done a new Management Scope and Object Query can be created:<br />
<code><br />
&nbsp;System.Management.ManagementScope oMs =<br />
&nbsp;&nbsp;new System.Management.ManagementScope(strNameSpace, ConOpt);<br />
&nbsp;System.Management.ObjectQuery oQuery = oQuery =<br />
&nbsp;&nbsp;new System.Management.ObjectQuery("select " + QUERYITEM + " from " + CLASS);<br />
</code><br />
&#8216;Executing&#8217; the query requires the utilisation of a Management Object Searcher (its searches for objects!!) and returns a nice array of objects (assuming of course there are more than one otherwise it&#8217;ll only return the one). By looping through the array I can grab all the requested data and then it can be returned.</p>
<p><code><br />
&nbsp;ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);<br />
<br />
&nbsp;try<br />
&nbsp;{<br />
&nbsp;&nbsp;//Get the results<br />
&nbsp;&nbsp;ManagementObjectCollection oReturnCollection = oSearcher.Get();<br />
<br />
&nbsp;&nbsp;//loop through and return what was asked for!<br />
&nbsp;&nbsp;foreach (ManagementObject oReturn in oReturnCollection)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;ReturnValue = oReturn[QUERYITEM].ToString();<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return ReturnValue;<br />
</code></p>
<p>There is no checking to make sure that &#8216;hostile&#8217; WQL isn&#8217;t being passed mainly because I couldn&#8217;t be bothered but mostly because the inter-vlan firewalls don&#8217;t let clients send to these ports. Anyhow, basically all that happens is that the WMI property requested is extracted from the WMI class that was defined. If there are several instances (say for example free space on x amount of disk drives) then they get added together and then returned.</p>
<p><code><br />
//Re-send the DataGram<br />
byte[] sendData = encode.GetBytes(WMIResult);<br />
<br/><br />
//We use the IP and Port sent by the user to send the DataGram back<br />
server.Send(sendData, sendData.Length, temp[0], Int32.Parse(temp[1]));<br />
</code></p>
<p>If anyone noticed the potential for foul play (Hint: Smurf stylee) then yes I was indeed too lazy to work out where the connection came from and send it back to that host.</p>
<p>Once the host is happily sitting there doing what it needs to do (listening for packets that is) we need to send it something. Whilst I love scripting in Bash I felt that PHP would be a better avenue to explore (mainly because I could create a few intranet pages with &#8216;on demand&#8217; stats generation!).</p>
<p>First I grab the command line arguements that were passed and add a couple of my own:<br />
<code><br />
$ScriptName = $argv[0]; // Script name<br />
$TargetIP 	= $argv[1]; // Target IP<br />
$Class1			=	$argv[2]; // WMI Class1<br />
$Prop1			=	$argv[3]; // WMI Property1<br />
$Class2			=	$argv[4]; // WMI Class2<br />
$Prop2			=	$argv[5]; // WMI Property2<br />
$UptimeClass		= "Win32_PerfFormattedData_PerfOS_System";<br />
$UptimeProperty	= "SystemUpTime";<br />
</code></p>
<p>Then it calls the DoQuery function a couple of times and does a reverse DNS lookup of the host. This is because MRTG expects Input, Output, Uptime and System name as the 4 variables returned to it from an external script!<br />
<code><br />
DoQuery($TargetIP,$Class1,$Prop1);<br />
	DoQuery($TargetIP,$Class2,$Prop2);<br />
  DoQuery($TargetIP,$UptimeClass,$UptimeProperty);<br />
  print(gethostbyaddr($TargetIP));<br />
</code></p>
<p>Create the SourcePort (a bit of randomisation as there could be 10&#8242;s of these triggering at the same time!) and the socket:<br />
<code><br />
$SourcePort = rand(2200, 4500);<br />
		$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);<br />
</code><br />
With that done its time to create the packet:<br />
<code><br />
	$packet = "172.16.0.2/".$SourcePort."/".$WMIClass."/".$WMIProperty;<br />
</code></p>
<p>Sending the UDP request packet is painfully simple:<br />
<code><br />
   	socket_sendto($socket, $packet, strlen($packet), 0x100, '172.16.0.3', 6868);<br />
</code></p>
<p>With that done we need to create the listening socket and then wait for a reply:<br />
<code><br />
&nbsp;$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);<br />
<br />
&nbsp;if(!socket_bind($sock2, '172.16.0.2', $SourcePort))<br />
&nbsp;{<br />
&nbsp;&nbsp;socket_close($sock2);<br />
&nbsp;&nbsp;die( 'socket_bind failed: '.socket_strerror(socket_last_error()));<br />
&nbsp;}<br />
<br/><br />
&nbsp;//Set up a nonblocking socket<br />
&nbsp;socket_set_nonblock($sock2);<br />
</code></p>
<p>I&#8217;ve decided on 2 seconds as an acceptable time out:<br />
<code><br />
	//Initiate the timeout<br />
	$timeout = time() + (2); // 2 seconds timeout<br />
<br/><br />
	//While the time is less than 2 seconds from when we started this<br />
	while (time() <= $timeout)<br />
	{<br />
   		while (@socket_recv($sock2, $data, $SourcePort, 0)) //8192<br />
   		{<br />
				print($data);<br />
                                print("\n");<br />
   		}<br />
   		usleep(100000); // 100ms wait<br />
	}<br />
	//Close the socket<br />
	socket_close($sock2);<br />
?><br />
</code></p>
<p>With all that done you can simply add something like the following to your MRTG scripts:<br />
<code><br />
Directory[S411-1-cpu]: cpu<br />
Target[S411-1-cpu]: `php /etc/mrtg/scripts/WMIUDPMRTG.php 172.16.0.3 Win32_PerfFormattedData_PerfOS_Processor PercentProcessorTime Win32_PerfFormattedData_PerfOS_Processor PercentUserTime`<br />
MaxBytes[S411-1-cpu]: 10000<br />
Options[S411-1-cpu]: gauge,growright,nopercent,absolute<br />
ShortLegend[S411-1-cpu]: CPU<br />
#LegendI[S411-1-cpu]:CPU Usage<br />
WithPeak[S411-1-cpu]: wmy<br />
LegendI[S411-1-cpu]:CPU Time<br />
LegendO[S411-1-cpu]:User Time<br />
YLegend[S411-1-cpu]:CPU Usage<br />
Title[S411-1-cpu]: CPU Usage<br />
PageTop[S411-1-cpu]: CPU Usage<br />
</code></p>
<p>And you&#8217;ll be able to graph previously unreachable data:</p>
<p><strong>Win32_PerfFormattedData_PerfOS_Processor:</strong><br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/cpu1.png' title='WMIUDPCPU1'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/cpu1.png' alt='WMIUDPCPU1' /></a><br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/cpu2.png' title='WMIUDPCPU2'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/cpu2.png' alt='WMIUDPCPU2' /></a><br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/cpu3.png' title='WMIUDPCPU3'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/cpu3.png' alt='WMIUDPCPU3' /></a></p>
<p><strong>Win32_PerfFormattedData_ASP_ActiveServerPages:</strong><br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/iis.png' title='IIS Bytes Per Second'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/iis.png' alt='IIS Bytes Per Second' /></a></p>
<p><strong>Win32_PerfFormattedData_RemoteAccess_RASTotal:</strong><br />
<a href='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/ras.png' title='RAS Totals'><img src='http://blog.networksaremadeofstring.co.uk/wp-content/uploads/2007/07/ras.png' alt='RAS Totals' /></a></p>
<p>The full source code (if you dare) is <a href='http://blog.networksaremadeofstring.co.uk/WMIPerformanceViaUDP.zip' title='WMIPerformanceViaUDP.zip'> here.</a> <em>(edit: fixed link)</em></p>
<p>ToDo:</p>
<li>Stability / Security</li>
<li>Intelligent WQL Support</li>
<li>Not sucking</li>
]]></content:encoded>
			<wfw:commentRss>http://blog.networksaremadeofstring.co.uk/2007/07/01/monitoring-wmi-from-linux-via-a-c-daemon-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
