<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Garage4hackers Forum - Tip | Trick of the Day</title>
		<link>http://www.garage4hackers.com/</link>
		<description>Add in your Tip | Tricks here</description>
		<language>en</language>
		<lastBuildDate>Sat, 25 May 2013 09:21:28 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.garage4hackers.com/images/misc/rss.png</url>
			<title>Garage4hackers Forum - Tip | Trick of the Day</title>
			<link>http://www.garage4hackers.com/</link>
		</image>
		<item>
			<title>Using Beautiful Soup Library for Parsing HTML in python</title>
			<link>http://www.garage4hackers.com/f55/using-beautiful-soup-library-parsing-html-python-4498.html</link>
			<pubDate>Wed, 22 May 2013 11:27:21 GMT</pubDate>
			<description>This is a code which downloads a html page and then parses a table from it to display output . Without Beautiful Soup it would require a lot of work...</description>
			<content:encoded><![CDATA[<div><div style="direction:ltr;overflow:false;height:24px;float:left;">
<script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script><g:plusone size="small" count="false"></g:plusone>
 <!--Twitter button starts--><a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-via="garage4hackers" data-url="http://www.garage4hackers.com/external.php?t=4498&amp;postcount=">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><!--Twitter button ends-->
 <!--Facebook button starts--><iframe src="http://www.facebook.com/widgets/like.php?href=http://www.garage4hackers.com/external.php?t=4498&amp;postcount=&amp;layout=button_count&amp;show_faces=false" scrolling="no" frameborder="0" style="border:none; width:47px; height:22px;overflow: hidden;"></iframe><!--Facebook button ends-->
</div><br><br>This is a code which downloads a html page and then parses a table from it to display output . Without Beautiful Soup it would require a lot of work and a lot of exception handling but  Beautiful  Soup makes the work lot<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#!/usr/bin/python<br />
<br />
# D4rk-Parser-- A small code for parsing HTML tables in python using Beautiful Soup <br />
# Coded By D4rk357[2013]<br />
<br />
<br />
import os , sys, urllib2 ,re<br />
from bs4 import BeautifulSoup<br />
response = urllib2.urlopen('https://urlquery.net/report.php?id=2602506')<br />
html1 = response.read()<br />
<br />
soup = BeautifulSoup(html1)<br />
<br />
table = soup.find(lambda tag: tag.name=='table' ) <br />
rows = table.findAll('tr')<br />
<br />
for x in rows:<br />
&nbsp;print '|'.join(x.stripped_strings) # important thing to note is the usage of stripped_strings function . This function is important in cases where there are some other HTML tags inside the table like &lt;b&gt; etc . In that case normal strip functions won't function properly . It is true in this particular case as well</code><hr />
</div>Output</div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Attached Images</legend>
			<div style="padding:10pxpx">
			<img class="attach" src="http://www.garage4hackers.com/attachments/f55/594d1369221908-using-beautiful-soup-library-parsing-html-python-image.png" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	

	</div>
]]></content:encoded>
			<category domain="http://www.garage4hackers.com/f55/">Tip | Trick of the Day</category>
			<dc:creator>D4rk357</dc:creator>
			<guid isPermaLink="true">http://www.garage4hackers.com/f55/using-beautiful-soup-library-parsing-html-python-4498.html</guid>
		</item>
		<item>
			<title>Crack passwords using John the Ripper (JTR) using multiple CPU cores</title>
			<link>http://www.garage4hackers.com/f55/crack-passwords-using-john-ripper-jtr-using-multiple-cpu-cores-4497.html</link>
			<pubDate>Wed, 22 May 2013 10:06:58 GMT</pubDate>
			<description>oclhashcat, cudahashcat etc. have capability to exploit the power of GPU for cracking. I am not sure whether JTR too possess the same. Anyway, my...</description>
			<content:encoded><![CDATA[<div>oclhashcat, cudahashcat etc. have capability to exploit the power of GPU for cracking. I am not sure whether JTR too possess the same. Anyway, my requirement was to use all 8 cores of my machine, which doesn't have GPU, while running JTR.<br />
<br />
Earlier, what I was aware of till date, was MPI patch for JTR for the same purpose. But with the latest releases of JTR, it has got built-in feature for it.<br />
<br />
Following snippet is the work around taken from <a href="http://blog.thireus.com/crack-passwords-using-john-the-ripper-with-multiple-cpu-cores-openmp" target="_blank">Crack Passwords using John the Ripper with Multiple CPU Cores (OpenMP) « Thireus' Bl0g</a><br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Quote:</div>
	<div class="bbcode_quote printable">
		<hr />
		
			<b>John</b><span style="font-family: trebuchet ms">can break many password hashes, but one of the primary missing feature was the <u>CPU multiple core support</u>. But today, </span><b><a href="http://www.openwall.com/john/g/john-1.7.9.tar.gz" target="_blank">John the Ripper 1.7.9</a></b><span style="font-family: trebuchet ms"> supports <u><a href="http://openmp.org/wp/" target="_blank">OpenMP</a></u> which brings Multi-Processing. Of course this feature was present on some patched versions of John, but since the 1.7.9 version it is <u>officially integrated</u>.<i>One of the best platform where you should use John the Ripper is UNIX, I personally prefer using john on Debian x86_64.</i></span><b>Let’s try some simple steps to enable and illustrate the new feature <img src="http://blog.thireus.com/wp-includes/images/smilies/icon_wink.png?018cff" border="0" alt="" /></b><br />
<ul><li>First go to <a href="http://www.openwall.com/john/" target="_blank">John the Ripper password cracker</a>, and download the latest version. When I write this article the latest stable release was 1.7.9.</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">$ wget <a href="http://www.openwall.com/john/g/john-1.7.9.tar.gz" target="_blank">http://www.openwall.com/john/g/john-1.7.9.tar.gz</a><br />
$ tar -xvzf john-1.7.9.tar.gz</td>
</tr>
</table></div>
<br />
</span><br />
</span><ul><li>Now let’s make some changes into the <b>Makefile</b> to enable the use of OpenMP</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">$ cd john-1.7.9/src/<br />
john-1.7.9/src$ nano Makefile</td>
</tr>
</table></div>
<br />
</span><br />
</span><ul><li>Locate the following lines</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code"># gcc with OpenMP<br />
#OMPFLAGS = -fopenmp<br />
#OMPFLAGS = -fopenmp -msse2</td>
</tr>
</table></div>
<br />
</span><br />
</span><ul><li>Uncomment OMPFLAGS</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code"># gcc with OpenMP<br />
OMPFLAGS = -fopenmp<br />
OMPFLAGS = -fopenmp -msse2</td>
</tr>
</table></div>
<br />
</span><br />
</span><ul><li>Before compiling john, make sure you have <b>gcc</b> installed! Now, let’s compile john.</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">john-1.7.9/src$ make</td>
</tr>
</table></div>
<br />
</span><br />
</span><br />
<span style="font-family: trebuchet ms"><i>This command will list all the systems where john can be compiled on. As I’m running Debian x86_64, I will choose linux-x86-64.</i><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">john-1.7.9/src$ make linux-x86-64</td>
</tr>
</table></div>
<br />
</span><br />
</span><br />
<span style="font-family: trebuchet ms"><i>John should be located in the ../run folder.</i></span><ul><li>Let’s try John</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">john-1.7.9/src$ cd ../run/<br />
john-1.7.9/run$ ./john --test</td>
</tr>
</table></div>
<br />
</span><br />
</span><br />
<span style="font-family: trebuchet ms"><i>Some benches should appear… <img src="http://blog.thireus.com/wp-includes/images/smilies/icon_cool.png?018cff" border="0" alt="" /></i><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">Benchmarking: Traditional DES [128/128 BS SSE2-16]... DONE<br />
Many salts: 7651K c/s real, 3872K c/s virtual<br />
Only one salt:  6876K c/s real, 3487K c/s virtual</td>
</tr>
</table></div>
<br />
</span><br />
</span><br />
<span style="font-family: trebuchet ms"><i>And John might use all your CPU cores.</i></span><ul><li>Now let’s do something fun, if you want John to use a certain amount of cores you can adjust it with the environment variable <b>OMP_NUM_THREADS</b>:</li>
</ul><span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">john-1.7.9/run$ OMP_NUM_THREADS=1 ./john --test</td>
</tr>
</table></div>
<br />
</span><br />
</span><br />
<span style="font-family: trebuchet ms"><span style="font-family: Consolas"><div class="cms_table"><table width="925" class="cms_table"><tr valign="top" class="cms_table_tr"><td class="cms_table_code">Benchmarking: Traditional DES [128/128 BS SSE2-16]... DONE<br />
Many salts: 3982K c/s real, 3990K c/s virtual<br />
Only one salt:  3770K c/s real, 3770K c/s virtual</td>
</tr>
</table></div>
<br />
</span></span><font color="#EFEFEF"><span style="font-family: trebuchet ms"><br />
</span></font>
			
		<hr />
	</div>
</div></div>

]]></content:encoded>
			<category domain="http://www.garage4hackers.com/f55/">Tip | Trick of the Day</category>
			<dc:creator>b0nd</dc:creator>
			<guid isPermaLink="true">http://www.garage4hackers.com/f55/crack-passwords-using-john-ripper-jtr-using-multiple-cpu-cores-4497.html</guid>
		</item>
		<item>
			<title>Python SSl connections.</title>
			<link>http://www.garage4hackers.com/f55/python-ssl-connections-4088.html</link>
			<pubDate>Fri, 10 May 2013 06:06:11 GMT</pubDate>
			<description>Last day we were stuck with an error in a python program of ours . The code was working fine on our dev environment, but when it was moved to...</description>
			<content:encoded><![CDATA[<div>Last day we were stuck with an error in a python program of ours . The code was working fine on our dev environment, but when it was moved to production, we were getting the following error <a href="!3714!http://www.garage4hackers.com/f55/how-copy-python-virtual-environment-duplicate-virtualenv-3714.html" target="_blank">[ even when we had the same python virtual environment as that of production ]</a> for a particular domain/server.<br />
<br />
Error:<br />
<br />
&lt;class 'socket.error'&gt;: [Errno 104] Connection reset by peer)<br />
<br />
A sample code to make a python Https request [something we used]. <br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">import httplib<br />
&nbsp;h = httplib.HTTPSConnection(host, port)<br />
&nbsp;headers = {<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'User-Agent': 'trap',<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Content-Type': content_type<br />
&nbsp; &nbsp; }<br />
h.request('POST', uri, body, headers)<br />
res = h.getresponse()<br />
return res.status, res.reason, res.read()</code><hr />
</div>Python handles https communication by using Openssl lib [ Python openssl lib ] . Actually many apps out there use openssl libs for there https communication. <br />
<br />
Even Wget was failing<br />
<br />
So for debugging an htpps /ssl issue you can use the openssl client to directly connect to our target the following way.<br />
<br />
openssl s_client -connect <a href="http://www.google.com:443" target="_blank">Google</a> -verify -debug -ssl3<br />
<br />
And this should give back the server Cert, tokens and necessary info for the communication .<br />
<br />
But when we tried to connect to our faulting server we were getting .<br />
<br />
openssl s_client -connect target-server.com:443 -verify -debug -ssl3<br />
verify depth is 0<br />
CONNECTED(00000003)<br />
52709:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:/SourceCache/OpenSSL098/OpenSSL098-47/src/ssl/s3_pkt.c:1102:SSL alert number 40<br />
52709:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:/SourceCache/OpenSSL098/OpenSSL098-47/src/ssl/s3_pkt.c:539:<br />
<br />
Based on Openssl documentation the faulting function is used to initiate the ssl connection |<a href="http://en.wikipedia.org/wiki/Transport_Layer_Security" target="_blank">ssl handshake </a>http://www.openssl.org/docs/ssl/SSL_do_handshake.html  <br />
<br />
So from this it is clear that the ssl handshake failed and that's the reason why the server closed the connection. So I tried to changing from ssl3 to tls1<br />
<br />
openssl s_client -connect <a href="http://www.google.com:443" target="_blank">Google</a> -verify -debug -tls1<br />
<br />
and the connection was successful. So this solution was to force tls1 when making the request. And later I found that the current issue was a bug in openssl <a href="https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/965371" target="_blank">https://bugs.launchpad.net/ubuntu/+s...sl/+bug/965371</a> . And why it was working on dev server was it was running an updated version of openssl, and the production had an outdated openssl. <br />
<br />
Fix is you can upgrade openssl [fekd up thing to do ] or force tls1 on your programs when dealing with such servers.<br />
<br />
You can also patch <a href="http://askubuntu.com/questions/116020/python-https-requests-urllib2-to-some-sites-fail-on-ubuntu-12-04-without-proxy/116059" target="_blank">httplib in python</a><br />
<br />
<br />
Forcing TLSv1 on python:<br />
<br />
sock = socket.create_connection(host, port),<br />
                                  self.timeout, self.source_address)<br />
                                  <br />
    self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file,<br />
        ssl_version=ssl.PROTOCOL_TLSv1)<br />
httplib.HTTPSConnection.connect = connect<br />
<br />
<br />
<br />
Forcing tls in perl:<br />
<br />
my $thing = whatever-&gt;new(<br />
                ssl_opts =&gt; { SSL_version =&gt; 'TLSv1' },<br />
        );<br />
<br />
Forcing TLS in Wget and Curl<br />
<br />
wget --secure-protocol=TLSv1 ...<br />
<br />
curl --tlsv1<br />
<br />
<br />
Ref: <a href="http://askubuntu.com/questions/116020/python-https-requests-urllib2-to-some-sites-fail-on-ubuntu-12-04-without-proxy/116059#116059" target="_blank">Python HTTPS requests (urllib2) to some sites fail on Ubuntu 12.04 without proxy - Ask Ubuntu</a><br />
 <a href="https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/965371" target="_blank">https://bugs.launchpad.net/ubuntu/+s...sl/+bug/965371</a><br />
<a href="http://stackoverflow.com/questions/385634/is-there-a-difference-between-sslv3-and-tls1-0" target="_blank">ssl - Is there a difference between SSLv3 and TLS1.0? - Stack Overflow</a><br />
<a href="http://pyopenssl.sourceforge.net/" target="_blank">pyOpenSSL - Python interface to the OpenSSL library</a></div>

]]></content:encoded>
			<category domain="http://www.garage4hackers.com/f55/">Tip | Trick of the Day</category>
			<dc:creator>fb1h2s</dc:creator>
			<guid isPermaLink="true">http://www.garage4hackers.com/f55/python-ssl-connections-4088.html</guid>
		</item>
	</channel>
</rss>
