annotate contrib/whoisd/whoisd.pl @ 1141:58130f5eecf2 draft

found a bug when sending just '.'... wasn't good.
author epoch <epoch@hacking.allowed.org>
date Sun, 06 Oct 2013 11:45:06 +0000
parents eec8e319f5bd
children ca4d35064aa2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
1 #!/usr/bin/perl
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
2 # coded by epoch.
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
3 # use inetd or tcpserver or something else.
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
4 # waste of time to do manual sockets for something like this.
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
5 # this isn't my baby. you can murder it if you want.
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
6
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
7 use strict;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
8
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
9 my $RESDB = "/services/resdb/resdb";
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
10
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
11 my $HACK=0;
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
12 my $QUERY=<stdin>;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
13 $QUERY =~ s/\r\n//g;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
14 my $out;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
15 my $title;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
16 my $value;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
17 my @parts;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
18 my $i;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
19
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
20 if($QUERY eq "!!\n") {
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
21 $QUERY=<stdin>;
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
22 $QUERY =~ s/^!r(.+?)[\/,].*$/\1/;
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
23 printf "A500\n"; #fake this I guess. Does it even use that number for anything?
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
24 printf "%% Looks like you're trying -A on a BSDian traceroute with this server.\n";
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
25 $HACK=1;
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
26 }
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
27
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
28 # ASNs
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
29 if($QUERY =~ m/^AS(.+?)$/) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
30 printf "%% AS section for %s\n", $QUERY;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
31 my $AS=$1;
1141
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
32 chdir("$RESDB/db/as") || die "%% error";
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
33 if(chdir($AS) || die "%% error") {
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
34 foreach(split(/\n/,`grep '' -r .`)) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
35 $out = $_;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
36 $out =~ s/^\.\///g;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
37 $out =~ m/^(.+?):(.+?)$/;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
38 ($title, $value) = ($1, $2);
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
39 printf "%-20s %s\n", $title . ":", $value;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
40 if($title eq "owner") {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
41 $QUERY = $value;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
42 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
43 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
44 } else {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
45 printf "AS not found.";
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
46 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
47 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
48
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
49 # IPv4 addresses
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
50 if($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) {
1140
eec8e319f5bd forgot a newline
epoch <epoch@hacking.allowed.org>
parents: 1138
diff changeset
51 printf "%% IP section for %s\n", $QUERY unless $HACK;
1141
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
52 chdir("$RESDB/db/ip") || die "%% error";
1133
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
53 @parts=split(/\./,$QUERY);
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
54 for($i=0;$i<scalar(@parts)-1;$i++) {
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
55 if(!chdir(sprintf("%02X",$parts[$i]))) {
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
56 printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK;
1133
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
57 exit;
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
58 }
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
59 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
60 foreach(split(/\n/,`grep '' -r .`)) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
61 $out = $_;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
62 $out =~ s/^\.\///g;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
63 ($title, $value) = split(/:/,$out);
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
64 printf "%-20s %s\n", $title . ":", $value unless $HACK;
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
65 if($title eq "owner") {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
66 $QUERY = $value;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
67 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
68 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
69 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
70
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
71
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
72 # if we get here and there's still a . in the query it is probably a domain.
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
73 if($QUERY =~ m/\./) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
74 printf "%% domain section for %s\n", $QUERY;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
75 @parts=split(/\./,$QUERY);
1141
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
76 chdir("$RESDB/db/dom") || die "%% error";
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
77 for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) {
1141
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
78 if(!$parts[$i]) {
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
79 printf "%% error";
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
80 exit
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
81 }
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
82 if(!chdir($parts[$i])) {
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
83 printf "%-20s %s", "warning" . ":", "domain not found.";
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
84 exit;
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
85 }
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
86 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
87 foreach(split(/\n/,`grep '' -r .`)) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
88 $out = $_;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
89 $out =~ s/^\.\///g;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
90 $out =~ m/^(.+?):(.+?)$/;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
91 ($title, $value) = ($1, $2);
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
92 printf "%-20s %s\n", $title . ":", $value;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
93 if($title eq "owner") {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
94 $QUERY = $value;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
95 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
96 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
97 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
98
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
99 # default to assuming it is a name.
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
100 printf "%% user section for %s\n", $QUERY unless $HACK;
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
101
1141
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
102 chdir("$RESDB/db/usr") || die "%% error";
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
103 if(chdir($QUERY)) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
104 foreach(split(/\n/,`grep '' -r .`)) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
105 $out = $_;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
106 $out =~ s/^\.\///g;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
107 $out =~ m/^(.+?):(.+?)$/;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
108 ($title, $value) = ($1, $2);
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
109 printf "%-20s %s\n", $title . ":", $value unless $HACK;
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
110 }
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
111 } else {
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
112 printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK;
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
113 }
1141
58130f5eecf2 found a bug when sending just '.'... wasn't good.
epoch <epoch@hacking.allowed.org>
parents: 1140
diff changeset
114 chdir("$RESDB/db/as") || die "%% error";
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
115 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) {
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
116 $out = $_;
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
117 $out =~ s/\n//g;
1138
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
118 printf "%-20s AS%s\n", "origin" . ":", $out if $HACK;
c95369b825a2 whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents: 1133
diff changeset
119 printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK;
1131
16cef39f682d Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff changeset
120 }
1132
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
121
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
122 foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) {
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
123 $out = $_;
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
124 $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/;
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
125 if ($out ne "") { #fix this comparison.
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
126 printf "%-20s %s\n", "domain" . ":", $out;
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
127 }
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
128 }
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
129 #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet";