Linux Keylogger Proof of Concept

I’ve just read ‘The Linux Security Circus: On GUI isolation’

It struck me that a linux keylogger is perfectly easy to write – I had previously (naïvely) thought such a program would only work given root permissions.

Alas! It’s stupidly easy.

see result of 30 minutes of hacking

The code simply calls xinput test [id of keyboard device] and parses out the keycodes. The id of your keyboard device can be found from the device listing given by xinput list.

Linux Keylogger Proof of Concept

Script to print the name of the current desktop

Just a python script, to print the name of the current desktop. Could be useful to pipe to conky or something.

#!/usr/bin/env python
from Xlib import display, Xatom
dsp = display.Display()
rootwin = dsp.screen().root

DESKTOP_NAMES = dsp.intern_atom("_NET_DESKTOP_NAMES")
CURRENT_DESKTOP = dsp.intern_atom("_NET_CURRENT_DESKTOP")

def get_names():
    names = rootwin.get_full_property(DESKTOP_NAMES, 0)
    names = names.value.split("\x00")
    return names

def current_desktop():
    return rootwin.get_full_property(CURRENT_DESKTOP, 
                                     Xatom.CARDINAL
                                     ).value[0]

try:
    print get_names()[current_desktop()]
except:
    print "error getting name"

Requires the python bindings for xlib

Script to print the name of the current desktop

Xlib Window Transparency

How to set the transparency opacity of a window with Xlib.

Set the _NET_WM_WINDOW_OPACITY property to an integer between 0x0 and 0xffffffff
An example function to set the opacity of a window using Xlib and python:

from Xlib import Xatom
def setOpacity(self, display, window, opacity):
if 0.0 < = opacity <= 1.0: real_opacity = int(opacity * 0xffffffff) window.change_property( display.get_atom('_NET_WM_WINDOW_OPACITY'), Xatom.CARDINAL, 32, [real_opacity,], ) else: return [/sourcecode] For this to work however, a composite manager of some kind must be running, but

Xlib Window Transparency

If CUPS starts asking for authorisation…

For some reason, every time I tried to print CUPS was asking me for my username/password. This is fine when using applications which support this, and wasn’t enough of a hassle for me to bother with. Some applications however don’t have the capability to authenticate, and so it became an issue.

The solution is, however, trivial.
Open /etc/cups/printers.conf as root and comment out the line starting AuthInfoRequired like so:

<DefaultPrinter Canon>
#AuthInfoRequired username,password
Info This
Location Yes
...


then restart cups for the change to take effect.
On archlinux:
# /etc/rc.d/cups restart

If CUPS starts asking for authorisation…

XKB Map – GB Dvorak with other magic :Þ

After the upgrade to xorg1.5, my beloved keyboard map was once again rewritten, luckily I could salvage it from emacs’ backup files, but in the future I may not be so lucky, so thought I’d post here.

Keymap is fairly standard dvorak, with a few changes
– @ and ” placed in the ‘american’ places – I learnt with them there, so it’s strange to have ” on the 2 key now.
– added umlauts dead key and Eszett: ü ß…
– added thorn þ and mu µ for fun


partial alphanumeric_keys
xkb_symbols "dvorak" {
include "us(dvorak-intl)"

name[Group1]="United Kingdom - Dvorak";

key { [ numbersign, asciitilde ] };
key { [ 2, at, twosuperior, NoSymbol ] };
key { [ 3, sterling, threesuperior, NoSymbol ] };
key { [ backslash, bar ] };
key { [ apostrophe, quotedbl, dead_diaeresis, NoSymbol ] };
key { [ comma, less, acute, NoSymbol] };
key { [ period, more, grave, NoSymbol] };
key { [ s, S, ssharp, NoSymbol] };
key { [ t, T, thorn, THORN] };
key { [ m, M, mu, NoSymbol ] };
};

XKB Map – GB Dvorak with other magic :Þ

Awesome – move applications automatically to the tab they’re spawned on

I can move to an empty tag, launch openoffice, go back to browser while it’s loading, and it’ll load on the tab I launched it on. Magic!

Add the following somewhere (pretty much anywhere, but after the inclusion of awful, and before the hook_manage function)

spawn = awful.util.spawn
move_to = {}
awful.util.spawn = function (spawnwhat, screen)
    screen = screen or mouse.screen
    local current_tag = awful.tag.selected(screen)
    move_to[#move_to+1] = {tag=current_tag, screen=screen}
    spawn(spawnwhat, screen)
end

Now add to hook_manage

if #move_to then
   c.screen = move_to[#move_to].screen
   awful.client.movetotag(move_to[#move_to].tag, c)
   move_to.remove()
end
Awesome – move applications automatically to the tab they’re spawned on

Sorbi – Newton Fractals

I give you Sorbi – a program I’ve written for generating newton fractals.

Some Pretty Pictures

These have been generated using Sorbi.

What are Newton Fractals?

Newton Fractals are a type of iterated fractal, created when performing the Newton-Raphson iteration on the complex plane.

Newton-Raphson Iteration

z_{n+1} = \frac{f(z_n)}{f'(z_n)}

The resulting fractals can be coloured by root reached, or by the number of iterations required to reach the root (or various other methods, such as the value of arg(z_n) after n iterations.

How do I get the program?

Pull from git


git pull git://github.com/bavardage/sorbi.git

…And run the program


sorbi/gui.py

Requirements:

  • python
  • pygtk
  • numpy
  • PIL – ‘Python Imaging Library’
Sorbi – Newton Fractals

Awesome 3 rc.lua updated

Quite a change colour-wise, little change function wise (only a bit to randomly change active tag colour).
Obligatory screenshot:

Screenshot of awesome
Screenshot of awesome

This is what I added:
Added focus_choices to the bg table

 bg = {normal = "#e7e7e7", focus = "#d97600", focus_choices = {"#669bcb", "#d97600", "#6eb22c"}, urgent = "#ffaa88"}

Changed taglist.label

 function taglist.label(t)
                local bg_color
                local fg_color
                local background = ''
                if t.selected then
                        local choice = math.random(1,3)
                        bg_color = bg['focus_choices'][choice]
                        fg_color = fg['focus']
                end
...function continues

As always, the latest version of my config can be found here.

Awesome 3 rc.lua updated

A script to launch irssi within screen

Why bother opening a term, running screen and then running irssi, when it can all be automated.

irssi.sh

#!/bin/bash
if [ `screen -ls | grep irssi | wc -l` -ne 0 ]
then
	urxvt -title irssi -name irssi -e sh -c "screen -dr `screen -ls | grep irssi | sed -e 's/(\(Attached\|Detached\))//'`"
else
	urxvt -title irssi -name irssi -e sh -c "screen -S irssi irssi"
fi

If there is no exisiting screen session running irssi this script opens a new terminal and runs irssi within screen, otherwise it reconnects to the existing session.

The terminal it opens (urxvt) is named irssi, so that it can be themed separately in .Xdefaults and handled by your wm – e.g. awesome sends the irssi terminal to my ‘IM’ tag.

Urxvt themed in two ways
Urxvt themed in two ways
A script to launch irssi within screen