<?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>Josh Olson&#039;s Blog &#187; Work</title>
	<atom:link href="http://www.jpolson.com/category/work/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jpolson.com</link>
	<description>A blog about Security, Programming, and System Analysis.</description>
	<lastBuildDate>Tue, 15 Nov 2011 15:47:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Monitor a specific packet type with tcpdump</title>
		<link>http://www.jpolson.com/20090402/monitor-a-specific-packet-type-with-tcpdump/</link>
		<comments>http://www.jpolson.com/20090402/monitor-a-specific-packet-type-with-tcpdump/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 19:28:43 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[tcpdump]]></category>

		<guid isPermaLink="false">http://www.jpolson.com/?p=56</guid>
		<description><![CDATA[tcpdump is a powerful network traffic dump utility. Here&#8217;s an example of how to use it to watch for a specific packet type on a specific interface. Print SYN but not SYN ACK packets $ tcpdump -nn -i eth0 &#8216;tcp[13] &#038; 0&#215;12=0&#215;02&#8242; Print SYN or SYN ACK packets $ tcpdump -nn -i eth0 &#8216;tcp[13] &#038; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tcpdump.org/">tcpdump</a> is a powerful network traffic dump utility. Here&#8217;s an example of how to use it to watch for a specific packet type on a specific interface.</p>
<p><strong>Print SYN but not SYN ACK packets</strong><br />
$ tcpdump -nn -i eth0 &#8216;tcp[13] &#038; 0&#215;12=0&#215;02&#8242;</p>
<p><strong>Print SYN or SYN ACK packets</strong><br />
$ tcpdump -nn -i eth0 &#8216;tcp[13] &#038; 0&#215;02=0&#215;02&#8242;</p>
<p><strong>Print FIN packets</strong><br />
$ tcpdump -nn -i eth0 &#8216;tcp[13] &#038; 0&#215;01=0&#215;01&#8242;</p>
<p>Here&#8217;s a breakdown of how the previous commands work.</p>
<p>-nn <i>Don&#8217;t convert host addresses or port numbers to names</i></p>
<p>-i eth0 <i>Listen on interface</i></p>
<p>proto [ byte offset: size ]</p>
<p>Available proto (protocol) layers: ether, fddi, tr, wlan, ppp, slip, link, ip, arp, rarp, tcp, udp, icmp, ip6 or  radio.</p>
<p>Size (optional values: one, two, or four) defaults to one, and indicates the number of bytes for comparison.</p>
<p><strong>Example:</strong> $ tcpdump -nn -i eth0 &#8216;tcp[13] &#038; 0&#215;12=0&#215;02&#8242;</p>
<p>tcp[13] says use the data (one byte) inside the packet using the tcp protocol layer at byte offset 13 for comparison.&#8221;</p>
<p>&#038; 0&#215;12=0&#215;02 says execute a <a href="http://en.wikipedia.org/wiki/Mask_(computing)">bitwise AND</a> operation against the bits 0001 0010 and match on the bits 0000 0010. It&#8217;s important to bitmask at least down to the control bits which reside at 0x3f or 0011 1111, as we are not interested in the presence of ECN bits (which contain ECE and CWR), and they may manipulate our comparison results.</p>
<p>&#038; 0x3f=0&#215;02 is more thorough than 0&#215;12=0&#215;02 (because it checks all of the control bits (0011 1111) rather than just 0001 0010)  and can be used in its place. You can use the decimal value for the right side of the comparison (eg. 0&#215;12=2), but I find it helpful to use the Hex value as you&#8217;re already using a Hex value for the bitmasking.</p>
<p>It should be noted that you can also use the available TCP flags field values: tcp-fin, tcp-syn, tcp-rest, tcp-push, tcp-ack, tcp-urg.</p>
<p><strong>Print SYN but not SYN ACK packets</strong><br />
$ tcpdump -nn &#8216;tcp[tcpflags] &#038; tcp-syn != 0 and tcp[tcpflags] &#038; tcp-ack = 0&#8242;</p>
<p>But that&#8217;s not nearly as fun, right?</p>
<p><strong>References:</strong><br />
<a href="http://www.networksorcery.com/enp/protocol/tcp.htm">TCP Header</a><br />
<a href="http://en.wikipedia.org/wiki/Hexadecimal">Hexadecimal</a><br />
<a href="http://en.wikipedia.org/wiki/Mask_(computing)">Mask (computing)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20090402/monitor-a-specific-packet-type-with-tcpdump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows PowerShell Execution Policies</title>
		<link>http://www.jpolson.com/20080528/windows-powershell-execution-policies/</link>
		<comments>http://www.jpolson.com/20080528/windows-powershell-execution-policies/#comments</comments>
		<pubDate>Wed, 28 May 2008 17:15:17 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://josh.choosechose.com/20080528/windows-powershell-execution-policies/</guid>
		<description><![CDATA[Windows Powershell sets its Execution Policy to Restricted by default, which states that PowerShell can only be used in interactive mode (no scripts will run.) Use the Get-ExecutionPolicy cmdlet to check which execution policy is currently in-force. $ Get-ExecutionPolicy The following execution policy definitions are from Microsoft&#8217;s website: Restricted – No scripts can be run. [...]]]></description>
			<content:encoded><![CDATA[<p>Windows Powershell sets its Execution Policy to Restricted by default, which states that PowerShell can only be used in interactive mode (no scripts will run.) Use the Get-ExecutionPolicy cmdlet to check which execution policy is currently in-force.</p>
<p><code>$ Get-ExecutionPolicy<br />
</code></p>
<p>The following execution policy definitions are from <a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-executionpolicy.mspx">Microsoft&#8217;s website</a>:</p>
<ul>
<li>Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.</li>
<li>AllSigned – Only scripts signed by a trusted publisher can be run.</li>
<li>RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.</li>
<li>Unrestricted – No restrictions; all Windows PowerShell scripts can be run.</li>
</ul>
<p>To change the execution policy, use Set-ExecutionPolicy. The following will enable you to execute all PowerShell scripts.</p>
<p><code>$ Set-ExecutionPolicy Unrestricted</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20080528/windows-powershell-execution-policies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows PowerShell &#8211; Recursively delete files and directories modified more than &#8216;n&#8217; days ago.</title>
		<link>http://www.jpolson.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/</link>
		<comments>http://www.jpolson.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/#comments</comments>
		<pubDate>Thu, 22 May 2008 17:25:19 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://josh.choosechose.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/</guid>
		<description><![CDATA[I was recently tasked with writing a script that recursively deletes files and directories modified more than &#8216;n&#8217; days ago &#8211; here&#8217;s the kicker &#8211; using Windows. Many people have accomplished this with long VB Scripts. I was hoping for a much cleaner solution, and decided to try Windows PowerShell . I am quite impressed [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently tasked with writing a script that recursively deletes files and directories modified more than &#8216;n&#8217; days ago &#8211; here&#8217;s the kicker &#8211; using Windows. Many people have accomplished this with long VB Scripts. I was hoping for a much cleaner solution, and decided to try <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Windows PowerShell</a> . I am quite impressed with Windows Powershell&#8217;s capabilities.</p>
<p>The following script recursively deletes files and directories modified more than 16 days ago.<br />
<code><br />
# prune.ps1<br />
$sticky = (Get-date).AddDays(-16)<br />
$backupDir = "B:\backup"<br />
echo "Recursively deleting files and directories written before $sticky"<br />
Get-ChildItem $backupDir -Recurse | Where-Object { $_.LastWriteTime -lt $sticky } | Remove-Item -Recurse<br />
</code></p>
<p>Note that you can change <code>Remove-Item -Recurse</code> to <code>Remove-Item -Whatif</code> to &#8220;pretend&#8221; to delete files, and display potential deletes on STDOUT. You can also specify <code>Remove-Item -Confirm</code>.</p>
<p>I created a scheduled task that runs a .bat file containing the following:<br />
<code>powershell.exe c:\scripts\prune.ps1 &gt;&gt; c:\scripts\logs\prune.log</code></p>
<p>To watch and or view the output of the script, specify the -noexit switch on the command line.<br />
<code>powershell.exe -noexit c:\scripts\prune.ps1</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software raid 1 &#8211; Failing and recovering a disk</title>
		<link>http://www.jpolson.com/20080429/failing-a-software-raid-1-disk-with-software-raid/</link>
		<comments>http://www.jpolson.com/20080429/failing-a-software-raid-1-disk-with-software-raid/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 23:16:38 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://josh.choosechose.com/20080429/failing-a-software-raid-1-disk-with-software-raid/</guid>
		<description><![CDATA[A software raid group disk failed in one of my servers yesterday. The kernel was spewing SCSI errors: kernel: ata2: status=0xd0 { Busy } kernel: SCSI error : return code = 0&#215;8000002 # mdadm --display /dev/md0 # mdadm --display /dev/md1 both reported a failed disk sdb* The procedure to rebuild the md groups is as [...]]]></description>
			<content:encoded><![CDATA[<p>A software raid group disk failed in one of my servers yesterday.</p>
<p>The kernel was spewing SCSI errors:</p>
<p>kernel: ata2: status=0xd0 { Busy }<br />
kernel: SCSI error :  return code = 0&#215;8000002<br />
<code><br />
# mdadm --display /dev/md0<br />
# mdadm --display /dev/md1</code></p>
<p>both reported a failed disk sdb*</p>
<p>The procedure to rebuild the md groups is as follows:</p>
<p>Replace bad disk (sdb in this scenario.) Note that if you do not bring down the server to replace the disk, be sure to &#8220;remove&#8221; the disk from the raid groups using mdadm.</p>
<p><code># mdadm --remove /dev/md0 /dev/sdb0<br />
# mdadm --remove /dev/md1 /dev/sdb1</code></p>
<p>Read the good disk&#8217;s partition table (sda in this scenario.)<br />
<code><br />
# fdisk -l /dev/sda<br />
Disk /dev/sda: 160.0 GB, 160041885696 bytes<br />
255 heads, 63 sectors/track, 19457 cylinders<br />
Units = cylinders of 16065 * 512 = 8225280 bytes<br />
</code><code><br />
   Device Boot      Start         End      Blocks   Id  System<br />
/dev/sda1   *           1          13      104391   fd  Linux raid autodetect<br />
/dev/sda2              14       19457   156183930   fd  Linux raid autodetect<br />
</code><br />
Install identical partition table on newly replaced disk. Create partitions that start and end on the same listed cylinders and are of type &#8220;fd.&#8221; Be sure to set the boot flag, and don&#8217;t forget to write the changes.<br />
<code><br />
# fdisk /dev/sdb</code></p>
<p>Add partitions back to the appropriate raid groups.<br />
<code><br />
# mdadm --add /dev/md0 /dev/sdb0<br />
# mdadm --add /dev/md1 /dev/sdb1</code></p>
<p>Ensure the raid groups are rebuilding properly.<br />
<code><br />
# mdadm --display /dev/md0<br />
# mdadm --display /dev/md1</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20080429/failing-a-software-raid-1-disk-with-software-raid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Searching and executing with find(1)</title>
		<link>http://www.jpolson.com/20080417/the-power-of-find1/</link>
		<comments>http://www.jpolson.com/20080417/the-power-of-find1/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 01:04:49 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://josh.choosechose.com/20080417/the-power-of-find1/</guid>
		<description><![CDATA[This afternoon I was faced with searching a directory tree for large files that have rotated within the last 24 hours &#8211; a symptom of a problem we were experiencing with a service. Here&#8217;s what I put together quickly: # find -iname name-\*.log -mtime 0 -exec du -sh {} \; Explanation of the switches (from [...]]]></description>
			<content:encoded><![CDATA[<p>This afternoon I was faced with searching a directory tree for large files that have rotated within the last 24 hours &#8211; a symptom of a problem we were experiencing with a service.</p>
<p>Here&#8217;s what I put together quickly:</p>
<p><code># find -iname name-\*.log -mtime 0 -exec du -sh {} \;</code></p>
<p>Explanation of the switches (from the find man page):<br />
<code><br />
-iname <em>pattern</em><br />
Base  of  file  name  (the  path with the leading directories removed) matches case insensitive shell pattern <em>pattern</em><br />
</code><code><br />
-mtime <em>n</em><br />
data was last modified <em>n</em>*24 hours ago.<br />
</code><code><br />
-exec <em>command</em> {} \;<br />
run the specified <em>command</em> on the matched files<br />
</code></p>
<p>It&#8217;s not complex (and probably not post-worthy,) but someone may find it helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20080417/the-power-of-find1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

