/
aprof
executable file
·295 lines (257 loc) · 8.22 KB
/
aprof
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/perl
# Apache profiler script
# Written by Eldar "Wireghoul" Marcussen - http://www.justanotherhacker.com
use strict;
use warnings;
use IO::Socket::INET;
use IO::Socket::SSL;
use Getopt::Long;
my $VERSION = '0.3';
my $AUTHOR = 'Eldar "Wireghoul" Marcussen';
my $timeout = 20;
my $path = '/';
my ($sock, $force);
my $opts = GetOptions(
"basepath=s" => \$path,
"timeout" => \$timeout,
"force" => \$force,
"version" => sub { print "aprof version: $VERSION\n"; exit 0; },
"help" => sub { &show_help },
);
&show_help unless $ARGV[0];
my ($ssl, $target, $port) = &_parse_uri($ARGV[0]);
&banner;
# General stuff here
$path = "/".$path if $path !~ /^\//;
$path = $path."/" if $path !~ /\/$/;
&print_msg('Analysing: '. ($ssl ? 'https' : 'http') . "://$target$path\n");
if (!$force) {
my $tmp = &check_server;
chop($tmp);
if ($tmp !~ /Apache/) {
&error_msg("Not Apache ($tmp)! Use --force if you think the server is faking it.\n");
exit;
}
&status_msg("Server signature: $tmp\n");
}
# Module detection here
&status_msg("Attempting to identify modules:\n");
&check_default_host;
&check_mod_alias;
&check_mod_caucho;
&check_mod_cgi;
&check_mod_dav;
&check_mod_deflate;
&check_embperl;
&check_mod_imagemap;
&check_mod_info;
&check_mod_mime;
&check_mod_php;
&check_mod_proxy_balancer;
&check_mod_python;
&check_mod_rivet;
&check_mod_ruby;
&check_mod_status;
&check_mod_setenvif;
&check_Frontpage;
&status_msg("Done!\n\n");
sub check_server {
if ( &request("GET $path HTTP/1.1\r\nHost: $target") =~ m{^Server: (.*)$}m ) {
return $1;
}
}
sub check_default_host {
my $hreq = &request("GET $path HTTP/1.1\r\nHost: $target");
my $nhreq = &request("GET $path HTTP/1.1\r\nHost: KJAISJNKDCIUW9123ejkasdnKZ");
if ($hreq =~ /title>(.*)<\/title/i) {
my $htitle = $1;
if ($nhreq =~ /title>(.*)<\/title/i) {
if ($htitle eq $1) {
&success_msg("Host $target is the default virtual host\n");
return;
}
}
}
# in all other cases
&error_msg("Host $target is NOT the default virtual host\n");
}
sub check_mod_alias {
return;
}
sub check_mod_php {
my $php = 0;
if ( &request("GET $path HTTP/1.1\r\nHost: $target") =~ m{^(X-Powered-By: PHP|Set-Cookie: PHPSESSID|Server: .* PHP/)}m ) {
$php = 1;
} elsif ( &request("GETSPHP ${path}index.php HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|30[12]|404|500)} && &request("GETSPHP ${path}notaphp.file HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. 501} ) {
$php = 1;
}
if ($php) {
&success_msg("mod_php detected\n");
&status_msg("Checking what extensions have php bindings:\n");
foreach my $ext ('.php','.php3','.php4','.php5','.php7','.pht','.phtm','.phtml','.phps') {
if (&request("GETSPHP ${path}index$ext HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|30[12]|404|500)}) {
&success_msg("\t$ext in use\n");
}
}
}
}
sub check_mod_caucho {
if ( &request("GET ${path}caucho-status HTTP/1.0") =~ m{(Server: .* Resin/|Status : Caucho Servlet Engine)}m) {
&success_msg("mod_caucho detected\n");
}
}
sub check_mod_cgi {
if ( &request("GETCGI ${path}cgi-bin/ HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|30[12]|403|500)} && &request("GETCGI ${path}notacgi.gob HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. 501} ) {
&success_msg("mod_cgi detected\n");
}
}
sub check_mod_dav {
return;
}
sub check_mod_deflate {
return;
}
sub check_embperl {
if ( &request("GETSPL ${path}somefile.epl HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|404|500)} ) {
&success_msg("mod_perl => Embperl detected\n");
}
}
sub check_mod_mime {
if ( &request("GETSVAR ${path}somefile.var HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|404|500)} ) {
&success_msg("mod_mime detected\n");
}
}
sub check_mod_imagemap {
if ( &request("GETSMAP ${path}image.map HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|404|500)} ) {
&success_msg("mod_imagemap detected\n");
}
}
sub check_mod_info {
my $response = &request("GET ${path}server-info HTTP/1.1\r\nHost: $target");
if ( $response =~ m{^HTTP/1.. 403} ) {
&success_msg("mod_info (restricted access) detected\n");
} elsif ( $response =~ m{Apache Server Information} ) {
&success_msg("mod_info (public access) detected - http://$target:$port/server-info\n"); # Should be parsed for 100% accurate information
}
}
sub check_mod_rivet {
if ( &request("GET ${path}index.rvt HTTP/1.1\r\nHost: $target") =~ m{(Server: .*Rivet)} ) {
&success_msg("mod_rivet detected\n");
}
}
sub check_mod_ruby {
if ( &request("GET ${path}index.rb HTTP/1.1\r\nHost: $target") =~ m{(Server: .*mod_ruby)}m) {
&success_msg("mod_ruby detected\n");
}
}
sub check_mod_python { #TODO add check for server headers and other extension bindings
if ( &request("GETPY ${path}index.psp HTTP/1.1\r\nHost: $target") =~ m{(Server: .*mod_python)}m) {
&success_msg("mod_python detected\n");
}
}
sub check_mod_ldap {
my $response = &request("GET ${path}ldap-status HTTP/1.1\r\nHost: $target");
if ( $response =~ m{^HTTP/1.. 403} ) {
&success_msg("mod_ldap (restricted access) detected\n");
} elsif ( $response =~ m{Apache ldap} ) {
&success_msg("mod_ldap (public access) detected\n");
}
}
sub check_mod_qos {
if ( &request("GET ${path}qos HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. (200|403)} ) {
&success_msg("mod_qos detected\n");
}
}
sub check_mod_status {
my $response = &request("GET ${path}server-status/ HTTP/1.1\r\nHost: $target");
if ( $response =~ m{^HTTP/1.. 403} ) {
&success_msg("mod_status (restricted access) detected\n");
} elsif ( $response =~ m{Apache Status} ) {
&success_msg("mod_status (public access");
if ($response !~ m{ExtendedStatus On}) {
&print_msg(" - full status");
} else {
&print_msg(" - limited status");
}
&print_msg(") detected http://$target:$port/server-status/\n");
}
}
sub check_mod_setenvif {
return;
}
sub check_Frontpage {
if ( &request("GET ${path}_vti_bin/ HTTP/1.1\r\nHost: $target") =~ m{^HTTP/1.. 200} ) {
&success_msg("Frontpage detected\n");
}
}
sub check_mod_proxy_balancer {
my $response = &request("GET ${path}balancer-manager HTTP/1.1\r\nHost: $target");
if ( $response =~ m{^HTTP/1.. 403} ) {
&success_msg("mod_proxy_balancer (restricted access) detected\n");
}
}
sub request {
# Need timeout
my $request = shift;
my $resp = '';
if (&connect($target, $port, $timeout)) {
print $sock "$request\r\nConnection: Close\r\n\r\n";
while (<$sock>) {
$resp .= $_;
}
}
# warn "DEBUG:\n".$resp;
return $resp;
}
sub connect {
my ($target, $port, $timout) = @_;
if ($ssl) {
$sock = IO::Socket::SSL->new("$target:$port") or die "Unable to connect to $target:$port: $!\n";
} else {
$sock = IO::Socket::INET->new("$target:$port") or die "Unable to connect to $target:$port: $!\n";
}
# Reconnect attempts?
return 1 if ($sock);
}
sub _parse_uri {
my $uri = shift;
my @p = (0, '', 80); #Defaults
# Quick fix to handle uri's without protocol designation
$uri = "http://$uri" if ($uri !~ m!://!);
$p[0] = 1 if ($uri =~ m!^https://!);
$uri =~ m!https?://([^:/]+):?(\d+)?/?!;
$p[1] = $1;
if ($2) {
$p[2]=$2;
} elsif ($p[0]) {
$p[2]=443;
}
return @p;
}
sub show_help {
&banner;
print "Usage: $0 [options] <uri>\n";
print "Options:\n";
print " --basepath\tUse directory as root (default /)\n";
print " --force\tIgnore apache server banner check\n";
print " --timeout\tTimeout in seconds (default: 20)\n";
print " --version\tPrints aprof version number\n";
print " --help\tThis screen\n";
exit;
}
sub banner {
print "aprof - Apache profiler tool v$VERSION by $AUTHOR\n";
print "================================[ www.justanotherhacker.com ]===\n";
}
sub success_msg {
print "[+] ". shift;
}
sub error_msg {
print "[-] ". shift;
}
sub status_msg {
print "[*] ". shift;
}
sub print_msg {
print shift;
}