Hello Perl Monks. I'm trying to make a portscanner that will take values from a MySQL database. I was able to make it without SQL support with this code:
%h; $h{'Echo [Returns what is sent to server]'} = {service => ['7']}; $h{'Discard [A sink, like /dev/null]'} = {service => ['9']}; foreach $key(keys %h) {foreach $service (@{$h{$key}{'service'}}) {if($khost=~/^$service/) {chop($service) if ($service =~/\.$/); print "\n[!] Port: [$start_port] Service: $key"; print O "[!] Port: [$start_port] Service: $key\n"; $start_port++}}}}}
Now I'm trying to do the same thing but with DBI. I have a table called "vulnerabilities" and I want to create a hash in perl, populated by the 'port', 'name', 'comment' that can be found on the vulnerabilities table. Untill now my code is something like this:
$sql = "select * from scanner.vulnerabilities"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; my %ref; while (my $row = $sth ->fetchrow_hashref() ){ $ref{ $row ->{'port'}} = $row ->{'Name'} } foreach $key(keys %ref) {foreach $port (@{$ref{$key}{'port'}}) {if($khost=~/^$port/) {chop($port) if ($port =~/\.$/); print "\n[!] Port: [$start_port] Service: $key"; print O "[!] Port: [$start_port] Service: $key\n"; $start_port++}}}}}
The way it is does not working as it does not log the results. In small, I want to create a hash from MySQL that can do what the original program does. Although I have read a hell lot of resources it seems that I miss something. This program is for a college project and I cannot seem to be able to find the answer anywhere. Thank you in advance.
In reply to Hash from mySQL by CreationP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |