forked from pedroasr/Sniffer_Wifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app24_11.js
69 lines (57 loc) · 2.27 KB
/
app24_11.js
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
require("dotenv").config();
const pcap = require("pcap");
const colors = require("colors");
const Database = require("better-sqlite3");
const db = new Database("Sniffer-Wifi.db");
const createTable =
"CREATE TABLE IF NOT EXISTS ProbeRequestFrames ('timestamp', 'snifferId', 'SSID', 'RSSI', 'MAC_origen', 'canal')";
db.exec(createTable);
const insertInto = db.prepare(
"INSERT INTO ProbeRequestFrames (timestamp, snifferId, SSID, RSSI, MAC_origen, canal) VALUES (?, ?, ?, ?, ?, ?)"
);
// ====================== SNIFFER WIFI ==================================
const snifferId = "sniffer2.4Ghz_11"; //cambiar por id del sniffer en el que se ejecute
const { parseSSID, parseType, parseFreq } = require("./functions");
var timestamp = new Date();
function init() {
console.log("iniciando capturas...");
// creamos sesion de pcap indicando interfaz (en modo monitor con airmon-ng) y filtros
// sustituir interfaz por la del dispositivo en el que se ejecuta la app
var pcapSession = pcap.createSession("wlan3", {
filter: "type mgt subtype probe-req",
});
let SSID;
let RSSI;
let MAC_origen;
let frec;
let canal;
let date;
pcapSession.on("packet", (rawPacket) => {
var length_RT = rawPacket.buf[2];
frec = parseFreq(rawPacket.buf, length_RT);
canal = (frec % 2407) / 5;
if (canal == 11) {
var packet = pcap.decode.packet(rawPacket);
var tipo = parseType(rawPacket.buf, length_RT);
SSID = parseSSID(rawPacket.buf, length_RT, tipo);
RSSI = packet.payload.fields.antenna_signal;
MAC_origen = packet.payload.ieee802_11Frame.shost.toString(16);
date = `${timestamp.getFullYear()}-${
timestamp.getMonth() + 1
}-${timestamp.getDate()} ${timestamp.getHours()}:${timestamp.getMinutes()}:${timestamp.getSeconds()}:${timestamp.getMilliseconds()}`;
var disp =
`====================\n`.green +
`===PROBE RESQUEST===\n`.green +
`====================\n`.green +
`ssid: ${SSID}\n` +
`RSSI: ${RSSI} dBm\n` +
`TimeStamp: ${date}\n` +
`MAC origen: ${MAC_origen}\n` +
`Canal: ${canal}\n`;
console.log(disp);
insertInto.run(date, snifferId, SSID, RSSI, MAC_origen, canal);
}
});
}
console.log("esperando 5 seg a que se inicie script");
setTimeout(init, 5000);