2.1、工具简介
子域名是相对域名根来说的,如baidu.com是域名根,则1234.baidu.com为子域名不同服务级别,也就是大家常说的一级域名、二级域名、三级域名等。一个域名可有很多个子域名,但是域名解析选择不同的服务级别,可添加的子域名数量也不同。据一些平台的规则了解,免费级服务:可添加10个子域名;商业级服务 :可添加20个子域名。
子域名查询方法:
-
子域名查询工具
缺点:由于工具是人写的,难免有时候会不准确。
-
site:*根域名
缺点:由于site查询是模糊查询,所以不一定能够查处全部的二级域名;而且有些二级域名是无法收录的。
-
人为扫描工具
优点:对于一些规律性域名的网站有绝对的优势。
缺点:速度非常慢,误报率很高,用户体验很差。
关于查找和扫描子域名的作用,对于每一个搞渗透的人员来说是至关重要的。就一点:当主站无从下手的时候,你可以从C段,同IP站点下手,但往往子域名站点存在的潜在漏洞概率是非常高的。同时,这也对摸清目标的组织结构至关重要。
2.2、后端实现代码
package com.sducsrp.csrp.controller.ToolsController.SubDomain;
import com.alibaba.fastjson.JSONObject;
import com.sducsrp.csrp.common.Constants;
import com.sducsrp.csrp.common.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
@RestController
public class DomainFindController {
@RequestMapping("/DomainFind")
public @ResponseBody
Result domainfind(@RequestParam("urlP") String urlP){
String url = "https://domainhouse.buzz/query.php?token=9378409013576a0cb7c6fac863d5dfe03f0d288a&domain="+urlP;
System.out.println(url);
String return_json = sendRequest(url,"GET");
//将json转换为object
JSONObject jo = JSONObject.parseObject(return_json);
//查询到的子域名数量
String count = jo.get("count").toString();
//查询到的子域名数据
String data = jo.get("data").toString();
System.out.println(count+","+data);
Result res=new Result(Constants.CODE_200,null,count+","+data);
return res;
}
public String sendRequest(String urlParam,String requestType) {
HttpURLConnection con = null;
BufferedReader buffer = null;
StringBuffer resultBuffer = null;
try {
StringBuilder json = new StringBuilder();
URL url = new URL(urlParam);
//得到连接对象
con = (HttpURLConnection) url.openConnection();
//设置请求类型
con.setRequestMethod(requestType);
//设置请求需要返回的数据类型和字符集类型
//con.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
con.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 Edg/101.0.1210.32");
//允许写出
con.setDoOutput(true);
//允许读入
con.setDoInput(true);
//不使用缓存
con.setUseCaches(false);
//得到响应码
int responseCode = con.getResponseCode();
System.out.println(responseCode);
if(responseCode == HttpURLConnection.HTTP_OK){
//得到响应流
InputStream inputStream = con.getInputStream();
//将响应流转换成字符串
resultBuffer = new StringBuffer();
String line;
buffer = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
while ((line = buffer.readLine()) != null) {
//resultBuffer.append(line);
json.append(line);
}
return json.toString();
}
}catch(Exception e) {
e.printStackTrace();
}
return "{\"count\":0,\"data\":\"fail\n";
}
}
2.3、前端实现代码
<template>
<div style="margin-top: 100px">
<el-input v-model="urlP" style="width: 250px;margin-right: 50px" placeholder="域名"></el-input>
<el-button @click="subdomain" type="primary">Query</el-button>
</div>
<el-card style="width: 40%;height: 500px;margin-left: 30%;margin-top: 5%">
<p>返回结果:</p>
<p>{{ myresult }}</p>
</el-card>
</template>
<script>
import request from "@/utils/request";
export default {
data(){
return{
urlP:'',
myresult:''
}
},
methods:{
subdomain(){
request.get("/DomainFind",{
params:{
urlP:this.urlP
}
}).then(res =>{
this.myresult=res.data
})
}
}
}
</script>