PDA

Просмотр полной версии : distributed john the ripper


ShAnKaR
13.07.2008, 19:25
появилось тут несколько свободных серверов и дабы занять их решил наконецто разбрутить все что накопилось, поначалу хотел заюзать dJohn (http://ktulu.com.ar/blog/software/djohn) но чето оно глючило с диапазонами пасов и решил сделать небольшой свой скрипт для этого.
в общем написал кое как корявенько ибо не программист два скрипта - сервер и клиент, заюзав код для john.conf из dJohn`а :

#!/usr/bin/perl -w

use strict;
use IO::Socket;
use Thread;
use POSIX qw(ceil floor);
use MIME::Base64;
use POSIX 'setsid';

die "cant fork" unless defined (my $child=fork);

exit 0 if $child;
setsid();
open (STDIN,"</dev/null");
open(STDOUT,">.dev.null");
open(STDERR,">&STDOUT");

our $chars='~!@#$%^&*()_+=-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn opqrstuvwxyz';# chars
our $len=8;# max len password
our $step=100000;#kolichestvo iteraciy

my $port=12345;





our $count=length($chars)**$len;
our $nowcount=1;



my $listen_s=IO::Socket::INET->new(LocalPort=>$port,Listen=>20,Proto=>'tcp',Reuse=>1);

die $@ unless $listen_s;

while(my $conn=$listen_s->accept){
my $thr=Thread->new(\&interact,$conn);
$nowcount+=$step;
}

sub interact{
my $hand=shift;
Thread->self->detach;
my $inp;
chomp($inp=<$hand>);
if($inp=~m/givedata/){ # get word data
print $hand encode_base64($chars).':'.$len.':'.encode_base64(p wd($nowcount)).':'.encode_base64(pwd($nowcount+$st ep))."\n";
}
$hand->close();
}






sub pwd{
my $ncount=shift;
my $a=1;
my $b=0;
my ($c,$d1,$c1,$cc,$skstep);
while($b<$ncount){
$b+=length($chars)**($a++);
}
$a=$a-1;
$c1=$b-length($chars)**($a);
$skstep=$ncount-$c1;
for(my $sts=0;$sts<$a;$sts++){
$d1=floor($skstep/(length($chars)**$sts));
while($d1>=length($chars)){
$d1=$d1-floor($d1/length($chars))*length($chars);
}
$c.=substr($chars,$d1,1);
}
for(my $i=length($c)-1;$i>-1;$i--){
$cc.=substr($c,$i,1);
}
return $cc;
}


и клиент:

#!/usr/bin/perl -w


use strict;
use IO::Socket;
use MIME::Base64;
use POSIX 'setsid';

die "cant fork" unless defined (my $child=fork);

exit 0 if $child;
setsid();
open (STDIN,"</dev/null");
open(STDOUT,">.dev.null");
open(STDERR,">&STDOUT");



my $socket;


my $host=$ARGV[0];

while(1){
if($socket=IO::Socket::INET->new($ARGV[0])){

my $data;

print $socket "givedata\n";
sysread($socket,$data,1024);
print $socket "exit\n";
close($socket);

if($data=~m/([^:]+):([^:]+):([^:]+):([^:]+)/){

open(LOG,'>'.$ENV{HOME}.'/.john/djohn_log.txt');
print LOG decode_base64($1).':'.$2.':'.decode_base64($3).':' .decode_base64($4)."\n";
close(LOG);

my $chars=decode_base64($1);
my $len=$2;
my $stch=decode_base64($3);
my $ench=decode_base64($4);







my ($ch_1,$ch_2,$ch_3);

for($a=0;$a<length($chars);$a++){
$ch_1.=" charset[$a] = '".substr($chars,$a,1)."';\n";
}


for($a=0;$a<length($stch);$a++){
$ch_2.=" word[$a] = '".substr($stch,$a,1)."'; rword[$a] = ".(index($chars,substr($stch,$a,1))).";\n";
}


for($a=0;$a<length($ench);$a++){
$ch_3.="word[$a] == '".substr($ench,$a,1)."' && "
}




my $conf="
[List.External:dJohn]
int length; // Current length
int charset[".length($chars)."];
int rword[15];
int charsetl;
int first_time;

void init()
{
length = ".length($stch)."; charsetl = ".length($chars).";
".$ch_1.$ch_2."
word[".($a++)."] = 0;

first_time = 1;
}

void generate()
{
int i;

if (first_time) {
first_time = 0;
return;
}

if (".substr($ch_3,0,-3).") {
word = 0;
return;
}

i = length - 1; // Start from the last character
while (++rword[i] == charsetl) // Try to increase it
if (i) // Overflow here, any more positions?
rword[i--] = 0; // Yes, move to the left, and repeat
else // No
if (length < 15-1) {
i = ++length; // Switch to the next length
while (i--)
rword[i] = 0;
while (i < length)
word[i] = charset[rword[i++]];
word[length] = 0;
return;
} else {
word = 0; return; // We're done
}
i = 0;
while (i < length)
word[i] = charset[rword[i++]];
word[length] = 0;
}

";


my $fp=open(IN,'>/tmp/j.conf');
print IN $conf;
close(IN);

system('cat /etc/john.conf /tmp/j.conf > '.$ENV{HOME}.'/.john/john.conf');
unlink('/tmp/j.conf');
system('john -external=dJohn --session=/tmp/session_'.$$.'.john '.$ARGV[1]);
}
else{
sleep(600);
}}
else{
sleep(600);
}

}

сервер запускается просто ./server.pl, клиент ./client 127.0.0.1:12345 /home/user/password.txt
для работы требуется установленный JTR, default конфиг /etc/john.conf, папка ~/.john/ , файл с хешами /home/user/password.txt

хотя все можно сделать еще проще например серверную часть через веб сайт,
, ну в общем вроде все работает и так вроде как корректно.
принцип работы- сервер расчитывает начальный и конечный пароль которые и отдает клиенту , клиент в свою очередь подсодиняется к серверу на порт 12345 получает задание, исправляет конфиг JTR и запускает его, и так бесконечно,