-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
crtsh.php
executable file
·107 lines (84 loc) · 2.01 KB
/
crtsh.php
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
#!/usr/bin/php
<?php
// function isSubdomain( $str )
// {
// $str = strtolower( $str );
// if( preg_match('/[^0-9a-z_\-\.]/',$str) || preg_match('/[^0-9a-z]/',$str[0]) || preg_match('/[^a-z]/',$str[strlen($str)-1]) || substr_count($str,'.')<2 ) {
// return false;
// } else {
// return true;
// }
// }
// function extractDomain( $host )
// {
// $tmp = explode( '.', $host );
// $cnt = count( $tmp );
// $domain = $tmp[$cnt-1];
// for( $i=$cnt-2 ; $i>=0 ; $i-- ) {
// $domain = $tmp[$i].'.'.$domain;
// if( strlen($tmp[$i]) > 3 ) {
// break;
// }
// }
// return $domain;
// }
function usage( $err=null ) {
echo 'Usage: '.$_SERVER['argv'][0]." <domain>\n";
if( $err ) {
echo 'Error: '.$err."\n";
}
exit();
}
if( $_SERVER['argc'] != 2 ) {
usage();
}
$t_host = [];
$domain = $_SERVER['argv'][1];
$src = 'https://crt.sh/?output=json&q=%25.'.$domain;
$json = file_get_contents( $src );
if( strlen($json) ) {
$t_json = json_decode( $json, true);
}
// var_dump($t_json);
$t_subs = [];
foreach( $t_json as $sub ) {
if( isset($sub['name_value']) && !in_array($sub['name_value'],$t_subs)) {
$t_subs[] = $sub['name_value'];
}
}
sort($t_subs);
foreach( $t_subs as $s ) {
echo $s."\n";
}
exit();
// $doc = new DOMDocument();
// $doc->preserveWhiteSpace = false;
// @$doc->loadHTML( $html );
// $xpath = new DOMXPath( $doc );
// $table = $xpath->query( '//table' );
// //var_dump($table->length);
// if( $table->length >= 3 )
// {
// $row = $xpath->query( 'tr', $table[2] );
// //var_dump( $row->length );
// foreach( $row as $r ) {
// $column = $xpath->query( 'td', $r );
// //var_dump( $column->length );
// if( $column->length == 6 ) {
// $h = str_replace( '*.', '', trim($column[4]->nodeValue) );
// if( isSubdomain($h) && extractDomain($h) == $domain ) {
// $t_host[] = $h;
// }
// }
// }
// }
// if( count($t_host) )
// {
// $t_host = array_unique( $t_host );
// sort( $t_host );
// foreach( $t_host as $h ) {
// echo $h."\n";
// }
// }
// exit( 0 );
?>