Archive

Archive for the ‘hack’ Category

Behaviour of ConfigParser.read() – Python

February 7, 2011 2 comments

I am playing around with python for a while. My code uses ConfigParser to parse a piece of configuration file. Now the documentation says ConfigParser.read() accepts list of file names as an argument and tries to read them one by one and returns the list of files that are read successfully.This behaviour is helpful when you have multiple configuration files all across your system.

what the documentation doesn’t tell you is, which configuration file it will use for further processing in case of multiple successful reads. ConfigParser actually uses the last read file for further processing. So prioritize your  configuration files accordingly

import ConfigParser

config_parser = ConfigParser.ConfigParser()

filenames = [‘low_priority_file’,’medium_priority_file’,’high_priority_file’]

config_parser.read(filenames)

Advertisement
Categories: fedora, foss, fun, hack, python Tags: , ,

Micro blogging with emacs addons

November 1, 2009 3 comments


Emacs has become my favourite application these days, Its now part of my digital life. I always wondered why i have missed such an nice app before.

For those who are n00bs and non-geeks goto http://www.gnu.org/software/emacs/tour/

Emacs-color-theme:
Makes life colourful :D. It hasn’t made into Fedora repository yet, But package review is on at https://bugzilla.redhat.com/show_bug.cgi?id=501101

Add the following to your ~/.emacs file to get it working

(require ‘color-theme)
(color-theme-initialize)
(color-theme-robin-hood

Emacs-jabber:
I used it to connect Gtalk from emacs, FYI gtalk uses a open protocol named XMPP (jabber).It is a great app. Find the package review request at https://bugzilla.redhat.com/show_bug.cgi?id=508316

Add the following to your ~/.emacs file to get it working

(setq jabber-account-list
‘((“email@gmail.com”
(:network-server . “talk.google.com”)
(:connection-type . ssl))))

Back to Micro blogging:

Identi.ca is a free software microblogging service, similar to Twitter, based on the Laconi.ca code base. It has a Twitter bridge, which means you can associate your twitter account to identi.ca , so that the notices you post to identi.ca will be posted to your twitter account too;

It has a XMPP bridge, which means you can post notices to identi.ca from gtalk (gtalk uses XMPP). To post notices to identi.ca using gtalk add update@identi.ca bot to your gtalk contacts list and activate the bridge in identi.ca .

Facebook has a identi.ca app http://apps.facebook.com/identica/, which fetches notices from your identi.ca account and posts updates in facebook;

So the tree goes like,
XMPP (gtalk)-> Identi.ca ->{Twitter,facebook}

Now, the heck it relates to emacs? yes, use emacs-jabber and msg update@identi.ca to post notices;

BitlBee:

Alternatively, you can use BitlBee; BitlBee brings IM (instant messaging) to IRC clients. It’s a great solution for people who have an IRC client running all the time and don’t want to run an additional MSN/AIM/whatever client.

Bitlbee and erc can be combined to get a good experience;

Configuring bitlbee:

cat /etc/bitlbee/bitlbee.conf |grep -v “#”
[settings]

RunMode = inetd
User = bitlbee
DaemonInterface = 127.0.0.1
DaemonPort = 6667
ClientInterface = 0.0.0.0
AuthMode = Open
ConfigDir = /var/lib/bitlbee/
PingInterval = 0

[defaults]

We use xinetd to run bitlbee:

bash-4.0$ cat /etc/xinetd.d/bitlbee
# default: off
# description: bitlbee is an IRC gateway to other IM networks.
service ircd
{
disable = no
socket_type = stream
protocol = tcp
wait = no
user = bitlbee
bind = 127.0.0.1
server = /usr/sbin/bitlbee
type = UNLISTED
port = 6667
log_on_failure += USERID
}

Start xinetd,

service xinetd start
chkconfig xinetd on

Now in emacs,

M-x erc
IRC Server: 127.0.0.1
IRC Port:6667
Nick:zer0c00l
Password:

Above erc commands should get you inside bitlbee’s local irc server;

Register your nickname:

You should register your nick with local bitlbee irc server using,

register ‘password’

(Don’t forget to auto identify =P )

Add your IM account(s):

account add jabber email@gmail.com ‘password’

Activate your IM account(s):

account on 0

Now it should automatically connect you to gtalk; Bitlbee supports Various IM networks including yahoo;

Identica Mode for Emacs:

If you don’t want wasting your time with bitlbee, emacs-jabber and XMPP bridge; Then emacs-identica-mode is the one for you;Its under review at https://bugzilla.redhat.com/show_bug.cgi?id=532241

Identica mode for emacs HOWTO: http://blog.nethazard.net/identica-mode-for-emacs/

Categories: emacs, fun, hack

My Summer Training Task:Kannel SMS setup on fedora

July 1, 2009 1 comment

I came to know about dgplug’s summer training when kushal announced it in ilugc,i didn’t know mbuf will be there to guide us [:)] ,my task in summer training is to setup a SMS gateway on fedora with kannel, test it and document it.

With the help of kannel you can send/receive sms from your GNU/Linux box.(Don’t just think of some third party text message sending sites [:P], its more than that )

Here are the use case scenarios i am trying to address:

* User sends us a text message.

* We might send them a reply after processing it (web application is used to process the text message).

* We might also periodically able to send the user text messages.

I successfully completed testing the last use case and in the process of documenting it.

I always wanted to create a desktop app for GNU/Linux with GTK+ ,i am thinking of picking up another project after finishing this task [;)].

Apart from summer training i am now teaching php in a private training centre for free,you know what teaching is the best way for doing some GNU/Linux advocacy [:D].

btw: Switch to firefox 3.5 😉

Categories: dgplug, fun, hack, install

Flirting with ettercap #1

April 3, 2009 1 comment


Playing in schools network is kind of fun ;-).You might have heard about cain , it for windoze to play around in network.

Gnu/Linux got a more cool tool called ettercap (i have been using it for years) get it from ettercap.sourceforge.net.

Fedora Guys could install it with “yum install ettercap”

Getting Started with Ettercap:

i mostly work in runlevel 3, if not open up terminal (or ctrl+alt+f1 ;)) Switch to root user, because normal users cannot open raw sockets i guess. (correct me if i am wrong)

Just type: “ettercap”

It will ask you to select an user interface.

ettercap NG-0.7.3 copyright 2001-2004 ALoR & NaGA

Please select an User Interface

Here Interface refers to whether you want “Text” interface or “Ncurses” interface or “Gtk” interface.As we are working in terminal we use text interface (I am a command freak )

T <- for Text interface
C <- for Ncurses interface
G <- for GTK interface

we are going to use T. Type:”ettercap -T” in terminal.

You will see contents of packets being printed on your terminal so we started listening to the active interface.Any time press ‘q’ to quit ettercap its the safest way to quit ettercap (no ctrl+c please, its deprecated )

Now Type: “ettercap -Tq”

What we are doing is, asking ettercap to be quiet, “Hey ettercap don’t sh*t on my screen by printing the contents of each packet you capture”

Network Interface Selection:

A computer might have more than one network interfaces like your wired lan, wireles lan,loopback interface and so on.

ettercap can work on any interfaces, all we have to is tell ettercap which network interface to use.

To list the available network interfaces

Type “ettercap -Tq -I”

ettercap NG-0.7.3 copyright 2001-2004 ALoR & NaGA

List of available Network Interfaces:

eth0 eth0
lo Local Loopback

so, we have two network interfaces eth0 and lo.

To select the network interface use “ettercap -Tq -i eth0”, i have selected my wired lan so that ettercap will listen and sniff packets.

If you are those windoze user, i am sorry you have to deal with odd network interface names.

Man in the niddle attack with ettercap:

Type:”ettercap -Tq -i eth0 -M arp:remote /target-range1/ /target-range2/

The packets between target-range1 and target-range will be hijacked and they will be going through our machine (magic of arp-cache-poisoning)

Example:”ettercap -Tq -i eth0 -M arp:remote /192.168.1.1/ //”

Let 192.168.1.1 is the gateway of our network,then all the packets between the gateway and all the machines in the subnet will be going through our machine (i.e we are the gateway for all the machines 😛 )

Another Example:”ettercap -Tq -i eth0 -M arp:remote /192.168.1.12-25/ /192.168.1.26-50/

We could specify range of ip address.

Packet Logging:

type:”ettercap -Tq -L dump -i eth0″

Two files will be created dump.eci and dump.ecp these files can be analysed with etterlog 😉 .

type:”etterlog dump.eci”

It will display the connection details of dumped packets.

type:”etterlog -p dump.eci”

It will display the passwords captured if any 😉

man etterlog for more details.

Some people might want to view the captured packets in more cool protocol analyser like wireshark, but you cannot open dump.eci and dump.ecp with wireshark.To do so you have to save the packets in pcap (tcpdump) format.

use “ettercap -Tq -w dump -i eth0”

After completing packet capture you could directly open the dump using wireshark.

converting from pcap format to etterlog format:

Type:”ettercap -Tq -L dump -r pcap” where pcap is the packet dump file we just saved in tcpdump format.

Links:

http://openmaniak.com/id/ettercap_arp.php

http://openmaniak.com/ettercap_filter.php

Coming soon: Ettercap plugins 😀

Categories: ettercap, hack, Linux, network