<?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>4sak3n Design &#187; Tutorials</title>
	<atom:link href="http://4sk.us/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://4sk.us</link>
	<description>The trials and tribulations of a programmer.</description>
	<lastBuildDate>Mon, 07 May 2012 20:13:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>PowerShell: Modifying DHCP Scope Options</title>
		<link>http://4sk.us/2012/05/powershell-modifying-dhcp-scope-options/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=powershell-modifying-dhcp-scope-options</link>
		<comments>http://4sk.us/2012/05/powershell-modifying-dhcp-scope-options/#comments</comments>
		<pubDate>Mon, 07 May 2012 20:13:35 +0000</pubDate>
		<dc:creator>Justin Jahn</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[bulk]]></category>
		<category><![CDATA[dhcp]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://4sk.us/?p=85</guid>
		<description><![CDATA[Recently my organization had moved toward a more Windows-based infrastructure. &#160;I needed to change the DNS server information on several of our scopes and quite frankly I&#8217;m much too lazy to do everything by hand. &#160;Enter PowerShell. I was able to hack together a pretty quick solution to do this in bulk: $sScopes = netsh [...]]]></description>
			<content:encoded><![CDATA[<p>Recently my organization had moved toward a more Windows-based infrastructure. &nbsp;I needed to change the DNS server information on several of our scopes and quite frankly I&#8217;m much too lazy to do everything by hand. &nbsp;Enter PowerShell.</p>
<p>I was able to hack together a pretty quick solution to do this in bulk:</p>
<pre class="brush: powershell; gutter: true">$sScopes  = netsh dhcp server show scope
$sRegex   = &quot;10\.11\.\d{1,}\.\d{1,}&quot;
$aMatches = [regex]::Matches($sScopes, $sRegex)

if ($aMatches.count -gt 0) {
    foreach ($match in $aMatches) {
        netsh dhcp server scope $match.Value set optionvalue 006 IPADDRESS 10.0.0.1 10.0.0.2
    }
}</pre>
<p>Let&#8217;s go through the code. &nbsp;The first line fetches every scope from the <code>netsh</code> command.  The second line defines the regular expression that matches the scope addresses we want to modify.  The third line actually performs the regular expression matching.</p>
<p>Jumping down to the loop, we run the <code>netsh</code> command again, but pass in the value of the match (which will be the ip address defined on line two and set our options accordingly.</p>
<p>I hope this helps someone out there!</p>
]]></content:encoded>
			<wfw:commentRss>http://4sk.us/2012/05/powershell-modifying-dhcp-scope-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory Authentication in Red Hat</title>
		<link>http://4sk.us/2011/11/active-directory-authentication-in-red-hat/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=active-directory-authentication-in-red-hat</link>
		<comments>http://4sk.us/2011/11/active-directory-authentication-in-red-hat/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 21:03:52 +0000</pubDate>
		<dc:creator>Justin Jahn</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[kerberos]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[pam]]></category>
		<category><![CDATA[red hat]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[winbind]]></category>

		<guid isPermaLink="false">http://4sk.us/?p=68</guid>
		<description><![CDATA[Single sign on is an amazing timesaver and a must in any larger organization.&#160; It allows system administrators to create one single account that allows access to many other different services. Windows does this extremely well with Active Directory; almost any good enterprise product will support Active Directory for authentication.&#160; But, where do mixed environments [...]]]></description>
			<content:encoded><![CDATA[<p>Single sign on is an amazing timesaver and a must in any larger organization.&nbsp; It allows system administrators to create one single account that allows access to many other different services.</p>
<p>Windows does this extremely well with Active Directory; almost any good enterprise product will support Active Directory for authentication.&nbsp; But, where do mixed environments fit in with Windows software and technologies?&nbsp; Quite well, in fact.&nbsp; In this article, I will be outlining how to configure authentication and authorization with Active Directory using CentOS, Scientific Linux, or any other Red Hat based distribution.&nbsp; The concepts within can be applied Debian-based distributions with relative ease (but <code>authconfig</code> saves a ton of time).</p>
<p><span id="more-68"></span></p>
<h2>Winbind</h2>
<p>The process of linking Linux with Winbind has become increasingly straightforward, but there are some redundant pieces involved.</p>
<h3>Installing Dependencies</h3>
<p>We need to make sure winbind and friends are installed so there are no issues later on down the line:<code></code></p>
<pre class="brush: bash; gutter: true">yum install -y samba-common samba-winbind-clients samba-winbind nscd ntp ntpdate</pre>
<h2>Updating the Time</h2>
<p>Keeping in sync with time is very important in an AD environment. Without the correct time, a machine will not even be able to join the domain.</p>
<pre class="brush: bash; gutter: true">ntpdate pool.ntp.org
/sbin/chkconfig --level 35 ntpd on
/sbin/service ntpd start</pre>
<h2>Authconfig</h2>
<p>Authconfig is Red Hat&#8217;s utility for configuring PAM authentication. We will utilize it to do the bulk of our configuration for us. Run <code>authconfig-tui</code> and select Winbind for both <code>User Information</code> and <code>Authentiction</code>. Also, <code>Cache Information</code> should be checked. <strong>Make sure that <code>local authorization is sufficient</code> is selected in case there are problems!</strong> Do not select <code>Join Domain</code> in this dialog, as it will be done later.</p>
<ul>
<li>Security Model: ads</li>
<li>Domain: The <code>WORKGROUP</code> of your domain.</li>
<li>Domain Controllers: Specified in <code>{server}</code></li>
<li>ADS Realm: <code>{DOMAIN}</code></li>
<li>Template Shell: <code>/bin/bash</code></li>
</ul>
<p>We should also enable home directory auto creation, unless special provisioning for such things is already in place (shared filesystem for example):<code></code></p>
<pre class="brush: bash; gutter: true">authconfig --enablemkhomedir --update</pre>
<h2>Kerberos Configuration</h2>
<p><strong>The authconfig script sets this up for us, but we want to verify the script did it&#8217;s job correctly.</strong></p>
<p>The Kerberos configuration file is used to join the machine to the domain as well as to reference it later on. I&#8217;ve provided an example configuration file, however some of the items need to be replaced with customized values:</p>
<ul>
<li><code>{DOMAIN}</code> Your AD domain in all caps.</li>
<li><code>{domainname}</code> Your AD domain in all lowercase.</li>
<li><code>{server}</code> The IP address of your DC.</li>
</ul>
<h3>Example</h3>
<pre class="brush: bash; gutter: true">vi /etc/krb5.conf

[libdefaults]
default_realm = {DOMAIN}

[realms]
{DOMAIN} = {
    admin_server   = {server}
    default_domain = {domainname}
    kdc            = {server}
}

[domain_realm]
{domainname}  = {DOMAIN}
.{domainname} = {DOMAIN}</pre>
<h2>Samba Configuration</h2>
<p>Authconfig sets up the <code>smb.conf</code> file as well, but a few things must be changed for a easier to use solution. There is one variable in the example configuration that must be changed to suit your environment:</p>
<ul>
<li><code>{name}</code> The base hostname of the system. In the case of test.example.com, it&#8217;s TEST.</li>
</ul>
<h3>Example</h3>
<pre class="brush: bash; gutter: true">vi /etc/smb.conf

[global]
netbios name = {name}
winbind use default domain = true
add machine script = /usr/sbin/useradd -s /sbin/nologin -M %u

[homes]
valid users = %S</pre>
<h2>Connecting to Active Directory</h2>
<p>Now comes the fun part, connecting our server with Active Directory, joining it to the domain.&nbsp; We will then need to add a user account that is linked to the value set in <code>{name}.</code></p>
<pre class="brush: bash; gutter: true">useradd -s /sbin/nologin -M {name}$
passwd -l {name}$</pre>
<p>Finally, join the machine to the domain. To do this, you need access to an account with enough permissions (Usually a member of the <code>Domain Admins</code> group).</p>
<pre class="brush: bash; gutter: true">net join -w {domain} -S {server} -U {user}</pre>
<h2>PAM</h2>
<p>From here, we must configure PAM itself. There are two main files to modify here,<code> password-auth</code>, which handles SSHd (and a few others) authentication, and<code> system-auth</code>, which deals with everything else.</p>
<p>Authconfig makes this pretty easy to do, but if not done right, modifications will be overwritten if something is changed. The good news is, this can be solved via changing the symlink from <code>system-auth-ac</code> to a custom file, <code>system-auth-custom</code> and using some include statements to link back to <code>system-auth-ac</code>:</p>
<h3>password-auth-custom</h3>
<pre class="brush: bash; gutter: true"># This file is designed to be used with authconfig.  It adds functionality
# while still allowing authconfig to generate configuration.  The symlink
# password-auth -&gt; password-auth-ac was replaced with this file.

# The listsep argument is important as Windows groups may contain spaces
account required pam_access.so listsep=,

# Include authconfig file
auth include password-auth-ac
account include password-auth-ac
password include password-auth-ac
session include password-auth-ac</pre>
<h3>system-auth-custom</h3>
<pre class="brush: bash; gutter: true"># This file is designed to be used with authconfig.  It adds functionality
# while still allowing authconfig to generate configuration.  The symlink
# system-auth -&gt; system-auth-ac was replaced with this file.

# The listsep argument is important as Windows groups may contain spaces
account required pam_access.so debug listsep=,

# Include authconfig file
auth include system-auth-ac
account include system-auth-ac
password include system-auth-ac
session include system-auth-ac</pre>
<h3>Changing the Symlinks</h3>
<pre class="brush: bash; gutter: true">rm system-auth password-auth
ln -s system-auth-custom system-auth
ln -s password-auth-custom password-auth</pre>
<p>Now we&#8217;ve got a custom authentication piece that won&#8217;t be overwritten when<code> authconfig</code> does it&#8217;s magic!</p>
<h2>Configuring Authorization With pam_access.so</h2>
<p>Because of the previous step, the contents of <code>/etc/security/access.conf</code> are no longer valid as they assume lists are separated with spaces. Since Active Directory allows spaces in group names, (and encourages it), we&#8217;ve changed it to a comma.</p>
<p>To allow only members of <code>Domain Admins</code>, and <code>wheel</code> access to the system we would do the following:</p>
<pre class="brush: text; gutter: true">vi /etc/security/access.conf
+:root,Domain Admins,wheel:ALL
-:ALL:ALL</pre>
<h2>Sudoers</h2>
<p>Well, <code>Domain Admins</code> can log in, but they don&#8217;t have any privileges. How do we fix that? Sudoers of course! <strong>Warning:</strong> Whitespace characters must be escaped in the sudoers file or a syntax error will be thrown:</p>
<pre class="brush: text; gutter: true">visudo
%domain\ admins ALL=(ALL) ALL</pre>
<p>If you guys have any questions, feel free to post them in the comments below. Hope you learned something!</p>
]]></content:encoded>
			<wfw:commentRss>http://4sk.us/2011/11/active-directory-authentication-in-red-hat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Secure Plain Text Authentication in PHP using SCRAM</title>
		<link>http://4sk.us/2011/10/secure-plain-text-authentication-in-php-using-scram/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=secure-plain-text-authentication-in-php-using-scram</link>
		<comments>http://4sk.us/2011/10/secure-plain-text-authentication-in-php-using-scram/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 08:27:40 +0000</pubDate>
		<dc:creator>Justin Jahn</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[Crypto JS]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SCRAM]]></category>

		<guid isPermaLink="false">http://4sk.us/?p=28</guid>
		<description><![CDATA[In today&#8217;s world, a secure authentication mechanism for web sites is an absolute necessity.  Hackers and script kiddies love to hijack accounts in any way possible.  In some cases even entire databases hackers are compromising entire databases, which, is the last thing a developer wants to be held responsible for. Today, I will be showing [...]]]></description>
			<content:encoded><![CDATA[<p>In today&#8217;s world, a secure authentication mechanism for web sites is an absolute necessity.  Hackers and script kiddies love to hijack accounts in any way possible.  In some cases even entire databases hackers are compromising entire databases, which, is the last thing a developer wants to be held responsible for.</p>
<p>Today, I will be showing you a mechanism to not only secure the passwords being held in your databases, but a way to secure the authentication process itself from prying eyes.  Enter SCRAM.  While it&#8217;s impossible to completely prevent a man in the middle access attack, utilizing SCRAM will certainly make it exponentially more difficult.  For a site that isn&#8217;t running e-commerce, I believe this is a much more cost-effective solution to an SSL certificate.</p>
<p><span id="more-28"></span></p>
<h2>SCRAM</h2>
<p>SCRAM is a <a title="Scram Whitepaper" href="http://www.isode.com/whitepapers/scram.html" target="_blank">relatively new</a> protocol for authentication written under <a title="SCRAM RFC" href="http://tools.ietf.org/html/rfc5802" target="_blank">RFC 5802</a> that works very well with web technologies as they are today.  It is algorithm agnostic, protocol agnostic (for the most part), and straightforward to implement.  The basic concept of SCRAM is that the client and server never send enough information for a hacker to simply decrypt (or use rainbow tables) the password.  Instead, a &#8216;client proof&#8217; is generated that the server uses to determine authentication.  If you wish to know more about it, feel free to read the links above.</p>
<h3>Differences</h3>
<p>There are some key differences in the SCRAM-SHA256-JSON approach we will be utilizing today:</p>
<ol>
<li>The protocol is HTTP, so some bits of the protocol are no longer necessary/possible.</li>
<li>In lieu of an AuthMessage, a JSON object is sent back and forth.  This is possible because the RFC defines the order of each part included in an AuthMessage.</li>
<li>The &#8216;third phase&#8217;, where client verifies server authentication has been left out to reduce client-side overhead.</li>
<li>A smaller iteration was chosen to cut the impact on performance caused by JavaScript code.</li>
<li>Input passwords will be hashed before salting.</li>
</ol>
<p>I tried to stay as true to the protocol as possible, however some things just didn&#8217;t make sense in a web environment where connections do not persist and encryption transparent to the code itself.  None of the authentication steps have changed, just the way they are sent.</p>
<h2>The Code</h2>
<p>This tutorial is broken up into two major sections, the server-side and client side.  I will talk about what needs to happen on each step and present you with the well commented and completed source code.</p>
<h3>Overview</h3>
<p>I think it will be necessary to outline what we are actually trying to do in each section.   The SCRAM authentication process works like this:</p>
<pre class="brush: text; gutter: false">1. Client sends username and ClientNonce.
    a. The client stores its own request string in memory for later use.
2. Server sends salt, ClientNonceServerNonce, and iterations.
    a. The server stores the client request and its own in SESSION
       for later use.
    b. The client stores the server request in memory for later use.
    c. The client uses the iterations response to determine the strength
       of the hash.
3. Client performs the calculations necessary to form a ClientProof,
   sending it and a ClientNonceServerNonce to the server.
    a. The server verifies the ClientNonceServerNonce with the one
       stored in SESSION.
    b. The server performs the calculations necessary to get a
       ClientSignature.
    c. The server obtains the ClientKey by performing an XOR on
       ClientSignature and ClientProof.
    d. The server hashes the SaltedPassword using the iterations
       provided in step 2.
    e. If the passwords match, an HTTP 200 response is sent with
       a URL to use on page refresh.  If the passwords don't
       match, an HTTP 401 response is sent.</pre>
<h3>Technologies Used</h3>
<p>You should not need to install additional PHP extensions, however, <a title="PHP Manual on Mcrypt" href="http://php.net/manual/en/book.mcrypt.php" target="_blank">mcrypt</a> is highly recommended if you don&#8217;t already have it.  You might also want to pickup <a title="PHP Manual on Multibyte Strings" href="http://php.net/manual/en/book.mbstring.php" target="_blank">mbstring</a> (if you don&#8217;t already have it).  A minimum PHP version of 5.2 is required to run the provided code.  It can certainly run on older versions with some effort, but PHP 5.3 is becoming the norm, so get with the program!</p>
<p>The client side will use the <a title="Dojo Toolkit Main Page" href="http://dojotoolkit.org/" target="_blank">Dojo Toolkit&#8217;s</a> core libraries for element manipulation and prototyping.  There isn&#8217;t much Dojo-specific code in the provided file, so it will be easy to remove if you so choose.  On the other hand, <a title="Crypto JS on Google Code" href="http://code.google.com/p/crypto-js/" target="_blank">Crypto-JS</a> is definitely engrained within the client side code.  Crypto-JS can be custom compiled using Google&#8217;s <a title="Closure Compiler on Google Code" href="http://code.google.com/closure/compiler/" target="_blank">Closure Compiler</a> if need be, which makes it an extremely small library to include.</p>
]]></content:encoded>
			<wfw:commentRss>http://4sk.us/2011/10/secure-plain-text-authentication-in-php-using-scram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

