#! /usr/bin/perl # Wrapper around John the Ripper (part of MJohn) # Sends attack descriptions to the server # !!! Experimental: this all is subject to change very soon !!! use strict; use warnings; use File::Copy; use YAML::XS; my @args = @ARGV; # Usage: wrapper keys path-to-john john-keys # Limitations: only full names of keys are supported, order of keys # should not affect behaviour, and many others not found yet. # Store keys into file # User name # TODO: move to config. my $user = 'u1'; # Each wrapper has its own store. # TODO: set store up if there is not one. Or at least exit if so. # TODO: move it to config. my $store = '/home/a/desktop/wrapper/test-store1'; my $pwd = $ENV{PWD}; # TODO: create dir (with path) if there are no one. chdir $store; # Sync store with server. # TODO: conflicts? They should be avoided here, solved somewhere else. `git pull`; # Each attack has its own dir in store. # Name of attack # TODO: name from cmdline. # TODO: easier name, maybe with incremental counter. # TODO: this does not reflect real user+attack_name. my $attack_name = "${user}_name" . time(); # TODO: check if this attack already exists. mkdir "$attack_name"; # Check that all files are available and copy them into store. for (@args) { # Use only one key-value separator. # TODO: does john accept only = and : as separater for keys? s/(-.*?)[=:]/$1=/; if (/(-.*?=)(.*)/) { # TODO: respect type of key! Do not copy file named 'all' # from original dir if we just call --incremental=all . if (-r $2) { warn "$2 exists here"; } elsif (-r "$pwd/$2") { # TODO: is it correct to use slashes everywhere? warn "$2 exists in original folder"; # Copy file to store # TODO: do files in keys for wrapper need copies? copy "$pwd/$2", "$attack_name"; # Overwrite args with new path. $_ = "$1$attack_name/$2"; # TODO: there will be duplicated files. We should track # them. How? Probably we should remember original pairs.{ # TODO: remember about relative paths (i.e. with ../ inside). } else { warn "$2 does not exist anywhere"; } } } my $attack_keys = "$attack_name/keys"; my $f; open $f, '>', $attack_keys or die "could not open file $attack_keys"; # TODO: when we sort keys we mix keys for wrapper with keys for john. # We need to sort keys (really?) but do not need to mix them. So we # should split them before sort and store in separate files (or # containers in one yaml file). print $f Dump sort @args; close $f; # TODO: Check for duplicated commands. # Start john. # TODO: handle keys for wrapper. # Drop keys for wrapper. # TODO: here we loose them. shift @args while @args && $args[0] =~ /^-/; # TODO: dump john's version here. # TODO: do short test run here. # Push changes to server. # TODO: Pushing to server could be async. # TODO: quoting or restrictions on user/attack names: double quotes # are not allowed for user and attack names, also backslashes are not # allowed. # NOTE: While we do not touch the same file simultaneously from # multiple place we do not have conflict. So while we do not have # collisions in names of attacks we have no problems. `git add "$attack_name"`; `git commit -m auto1`; # NOTE: git prefers "bare" repositories for pushes. `git push`; # Really run john. # TODO: do not count john without args or with help keys as attack. # TODO: check if we have command for john. warn "run @args"; # TODO: pipes? system @args; # John finished or aborted. # TODO: Report finish or abort