Archive for the 'Hacking' Category

PNG-24 Alpha Transparency With Microsoft Internet Explorer 5.5 or better (MSIE 5.5+)

Tuesday, September 27th, 2005

Just a few links:

PNG-24 Alpha Transparency With Microsoft Internet Explorer 5.5 or better (MSIE 5.5+)

PNG Files Do Not show Transparency in Internet Explorer

PNG in Windows IE

Problems mounting ipod on linux: end_request: I/O error,…

Tuesday, September 27th, 2005

Here is a nice explanation and how to fix the problem: LinuxQuestions.org- The iPod and the Penguin – LinuxAnswers

At the end, I enabled additional partiotion types and disabled the EFI. It seems to work now. CONFIG_PARTITION_ADVANCED=y CONFIG_MAC_PARTITION=y CONFIG_MSDOS_PARTITION=y

CONFIG_EFI_PARTITION is not set

Configuring PostgreSQL ODBC connector

Thursday, September 22nd, 2005
  1. apt-get install unixodbc odbc-postgresql

  2. Add the following line into /etc/odbcinst.ini

    [Postgres]
    Description             = Postgres
    Driver          = /usr/lib/odbc/psqlodbc.so
    Driver64                = /usr/lib
    Setup           = /usr/lib/odbc/libodbcpsqlS.so
    Setup64         = /usr/lib
    UsageCount              = 1
    CPTimeout               =
    CPReuse         =
    
  3. Add the following DSN into /etc/odbc.ini

    [test]
    Description   = test
    Driver    = Postgres
    Trace   = No
    TraceFile   =
    Database    = test
    Servername    = localhost
    Username    =
    Password    =
    Port    = 5432
    Protocol    = 6.4
    ReadOnly    = No
    RowVersioning   = No
    ShowSystemTables    = No
    ShowOidColumn   = No
    FakeOidIndex    = No
    ConnSettings    =
    

NOTE that the hostname is called servername here! If you use a standard hostname, the driver will connect to a socket, not the inet and you get a “connection refused” message.

  1. The DNS-less connection string to PostgreSQL (don’t need step 3 then) would be: "Driver=Postgres;Database=test;Servername=localhost;Port=5432;Username=test;Password=xxxx;"

NOTE: It’s error-prone and hell to debug.

  1. Driver should not be in curly braces {} (should be according to the spec).
  2. Absolutely no spaces anywhere (should be ok according to the spec).
  3. Error messages are not very informative as it fails silently and calls another connection methos producing “Data source name not found, and no default driver specified” :-|

A useless pointer: DSN-less connection strings – discussed here.

Monitoring resource usage in Linux

Wednesday, September 14th, 2005

Three packages I found in Debian: dstat, ifstat, systat – allow to show cumulative statistics, but not on per-process basis.

Here’s an interesting discussion on what can an cannot be done with Linux: http://mirror.hamakor.org.il/archives/linux-il/01-2005/13574.html

One pointer is laptop-mode (Documentation/laptop-mode), although for different reasons the information there might not be accurate.

A nice summary on linux profiling: http://www.cs.utk.edu/~mucci/latest/pubs/LCSC2004.pdf

Perfsuite: http://perfsuite.sourceforge.net/ IOTrack: http://www.pdc.kth.se/~pek/iotrack/

Conifure Ad-hoc wireless router on Linux

Thursday, September 8th, 2005

It’s acutally quite simple-got it to work in 5 min.

Setup at the server:

  1. iwconfig eth1 essid <essid> mode ad-hoc
  2. ipconfig eth1 10.0.0.1 up
  3. echo “1″ > /proc/sys/net/ipv4/ip_forward
  4. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Setup on a client:

  1. iwconfig eth1 essid <essid> mode ad-hoc
  2. ipconfig eth1 10.0.0.2 up
  3. route add default gw 10.0.0.1
  4. echo “nameserever 10.0.0.1″ > /etc/resolv.conf

Should work. Another thing you may try is if your network card supports a “master” mode (iwconfig <interface> mode master) and if it does, you can setup an access point. I guess the rest should be similar (use “mode managed” on a client of course).

Counting a number of modified lines in a patch file (per file)

Tuesday, August 23rd, 2005

Just a neat one liner:

perl -ne ‘if (/^diff .* ([^\s]+)$/ || eof()) { print “$file $plus $minus\n”; $file = $1; $plus = 0; $minus = 0;} /^+/ && $plus++; /^-/ && $minus–;’

Parsing Bro’s connection logs and writing it into a database

Wednesday, August 17th, 2005
  1. Create a database table with the following fields:
    • sip address
    • sport
    • dip address
    • dport -sbytes -rbytes -conn length

create table conn(sip inet, sport int, dip inet, dport int, rbytes int, sbytes int, length float);

  1. Use perl one liner: perl -ne ‘ @a = split; print “INSERT INTO conn VALUES(‘”‘”‘$a[2]‘”‘”‘, $a[5], ‘”‘”‘$a[3]‘”‘”‘, $a[6], $a[8], $a[9],$a[1]);\n”;’

BTW need also to replace ? with NULLs — do it with =~ s/// command.

  1. Combine all of them into a horrible thing: cat conn.log | perl -ne ‘@a = split; $a[8] =~ s/\?/NULL/; $a[9] =~ s/\?/NULL/; $a[1] =~ s/\?/NULL/; print “INSERT INTO conn VALUES(‘”‘”‘$a[2]‘”‘”‘, $a[5], ‘”‘”‘$a[3]‘”‘”‘, $a[6], $a[8], $a[9], $a[1]);\n”;’ | psql test test -h 127.0.0.1

Printing a single quote in a shell script

Wednesday, August 17th, 2005

Diego’s “shell nasty quoting tricks”: print ” ‘ ” ‘ ” ‘ ” ‘

or in more details: perl -e ‘print ” a’ ” ‘ ” ‘b ” ‘

Matching all outgoing (and only outgoing) traffic with tcpdump

Tuesday, August 16th, 2005

Task: match all outgoing traffic (not including local services, e.g. 80, 22, 25). Actually, not as simple as it could have been. Moreover, contrary to a manpage, my tcpdump does not seem to support “portrange”. Hopefully, can do something like this: tcp[0:2] for source port and tcp[2:2] for destination port.

At the end the rule is as follows: tcpdump -n -i eth0 “(udp and ( ((dst host $MYIP) and (udp[2:2] >= 1024)) or ((src host $MYIP)and(udp[0:2] >= 1024)) )) or (tcp and ( ((dst host $MYIP) and (tcp[2:2] >= 1024)) or ((src host $MYIP)and(tcp[0:2] >= 1024)) ) and (not port (9030||9001)))”

Capturing local traffic for further analysis (long term)

Monday, August 15th, 2005

Add this line to cron.daily/cron.hourly/…

tcpdump -np -i eth0 -s 0 -w /<path>/date +"%Y%m%d-%H%M%S.tcpdump" “<filter>”