Thursday 25 November 2010

Pager and menu button using dzen2

This is what they look like. They go nicely with tint2.




There are three scripts. One is combined, and the other two are just the menu and just the workspaces, so you can have them at different corners. They use xdotool to simulate the menu and change workspace button presses and should work under most environments (except probably compiz, because it's funny about virtual desktops).

Scripts here

You'll want to change the coordinates, the xdotool shortcuts and probably the colours. These are all at the top of the scripts.

Tuesday 9 November 2010

Quickly search several PDFs at once

Takes PDFs as arguments, and can be used with nautilus-actions or thunar's custom actions. The script uses grep and thus grep regex, but i've added easy conditional searching at the expense of some limitations regarding normal grep conditionals. You're presented with this when you run it, which just about covers things:

The search ignores case. Conditionals cannot be joined. Let me know if this is a problem.
Wildcards:
A single . represents any character, and an asterisk represents zero or more occurances of the preceeding character eg:
'c...h' will find catch, clash, cloth, coach etc.
'c.*h' will find caliph, cash, catch, cheesecloth etc.
Conditionals:
OR : '(this|that|the)' will show lines containing 'this', 'that', or 'the'.
AND : '(this&&that&&the)' will search for lines that contain 'this', 'that' and 'the'.
NOT : '(this!that)' will search for lines that contain 'this' but don't contain 'that'

The script can be downloaded here. You'll need pdftotext for this to work.

Saturday 10 July 2010

Short term 'back in time' snapshots




If files stand a chance of getting corrupted (such as openoffice documents), or you run the risk of hacking away and accidentally breaking one part of your code, it can be nice to have a 'back in time' feature. This script is intended for short term snapshots. Add it to your nautilus-actions or whatever, and select the files or folders you want snapshots of and the time in minutes between each snapshot. 

It uses rsync to create a backup folder every x minutes containing your selected file(s), and 'cp -al' to create hardlinks to prior versions to keep disk space low. This means it'll only save new copies of the bits that change, but give you all available data for any given snapshot)

Perhaps ill create a GUI for it at some point, but for now its CLI only, so if you add it to nautilus-actions, make sure you specify that it's to be launched with a terminal, eg:
gnome-terminal -x python ~/scripts/short_term_sync.py

Click here to grab it, and don't forget to edit the 'dest', around line 27.

Merge and burst PDFs with nautilus-actions

Two scripts, one for merging and one for bursting (splitting up into single pages). Grab them here.

They output to the directory the PDFs are in. The merge script collates the PDFs in alphabetical order and outputs to 'merged.pdf', the burst script numbers the pages.

Add it to nautilus-actions the normal way, with %M as the parameter and to only show when *.pdf is displayed, obviously.

These scripts rely on pdftk to do the work.

Friday 7 May 2010

Update to Deluge scheduling script

This is a little update. The original post has been updated too.

So the syntax has changed for versions of deluge including and above 1.2.0. There's also a handy scheduler plugin again, finally, but i also use my deluge_sched.py for toggling between 3 sets of bandwidth limits, so its still sitting in my gnome menu next to deluge client.

The only difference is the syntax used for deluge-client. Since you may have changed your bandwidth limits to ones different from mine, you may want to just do a find-and-replace on the script instead of downloading it afresh.
Change all instances of: 'deluge -u console -a'
To: 'deluge-console'

Simple as that. The updated script can be found here and the original one can now be found here

Friday 30 April 2010

mitm.py updated

Coldfire over at the hak5 forums suggested a change to the targetting function in my ettercap/sslstrip man-in-the-middle script (see previous blog post) to overcome a problem with his version of nmap (or perhaps, actually, the LAN he was testing since we both use nmap v5.00)

The script has been updated and can be found in the same place, namely here. If it worked before, it'll work now and may now work on a wider variety of LANs.

Thursday 15 April 2010

Batch renaming script updated

I added some command line arguments so you can easily use it directly from the terminal. You can navigate to the directory where your files are and use the argument * to select all the files in the current working directory, or use the -c argument to add conditionals (boolean 'not', 'and', 'or') that'll apply a filter on the current working directory, eg:

renamer.py -c 'foo'
will select all files with 'foo' in their name

renamer.py -c 'foo' and not 'bar'
will select all files with 'foo' in their name, except for those with 'bar'.

Click here to get it

Tuesday 13 April 2010

Batch renamer using python string methods

I'll admit it: I'm crap at regex. I find python's string manipulation a lot more intuitive, and I'm finding this script a lot quicker to work with than any GUI renaming tools or the bash shell, too.

Add it to your nautilus or thunar action menu and work with the filenames like you've put them all in a python list and are writing the for loop expression


You have a few variables available to you: the filename, it's basename, it's extention and the element's index within the list. It lets you do most things to strings that python lets you do since it passes your command directly to python. The only limitation is that it need to be a one-liner, and it needs to return a string. Click here to familiarise yourself with python's string methods.

It'll let you confirm before applying changes, and reset if you tell it not to confirm.



Here are some examples from the help section if you're new to python:

n = b.replace('foo', 'bar')+e
Renames feefoobar.txt to feebarbar.txt
Replaces foo with bar in basename, and appends the extention

n = n.split('foo')[0]+'.log'
Renames feefoobar.txt to fee.log
Splits the filename at 'foo' and returns the part before the split, and appends a .log extention

n = b+str(i)+e
Renames feefoobar.txt to feefoobar0.txt
Adds the current element's index integer as a string to the end of the basename, then appends the extention


Click here to get it

Edit: This has been updated 

Thursday 8 April 2010

Man in the middle mischief with a simple automating script

I haven't published any of my security related scripts or talked about any penetration testing and security auditing here before, but it's probably something I'll start to do more of.

This is really just to make sslstrip setup more convenient. What's so interesting about sslstrip is how it shows that the average user completley ignores whether an apparently secure site is actually https:// or if its plain old http://. If you're unfamiliar with sslstrip then you should really be visiting Moxie's website.

This script automates the process of becoming the man in the middle and running sslstrip, a tool to present the target with an http page whenever they should be getting an https page. It uses ettercap to arp poison the target on the LAN, and also to display any caught login information. Ettercap on it's own is great for capturing http login info and can also manipulate SSL, although we're using it here because it partners so nicely with sslstrip so we can disregard SSL all together for any target on our LAN. The script uses nmap to create a target choice menu and finds your IP and the gateway IP, making everything except the choice of target automatic.

Click here to grab it.

Depends on:
iptables nat
nmap
sslstrip
ettercap (with the iptables uncommented from the ettercap config file, often located at /etc/etter.conf)

Tuesday 16 March 2010

Limit Deluge based on time of day, command arguments or a toggle button

I live with my girlfriend and share the apartment with two others, so I can't use all of the bandwidth all of the time. I also work from home, and like to limit my torrent sharing if I'm doing something that requires more bandwidth, so I made this script.

It runs at startup and at 7.10pm on week days. If my computer is turned on in the evening, it limits the bandwidth deluge uses so others in the apartment can do what they like without me clogging things up. This works better than a normal cron job would since I may not have my computer turned on when the cron job is scheduled to run.

I also run this command via a menu entry, with the argument 'toggle', so i can cycle through the three bandwidth settings when i need to.



For deluge versions >= 1.2.0, the script is available here. For pre 1.2.0, the script is available here. See update post for details.

Change the config values at the top of the script to ones that are suitable for you. The script sends a notification via send-notify, and also logs actions to /var/log/messages.


Because it also accepts the arguments 'limit', 'partial' and 'unlimit', it can also be run from the command line, perhaps via ssh if you run deluge on your server or if you want to create buttons for every setting, rather than rely on the 'toggle' functionality.

Monday 1 March 2010

Securely delete files using shred via nautilus-actions

"shred - overwrite a file to hide its contents, and optionally delete it"



I encrypt my sensitive information with PGP, but when unencrypting the files to view them I'm left with a plain text version. Using this script enables me to get rid of the plain text versions from within the right-click menu in a secure manner using shred. Shred will overwrite the file(s) 25 times with various patterns before deleting it from the filesystem, making recovery difficult without specialist equipment.

 

Simply download the script and create a nautilus-actions config. Just pass it the parameter %M, and use it on single or multiple file selections.