mike west
mike west

Reputation: 49

Need help with my first perl program

I am only a few days in and have only made a couple things from the book I have been going through, so go easy :P. I have tried searching online and have tried different ways but I can not seem to pass the MAC properly to system(). What I am trying to achieve is have perl open a .txt file of MAC's each MAC is on its own separate line. Then with it reading each line taking one MAC at a time and passing it system() as an arg so aircrack can be passed the MAC arg. I have it showing the MAC being read each line properly but I can not figure out why aircrack complains the MAC its being given is not a valid MAC. Is this due to me not chomping the line read?

What I have not tried as of yet due to this complication is I eventually want it to print a found key to a file if aircrack says it has found one, or if it does not find one moves on to the next BSSID, continuing until there are no more MACs in the file to try.

the MACs are in a txt file as so

00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00

and so on

#!/usr/bin/perl
use strict;
use warnings;


my $file = '/kismetLOGS/PcapDumpKismet/WEPMACS.txt';
open my $info, $file or die "Could not open $file: $!";

while( my $line = <$info>) 
  {
    print $line;
    system("/usr/local/bin/aircrack-ng", "-b $line", "*.pcap *.pcapdump");
    last if $. == 0;
  }

close $info;
exit;

Thanks for any help, tips and pointers. Not looking for a spoon feed :) And hopefully I posted properly for everyone and if I am way off in how I am trying this for my end goal please feel free to say and any tips about the correct route to try would be appreciated

Upvotes: 1

Views: 161

Answers (3)

tadmc
tadmc

Reputation: 3734

$line ends with a newline character. You should remove the newline character.

chomp $line;

Upvotes: 1

wespiserA
wespiserA

Reputation: 3168

about last if $. == 0;,change it to last if $. ~~ 0 which infers the type of the variables when doing the comparison. Remove it if you want to iterate over all of the MAC addresses, as is it will only run on the first ( 0th ) line.

Upvotes: 0

david van brink
david van brink

Reputation: 3642

You can either combine all your arguments together, like

system("/usr/local/bin/aircrack-ng -b $line *.pcap *.pcapdump");

or separate them all, like

system("/usr/local/bin/aircrack-ng", "-b","$line", "*.pcap","*.pcapdump");

The latter is usually safer, for spaces in the items not to need be escaped. But then globbing doesnt work, as the arguments are passed directly to the system for execution.

If you want *.pcap to work, you'll need to go with the first version.

Upvotes: 2

Related Questions