Friday, January 29, 2010

count all files matching some weird spec and piping though grep and stuff

You could probably do all this with find, but piping though grep a) makes me happy and is exciting b) is a bit more flexible:

find . -atime +30 | grep somethinginfilename | xargs ls -l | awk '{print $5}' | awk 'BEGIN{n=0}{n += $1}END{print n/1024/1024/1024}'

Tuesday, January 26, 2010

Switching from tcsh to bash when you can't change your shell in /etc/passwd or whereever...

Just add bash to your tcsh startup script. Edit ~/.cshrc and at the end add a single line saying: bash

When you exit you'll still have to exit twice if you do this a better option might be:

exec bash

Sunday, January 17, 2010

Using gnu screens tab like functionality

gnu screen is a cool tool, I normally use it for persisting shell sessions running over ssh when moving between workstations or sites. However screen also has tab like functionality which I've been looking at using after fire up screen and then use the follow to create and navigate between tabs:

Ctrl+a c: create a window

Ctrl+a n: next window
Ctrl+a p: previous window
Ctrl+a ": list all windows
Ctrl+a A: name a window
Ctrl+a k: close (kill) a window
Ctrl+a number: jump to a window

What's even better is that screen has console based cut and paste! Here's how you use it:

Ctrl+a [: enter copy mode (scrollback)

In copy mode, you can use the cursor keys (or vi navigation keys if you like) to move around. Press space to begin a selection and space again to end it.

Ctrl+a ]: paste text from buffer.

Friday, January 15, 2010

Thursday, January 7, 2010

Simple python parallelisation example

#!/usr/bin/python

import pp

def add_one(n):
return n+1

job_server = pp.Server()

args1 = (1,)
args2 = (2,)
args3 = (3,)

f1 = job_server.submit(add_one, args1)
f2 = job_server.submit(add_one, args2)
f3 = job_server.submit(add_one, args3)

r1 = f1()
r2 = f2()
r3 = f3()

print "r1 is " + str(r1)
print "r2 is " + str(r2)
print "r3 is " + str(r3)

Saturday, January 2, 2010

Annotating a Proxmark 3 mifare classic trace

Proxmark 3s hi14areader command seems to initialise a card and send a request for block 0 using key A. It does this repeatedly a few times. I've annotated a trace from a mifare classic card.

 +      0:    :     52                                    # No idea, part of anti-collision from Koning thesis...
+ 68: 0: TAG 04 00 # No idea, part of anti-collision from Koning thesis...
+ -68: : 93 20 # Card UID request (READER)
+ 136: 0: TAG eb 5c 96 69 48 # Card UID
+ -136: : 93 70 eb 5c 96 69 48 15 d4 # 93 70 followed by UID, followed by 2 CRC bytes (READER)
+ 212: 0: TAG 08 b6 dd # No idea, part of anti-collision from Koning thesis...
+ -212: : 60 00 f5 7b # Authentication request. 60 means auth with key A. (61 means key B). Use block 00. Last 2 bytes CRC (READER)
+ 337: 0: TAG a0 f4 b9 78 # No idea * mifarecrack tries to parse data from here 1
+ -337: : 52 # No idea - All starts again! * mifarecrack tries to parse data from here 2
+ 0: : 52 # No idea * mifarecrack tries to parse data from here 3
+ 405: 0: TAG 04 00 # No idea
+ -405: : 93 20 # Card UID request (READER)
+ 481: 0: TAG eb 5c 96 69 48 # Card ID
+ -481: : 93 70 eb 5c 96 69 48 15 d4 # Reader sends UID again