-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathFofa_view.js
More file actions
269 lines (246 loc) · 13.2 KB
/
Copy pathFofa_view.js
File metadata and controls
269 lines (246 loc) · 13.2 KB
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
// ==UserScript==
// @name FOFA view
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Send the current website to FOFA
// @author 0cat
// @match http://*/*
// @match https://*/*
// @grant GM_registerMenuCommand
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @connect *
// @license MIT
// ==/UserScript==
GM_registerMenuCommand("FOFA Login", openLoginForm, "l");
GM_registerMenuCommand("FOFA 识别结果", FofaFind, "s");
// 创建自定义输入表单
function openLoginForm() {
const body = document.getElementsByTagName('body')[0];
const loginDiv = document.createElement('div');
loginDiv.innerHTML = `
<div style="position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); background-color:white; padding:20px; border-radius:10px; box-shadow:0 0 10px rgba(0, 0, 0, 0.5); z-index:100000;">
<h3>Login to FOFA</h3>
<label>Username (一般是邮箱):
<input type="text" id="fofaUsername" style="width:100%;" placeholder="e.g., 1234567890" />
</label><br/><br/>
<label>Fofa Key:
<input type="password" id="fofaKey" style="width:100%;" />
</label><br/><br/>
<button id="loginSubmit">Submit</button>
<button id="loginCancel">Cancel</button>
</div>
`;
body.appendChild(loginDiv);
document.getElementById('loginSubmit').onclick = function() {
const username = document.getElementById('fofaUsername').value;
const FofaKey = document.getElementById('fofaKey').value;
if (username && FofaKey) {
GM_setValue("username", username);
GM_setValue("FofaKey", FofaKey);
alert("Login successful!");
body.removeChild(loginDiv); // Remove form after login
} else {
alert("Please fill in both fields.");
}
};
document.getElementById('loginCancel').onclick = function() {
body.removeChild(loginDiv);
};
}
// 识别功能
function FofaFind() {
var username = GM_getValue("username");
var FofaKey = GM_getValue("FofaKey");
if (!username || !FofaKey) {
console.error("No username or FofaKey found");
return;
}
const body = document.getElementsByTagName('body')[0];
const div = document.createElement('div');
div.innerHTML = `<div style="font-size:14px;color:rgba(0,0,0,0.65);box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1) ;background-color: #fff;border-radius: 5px;border: 1px solid #ebebeb;left:20px;top:20px;position: fixed;z-index: 1000000">
<div style="display: flex;justify-content: flex-end;margin-right: 8px;">
<div id="expandBtn" style="color:rgb(24, 36, 127);cursor: pointer;margin-left: 8px;margin-top: 4px;font-size: 12px;margin-bottom: 4px;display: none">FOFA展开</div>
<div id="hideBtn" style="cursor: pointer;font-size: 12px;margin-top: 2px;color:rgb(96, 98, 102);">隐藏</div>
</div>
<div id="contentDiv" class="plugs_content_fofa" style="padding-bottom: 10px;">
<div style="margin-left: 4px;border-radius: 2px;display: inline-block;padding: 8px;padding-right: 40px;">
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">RDAP_IP_CIDR:</div>
<div class="rdap_cidr" style="word-wrap:break-word;word-break:normal;overflow: hidden;">N/A</div>
</div>
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">RDAP_描述:</div>
<div class="rdap_description" style="word-wrap:break-word;word-break:normal;overflow: hidden;">N/A</div>
</div>
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">地区:</div>
<div class="area_fofa" style="word-wrap:break-word;word-break:normal;overflow: hidden;">null</div>
</div>
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">运营商和org:</div>
<div class="org_fofa" style="word-wrap:break-word;word-break:normal;overflow: hidden;">null</div>
</div>
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">ICP:</div>
<div class="icp_fofa" style="word-wrap:break-word;word-break:normal;overflow: hidden;">null</div>
</div>
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">协议:</div>
<div class="protocol_fofa" style="word-wrap:break-word;word-break:normal;overflow: hidden;">null</div>
</div>
<div style="margin-bottom: 4px;display: flex">
<div style="margin-right: 6px;white-space: nowrap">端口:</div>
<div class="port_fofa">null</div>
</div>
</div>
<div class="copy-text-data" style="cursor: pointer;display: flex;margin-top: 8px;border-top:1px solid #ebebeb;justify-content: flex-end;padding-right: 4px;">复制</div>
<ul class="demo1" style="width: 100%;max-height: 350px;max-width: 600px; overflow: auto;">
<div style="display: flex;margin-top: 8px;">
<div style="padding: 0 10px;">
<div class="table_title_fofa">null</div>
</div>
<div style="padding: 0 10px;">
<div class="table_protocol_fofa">null</div>
</div>
<div style="padding: 0 10px;">
<div class="table_port_fofa">null</div>
</div>
<div style="padding: 0 10px;">
<div class="table_server_fofa">null</div>
</div>
<div style="padding: 0 10px;">
<div class="table_url_fofa">
<div>
<a href="" class="url1" style="color: #1890ff;text-decoration: none">url</a>
</div>
</div>
</div>
</div>
</ul>
</div>
</div>`;
body.appendChild(div);
// 隐藏/展开功能
const hideBtn = document.getElementById('hideBtn');
const expandBtn = document.getElementById('expandBtn');
const contentDiv = document.getElementById('contentDiv');
hideBtn.onclick = function() {
contentDiv.style.display = 'none';
hideBtn.style.display = 'none';
expandBtn.style.display = 'block';
};
expandBtn.onclick = function() {
contentDiv.style.display = 'block';
hideBtn.style.display = 'block';
expandBtn.style.display = 'none';
};
var target = window.location.hostname;
var isValidIP_reg = /(\d{1,3}\.){3}\d{1,3}/;
// 如果是 IP,则执行 RDAP 查询
if (isValidIP_reg.test(target)) {
// 发起 RDAP 请求
var rdap_url = `https://rdap.apnic.net/ip/${target}`;
GM_xmlhttpRequest({
method: "GET",
url: rdap_url,
onload: function(xhr) {
if (xhr.status !== 200) {
console.error("RDAP Request failed, status code:", xhr.status);
return;
}
const rdap_res = JSON.parse(xhr.responseText);
// 提取 CIDR 和描述
const handle = rdap_res.handle;
const cidr = rdap_res.cidr0_cidrs[0].v4prefix + "/" + rdap_res.cidr0_cidrs[0].length;
const description = rdap_res.remarks[0].description[0] || 'N/A';
// 将 CIDR 和描述信息填充到小卡片中
const rdap_cidr_element = document.getElementsByClassName('rdap_cidr')[0];
const rdap_description_element = document.getElementsByClassName('rdap_description')[0];
rdap_cidr_element.textContent = cidr || 'N/A';
rdap_description_element.textContent = description || 'N/A';
},
onerror: function(xhr) {
console.error("RDAP Request error:", xhr);
}
});
}
var Fofa_url = "https://fofa.info/api/v1/search/all?email=" + username + "&key=" + FofaKey + "&fields=country,province,city,isp,as_organization,ip,title,protocol,port,host,server,icp&qbase64=";
var search, url;
if (isValidIP_reg.test(target)) {
search = btoa('ip=="' + target + '"');
url = Fofa_url + search;
} else {
search = btoa('host=="' + target + '"');
url = Fofa_url + search;
}
if (!url) {
console.error("URL generation failed.");
return;
}
// 发起 FOFA 查询请求
try {
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(xhr) {
if (xhr.status !== 200) {
console.error("FOFA Request failed, status code:", xhr.status);
return;
}
const res = JSON.parse(xhr.responseText);
const target_data = res.results || [];
if (target_data.length === 0) {
return;
}
// 获取 HTML 元素
const area = document.getElementsByClassName('area_fofa')[0];
const org = document.getElementsByClassName('org_fofa')[0];
const protocol = document.getElementsByClassName('protocol_fofa')[0];
const port = document.getElementsByClassName('port_fofa')[0];
const icp = document.getElementsByClassName('icp_fofa')[0];
const table_title = document.getElementsByClassName('table_title_fofa')[0];
const table_protocol = document.getElementsByClassName('table_protocol_fofa')[0];
const table_port = document.getElementsByClassName('table_port_fofa')[0];
const table_server = document.getElementsByClassName('table_server_fofa')[0];
const table_url = document.getElementsByClassName('table_url_fofa')[0];
// 遍历数据并展示到页面
let title_innerHTML = `<div style='white-space: nowrap'>标题</div>`;
let protocol_innerHTML = `<div style='white-space: nowrap'>协议</div>`;
let port_innerHTML = `<div style='white-space: nowrap'>端口</div>`;
let server_innerHTML = `<div style='white-space: nowrap'>server</div>`;
let url_innerHTML = `<div style='white-space: nowrap'>url</div>`;
target_data.forEach(item => {
title_innerHTML += `<div style="white-space: nowrap;height: 20px">${item[6] || 'N/A'}</div>`;
protocol_innerHTML += `<div style="white-space: nowrap;height: 20px">${item[7] || 'N/A'}</div>`;
if (item[7] === "http" || item[7] === "https") {
var urlNoProtocol = item[9].replace(/^https?\:\/\//i, "");
var urlProtocol = item[7] + "://" + urlNoProtocol;
url_innerHTML += `<div style="white-space: nowrap;height: 20px"><a href="${urlProtocol}" target='_blank' style="color: #1890ff;text-decoration: none">${urlProtocol}</a></div>`;
} else {
url_innerHTML += `<div style="white-space: nowrap;height: 20px"><a href="" target='_blank' style="color: #1890ff;text-decoration: none"></a></div>`;
}
port_innerHTML += `<div style="white-space: nowrap;height: 20px">${item[8] || 'N/A'}</div>`;
server_innerHTML += `<div style="white-space: nowrap;height: 20px">${item[10] || 'N/A'}</div>`;
});
table_title.innerHTML = title_innerHTML;
table_protocol.innerHTML = protocol_innerHTML;
table_port.innerHTML = port_innerHTML;
table_server.innerHTML = server_innerHTML;
table_url.innerHTML = url_innerHTML;
const target_location = target_data[0] || {};
area.textContent = [target_location[0] || '', target_location[1] || '', target_location[2] || ''].filter(item => item).join('-') || 'N/A';
org.textContent = [target_location[3] || '', target_location[4] || ''].filter(item => item).join(',') || 'N/A';
icp.textContent = Array.from(new Set(target_data.filter(item => item[11]).map(item => item[11]))).join(',') || 'N/A';
protocol.textContent = Array.from(new Set(target_data.filter(item => item[7]).map(item => item[7]))).join(',') || 'N/A';
port.textContent = Array.from(new Set(target_data.filter(item => item[8]).map(item => item[8]))).join(',') || 'N/A';
},
onerror: function(xhr) {
console.error("FOFA Request error:", xhr);
}
});
} catch (e) {
console.error("Error while sending request:", e);
}
}