<?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> &#187; programming</title>
	<atom:link href="http://travisaltman.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://travisaltman.com</link>
	<description></description>
	<lastBuildDate>Sat, 24 Mar 2012 04:16:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Search windows open shares with python</title>
		<link>http://travisaltman.com/search-windows-open-shares-with-python/</link>
		<comments>http://travisaltman.com/search-windows-open-shares-with-python/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 17:21:50 +0000</pubDate>
		<dc:creator>travis</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://travisaltman.com/?p=399</guid>
		<description><![CDATA[It&#8217;s rare during a penetration test that I actually exploit a vulnerability to gain more information. Newcomers to my filed will often use the term &#8220;network security&#8221;. I don&#8217;t care about the network, have the network for all I care. What I&#8217;m more concerned about is the information inside the network. The better way to [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s rare during a penetration test that I actually exploit a vulnerability to gain more information. Newcomers to my filed will often use the term &#8220;network security&#8221;. I don&#8217;t care about the network, have the network for all I care. What I&#8217;m more concerned about is the information inside the network. The better way to describe it is &#8220;information security&#8221;. Performing penetration tests one has to keep that in mind, yea it&#8217;s fun to exploit some user that&#8217;s running an old version of war-ftp but if that user doesn&#8217;t yield sensitive information then who cares to some extent.</p>
<p>I often see that professional penetration testers will highlight an open windows share that can be read or written to by everyone. They will often highlight other shares that are accessible by a large group such as Authenticated users. I don&#8217;t want to scoff at these types of open shares as they should be investigated by the business owner that created the open shares. The main thing to consider is what information lies within those open shares. Open shares are usually created for a reason, so that users easily share information. This is not bad unless the information in those shares is secret / classified material. To check for this possible sensitive information one would have to search all the files and folders in that share. Now you can use the cute little dog search feature inside of windows explorer to look for this information but using that your hands are somewhat tied. The search feature inside windows explorer actually does a nice job but if you wanted to automate the process to look at multiple shares and search for multiple terms then you&#8217;re out of luck. Because of this I wanted to script something that would automate the process. Powershell could have been an option but because I&#8217;m already familiar with python I stuck to what I know. This means that in order to run the script you&#8217;ll have to have python installed on windows. I could have written the script to work in Linux but that would have meant using cifs to map drives which seemed like more of a headache then just using python on windows.</p>
<p>You&#8217;ll need to open up a windows command prompt to run the script and it&#8217;s a good idead to <a href="http://showmedo.com/videotutorials/video?name=960000&amp;fromSeriesID=96" target="_blank">add Python to the windows path</a>. So the script takes two arguments. The first argument is the file containing all the shares that you want to search. The second argument is the file that contains all the terms you want to search for. So to run the script you would issue a command similar to below, where searchShares.py is the name of the python script.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">python.exe  searchShares.py  shares.txt  searchTerms.txt</div></div>
<p>Your shares.txt file should look similar to below.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">\\one\two<br />
\\three\four\five<br />
\\six\seven\eight\nine</div></div>
<p>Your searchTerms.txt file should look similar to below.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">secret<br />
password<br />
username</div></div>
<p>In the example above the term &#8220;secret&#8221; will be recursively searched in all three shares. Then &#8220;password&#8221; will be recursively searched in all three shares, then so on and so on. The script will output any file, file name, or folder name that matches any of the search terms. Currently the script will read each file in <a href="http://en.wikipedia.org/wiki/Binary_file" target="_blank">binary format</a> which means if it comes across a word document file (such as document.doc) it doesn&#8217;t open / read the file like microsoft word would. The current script reads each line of the binary file looking for your search term. Reading a text file as binary seems to work fine but reading in microsoft office documents as binary have different results. One thing I&#8217;ve noticed in my testing is that generally speaking it does just fine searching through a *.doc file but has trouble searching through a *.docx file. Binary searching is not ideal but it&#8217;s my current solution. Python has the capability to open microsoft office documents in a more native format but for my first go round I haven&#8217;t implemented that solution.</p>
<p>Once you run the script you will see output similar to below.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">C:\temp&gt;python searchShares.py shares.txt searchTerms.txt<br />
<br />
Walking directory \\192.168.99.184\test<br />
<br />
Found \\192.168.99.184\testtest.txt<br />
Found \\192.168.99.184\testTravisAltmanResume.doc<br />
Found \\192.168.99.184\test\onewordDoc1.docx<br />
Found \\192.168.99.184\test\one\twopasswords.txt<br />
Found \\192.168.99.184\test\one\two\threewordDoc2.docx<br />
Searching file \\192.168.99.184\test\test.txt for term secret<br />
<br />
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term secret<br />
<br />
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term secret<br />
<br />
Searching file \\192.168.99.184\test\one\two\passwords.txt for term secret<br />
<br />
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term secret<br />
<br />
Searching file \\192.168.99.184\test\test.txt for term password<br />
<br />
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term password<br />
<br />
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term password<br />
<br />
Searching file \\192.168.99.184\test\one\two\passwords.txt for term password<br />
<br />
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term password<br />
<br />
Searching file \\192.168.99.184\test\test.txt for term username<br />
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term username<br />
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term username<br />
Searching file \\192.168.99.184\test\one\two\passwords.txt for term username<br />
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term username</div></div>
<p>This output on the command prompt is to given as a verbose message so that you know what&#8217;s going on with the script. The output on the command prompt will not tell you if it found a search term. The results of your searching is placed in a text file called output.txt located in the current directory. The content of output.txt should look similar to the following.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">=== Directories or file names matching search criteria ===<br />
<br />
\\192.168.99.184\test\one\two\passwords.txt<br />
<br />
=== Files matching search criteria ===<br />
<br />
found secret in file \\192.168.99.184\test\one\two\passwords.txt<br />
found password in file \\192.168.99.184\test\one\two\passwords.txt</div></div>
<p>So you can see that it matches the file name as well as the contents of the file. One thing to keep in mind is that this script can take a while to run. There two factors that control how fast it runs, 1) Speed of the network and 2) Size (GB, MB, etc) of the share. It works best when your network is local and not in another city. The biggest factor is going to be the size of the share. Running this script on a major file sahre that is say 800 GB in size will take a very long time. Keep in mind you can specify specific directories, so instead of searching in the root share such as \\share\one maybe it&#8217;s a better idea to searh in \\share\one\two\three. So keep these factors in mind when running the script. Below is the script, simply cut and paste into your text editor of choice and save as searchShares.py</p>
<pre>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span><br />
<br />
output <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'output.txt'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'a'</span><span style="color: black;">&#41;</span><br />
output.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
fileList <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
shareList <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
eachShare <span style="color: #66cc66;">=</span> shareList.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> shares <span style="color: #ff7700;font-weight:bold;">in</span> eachShare:<br />
&nbsp; &nbsp; path <span style="color: #66cc66;">=</span> shares.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>Walking directory '</span> + path + <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> root<span style="color: #66cc66;">,</span> subFolders<span style="color: #66cc66;">,</span> files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#print 'Indexing ' + root + '\n'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">in</span> files:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>root<span style="color: #66cc66;">,</span><span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Found '</span> + root + <span style="color: #008000;">file</span><br />
keywords <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
searchTerm <span style="color: #66cc66;">=</span> keywords.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
output.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'=== Directories or file names matching search criteria ===<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> term <span style="color: #ff7700;font-weight:bold;">in</span> searchTerm:<br />
&nbsp; &nbsp; strip <span style="color: #66cc66;">=</span> term.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">any</span><span style="color: black;">&#40;</span>strip <span style="color: #ff7700;font-weight:bold;">in</span> s <span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> fileList<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; matching <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>s <span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> fileList <span style="color: #ff7700;font-weight:bold;">if</span> strip <span style="color: #ff7700;font-weight:bold;">in</span> s<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> matching:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> + item<span style="color: black;">&#41;</span><br />
output.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>=== Files matching search criteria ===<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> term <span style="color: #ff7700;font-weight:bold;">in</span> searchTerm:<br />
&nbsp; &nbsp; strip <span style="color: #66cc66;">=</span> term.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> fileList:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Searching file '</span> + item + <span style="color: #483d8b;">' for term '</span> + term<br />
&nbsp; &nbsp; &nbsp; &nbsp; searchFile <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>item<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'rb'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> searchFile:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>strip<span style="color: #66cc66;">,</span> line<span style="color: #66cc66;">,</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'found '</span> + strip + <span style="color: #483d8b;">' in file '</span> + item + <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; searchFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
output.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
</pre>
<p>Let me know if this works / doesn&#8217;t work and also let me know if you have any suggestions on how to make it better. One thing I might do in the future is to limit the types of files it searches to say only .txt, .doc, .xls, etc. Happy hunting for information on shares.</p>
]]></content:encoded>
			<wfw:commentRss>http://travisaltman.com/search-windows-open-shares-with-python/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>password dictionary generator</title>
		<link>http://travisaltman.com/password-dictionary-generator/</link>
		<comments>http://travisaltman.com/password-dictionary-generator/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 04:13:59 +0000</pubDate>
		<dc:creator>travis</dc:creator>
				<category><![CDATA[learning]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://travisaltman.com/?p=199</guid>
		<description><![CDATA[I had the need to generate a password dictionary that would cover every possible combination for a defined character set.  I first learned to program in Python so I was going to start there first.  Before writing the program I decided to Google and see if anyone else had tackled this problem via Python, turned [...]]]></description>
			<content:encoded><![CDATA[<p>I had the need to generate a password dictionary that would cover every possible combination for a defined character set.  I first learned to program in Python so I was going to start there first.  Before writing the program I decided to Google and see if anyone else had tackled this problem via Python, turned out they had.  <a href="http://forums.remote-exploit.org/programming/14204-another-password-wordlist-generator-python.html" target="_blank">Siph0n posted his Python code</a> to create a password dictionary over at the BackTrack forums.  I wanted to post it here as a mirror and to discuss the implications of creating a password dictionary with every possible combination.  Below is the Python code.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">f<span style="color: #66cc66;">=</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'wordlist'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> xselections<span style="color: black;">&#40;</span>items<span style="color: #66cc66;">,</span> n<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> n<span style="color: #66cc66;">==</span><span style="color: #ff4500;">0</span>: <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>items<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> ss <span style="color: #ff7700;font-weight:bold;">in</span> xselections<span style="color: black;">&#40;</span>items<span style="color: #66cc66;">,</span> n-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span>items<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>+ss<br />
<br />
<span style="color: #808080; font-style: italic;"># Numbers = 48 - 57</span><br />
<span style="color: #808080; font-style: italic;"># Capital = 65 - 90</span><br />
<span style="color: #808080; font-style: italic;"># Lower = 97 - 122</span><br />
numb <span style="color: #66cc66;">=</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">48</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">58</span><span style="color: black;">&#41;</span><br />
cap <span style="color: #66cc66;">=</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">65</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">91</span><span style="color: black;">&#41;</span><br />
low <span style="color: #66cc66;">=</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">97</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">123</span><span style="color: black;">&#41;</span><br />
choice <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0</span><br />
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>choice<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; choice <span style="color: #66cc66;">=</span> <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'''<br />
&nbsp; &nbsp; 1) Numbers<br />
&nbsp; &nbsp; 2) Capital Letters<br />
&nbsp; &nbsp; 3) Lowercase Letters<br />
&nbsp; &nbsp; 4) Numbers + Capital Letters<br />
&nbsp; &nbsp; 5) Numbers + Lowercase Letters<br />
&nbsp; &nbsp; 6) Numbers + Capital Letters + Lowercase Letters<br />
&nbsp; &nbsp; 7) Capital Letters + Lowercase Letters<br />
&nbsp; &nbsp; : '''</span><span style="color: black;">&#41;</span> <br />
<br />
choice <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>choice<span style="color: black;">&#41;</span><br />
poss <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">1</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> numb<br />
<span style="color: #ff7700;font-weight:bold;">elif</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">2</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> cap<br />
<span style="color: #ff7700;font-weight:bold;">elif</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">3</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> low<br />
<span style="color: #ff7700;font-weight:bold;">elif</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">4</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> numb<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> cap<br />
<span style="color: #ff7700;font-weight:bold;">elif</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">5</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> numb<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> low<br />
<span style="color: #ff7700;font-weight:bold;">elif</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">6</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> numb<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> cap<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> low<br />
<span style="color: #ff7700;font-weight:bold;">elif</span> choice <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">7</span>:<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> cap<br />
&nbsp; &nbsp; poss +<span style="color: #66cc66;">=</span> low<br />
<br />
bigList <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> poss:<br />
&nbsp; &nbsp; bigList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">chr</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
MIN <span style="color: #66cc66;">=</span> <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;What is the min size of the word? &quot;</span><span style="color: black;">&#41;</span><br />
MIN <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>MIN<span style="color: black;">&#41;</span><br />
MAX <span style="color: #66cc66;">=</span> <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;What is the max size of the word? &quot;</span><span style="color: black;">&#41;</span><br />
MAX <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>MAX<span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>MIN<span style="color: #66cc66;">,</span>MAX+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> s <span style="color: #ff7700;font-weight:bold;">in</span> xselections<span style="color: black;">&#40;</span>bigList<span style="color: #66cc66;">,</span>i<span style="color: black;">&#41;</span>: f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span></div></div>
<p>If you&#8217;re familiar with programming and Python in particular then you could just grab the code and roll but I really wanted to discuss the usefulness of an application like this.  First I will discuss the basics of how to get this program up and running but will eventually jump into other implications such as time, storage, and usefulness of a password dictionary.</p>
<p>How to install and use the program</p>
<ol>
<li>You must have Python installed.  If you&#8217;re running Linux (you should be) then it&#8217;s probably already installed.  If you&#8217;re running then Windows then you will have to <a href="http://www.python.org/download/" target="_blank">download Python</a>.</li>
<li>Now that you have Python installed simply copy and paste the code above into a text file and name it passwordDictionaryGenerator.py.  The .py extension is needed because that&#8217;s how Python recognizes code that it&#8217;s suppose to execute.</li>
<li>Modify appropriate variables within the program.  The only variables you may want to modify are numb, cap, and low.  These variables contain the ASCII equivalent ranges for the letters and numbers you will be using to generate your dictionary.  You may want to modify these variables so that your dictionary does not contain a-z but only a-k, I&#8217;ll leave that up to you.</li>
<li>Now to run the program simply type
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">python passwordDictionaryGenerator.py</div></div>
<p>You will have to answer the questions about which character set you want to use and how long / short your password dictionary is going to be.  Once you answer the questions it may seem like the program isn&#8217;t doing anything but it is, it will spit you back to the command line once the program has completed.  The output will be a file called wordlist.</li>
</ol>
<p>So now you have this cool program that can generate a password dictionary for you, how big (size MB, GB, TB, etc) will this dictionary be?  How long will it take to generate this dictionary?  Let&#8217;s tackle the size question first as it will help us calculate the time as well.  The key to calculating the size is a math term called permutations.  <a href="http://www.aaaknow.com/sta-permu.htm" target="_blank">Permutations</a> is a simple equation to determine the number of words for that particular character set and length of word.  The basic equation is below.</p>
<p>n<sup>r</sup></p>
<p>n = total character set (e.g.  a-z + A-Z + 0-9 = 62)</p>
<p>r = length of the word</p>
<p>Now you&#8217;ll have to calculate n<sup>r</sup> for each length to get every possible combination.  So for a 6 digit long password your equation will look like the following.</p>
<p>n<sup>6</sup> + n<sup>5</sup> + n<sup>4</sup> + n<sup>3</sup> + n<sup>2</sup> + n<sup>1</sup> = every possible combination</p>
<p>Let&#8217;s try an example where our character set is a-z (n = 26) and our password is no longer than 6 (r = 1-6) digits, how many words will be in our dictionary?</p>
<p>26<sup>6</sup> + 26<sup>5</sup> + 26<sup>4</sup> + 26<sup>3</sup> + 26<sup>2</sup> + 26<sup>1</sup> = 321,272,406 = total # of words</p>
<p>So now we understand how to calculate the total number of words in our dictionary.  How does that relate to the size?  Well for the most part if the length of the password is x then the size in bytes will be x + 1 for that particular line.  Then all we have to do is multiply each n<sup>r</sup> times the size of that particular line to get the size for that particular length.  That may have just sound really confusing so hopefully the following graph clears that up some.</p>
<p><a href="http://travisaltman.com/wp-content/possibleCombinationChart.png"><img class="aligncenter size-full wp-image-212" title="possibleCombinationChart" src="http://travisaltman.com/wp-content/possibleCombinationChart.png" alt="" width="395" height="210" /></a></p>
<p>I went ahead and generated this dictionary, it took about 30 minutes.  Turns out the size matched my calculations.</p>
<p><a href="http://travisaltman.com/wp-content/wordlistSize.png"><img class="aligncenter size-full wp-image-215" title="wordlistSize" src="http://travisaltman.com/wp-content/wordlistSize.png" alt="" width="250" height="198" /></a></p>
<p>So now you have the basic formula for calculating the size of your desired dictionary.  Let&#8217;s take a look at a larger example just to cure our curiosity.  Let&#8217;s assume the following parameters.</p>
<ul>
<li>character set = a-z, A-Z, &amp; 0-9</li>
<li>password length = 1-8</li>
<li>n = 62</li>
<li>r = 1 &#8211; 8</li>
</ul>
<p>With these parameters the size of our dictionary jumps to 1,800 terabytes or 1.8 petabytes. Take a look at the chart below.</p>
<p><a href="http://travisaltman.com/wp-content/possibleCombinationChart2.png"><img class="aligncenter size-full wp-image-221" title="possibleCombinationChart2" src="http://travisaltman.com/wp-content/possibleCombinationChart2.png" alt="" width="487" height="290" /></a></p>
<p>You can see how quickly the size jumps up. I don&#8217;t know about you but I don&#8217;t have a two petabyte drive lying around. Generating this dictionary is just infeasible. I did calculate the time it would probably take to generate this dictionary, it came out to be about 11 days. So the time to create such a dictionary is nothing compared to the storage required to house it. Not only that I don&#8217;t know to many applications that can handle a large dictionary as input, so that&#8217;s another factor you&#8217;ll have to keep in mind when generating your dictionary.</p>
<p>Calculating the time it takes to generate these dictionaries I&#8217;ll leave up to you.  The basic idea is that you can run the python program for a particular length password for a set amount of time and then extrapolate form there.  For the most part time isn&#8217;t really a factor but storage is. The concepts I&#8217;ve talked about here are nothing new. The idea of generating a password came to me and my coworkers as we were thinking of ways to test a WPA wireless infrastructure. Attacking WPA can be done offline so we were thinking of generating a dictionary to accomplish this. Hours later we soon realized the difficulty with generating such a large dictionary. This was actually good news because it meant that an attacker would have an extremely difficult time attacking a WPA access point with a complex password. <a href="http://www.renderlab.net/projects/WPA-tables/" target="_blank">Renderman and the Church of Wifi</a> have thought about this problem way before I did and came up with some rainbow tables to help test the strength of your WPA access point. You can&#8217;t really create a dictionary with every single combination for a lengthy password, your best bet is to create a dictionary with the most &#8220;common&#8221; passwords, which is no easy task either.</p>
<p>The moral of the story is to use lengthy complex passwords with a high character set, but you knew that already. So I just suggested that this program is somewhat useless, well it is but it isn&#8217;t. You can use this program to generate a small dictionary but a large dictionary (greater than a couple of terabytes) is probably out of the question. So use this program and let me know what your results are, I&#8217;m always interested in your feedback. Happy cracking.</p>
]]></content:encoded>
			<wfw:commentRss>http://travisaltman.com/password-dictionary-generator/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

