<?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>jathanism &#187; technical</title>
	<atom:link href="http://jathan.com/tag/technical/feed/" rel="self" type="application/rss+xml" />
	<link>http://jathan.com</link>
	<description>computers, robots, and other cool things.</description>
	<lastBuildDate>Thu, 20 Oct 2011 01:50:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python List Comprehension for Dummies</title>
		<link>http://jathan.com/2009/08/12/python-list-comprehension-for-dummies/</link>
		<comments>http://jathan.com/2009/08/12/python-list-comprehension-for-dummies/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 18:59:36 +0000</pubDate>
		<dc:creator>jathan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[list comprehension]]></category>
		<category><![CDATA[losers]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jathan.com/?p=72</guid>
		<description><![CDATA[So I code a lot. I code in Python a lot. You might say I love Python. I might say you&#8217;re right. One of the most powerful things about Python is its ability to iterate over ANYTHING as if it were a list. Lists, tuples, dictionaries, and even strings can all be iterated quickly and [...]]]></description>
			<content:encoded><![CDATA[<p>So I code a lot.  I code in Python a lot.  You might say I love Python.  I might say you&#8217;re right.</p>

<p>One of the most powerful things about Python is its ability to iterate over ANYTHING as if it were a list. Lists, tuples, dictionaries, and even strings can all be iterated quickly and elegantly.  Python also introduces a concept known as <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" target="_blank">list comprehension</a> which allows you to do rather complex filtering of list contents within a single statement.</p>

<p>To illustrate how awesome and powerful list comprehension is, let&#8217;s start with a basic example that is NOT using it:
<pre>&gt;&gt;&gt; my<em>list = [1,2,3,4,5]
&gt;&gt;&gt; for item in my</em>list:
...     if item % 2 == 0: print item, 'is an even number.'
...
2 is an even number.
4 is an even number.</pre>
So, let&#8217;s assume that we want to identify all even numbers inside of <code>my<em>list</em></code>, and put them into a new list called <code>evens</code> the old-fashoned way:
<pre>&gt;&gt;&gt; mylist = [1,2,3,4,5]
&gt;&gt;&gt; evens = []
&gt;&gt;&gt; for item in my<em>list:
...     if item % 2 == 0: evens.append(item)
...
&gt;&gt;&gt; evens
[2, 4]</em></pre>
<strong>Why the old-fashioned way sucks</strong>
First things first, the empty list called <code>evens</code> had to be declared ahead of time.  This is because when we looped thru the list called <code>mylist</code> using the <code>for</code> statement, when the if test is performed on each <code>item</code> we have to reference <code>evens</code> by name to <code>append()</code> the even numbers to it.</p>

<p><strong>Why list comprehension rocks</strong>
With list comprehension, the logic that isolates the even numbers and the declaration of the list that will capture this output are compressed into a single statement:
<pre>&gt;&gt;&gt; my<em>list = [1,2,3,4,5]
&gt;&gt;&gt; evens = [i for i in my</em>list if i % 2 == 0 ]
&gt;&gt;&gt; evens
[2, 4]</pre>
The logic is encapsulated in <em>[square brackets]</em> indicating that the output will be a list.  The list comprehension itself is the logic between the brackets that determines what will be in the list that it spits out.</p>

<p>So list comprehensions at their most basic level allow for compression of code and streamlining of logical statements. Advanced usage of list comprehension can get pretty silly, but then so can nested loop statements.  It supports nesting as many statements as you can throw at it so longs as they are syntactically correct.</p>

<p>If you find yourself coding shit like this:
<pre>&gt;&gt;&gt; losers = ['Joe','Jim','Jon','Jen']
&gt;&gt;&gt; for u in losers:
...     if u.startswith('J'):
...             if u.endswith('n'):
...                     if u != 'Jon':
...                             print u
...
Jen</pre>
Then maybe list comprehension is for you:
<pre>&gt;&gt;&gt; [u for u in losers if u.startswith('J') and u.endswith('n') and u != 'Jon']
['Jen']</pre>
No offense to anyone named Joe, Jim, or Jon.</p>
]]></content:encoded>
			<wfw:commentRss>http://jathan.com/2009/08/12/python-list-comprehension-for-dummies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Proxying SSH with SOCKS (HTTP was so 2007)</title>
		<link>http://jathan.com/2009/07/30/proxying-ssh-with-socks-http-was-so-2007/</link>
		<comments>http://jathan.com/2009/07/30/proxying-ssh-with-socks-http-was-so-2007/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 23:07:18 +0000</pubDate>
		<dc:creator>jathan</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[coconut]]></category>
		<category><![CDATA[fucking]]></category>
		<category><![CDATA[monkey]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[socks]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jathan.com/?p=39</guid>
		<description><![CDATA[By writing this I am assuming you know what SOCKS is, and you know what SSH is. If you don&#8217;t, here is a picture of a monkey fucking a coconut to make this visit worth your while: So, there comes a time in a man&#8217;s life when people at work on the inside network need [...]]]></description>
			<content:encoded><![CDATA[<p>By writing this I am assuming you know what <a href="http://en.wikipedia.org/wiki/SOCKS" target="_blank">SOCKS</a> is, and you know what <a href="http://en.wikipedia.org/wiki/Secure_Shell" target="_blank">SSH</a> is. If you don&#8217;t, here is a picture of a monkey fucking a coconut to make this visit worth your while:</p>

<div class="wp-caption alignright" style="width: 191px"><img title="MFC? Is that you?" src="http://i14.photobucket.com/albums/a346/Gargamel198024/monkeyfuckingacoconut.gif" alt="Could be a melon, but looks like a co-co-nut." width="181" height="161" /><p class="wp-caption-text">Could be a melon, but looks like a co-co-nut.</p></div>

<p>So, there comes a time in a man&#8217;s life when people at work on the inside network need to access things on the internet.  This is called &#8220;proxying&#8221;.  Yes, yes, I know; very fascinating.  These secure machines on the inside network don&#8217;t have access to the internet by design (See <a href="http://en.wikipedia.org/wiki/Private_network" target="_blank">RFC 1918</a>).  It&#8217;s the most basic layer of obfuscation (a 25 cent word we use a lot in the security world) and protection from bad internet traffic, not including firewalls and all that other exciting stuff.</p>

<p>Ok so we want to let our secure hosts on the inside proxy SSH to the internet via our SOCKS server.</p>

<p><strong>Assumptions:</strong>
<ul>
    <li>A Unix/Linux machine with the latest version of <a href="http://en.wikipedia.org/wiki/Netcat" target="_blank">netcat</a> installed (assumed to be found at <tt>/usr/bin/nc</tt>).  All modern operating systems have this.  Stop whining.</li>
    <li>A SOCKS proxy listening on TCP port 1080.</li>
    <li>A remote internet server listening for SSH connections on TCP port 22.</li>
    <li>You know what <tt>~</tt> means.  (Hint:  It&#8217;s shorthand for your home directory.)</li>
</ul>
<strong>Do the damn thing:</strong></p>

<p>Create an entry in <tt>~/.ssh/config</tt>.  If this file doesn&#8217;t exist, create it.  If it does, add this shit to the bottom:
<pre>Host proxythatshit
    ProxyCommand /usr/bin/nc -X 5 -x proxy.whatever.com:1080 internet.com 22</pre>
Write, quit, and then test that shit!  I am hoping that you gathered &#8220;proxythatshit&#8221; is the nickname we&#8217;re assigning this proxied connection to <em>internet.com</em>.  By putting this stuff in the config file, it makes it easy to reuse.
<pre>% ssh proxythatshit
jathan@proxythatshit's password:
[jathan@internet.com]~%</pre>
Did you see that?  It worked!! OMGZ!!JLk</p>

<p><strong>A little breakdown:</strong></p>

<p><tt>ProxyCommand /usr/bin/nc -X 5 -x proxy.whatever.com:1080 internet.com 22</tt>
<ul>
    <li><strong>ProxyCommand:</strong> An OpenSSH directive that tells SSH how to proxy the connection</li>
    <li><strong>/usr/bin/nc:</strong> The path to the netcat binary and the ProxyCommand in question here.  Proxying is one of the many things netcat does.</li>
    <li><strong>-X 5</strong>: Tells netcat to use SOCKS version 5</li>
    <li><strong>-x proxy.whatever.com:1080</strong>: Tells netcat to proxy the connection using <em>proxy.whatever.com</em> on port 1080</li>
    <li><strong>internet.com 22</strong>: The name and port of the destination we&#8217;re trying to get to by way of the proxy</li>
</ul>
<strong>Why SOCKS?</strong></p>

<p>You may be asking yourself, &#8220;Why not just use an HTTP proxy?&#8221;  Because HTTP proxies tend to be very picky about allowing you to proxy non-HTTP connections to destination ports other than the one you connected to.  In other words, if the proxy is listening on port 8080, good luck proxying a connection that isn&#8217;t HTTP (such as this SSH proxy thing) on anything other than port 80, 443, or 8080 it probably won&#8217;t work. If you&#8217;re using <a href="http://httpd.apache.org/docs/2.0/mod/mod_proxy.html" target="_blank">mod_proxy</a>, it absolutely will not work.  Don&#8217;t ask me why.  It just doesn&#8217;t.  <a href="http://www.squid-cache.org/" target="_blank">Squid</a> might work, but it is a pain in the ass to setup.</p>

<p>There you have it.  Don&#8217;t blame me if you get fired because you were looking at a picture of a monkey fucking a coconut for the 52 seconds it took to read this.</p>
]]></content:encoded>
			<wfw:commentRss>http://jathan.com/2009/07/30/proxying-ssh-with-socks-http-was-so-2007/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating read-only user accounts on ScreenOS</title>
		<link>http://jathan.com/2009/07/23/creating-read-only-user-accounts-on-screenos/</link>
		<comments>http://jathan.com/2009/07/23/creating-read-only-user-accounts-on-screenos/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:06:24 +0000</pubDate>
		<dc:creator>jathan</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[firewalls]]></category>
		<category><![CDATA[netscreen]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jathan.com/?p=3</guid>
		<description><![CDATA[Need to create a read-only account on a NetScreen (ScreenOS 6.x or lower) firewall? It&#8217;s simple: netscreen(M)-&#62; set admin user nocadmin password abc123 privilege read-only And there you have it. Now let&#8217;s test it: % ssh nocadmin@netscreen nocadmin@netscreen's password: For Authorized Use Only, Violators Will Be Prosecuted. netscreen(M)-&#62; It works! Notice the limited command set [...]]]></description>
			<content:encoded><![CDATA[<p>Need to create a read-only account on a NetScreen (ScreenOS 6.x or lower) firewall?</p>

<p>It&#8217;s simple:
<pre>netscreen(M)-&gt; set admin user nocadmin password abc123 privilege read-only</pre>
And there you have it.  Now let&#8217;s test it:
<pre>% ssh nocadmin@netscreen
nocadmin@netscreen's password:
For Authorized Use Only, Violators Will Be Prosecuted.
netscreen(M)-&gt;</pre>
It works!  Notice the limited command set available:
<pre>netscreen(M)-&gt; ?
exit                 exit command console
get                  get system information
mtrace               multicast traceroute from source to destination
ping                 ping other host
trace-route          trace route
netscreen(M)-&gt;</pre>
Now hop to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://jathan.com/2009/07/23/creating-read-only-user-accounts-on-screenos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

