zmap套装之zdns:批量查询域名ip

最近收到全球域名以后想做一个对应的ip list方便用Zgrab扫描

CSV格式:

domain,”date added”,”NS servers”,”IP address”,country


用python预处理为一行一个域名:

import csv
with open("all.csv") as cfile:
  reader = csv.DictReader(cfile)
  f = open("all.list", "w")
  for row in reader:
    print row.get("domain")
    f.write(row.get("domain") + "\n")

 

安装zmap+Go+zdns

yum install zmap git wget
wget https://storage.googleapis.com/golang/go1.10.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/usr/local/go/bin/
go get github.com/zmap/zdns/zdns
cd /usr/local/go/bin/src/github.com/zmap/zdns/zdns
go build

 

帮助:

./zdns --help

 


基本用法:
扫描一个domian list:

默认格式如下:

baidu.com
pptv.com
360.com
.....

 

A为A记录 其他记录可以相应替换 threads为线程数 建议更改linux的最大文件句柄数限制

./zdns A -input-file cn.csv -threads 100 -output-file cn.log

 

修改最大文件句柄数限制:

vi /etc/security/limits.conf

 

加入

* soft nofile 32768
* hard nofile 65536

重启

reboot

后期筛选:

输出格式:
ip,domain

python版:

import demjson
import re
xxx = open('xxx.log').read().split('\n')
count = 0;
for xx in xxx:
  js = demjson.decode(xx)
  domain = js['name']
  ip = 'NULL'
  if js['status'] == 'NOERROR':
    answers = js['data']['answers']
    for answer in answers:
      if answer['type'] == 'A':
        ip = answer['answer']
        break;
        if ip != 'NULL':
          log = ip+','+domain+'\n'
          domainlist = open('domainlist.txt','a+')
          domainlist.write(log)
          domainlist.close()
          count = count + 1
          print count

 

php版:
调用:

php ./dns.php <./cn.log >cn.list

 

<?php

if ($handler = fopen('php://stdin', 'r')) {
  while (($line = fgets($handler))) {
    try {
      $record = json_decode($line);
      $domain = $record->name;
      if (empty($record->data->answers)) {
        continue;
      }
      // Single record
      echo $record->data->answers[0]->answer . ',' . $domain . PHP_EOL;
      // Multiple records
      foreach ($record->data->answers as &$answer) {
        $answer = $answer->answer;
      }
      echo implode('/', $record->data->answers) . ',' . $domain . PHP_EOL;
    } catch (Exception $e) {
      // error parsing line as json
    }
  }
  fclose($handler);
} else {
  // error opening the dns list
}

 

单行版:

<?php

if ($handler = fopen('php://stdin', 'r')) {
  while (($line = fgets($handler))) {
    try {
      $record = json_decode($line);
      $domain = $record->name;
      if (empty($record->data->answers)) {
        continue;
      }
      // Single record
      echo $record->data->answers[0]->answer . ',' . $domain . PHP_EOL;
      // Multiple records
      // foreach ($record->data->answers as &$answer) {
      // $answer = $answer->answer;
      // }
      // echo implode('/', $record->data->answers) . ',' . $domain . PHP_EOL;
    } catch (Exception $e) {
      // error parsing line as json
    }
  }
  fclose($handler);
} else {
  // error opening the dns list
}

Reference:
https://github.com/zmap/zdns
Credit To 汪老板~

 

[wpedon id=”461″ align=”center”]

Leave a Reply

Your email address will not be published. Required fields are marked *