/usr/sbin/blackhole6 is in ipv6toolkit 2.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | #!/usr/bin/perl
#
# blackhole6: A tool to make complex IPv6 tasks easy
#
# Syntax: blackhole6 DESTINATION [HEADERSIZE [PROTOCOL [PORT]]]
use Socket();
$total=0;
$response=0;
$timeout=0;
sub usage{
print "usage: blackhole6 DESTINATION [EHTYPE[EHSIZE]] [PROTOCOL [PORT]]]\n";
}
# Function GetASN()
#
# Obtains the autonomous system number (ASN) for a given IPv6 address
#
sub GetASN{
@revname=`addr6 -a $_[0] -r`;
if( ($? >> 8) != 0){
return(-1);
}
else{
chomp($revname[0]);
$queryname= $revname[0] . ".origin6.asn.cymru.com.";
@reverse=`host -t TXT $queryname`;
if($reverse[0] =~ m/\"\s*((\d+)\s*)\s+|"/){
return($2);
}
else{
return(-1);
}
}
}
# Function GetORG()
#
# Obtains the organization corresponding to an autonomous system number (ASN)
#
sub GetORG{
$querystring="host -t TXT AS".$_[0].".asn.cymru.com";
@asinfo= `$querystring`;
if($asinfo[0] =~ m/\"*.\|.*\|.*\|.*\|\s*(.*)\"/){
return($1);
}
else{
return(-1);
}
}
# Remove all items from the array of IP addresses
undef @ipsfree;
print "SI6 Networks IPv6 Toolkit v2.0 (Guille)\n";
print "blackhole6: A tool to find IPv6 blackholes\n";
if($> != 0){
print "Error: blackhole6 requires superuser privileges\n";
exit 1;
}
if($#ARGV < 0){
print "Error: Must specify an IPv6 address\n";
usage();
exit 1;
}
# Obtain the IPv6 addres corresponding to the specified domain name
# (This implicitly obtains the canonic address if an IPv6 address was specified)
my ( $err, @addrs ) = Socket::getaddrinfo( $ARGV[0], 0, { 'protocol' => Socket::IPPROTO_TCP, 'family' => Socket::AF_INET6 } );
if($err){
die $err;
}
my ( $err, $fline ) = Socket::getnameinfo( $addrs[0]->{addr}, Socket::NI_NUMERICHOST );
if ($err){
die $err;
}
#$fline= Socket::inet_ntop(Socket::AF_INET6, $addrs[0]->{addr});
$ehtype= "do";
$ehsize= "8";
$prototype="icmp";
if($#ARGV > 0){
if($ARGV[1] =~ m/([a-zA-Z]+):?(\d+)/){
$ehtype= lc($1);
$ehsize= $2;
}
else{
$ehtype= $ARGV[1];
}
if($#ARGV > 1){
$prototype= $ARGV[2];
if($#ARGV > 2){
$port= $ARGV[3];
}
else{
$port= "80";
}
}
}
if($prototype eq "tcp"){
$protoopt= "--tcp-flags S -a $port";
}
else{
$protoopt="";
}
if($ehtype eq "fh" || $ehtype eq "frag"){
if($ehsize < 8){
print "Error: Fragment size should be larger than or equal to 8 bytes";
exit 1;
}
elsif($ehsize > 1280){
print "Error: Fragment size should be smaller than or equal to 1280 bytes";
exit 1;
}
$payload= ($ehsize * 2) - 20;
$protoopt="-P $payload " . $protoopt;
}
if($ehtype eq "fh" || $ehtype eq "frag"){
$eh= "-y $ehsize";
}
elsif($ehtype eq "hbh"){
$eh= "-H $ehsize";
}
elsif($ehtype eq "do"){
$eh= "-u $ehsize";
}
elsif($ehtype eq "esp"){
$eh= "-p esp";
}
elsif($ehtype eq "ah"){
$eh= "-p ah";
}
else{
print "Error: Unknown EH type";
exit 1;
}
print "Tracing $ARGV[0] ($fline)...\n";
$maxhopsfree=0;
$maxhopsfreeip="";
@tcp=`path6 -d $fline -p $prototype $protoopt --rate-limit 40pps`;
if(($? >> 8) != 0){
print "blackhole6: Found issues when running path6 to the specified target";
exit(1);
}
foreach $line (@tcp){
# Discard lines that do not contain a "probe" line
if($line =~ m/\s+(\d+)\s+\((\S*)\)/){
if($1 > $maxhopsfree){
if($2 ne ""){
$maxhopsfree=$1;
$maxhopsfreeip=$2;
}
# We store the IPv6 addresses of all hops
push(@ipsfree, $2);
}
}
}
$maxhopstrouble=0;
$maxhopstroubleip="";
# XXX: This is an ugly hack. should be removed. ESP and AH should possibly be handled as EHs, rather than probe types
if($ehtype eq "esp" || $ehtype eq "ah"){
@tcp=`path6 -d $fline $eh --rate-limit 40pps`;
}else{
@tcp=`path6 -d $fline -p $prototype $protoopt $eh --rate-limit 40pps`;
}
if(($? >> 8) != 0){
print "blackhole6: Found issues when running path6 to the specified target\n";
exit(1);
}
foreach $line (@tcp){
# Discard lines that do not contain a "probe" line
if($line =~ m/\s+(\d+)\s+\((\S*)\)/){
if($1 > $maxhopstrouble){
if($2 ne ""){
$maxhopstrouble=$1;
$maxhopstroubleip= $2;
}
}
}
}
$dropip="";
$dropip2="";
for($i=0; $i< $#ipsfree; $i++){
if($ipsfree[$i] eq $maxhopstroubleip){
$dropip= $ipsfree[$i+1];
$dropip2= $ipsfree[$i+2];
last;
}
}
$flineasn= GetASN($fline);
# fline holds the destination system
if($flineasn == -1){
# print "blackhole6: Error when trying to obtain ASN for $fline\n";
# exit(1);
$flineasn= " Unknown";
}
elsif($flineasn eq ""){
$flineasn= " Unknown";
}
$maxhopsfreeasn= GetASN($maxhopsfreeip);
if($maxhopsfreeasn == -1){
# print "blackhole6: Error when trying to obtain ASN for $maxhopsfreeip\n";
# exit(1);
$maxhopsfreeasn= " Unknown";
}
elsif($maxhopsfreeasn eq ""){
$maxhopsfreeasn= " Unknown";
}
$maxhopstroubleasn= GetASN($maxhopstroubleip);
if($maxhopstroubleasn == -1){
# print "blackhole6: Error when trying to obtain ASN for $maxhopstroubleip\n";
# exit(1);
$maxhopstroubleasn= " Unknown";
}
elsif($maxhopstroubleasn eq ""){
$maxhopstroubleasn= " Unknown";
}
$ehtype_uc= uc($ehtype);
$flineorg= GetORG($flineasn);
if($flineorg == -1){
# print "blackhole6: Error when trying to obtain organization for AS$flineasn\n";
# exit(1);
$flineorg= "Unknown organization";
}
$maxhopsfreeorg= GetORG($maxhopsfreeasn);
if($maxhopsfreeorg == -1){
# print "blackhole6: Error when trying to obtain organization for AS$maxhopsfreeasn\n";
# exit(1);
$maxhopsfreeorg= "Unknown organization";
}
$maxhopstroubleorg= GetORG($maxhopstroubleasn);
if($maxhopstroubleorg == -1){
# print "blackhole6: Error when trying to obtain organization for AS$maxhopstroubleasn\n";
# exit(1);
$maxhopstroubleorg= "Unknown organization";
}
print "\nDst. IPv6 address: $fline (AS$flineasn - $flineorg)\n";
print "Last node (no EHs): $maxhopsfreeip (AS$maxhopsfreeasn - $maxhopsfreeorg) ($maxhopsfree hop(s))\n";
print "Last node ($ehtype_uc $ehsize): $maxhopstroubleip (AS$maxhopstroubleasn - $maxhopstroubleorg) ($maxhopstrouble hop(s))\n";
if($maxhopsfreeip eq $fline){
if($maxhopstroubleip eq $fline){
print "Dropping node: No packet drops\n";
}
else{
$dropasn= GetASN($dropip);
if($dropasn == -1){
# print "blackhole6: Error when trying to obtain ASN for $dropip\n";
# exit(1);
$dropasn="";
}
$droporg= "";
if($dropasn ne ""){
$droporg= GetORG($dropasn);
if($droporg == -1){
# print "blackhole6: Error when trying to obtain organization for AS$dropasn\n";
# exit(1);
$droporg= "";
}
}
if($dropasn eq ""){
$dropasn= " Unknown";
}
if($droporg eq ""){
$droporg= "Unknown";
}
if($dropip2 ne ""){
$dropasn2= GetASN($dropip2);
if($dropasn2 == -1){
# print "blackhole6: Error when trying to obtain ASN for $dropip2\n";
# exit(1);
$dropasn2="";
}
$droporg2= "";
if($dropasn2 ne ""){
$droporg2= GetORG($dropasn2);
if($droporg2 == -1){
# print "blackhole6: Error when trying to obtain organization for AS$dropasn2\n";
# exit(1);
$droporg2="";
}
}
if($dropasn2 eq ""){
$dropasn2= " Unknown";
}
if($droporg2 eq ""){
$droporg2= "Unknown";
}
}
if( ($dropip2 eq "") || ($dropasn1 eq $dropasn2)){
print "Dropping node: $dropip (AS$dropasn - $droporg)\n";
}
else{
print "Dropping node: $dropip (AS$dropasn - $droporg || AS$dropasn2 - $droporg2)\n";
}
}
}
else{
print "Dropping nodes: Packets being dropped for both the no-EH and the EH case\n";
}
|