1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#VERSION,2.05
# $Id: nikto_apacheusers.plugin 632 2011-02-19 02:49:31Z sullo $
###############################################################################
# Copyright (C) 2004 CIRT, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###############################################################################
# PURPOSE:
# Apache user enumeration
###############################################################################
sub nikto_apacheusers_init {
my $id = {
name => "apacheusers",
full_name => "Apache Users",
author => "Javier Fernandez-Sanguinoi Pena",
description => "Checks whether we can enumerate usernames directly from the web server",
hooks => { scan => { method => \&nikto_apacheusers, }, },
copyright => "2008 CIRT Inc.",
options => {
enumerate => "Flag to indicate whether to attempt to enumerate users",
dictionary => "Filename for a dictionary file of users",
size => "Maximum size of username if bruteforcing",
home => "Look for ~user to enumerate",
cgiwrap => "User cgi-bin/cgiwrap to enumerate"
}
};
return $id;
}
sub nikto_apacheusers {
return if $mark->{'terminate'};
my ($mark, $parameters) = @_;
my $apacheusers = 0;
# First ensure that the server is vulnerable
(my $result, $content) = nfetch($mark, "/~root", "GET", "", "", "", "apacheusers: known user");
$content = quotemeta($content);
if ($content =~ /forbidden/i) # good on "root"
{
(my $result, $content) = nfetch($mark, "/~" . LW2::utils_randstr(8),
"GET", "", "", "", "apacheusers: invalid user");
$content = quotemeta($content);
if ($content !~ /forbidden/i) # Good, it gave an error instead of forbidden
{
add_vulnerability(
$mark,
"Enumeration of users is possible by requesting ~username (responds with 'Forbidden' for users, 'not found' for non-existent users).",
999999,
637,
"GET",
"/~root"
);
}
$apacheusers = 1;
}
# If we can't enumerate users then return
return unless ($apacheusers == 1);
# If we haven't been asked to enumerate users then return
return unless (defined $parameters->{'enumerate'}
&& $parameters->{'enumerate'} == 1);
# Now we can attempt to enumerate the users
my ($url, $dictfile, $size);
my @cgiwraps;
my @cfgcgi = split(/ /, $VARIABLES{"\@CGIDIRS"});
if (defined $parameters->{'dictionary'}) {
$dictfile = $parameters->{'dictionary'};
}
if (defined $parameters->{'size'}) {
$size = $parameters->{'size'};
}
# Set the URL according to the parameters
if (defined $parameters->{'cgiwrap'}) {
# Check for existence of cgiwrap
foreach my $cgidir (@CFGCGI) {
my $curl = "$cgidir" . "cgiwrap";
(my $result, $content) =
nfetch($mark, $curl, "GET", "", "", "", "user_enum_apache: cgiwrap");
if ($content =~ /check your URL/i) {
push(@cgiwraps, "$curl");
}
}
foreach my $cgiwrap (@cgiwraps) {
$url = "$cgiwrap/~";
# First check whether we use a dictionary attack of brute force it
if (defined $dictfile) {
# We have options - assume it is a dictionary attack
nikto_user_enum_apache_dictionary($url, $mark, $dictfile);
}
else {
nikto_user_enum_apache_brute($url, $mark, $size);
}
}
}
if (defined $parameters->{'home'}) {
$url = "/~";
# First check whether we use a dictionary attack of brute force it
if (defined $dictfile) {
# We have options - assume it is a dictionary attack
nikto_user_enum_apache_dictionary($url, $mark, $dictfile);
}
else {
nikto_user_enum_apache_brute($url, $mark, $size);
}
}
}
sub nikto_user_enum_apache_brute {
# Note1: This script only generates names with letters A-Z (no numbers)
#
# Note2: this script will generate SUM(26^n)(n=$min to $max)
# it's probably faster to write this to a file than to generate it
# on the fly BTW.
#
# Of course, it could be optimized to skip some "strange"
# combinations of usernames, but hey, then it wouldn't
# be 'brute force' would it? (jfs)
my ($url, $mark, $size) = @_;
$size = 5 if ($size eq "");
nprint("- Enumerating Apache users (1 to $size characters).", "v");
my $text = "a";
my $ctr = 0;
my $message = "Valid users found via Apache enumeration: ";
my ($result, $content);
my @foundusers = ();
while (length($text) <= $size) {
return if $mark->{'terminate'};
if (($ctr % 500) eq 0) { nprint("- User enumeration guess $ctr ($text)", "v"); }
($result, $content) =
nfetch($mark, $url . $text, "HEAD", "", "", "", "user_enum_apache: enumeration");
my $user = nikto_user_enum_apache_check($result, $text);
if (defined $user && $user ne "") {
push(@foundusers, $user);
}
$text++;
$ctr++;
}
if (scalar(@foundusers)) {
add_vulnerability($mark, $message . join(', ', @foundusers), 999997, "637", "HEAD", "/");
}
}
sub nikto_user_enum_apache_dictionary {
my ($url, $mark, $filename) = @_;
my $message = "Valid users found via Apache enumeration: ";
my @foundusers = ();
my ($result, $content);
my $ctr = 0;
nprint("- Enumerating Apache users (using dictionary $filename).", "v");
unless (open(IN, "<$filename")) {
nprint("+ ERROR: Unable to open dictionary file $filename: $!.");
}
# Now attempt on each entry
while (<IN>) {
return if $mark->{'terminate'};
chomp;
s/\#.*$//;
# remove preceding ~ just in case
s/^~//;
if ($_ eq "") { next }
if (($ctr % 500) == 0) { nprint("- User enumeration guess $ctr ($_)", "v"); }
($result, $content) =
nfetch($mark, $url . $_, "HEAD", "", "", "", "user_enum_apache: dictionary");
my $user = nikto_user_enum_apache_check($result, $_);
if ($user) {
push(@foundusers, $user);
}
$ctr++;
}
close(IN);
if (scalar(@foundusers)) {
add_vulnerability($mark, $message . join(', ', @foundusers), 999997, "637", "HEAD", "/");
}
}
sub nikto_user_enum_apache_check {
(my $code, $user) = @_;
my $result = "";
foreach my $found (split(/ /, $VARIABLES{"\@HTTPFOUND"})) {
if ($code eq $found) {
$result = $user;
last;
}
}
return $result;
}
1;
|