This commit is contained in:
以诺书 2024-02-10 21:58:50 +08:00
parent 2046a9ce7b
commit 43ea215233
3 changed files with 85 additions and 6058 deletions

View File

@ -20,7 +20,8 @@ class Dnsc
'0010'=>'TXT',
'001c'=>'AAAA',
'0021'=>'SRV',
'00ff'=>'RAW'
'00ff'=>'RAW',
'000c'=>'PTR'
);
return $type[strtolower($hex)];
}
@ -34,7 +35,8 @@ class Dnsc
'TXT'=>'0010',
'AAAA'=>'001c',
'SRV'=>'0021',
'RAW'=>'00ff'
'RAW'=>'00ff',
'PTR'=>'000c'
);
return $hex[strtoupper($type)];
}
@ -48,8 +50,6 @@ class Dnsc
$startbyte=$startbyte+(hexdec($dlen)*2);
$dlen=substr($data,$startbyte,2);
#var_dump($dlen);
#exit();
$startbyte=$startbyte+2;
$i++;
}
@ -107,6 +107,7 @@ class Dnsc
public static function decode($buffer)
{
$data=bin2hex($buffer);
$cdata=$data;
$id=substr($data,0,4);
$flag=substr($data,4,4);
$questions=substr($data,8,4);
@ -121,10 +122,28 @@ class Dnsc
$query['qtype']=Dnsc::hex2type(substr($data,$startbyte,4));
$query['class']=substr($data,$startbyte+4,4);
$startbyte=$startbyte+8;
}if($flag!='8180'){
switch($flag){
case '8183':
$answerRRs=1;
break;
case '8182':
$answer[0]['rdata']='SERVFAIL';
$return=['id'=>$id,'flag'=>$flag,'questions'=>$questions,'answerRRs'=>$answerRRs,'authorityRRs'=>$authorityRRs,'additionalRRs'=>$additionalRRs,'answer'=>$answer,'query'=>$query];
break;
case '8185':
$answer[0]['rdata']='REFUSE';
$return=['id'=>$id,'flag'=>$flag,'questions'=>$questions,'answerRRs'=>$answerRRs,'authorityRRs'=>$authorityRRs,'additionalRRs'=>$additionalRRs,'answer'=>$answer,'query'=>$query];
break;
}
}
for($i=0;$i<hexdec($answerRRs);$i++){
if(substr($data,$startbyte,4)=='c00c'){
$answer[$i]['realname']=$query['realname'];
if(substr($data,$startbyte,2)=='c0'){
$offset=substr($data,$startbyte+2,2);
$offset_name=Dnsc::getDomain($cdata,hexdec($offset)*2);
$answer[$i]['realname']=$offset_name['name'];
$offset_endbyte=$offset_name['startbyte'];
$startbyte=$startbyte+4;
}else{
$gdomain=Dnsc::getDomain($data,$startbyte);
@ -140,6 +159,17 @@ class Dnsc
$startbyte=$startbyte+4;
$answer[$i]['rdata']=substr($data,$startbyte,hexdec($answer[$i]['rdlength'])*2);
$startbyte=$startbyte+(hexdec($answer[$i]['rdlength'])*2);
$offset_byte=stripos($answer[$i]['rdata'],'c0');
if($offset_byte!==false){
$offset=substr($answer[$i]['rdata'],$offset_byte+2,2);
$offset_name=Dnsc::getDomain($cdata,hexdec($offset)*2);
$offset_rname=$offset_name['name'];
$offset_endbyte=$offset_name['startbyte'];
$cdata=str_replace('c0'.$offset,substr($cdata,hexdec($offset)*2,$offset_endbyte-hexdec($offset)*2),$cdata);
$answer[$i]['rdata']=str_replace('c0'.$offset,substr($cdata,hexdec($offset)*2,$offset_endbyte-hexdec($offset)*2),$answer[$i]['rdata']);
}
switch($answer[$i]['qtype']){
case 'A':
$answer[$i]['rdata']=long2ip(hexdec($answer[$i]['rdata']));
@ -150,8 +180,43 @@ class Dnsc
case 'CNAME':
$answer[$i]['rdata']=Dnsc::getDomain($answer[$i]['rdata'],0)['name'];
break;
case 'MX' :
$answer[$i]['pre']=hexdec(substr($answer[$i]['rdata'],0,4));
$answer[$i]['rdata']=Dnsc::getDomain($answer[$i]['rdata'],4)['name'];
break;
case 'NS' :
$answer[$i]['rdata']=Dnsc::getDomain($answer[$i]['rdata'],0)['name'];
break;
case 'PTR':
$answer[$i]['rdata']=Dnsc::getDomain($answer[$i]['rdata'],0)['name'];
break;
case 'SOA':
$primaryNS=Dnsc::getDomain($answer[$i]['rdata'],0);
$answer[$i]['PrimaryNS']=$primaryNS['name'];
$startbyte=$primaryNS['startbyte'];
$responsiblePerson=Dnsc::getDomain($answer[$i]['rdata'],$startbyte);
$answer[$i]['ResponsiblePerson']=$responsiblePerson['name'];
$startbyte=$responsiblePerson['startbyte'];
$answer[$i]['Serial']=hexdec(substr($answer[$i]['rdata'],$startbyte,8));
$startbyte=$startbyte+8;
$answer[$i]['Refresh']=hexdec(substr($answer[$i]['rdata'],$startbyte,8));
$startbyte=$startbyte+8;
$answer[$i]['Retry']=hexdec(substr($answer[$i]['rdata'],$startbyte,8));
$startbyte=$startbyte+8;
$answer[$i]['Expire']=hexdec(substr($answer[$i]['rdata'],$startbyte,8));
$startbyte=$startbyte+8;
$answer[$i]['Minimum']=hexdec(substr($answer[$i]['rdata'],$startbyte,8));
break;
case 'AAAA':
$answer[$i]['rdata']=inet_ntop(hex2bin($answer[$i]['rdata']));
break;
}
}
if($flag=='8183'){
$authorityRRs=0;
$answer[0]['ptr']=$answer[0];
$answer[0]['rdata']='NXDOMAIN';
}
$return=['id'=>$id,'flag'=>$flag,'questions'=>$questions,'answerRRs'=>$answerRRs,'authorityRRs'=>$authorityRRs,'additionalRRs'=>$additionalRRs,'answer'=>$answer,'query'=>$query];
return $return;
}

View File

@ -44,6 +44,17 @@ class Client
}
$this->data=$hex.'00';
return $this;
}
public function ptr(string $ip){
$iparray=array_reverse(explode('.',$ip));
$domain=join('.',$iparray).'.in-addr.arpa';
$domain=explode('.',$domain);
$hex='';
foreach($domain as $value){
$hex.=str_pad(dechex(strlen($value)),2,"0",STR_PAD_LEFT).bin2hex($value);
}
$this->data=$hex.'00';
return $this;
}
public function server($ip){
$this->server=$ip;
@ -54,18 +65,8 @@ $task = new Worker();
$task->onWorkerStart = function($task)
{
$query=new Client;
$query->server('8.8.8.8')->domain('77666.laysense.com')->query('NS');
$query->server('8.8.8.8')->domain('cnnic.laysense.cn')->query('A');
#PTR记录请求方式$query->server('8.8.8.8')->ptr('119.29.29.29')->query('PTR');
};
Worker::runAll();
?>
# A
# MX 可用未解析(C00C\C015\C030)
# TXT
# CNAME
# PTR # 29.29.29.119.in-addr.arpa
# NS 未解析
# 无记录的写法
?>

File diff suppressed because it is too large Load Diff