<?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>Kalimat al-Mutafalsif &#187; Perl</title>
	<atom:link href="http://thesnarky.com/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://thesnarky.com</link>
	<description>The Words of the One Who Calls Himself a Philosopher</description>
	<lastBuildDate>Mon, 24 May 2010 21:25:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Bluetooth Device Lookup</title>
		<link>http://thesnarky.com/2007/11/22/bluetooth-device-lookup/</link>
		<comments>http://thesnarky.com/2007/11/22/bluetooth-device-lookup/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 01:33:23 +0000</pubDate>
		<dc:creator>Snarky</dc:creator>
				<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://thesnarky.com/2007/11/22/bluetooth-device-lookup/</guid>
		<description><![CDATA[Happy Thanksgiving! I'm spending the break catching back up on the state of <a href="http://www.bluetooth.com/bluetooth/">Bluetooth</a> security because, hey, I love the subject. Everyone has a phone with Bluetooth, just about, and many overlook it as a security hole because they feel there's nothing insidious that can be done with just replacing wires with some radio broadcasts. I'll give a quick rundown on how to get Bluetooth working under Linux, then the software I use, and finally give a tool I wrote watching the Dallas Game to speed up identification of Bluetooth devices.]]></description>
			<content:encoded><![CDATA[<p>Happy Thanksgiving! I'm spending the break catching back up on the state of <a href="http://www.bluetooth.com/bluetooth/">Bluetooth</a> security because, hey, I love the subject. Everyone has a phone with Bluetooth, just about, and many overlook it as a security hole because they feel there's nothing insidious that can be done with just replacing wires with some radio broadcasts. I'll give a quick rundown on how to get Bluetooth working under Linux, then the software I use, and finally give a tool I wrote watching the Dallas Game to speed up identification of Bluetooth devices.<br />
<span id="more-185"></span><br />
<strong>Hardware</strong><br />
Naturally, those "USB Bluetooth devices" that you see in stores are for Windows, so how do you know what will work in Linux? Check <a href="http://www.holtmann.org/linux/bluetooth/features.html">this page</a>, put together by Marcel Holtmann, to get an idea. If a device has an HCI version, it almost definitely works under Linux. Unfortunately it hasn't been updated in over a year and a half (March 31st of 2006), but it gives a good estimate of which brands will work. I looked for devices that had decent <a href="http://newegg.com">Newegg</a> ratings, and a history of providing Linux support. In the end I grabbed an <a href="http://www.iogear.com/main.php?loc=product&Item=GBU221">IOGEAR GBU221</a> which has worked perfectly out of the box. Ironically this did NOT get good reviews on Newegg, and Bets Buy had it cheaper, but I promise that is a very rare occurrence. </p>
<p><strong>Software</strong><br />
As far as the drivers go, it's <a href="http://www.bluez.org/">BlueZ</a> or nothing. This is an excellent package that works enough to be qualified Bluetooth 2.0 though with some implementations out there, this may or may not be a selling point. But the point of the matter is, nab this and it'll work just like Windows.<br />
As far as software to interact with Bluetooth devices, it depends on what you want to do. I don't connect my phone via Bluetooth (preferring a USB cable) so I can't help you with that. However make sure you have hcitools installed to pair with devices and scan for new ones around you. To test your set up, put your phone (or headset, or keyboard, or whatever) into detection mode and then run:<br />
<code>hcitools scan</code><br />
If you're set up, it should detect your device and identify its MAC Address and Device Name.<br />
After you're set up legally checking on your phone, you can try checking out others. Try an hcitools scan in a busy area and see if any phones show up. Or perhaps a parking lot if you're really devious. I'd recommend checking out the <a href="http://trifinite.org">Trifinite Group</a> for ideas of what evilness can go on over Bluetooth.</p>
<p><strong>Device Lookup</strong><br />
Now that you have my 2 cent description of how to get Bluetooth working on Linux (Ubuntu 7.10) and done your own research on what vulnerabilities (might) exist out there, you may be interested in a quick way to identify devices you find. Quick identification of devices around you allows for quick knowledge of what exploits exist. I'm not advocating breaking devices, but this may be extremely useful when penetration testing a company or school. I wrote a quick perl script that will take a given MAC address and return the company that device is registered to. It has two text files with it, one is a list of known Bluetooth manufacturers and the device prefixes registered to them, the other is a full list of all MAC prefixes and who they're registered to. Download this <a href="http://thesnarky.com/wp-content/uploads/2007/11/mac_address.tar">tarball</a>, untar the file, change into the mac_address directory, and then run it using:</p>
<p><code><br />
tar -xf mac_address.tar<br />
cd mac_address<br />
perl mac_lookup.pl 00:16:8f:c0:5X:XX</code></p>
<p>It'll spit out info looking a little like:</p>
<p><code><br />
Looking up: 00:16:8f:c0:51:11<br />
Manufacturer Prefix: 00:16:8f<br />
Device Type: c0:51:11<br />
Manufacturer: GN Netcom as<br />
</code></p>
<p>I'm quickly porting it to php and tossing all that info into a database so you'll be able to bounce requests off of a php page to grab the relevant information. More information will come on that in a day or two, once I have it up and running. Of course all this was inspired by the <a href="http://trifinite.org/trifinite_stuff_blueprinting.html">BluePrinting</a> project, and I hope to work that into my database.</p>
<p>EDIT: Whoops, it appears I mis-read a paper and wrote a hasty article. It is not possible to assume the second three bytes of a Bluetooth MAC are the device model, as every manufacturer is different.  I've changed bits of the above article to reflect this knowledge, and changed the output of my tool. I'd also like to note there is another tool that is similar to this, @stake's redfang tool. However this tool is used to *find* non-discoverable devices, via brute-force, whereas mine is a simple lookup tool.</p>
<p>Also it should be noted that I'm using the term Bluetooth MAC address, though this may not be the best term. Its also called the Bluetooth Device Address.</p>
]]></content:encoded>
			<wfw:commentRss>http://thesnarky.com/2007/11/22/bluetooth-device-lookup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Can Has Pictures</title>
		<link>http://thesnarky.com/2007/10/14/i-can-has-pictures/</link>
		<comments>http://thesnarky.com/2007/10/14/i-can-has-pictures/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 00:29:52 +0000</pubDate>
		<dc:creator>Snarky</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://thesnarky.com/2007/10/14/i-can-has-pictures/</guid>
		<description><![CDATA[I've been badly addicted to <a href="http://icanhascheezburger.com/">I Can Has Cheezburger</a> for a while now. Like me, those pictures are cute and funny. Unlike those pictures, I know how to grab them all! I finally got fed up with having to click next, and decided "What the hey", I can get all the URLs for the direct images! So I cooked up a quick Perl script that spits out a text file, one line for each image. Of course, once you have the aforementioned file, wget becomes your best friend. I needed a quick script success, and this little tidbit has both provided that, and given me something to do for the rest of the wee--- erm, night.]]></description>
			<content:encoded><![CDATA[<p>I've been badly addicted to <a href="http://icanhascheezburger.com/">I Can Has Cheezburger</a> for a while now. Like me, those pictures are cute and funny. Unlike those pictures, I know how to grab them all! I finally got fed up with having to click next, and decided "What the hey", I can get all the URLs for the direct images! So I cooked up a quick Perl script that spits out a text file, one line for each image. Of course, once you have the aforementioned file, wget becomes your best friend. I needed a quick script success, and this little tidbit has both provided that, and given me something to do for the rest of the wee--- erm, night.</p>
]]></content:encoded>
			<wfw:commentRss>http://thesnarky.com/2007/10/14/i-can-has-pictures/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Software Design Oopsies</title>
		<link>http://thesnarky.com/2007/06/12/software-design-oopsies/</link>
		<comments>http://thesnarky.com/2007/06/12/software-design-oopsies/#comments</comments>
		<pubDate>Wed, 13 Jun 2007 03:40:02 +0000</pubDate>
		<dc:creator>Snarky</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Stupidity]]></category>

		<guid isPermaLink="false">http://thesnarky.com/2007/06/12/software-design-oopsies/</guid>
		<description><![CDATA[So, real quick as I just got the idea to actually post this little story, I was writing a little script. This script dealt with ids I'm using for a project. Basically I knew there was a lot to begin with, but wanted a flat file, not a database because I figured "Hey, I'm dealing with a lot, why pay the overhead every id of doing a bunch of queries?" Among other things, this script couldn't list an id more than once. So I (stupidly) chose an array to store the ids and sort through them. At first, no issues, I could process a few ids in a second and get all my work done on them. Well, after I hit around 15,000 I had issues. It was now taking about 5 seconds an id. It only got worse, and worse, and worse. Around 19,000 ids I finally CTRL-C's the script, to retool it. I changed it over to throwing all the ids into a database, accepting a tad more overhead per id, but overall this becomes linear time. I stupidly forgot my Big-O notation classes, and that sorting through a large list of numbers takes longer than a very short one. *sigh*. ]]></description>
			<content:encoded><![CDATA[<p>So, real quick as I just got the idea to actually post this little story, I was writing a little script. This script dealt with ids I'm using for a project. Basically I knew there was a lot to begin with, but wanted a flat file, not a database because I figured "Hey, I'm dealing with a lot, why pay the overhead every id of doing a bunch of queries?" Among other things, this script couldn't list an id more than once. So I (stupidly) chose an array to store the ids and sort through them. At first, no issues, I could process a few ids in a second and get all my work done on them. Well, after I hit around 15,000 I had issues. It was now taking about 5 seconds an id. It only got worse, and worse, and worse. Around 19,000 ids I finally CTRL-C's the script, to retool it. I changed it over to throwing all the ids into a database, accepting a tad more overhead per id, but overall this becomes linear time. I stupidly forgot my Big-O notation classes, and that sorting through a large list of numbers takes longer than a very short one. *sigh*. </p>
<p>Bottom line: For large amounts of data accept the higher overhead per unit when it'll lessen the overall overhead. Now my script runs happily all day without decreasing my speed. I only post so you geeks out there can laugh at me, and I'll remember this handy little lesson later on.</p>
<p>(I feel the need, as I do freelance programming, to point out I'm normally quite smart regarding how I design my code, and I'm posting this because I can't believe I did that!)</p>
]]></content:encoded>
			<wfw:commentRss>http://thesnarky.com/2007/06/12/software-design-oopsies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plaintext Passwords&#8230; Again!</title>
		<link>http://thesnarky.com/2007/05/25/plaintext-passwords-again/</link>
		<comments>http://thesnarky.com/2007/05/25/plaintext-passwords-again/#comments</comments>
		<pubDate>Fri, 25 May 2007 20:47:43 +0000</pubDate>
		<dc:creator>Snarky</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://thesnarky.com/2007/05/25/plaintext-passwords-again/</guid>
		<description><![CDATA[If you follow my blog, and sadly most of my readers have stopped checking, you'll remember the security hole I found on a major website around Valentine's Day. You should also remember I had a very good experience with the developers there, in terms of their competance and politness. Well, I just tried to log [...]]]></description>
			<content:encoded><![CDATA[<p>If you follow my blog, and sadly most of my readers have stopped checking, you'll remember the <a href="http://thesnarky.com/2007/02/13/plain-text-passwords/">security hole</a> I found on a major website around Valentine's Day. You should also remember I had a very <a href="http://thesnarky.com/2007/02/21/plain-text-passwords-followup/">good experience</a> with the developers there, in terms of their competance and politness. </p>
<p>Well, I just tried to log in to that site on an account I haven't used in... well.. a long time, lets leave it at that. Sadly, I'd forgotten my password, and they do a very smart thing in limiting how many failed logings one can have before resetting the password, forcing me to reset my password. Up to this point, everything is working as it should, removing the possibility of brute force attacks with only limited user annoyance every few months.</p>
<p>Then I noticed that... uh-oh... the reset page wasn't SSL. I thought "Oh, don't worry, I'll bet its posted to an SSL domain," but grepping the source proved otherwise. Bugged, I decided to sniff my traffic and see what was happening, and sure enough, my password flew by in plaintext. This time it wasn't anything as stupid as a "Mother's Maiden Name" type question that also requires a little social engineering, this is MY PASSWORD, and MY USERNAME flying by. </p>
<p>Here's a look at a sanitized version of the information in the packet that gives it all away.</p>
<blockquote><p>
Content-Type:application/x-www-form-urlencoded<br />
Content-Length:102<br />
submitok=1<br />
cc=ff6cda68ba7b4c<br />
tt=1180114618<br />
email=****@****.***<br />
newpass1=PLAINTEXT<br />
newpass2=PLAINTEXT
</p></blockquote>
<p><strong>The Impact:</strong><br />
If I have to be sniffing the traffic in order to catch the password, this isn't as effective as, say, just phishing for the credentials, but this attack doesn't require any human stupidity. </p>
<p>However, this again is a very effective attack for large networks. <a href="http://en.wikipedia.org/wiki/ARP_poisoning">ARP Poisoning</a> is fairly trivial in this day and age, so even on a switched network one can grab these credentials. On a large network such as a dormitory, or campus this attack will work on as many people as are connected to the router you have access to. Worse, combine this with a botnet or other malware on a victim's machine, and it'll work on everyone who logs on to the site on an infected computer. </p>
<p>Another fun trick, as identified by the <a href="http://www.indiana.edu/~phishing/">researchers at Indiana University</a>, is subverting routers. If one subverts a router to modify the firmware, such an attack could easily be set up to happen on all traffic passing through the router, eliminating the need for ARP Poisoning. However, this requires an insecure router to start with, and the target would be a much smaller number.</p>
<p><strong>The Attack:</strong><br />
I'll talk through an attack from a dormitory, as that's the first I thought of. Once you're set up with your ARP Poisoning, its time to get users to reset their password. Get a large list of email addresses from your school (this is very, very easy to script, you should be able to get tons of addresses. Now, you can either exploit the password reset security feature, or simply hit the reset.php page with each email address. Once you've reset the password, sit and sniff the network for any packets going to the page that actually does the resetting. Save all those packets, and you have all the information you need to compromise the accounts of everyone in your dorm!</p>
<p>I happen to know (whipped up a script to prove it) that this can quite easily be done in Perl where you never have to do anything, just sit and watch the logins go by.</p>
<p><strong>The Payoff:</strong><br />
Once you have all the logins, you can either be very malicious and overt, or very subtle and clever. One might immediately hit the account page to change the password to something to lock out the legitimate user, or maybe even delete the account. Or, to be clever, throw all the logins into a database for later exploitation. It'd be smarter to do the second, because then the attack will go unnoticed for a while.</p>
<p><strong>My Actions:</strong><br />
As usual, I'm accompanying this post with an email to the development squad of that website. I'm not releasing the name of the site, will delete any comments that say what site it is, and won't make my exploit code available anywhere. I will speak for the quality of the site's developers, from my last dealings with them, and know this will be fixed before any real attacks can be launched.</p>
]]></content:encoded>
			<wfw:commentRss>http://thesnarky.com/2007/05/25/plaintext-passwords-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Users</title>
		<link>http://thesnarky.com/2007/02/17/quick-users/</link>
		<comments>http://thesnarky.com/2007/02/17/quick-users/#comments</comments>
		<pubDate>Sun, 18 Feb 2007 04:57:40 +0000</pubDate>
		<dc:creator>Snarky</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Three Planets Software]]></category>

		<guid isPermaLink="false">http://thesnarky.com/archives/140</guid>
		<description><![CDATA[I don't think I've said it publically yet, so a little heads up, I've gotten my first contract as "Three Planets Software". Rather (I hope) easy site in PHP/MySQL and some other goodness, but you'll hear more about that later when I put out a call for Beta testers. So I coded up all the login and registration pages two days ago, and now am working on some other fun stuff. Some fun stuff that required more than one user to test. Ideally, more than 10. I did *not* want to sit in phpmyadmin creating 20 dummy users that would only be used in testing, so I turned to perl.]]></description>
			<content:encoded><![CDATA[<p>I don't think I've said it publically yet, so a little heads up, I've gotten my first contract as "Three Planets Software". Rather (I hope) easy site in PHP/MySQL and some other goodness, but you'll hear more about that later when I put out a call for Beta testers. So I coded up all the login and registration pages two days ago, and now am working on some other fun stuff. Some fun stuff that required more than one user to test. Ideally, more than 10. I did *not* want to sit in phpmyadmin creating 20 dummy users that would only be used in testing, so I turned to perl.<br />
<span id="more-140"></span><br />
Real simply, I used <a href="http://search.cpan.org/~petdance/WWW-Mechanize-1.20/lib/WWW/Mechanize.pm">WWW::Mechanize</a> to interface with my registration page (as I knew that worked already) and I wanted to prove it could handle a bunch of attention. </p>
<p>My registration page right now asks for first name, last name, an email, and a password. I needed data to through into those fields so a <a href="http://www.google.com/search?num=50&hl=en&safe=off&q=common+nicknames+census&btnG=Search">quick google search</a> turned up <a href="http://deron.meranda.us/data/nicknames.txt">this fine document</a>. I decided I'd use the nickname as a first name, and the real name as a last name. The password would be the first name concatenated with "1". This'll provide some overlap, along with unique passwords, and a password scheme I could easily figure out looking at hashed passwords in my database. </p>
<p><code>use WWW::Mechanize;<br />
my $mech =  WWW::Mechanize->new();<br />
open(NAMES, "$ARGV[0]");<br />
while($_ = <NAMES>) {<br />
        if(/^#.*/) {<br />
        } else {<br />
                m/^(\S*)\s*(\S*)\s*/;<br />
                $firstname = $1;<br />
                $lastname = $2;<br />
                $password = "$firstname";<br />
                $email = $firstname."@".$lastname.".com";<br />
                $mech->get("http://192.168.1.3/o2h/www/register.php") or die "Can't load page!\n";<br />
                $mech->form(1);<br />
                print "Registering $firstname $lastname!\n";<br />
                print $mech->set_visible("$firstname", "$lastname", "$email", "$password", "$password");<br />
                $result = $mech->click_button(number=>1);<br />
        }<br />
}<br />
close(NAMES);</code></p>
<p>This is a whopping 17 lines, took 10ish minutes to write. Yes, it could get smaller, but I wanted it somewhat readable. In about 10s of running I had 537 new additions to my users to test with, yippee!</p>
<p>This can easily be adapted for any website (that doesn't use CAPTCHAS and asks for information of the same nature as mine), feel free to steal it. </p>
]]></content:encoded>
			<wfw:commentRss>http://thesnarky.com/2007/02/17/quick-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
