Skip to content

Commit 03f6d76

Browse files
committed
get_kernel() and get_exploits() in, main() out
This is a minor maintainability update for the code. It provides the get_kernel() and get_exploits() functions, and moves main() to the top of the script. As such, developers are able to see the complete logic of the code just by opening the file and looking at the very first lines. The 'exit' at the end of the code also guarantees that no extra data is processed, and the rest are just auxiliary functions, created to provide extra readability and maintainability.
1 parent 89c6380 commit 03f6d76

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

Linux_Exploit_Suggester.pl

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,50 @@
99
getopt( 'k,h', \%opts );
1010
usage() if exists $opts{h};
1111

12-
my $khost = '';
13-
if ( exists $opts{k} ) {
14-
$khost = $opts{k};
12+
my $khost = get_kernel();
13+
print "\nKernel local: $khost\n\n";
14+
15+
my %exploits = get_exploits();
16+
17+
print "Possible Exploits:\n";
18+
foreach my $key ( keys %exploits ) {
19+
foreach my $kernel ( @{ $exploits{$key}->{vuln} } ) {
20+
21+
# printf "DEBUG:vuln:%s kernel:%s lk:%s\n", $key,$kernel,$khost;
22+
if ( $khost =~ /^$kernel$/ ) {
23+
chop($kernel) if ( $kernel =~ /.$/ );
24+
print "[+] " . $key;
25+
my $alt = $exploits{$key}->{alt};
26+
my $cve = $exploits{$key}->{cve};
27+
my $mlw = $exploits{$key}->{mil};
28+
if ( $alt or $cve ) {
29+
print "\n";
30+
}
31+
if ( $alt ) { print " Alt: $alt "; }
32+
if ( $cve ) { print " CVE-$cve"; }
33+
if ( $mlw ) { print "\n Source: $mlw"; }
34+
print "\n";
35+
}
36+
}
1537
}
16-
else {
17-
$khost = `uname -r |cut -d"-" -f1`;
18-
chomp($khost);
38+
exit;
39+
40+
41+
######################
42+
## extra functions ##
43+
######################
44+
45+
sub get_kernel {
46+
my $khost = '';
47+
if ( exists $opts{k} ) {
48+
$khost = $opts{k};
49+
}
50+
else {
51+
$khost = `uname -r |cut -d"-" -f1`;
52+
chomp($khost);
53+
}
54+
return $khost;
1955
}
20-
print "\nKernel local: $khost\n\n";
2156

2257
sub usage {
2358
print "Linux Exploit Suggester $VERSION\n"
@@ -27,7 +62,8 @@ sub usage {
2762
;
2863
}
2964

30-
my %h = (
65+
sub get_exploits {
66+
return (
3167
'w00t' => {
3268
vuln => [
3369
'2.4.10', '2.4.16', '2.4.17', '2.4.18',
@@ -409,32 +445,9 @@ sub usage {
409445
cve => '2013-0268',
410446
mil => 'http://www.exploit-db.com/exploits/27297/',
411447
},
412-
);
413-
run_main();
414-
415-
sub run_main {
416-
print "Possible Exploits:\n";
417-
foreach my $key ( keys %h ) {
418-
foreach my $kernel ( @{ $h{$key}->{vuln} } ) {
419-
420-
# printf "DEBUG:vuln:%s kernel:%s lk:%s\n", $key,$kernel,$khost;
421-
if ( $khost =~ /^$kernel$/ ) {
422-
chop($kernel) if ( $kernel =~ /.$/ );
423-
print "[+] " . $key;
424-
my $alt = $h{$key}->{alt};
425-
my $cve = $h{$key}->{cve};
426-
my $mlw = $h{$key}->{mil};
427-
if ( $alt or $cve ) {
428-
print "\n";
429-
}
430-
if ( $alt ) { print " Alt: $alt "; }
431-
if ( $cve ) { print " CVE-$cve"; }
432-
if ( $mlw ) { print "\n Source: $mlw"; }
433-
print "\n";
434-
}
435-
}
436-
}
448+
);
437449
}
450+
438451
__END__
439452
=head1 NAME
440453

0 commit comments

Comments
 (0)