Sunday, February 26, 2012

Project Dieselpunk-PC

Yesterday I finished a project, code-named "Project Diesel Punk-PC". Okay, it is probably more like an Atompunk-PC - but who wants to be so petty?

The basis was a 19 inch chassis, which is lying around here for ages. The front- and back plane was done with 3 mm Aluminium. Inside the rack, an old motherboard (MS-6340 Rev 1.0) took place. The computer is equipped with an AMD Athlon Thunderbird 1.2 GHz, 768 MB RAM, an 80 GB WD Harddisk, a 3Com fast ethernet NIC, and a Riva TNT M64 AGP graphics card. An old PC for an old chassis. ; )
The CPU fan is loud as hell but the CPU keeps my room warm.
On the front there are a number of LEDs, connectors, switches and instruments in order to make the chassis look like an old power supply.
As an additional feature I mounted some LED light strips to shed light on the motherboard. Looks pretty cool, right?












Monday, January 16, 2012

Extract links from web pages

One or two weeks ago, I tried to download some videos from a website under Linux. Of course it was not possible to simply download the videos using the browser - the videos were secured. A challenge for a hacker. ;) After a quick search in the Ubuntu Software Center I found get-flash-videos. It is a small Perl command line program, capable for retrieving flash movies from a wide variety of movie sites. But sadly it just worked one or two times for me. On the other day, it tried the program, it stopped working. And so began the search for a solution...

For Windows I am using URL Snooper 2 from Mouser software. It is a great utility. A very powerfull tool in combination with a download manager like the Firefox extension down them all. You can get every video from the web with ease.

But I did not find any tool like URL Snooper for Linux and so - I searched the web for some "inspiration". And finally - I found ngrep. It is an command line tool - a bit old (not maintained since 2006) - but easy to use.
Combined with some Perl commands and "down them all" it is quite powerfull. Not as easy and powerful like URL Snooper, but good enough to download the movies I wanted.
And the best: the command fits into one single line. ;) (okay, if you have a big display, where 177 chars will fit... but it is one line). Of course it could be optimized further and some chars could be saved.

Because this code is for the extraction of movies from an adult website, I will not post the link here. ;)
Here is the "proof of concept":
sudo ngrep -n 1 -q -d eth0 '(/key.*flv).*Host: ([\d.])' 'tcp and dst port 80' | perl -ne 'm/.*(\/key.*flv).*Host: (\d+.\d+.\d+.\d+).*/; if ($2){ print "http://$2$1\n"; exit; }'
Take it as a source for your inspiration. Try to figure out what the line of code is doing. Ngrep and Perl can be your friends!

Monday, December 26, 2011

Notes/wish list/TODO's...

... for me.
Some of these projects will be posted here in some weeks or months - i hope.

Finished projects:
  • uploading the executable and source of "bool_solver 2"
  • "The (dirty) 7zip password cracker" with exe and source
  • brute forcing [code snippet]

Unfinished projects:
  • Presentation of the project "Dieselpunk PC"
  • Some words about the Open Logic Sniffer
  • Creating a VBS (Video Baseband Signal) with an 8051 (+ Open Logic Sniffer)

Future projects:
  • Reverse engineering the Canon EF protocol with the Open Logic Sniffer

Creating random numbers on a µC [code snippet]

This is a small C function, to feed srand() with a random seed. I wrote it some weeks ago just to test if it would be possible to get random seeds with an 8051 microcontroller without additional hardware. And yes, it is possible. I was using an AT89C51ED, but the code should work with every 8051 compatible microcontroller.
How does it work and why? I took a closer look in the data sheet of the µC and i saw that some bits and bytes in the special function registers (SFRs) are not initialized with "1" or "0". Some bits were marked with "x" and those are the interesting ones. The value of those bits can be "0" or "1" after power up - their initial value is random. All i had to do was to iterate over all those SFR-bytes and XOR them. I am sure generations of 8051 coders have had the same idea, but i did not study all available information regarding 8051 and random numbers.
Just call the function like that "srand(getRandom());", and you will have a new random seed, after each power up of the microcontroller. (A normal µC reset will not give you a new random seed!)

unsigned char getRandom( void )
{
     unsigned char *random;
     unsigned char k;
     unsigned char value;
    random = 0x80; //Starting address of the SFRs
    for (k=0; k <= 127; k++) //iterate over the 128 bytes of the SFRs:
        value ^= random[k]; //XOR the values
    return value; //return the random seed
}

Sunday, September 25, 2011

Convert foobar2000 playlists into something useful

Because i had switched from Windows to Ubuntu (on my desktop computer) a week ago, i had the problem, that i had to say "good bye" to my favorite music player called "foobar2000", because he is only available for Windows.
I had some really cool online radio stations stored in foobar2000.
The biggest problem: foobar2000 stores the playlists (and my radio stations) in a non-open binary file format.

So I decided to write the program called "foobarConverter". It is capable to convert a foobar2000 playlist (".fpl") into ".pls", ".m3u" and extended ".m3u" playlists.
As it is written in Java, it should run on a variety of operating systems.

The program is freeware for non-commercial use.

Example of usage:
xxxx@ubuntu:~/$ java -jar ./foobarConverter.jar ../Radio_2011-09-09.fpl pls
Starting foobar2000 playlist converter.
Converting file to 'pls'...
Conversion done! :)

If you are interested in some details, look there: http://www.foobar2000.org/FAQ
(Question: "Are specifications of the FPL playlist format available? Why doesn't foobar2000 use some user-editable XML-based playlist file format instead?")

Have fun! :)

Saturday, July 23, 2011

New bool solver

Last year i released bool_solver - a little tool to convert boolean algebra into truth tables. I rewrote the program completely from scratch in C. It is now shorter and easier to understand than the old C++ version I hope.

Friday, July 22, 2011

Parsing source code files for function headers and function calls

Some weeks ago I wrote a small program, which is able to print a list of functions and function calls used in a program. It can parse a directory recursively for a given file type.

Here is the source code: functiondiagram.d
And here is the source as a "quote" (a function to present formated source code is missing on blogger.com...):
/*
    This console apllication written in D is able to parse C, C++, D and many more file types.
    It scans the files for functions and function calls and prints a list with all matches for every file.
    As first parameter you must specify a directory name, where the search will start. This folder will be scanned recursively for matches.
    The type of file must be specified by the second parameter.
  
    This code stands under the do-with-it-what-you-want license.
  
    Author: Energized
    E-mail: undervoltage@safe-mail.net
    Blog: http://electric-handicraft.blogspot.com
*/


import std.file;
import std.stdio;
import std.stream;
import std.regexp;

/*
TODO:
- Self defined data types are not recognized
- Comments will be parsed too. This can result in false "positives".
*/


/*
    Function is searching in a line of text/code for function calls and function headers:
*/
string[] returnFunctions( string data )
{
    string regex = r"([\w\d]+)\s*[(]";
    string[] rv;
  

    foreach( m; RegExp( regex, "ig" ).search( data ) )
    {
        if ( (m !is null) && (m.match(1) !is null) ) //is something was found:
        {
            //writefln("> '" ~ m.match(1) ~ "'");
            if ( RegExp( r"^(if|for|foreach|return|while|finally|try|catch)$" ).match( m.match(1) ) is null ) //is the match a reserved word?
            {
                rv ~= m.match(1); //if not, it will be part of our result

                //if no datatype is in front of the match, it is a function call:
                auto n = search( m.pre, r"^\s{0,}(string|bool|int|byte|char|long|short|float|double|void|signed|unsigned|HBITMAP)", "i" );
                if ( n is null )
                    rv ~= ";";
                else
                {
                    /*
                        If an assignment is done (function to variable), false positives will be produced.
                        Then the function call will be misinterpreted as a function header. Thats why we are searching for a
                        semicolon here. Is a semicolon in this line, it is a function call (or a forward declaration).
                    */
                    if ( std.string.find( m.post, ';' ) != -1 ) rv ~= ";";
                }
            }
        }
    }
    return rv;
}


/*
    Shows the result:
*/
void printTree( string[] data )
{
    if (data.length == 1)
        writefln( "\nFunction \"%s()\":", data[0] );
    else
    {
        foreach( t; data )
            if (t != ";") writefln("\t%s();", t);
    }
}


void main( char[][] parameters )
{
    string path = parameters[1];      //as first parameter the program needs a path name
    string extension = parameters[2]; //extension (like "*.cpp")
    string[] result = listdir( path, extension ); //crawl through all files with the given extension in the given directory and all sub directories and store the filenames in the "result" array.
  
    foreach( filename; result ) //scan one file after the other:
    {
        BufferedFile file = new BufferedFile( filename, FileMode.In ); //open the file for reading

        writefln( "\nFile: " ~ filename ); //print the filename
      
        foreach(ulong n, string line; file) //go through the lines and scan them for function names or function calls:
        {
            string[] functions = returnFunctions( line );
          
            if (functions !is null) printTree( functions ); //if the end of file is reached, print the result
        }
        file.close();
    }
}
 And here is an example, how the result looks like:

File: C:\functiondiagram.d

Function "returnFunctions()":
        RegExp();
        search();
        match();
        writefln();
        match();
        RegExp();
        match();
        match();
        match();
        search();
        done();
        call();
        find();

Function "printTree()":
        writefln();
        s();
        writefln();
        s();

Function "main()":

Function "extension()":
        listdir();
        BufferedFile();
        writefln();
        returnFunctions();
        printTree();
        close();

The program is not perfect yet. Some false positives are possible like in the example the function "s()" which is not a function but a regular expression.