Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Need help with Algorithm::Permute and openssl

by wdef2 (Acolyte)
on Jan 17, 2008 at 22:50 UTC ( #662973=perlquestion: print w/replies, xml ) Need Help??
wdef2 has asked for the wisdom of the Perl Monks concerning the following question:

Hi As a basic demonstration "cracking" program, I had a go at feeding permutations to openssl via the system command. With a simple permutation code snippet purloined from the web, this worked ok. However, when I try to feed a 3-char $perm from Algorithm::Permute as an environment variable via system to openssl (see code below), it is as if openssl somehow unsets or corrupts the contents of $perm - the 3-letter passphrase is never found. But if I replace the call in system to openssl with one to, say, echo $perm, there's no issue - the variable is clearly available in the shell.
#!/usr/bin/perl use strict; use warnings; use Algorithm::Permute; #~ my @array = 'a'..'d'; my @array = ( "", "a" .."z" ); # ranges and lists to permute my $perm = ""; my $i = 3; my $p = new Algorithm::Permute([@array], $i); my @res; while (@res = $p->next) { $perm = join("", @res); print "$perm\n"; if ($perm eq "art"){ # If the system command is included below, this test is _never +_ true. # So the system command changes $perm is some way!! # WTF? print "found $perm \n"; die; } system("echo $perm | openssl bf -pass stdin -d -in encryptedfile - +out out.txt && file -b out.txt | grep -q '^ASCII text'") == 0 && die +"Found passphrase \"$perm\""; }
My test file encryptedfile is blowfish encrypted with a 3-letter passphrase "art". The ascii text test is to eliminate false positives for which openssl produces binary garbage. I'm not very advanced yet in the Perl liturgy, O Monks. Can you help?

Replies are listed 'Best First'.
Re: Need help with Algorithm::Permute and openssl
by ikegami (Pope) on Jan 17, 2008 at 23:13 UTC

    it is as if openssl somehow unsets or corrupts the contents of $perm

    Which one is it? What does it contain? Are you sure it's actually reaching art?

      'art' is reached every time but only if I comment out the system line. If I leave the system call in, 'art' appears to never be reached. That's the only reason this test is in there (to prove that point):
      if ($perm eq "art"){ # If system command is run below, this test is never true. # So system command changes $perm is some way # WTF? print "found $perm \n"; die; }
      As for what is happening to $perm to do this (unset, altered in some way) I have no idea - otherwise I would have said so.

        No, if anything, that test proves that "art" wasn't reached.

        You have a print just before that if. Do you see it printing "art"? And again, if it does get cleared or corrupted, what does that print print? What's the last thing it prints that isn't corrupted? You already have the debugging statements in place, tell us what they show!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://662973]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-01-19 21:29 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (172 votes). Check out past polls.