Python Device Hacking (Gamepad)

So today I was reading an article on Hack A Day about a user who wrote a Python script to interrupt his USB Gamepad, I watched the video and realized I had a very similar gamepad laying around. One thing led to another and I found my self attempting the same sort of project. The Gamepad I am using is a Logitec Dual Action : Using some of the code posted on Hackaday I quickly realized my Gamepad returned quite different result and thus needed different code.

Python Frequency Analysis for Ciphers

Frequency Analysis is the study of the frequency of letters or groups of letters in a cipher text. Using Python we can extract the count of letters, bigrams, and trigrams, lets have a look shall we: $ ./frequency.py --help usage: frequency.py [-h] [--letters] [--bigrams] [--trigrams] msg positional arguments: msg Message to count letters in optional arguments: -h, --help show this help message and exit --letters, -l Frequency of letters --bigrams, -b Frequency of bigrams --trigrams, -t Frequency of trigrams Lets go ahead and enter a simple sentence and do some testing:

Wacky Python Image Creation

The other night I had a wacky idea of extracting each pixel from an image in order to save it as a plain text ASCII file. Of course this is not ideal and can take a bit of time, but like most things I do with python its just for the fun of it. I figured the easiest way to achieve this would be to use Python’s Image library and save the output to a serialized pickle text file.

Python Running System Command

So there are a few ways to run system command using python, but I tend to find the below approach the easiest to use and has error handling. First off I would create a function rather than running the commands over and over: import subprocess def run(command): '''takes a string command and hands back a subprocess object''' process = subprocess.Popen(command.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.wait() return process The function itself is pretty small and makes use of the subprocess library .

Creating QR Code with Google

So today I thought I would be neat to show how to quickly create QR codes using Google’s Chart Tools . Google gives us a extremely easy way to create QR code by sending GET data request via URL: https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=nessy That is nice and easy, but I figured I would wrap this up in a small Python script just because: #!/usr/bin/env python from urllib2 import quote, urlopen, Request from poster.encode import multipart_encode from poster.

Brute Forcing Salted Password

Since my last post showed how to check a salted password, I figured this time we can look over some example code for brute forcing a salted password. Of course this is just proof of concept and should not be used on any password you do not have access to. The code I tossed together is using a bit of some examples I found online, and is no where near optimized for speed, but as I will show it will work.

UNIX SHA-512 Passwords & Python

Well today I spent a bit of time looking up how /etc/shadow created their shadow passwords. I found a good source for the method at http://www.akkadia.org/drepper/SHA-crypt.txt , and if you take some time to review it you will notice the steps are a bit involved Lucky for us Python has a Crypt module that works nicely. First off I started by creating a dummy user with the password of test on one of my Linux computers:

Wordlist with all Possible ASCII Elements

After a bit of thinking I believe I have a better way to create all possible ASCII pass phrases, rather than create a recursive function that calls itself as I did in the previous post. This method takes a slightly different approach, but I believe it to return the same results. First off let’s create a list of all lower case ASCII character numbers: >>> chars = range(97, 123) >>> chars [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122] >>> map(chr, chars) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] Next we can set our max word width and current word width variables:

Python Libvirt Domain Configuration

So in my last article I talked a little bit about using libvirt to start and stop QEMU domains. In this article I would like to go over how domains are created. QEMU uses XML files for each domain configuration, and using libvirt we can access that data. First off lets connect to our local running QEMU instance: >>> import libvirt >>> conn = libvirt.open('qemu:///system') Next lets look for and link to a running domain:

Consuming Jenkins API using Python

Lately I’ve been using Jenkins as a central hub for automated task across multiple machines, think a central cron system with a slick web interface. In a nutshell Jenkins CI is the leading open-source continuous integration server. Built with Java, it provides over 400 plugins to support building and testing virtually any project. One thing that is very nice about Jenkins is the easy to use REST JSON API .