-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·83 lines (75 loc) · 1.88 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const { argv } = require('yargs')
const { spawn } = require('child_process')
const { parser } = require('stream-json')
const { streamArray } = require('stream-json/streamers/StreamArray')
const args = [
`-a duration:${parseInt(argv.d)}`,
`-Px`,
`-Y websocket`,
`-Y http`,
`-T json`,
`-e ip.src`,
`-e http.host`,
`-e http.request.full_uri`,
`-e http.user_agent`,
`-e http.cookie`,
`-e http.file_data`,
`-e http.request.method`,
`-e http.request.uri`,
`-e http.content_type`,
`-e http.response.code`,
`-e websocket.payload`
]
const { k, i, s, p, monitor } = argv
if (k) {
args.push(`-o "ssl.keylog_file: ${k}"`)
}
if (monitor) {
args.unshift(`-I -i ${i}`)
if (s && p) {
args.unshift(`-o 'uat:80211_keys:\"wpa-pwd\",\"${p}:${s}\"'`)
}
} else {
args.unshift(`-i ${i}`)
}
const captures = []
const capture = spawn('tshark', args, {
shell: true,
cwd: __dirname
})
capture.stdout
.pipe(parser())
.pipe(streamArray())
.on('data', data => {
const parsed = parseSource(data.value)
captures.push(parsed)
console.dir(parsed, {
depth: null,
colors: true
})
})
.on('end', () => {
const date = new Date().toISOString()
fs.writeFileSync(`captures/${date}.json`, JSON.stringify(captures))
})
capture.stderr.on('data', err => console.log(chalk.red(err.toString())))
const parseSource = data => {
const parsedSource = {}
const { layers } = data._source
Object.keys(layers).forEach(key => {
const suffix = key.split('.').pop()
parsedSource[suffix] = layers[key][0]
})
if (
parsedSource.file_data &&
parsedSource.content_type === 'application/json; charset=utf-8'
) {
parsedSource.file_data.replace('\\', '')
parsedSource.file_data = JSON.parse(parsedSource.file_data)
}
return parsedSource
}