How to add debugging to shellscripts

Debugging bash scripts is pretty straightforward, throwing around a couple echo and set -x quickly gives you what you need. But what if you want to add a nice breakpoint,  debugging to lots of paces in the code or turn all debugging on or off at once? Then this little script I wrote is the right thing for you: debug.sh just download it to the same directory as your script and include it with the following line:

It contains 4 simple functions that will make your bash coding easier.
debug and breakpoint both print the argument with a timestamp to STDERR
You can turn off all the functions by adding a DEBUG=false into your code

Example:

Output:

Disemvoweling

Talk about weird words … ok, according to Wikipedia disemvoweling is the term for replacing or removing vowels from words. Commonly used as a tool for moderating.  I’m pretty sure everyone has run across  certain disemvoweled  words on the internet like f*ck or sh*t. Anyway I went and made a pure html/javascript page that does just that, removes any vowels from an inputted text. The usefullness can certainly be argued, it was more for me to brush up on my javascript and css skills.

http://www.dopefish.de/projects/disemvoweling/

Virtualbox update

Anyone running Ubuntu as a Virtualbox guest is advised to update to Virtualbox 4.0.6 (+ the extensions) that was released today.  Don’t forget to recompile the guest additions after upgrading to 4.0.6. Besides the usual stuff in the changelog, the update fixes a problem with screen resolution in Ubuntu 11.04. Since the Ubuntu update is just around the corner updating Virtualbox beforehand will prevent a bit of hassle.

Thanks for the free games @Valve

For the release of their latest game Portal 2, Valve went to great lengths marketing wise. They set up an “Alternate reality game” (ARG) with tips and puzzles hidden in 13 independent games (to promote indie games). Some of the games even added extra levels just for the ARG.  Solving puzzles, finding passwords, and triggering special events led to the possibility to gain “potatoes” as a sign of progress. If all 36 potatoes were found in the 13 games involved players got a golden potato.

After the ARG was solved by the community, Valve added a countdown a few days before the release of Portal 2, allowing the community to get Portal2 to release early by collecting potatoes and (in the end phase) playing the 13 indie games.

Last Friday Valve announced in the official blog “There’s also still time to collect all 36 potatoes. Anyone accomplishing this feat by the time Portal 2 launches will receive a very special, non-hat-based reward.” An extra incentive for people to play the games involved and collect the potatoes. I spent most of the last days collecting all 36 potatoes, got the last one just hours before the deadline.

Today everyone with a golden potato  got the reward, a valve complete pack and a copy of portal2. I’m honestly impressed. I never would have expected them to not only give out all their previous games ($100), but also a free copy of their latest game they just released yesterday ($50).

Impressive move Valve, even if I was irritated at buying the game on steam on pre-order and then seeing Amazon and Best Buy drop the price shortly before release by 10$, the ARG and the potatoes blew everything out of the water. So now I have a few copies of games I already owned to give out 🙂

captcha cracking

This is a pretty old posting from 2009 I just recently discovered in my “drafts” directory. Nowadays there are probably easier and more elegant ways of defeating a captcha, but for old times sake, here is my simple approach.
———————–

Eclectic and Marko were so kind as to “provide” me a captcha to play around with. Took me a few days of poking around and googling but in the end it was easier than I had thought. As long as there aren’t and logic errors in the code (e.g. bad or no session handling) you probably won’t get around some kind of OCR. As OCR software I decided to use gocr because it is free, runs under linux, and it is fairly easy to train to specific needs. Because I knew which libraries were being used to create the captcha images, it was possible for me to build a testing area. This just speeds things up a bit, the process would have worked just as well off the original website. First off: the spambot in action -> http://captcha.dopefish.de/spambot.php, and the website it accesses: http://captcha.dopefish.de/

Now I’ll describe the steps I took to defeat the captcha. Look at what happens on failed and successful inputs, first write a script that works if you enter the solution manually. I used the following 2 php functions for getting and posting stuff (and keeping the session intact)

Now train a gocr database for the images. Obviously it get’s better the more you train it.
Since curl is taking care of  session handling, we can use the get_url() function for downloading the captcha image. I pipe it through this shell command to make it easier for gocr to read:

It turnes this:

into this:

Since the valid captcha result is always the same length, we can check if gocr matched all the chars. If it looks good we can use post_url() to continue our session and throw all the fields at the form and submit it. See, wasn’t that hard. Most of the time is spent training gocr and converting the image into something easier to read. It doesn’t solve 100% of the images, more like 80-90%, but still better than nothing ;-).