Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64 encoding for some image packets and update node-sass #41

Merged
merged 2 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions app/src/renderer/network-events/sniffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Sniffer extends EventEmitter {
pktArr = pktArr.concat(pkt[x])
}

var arpRequest = new Buffer(pktArr)
var arpRequest = Buffer.from(pktArr)
this.session.inject(arpRequest)
}

Expand Down Expand Up @@ -225,7 +225,9 @@ class Sniffer extends EventEmitter {
return false
}

const rBuffer = tcp.data
const r = tcp.data.toString('utf-8')

if (r.indexOf('Content-Length') === -1 &&
r.indexOf('Host') === -1 &&
r.indexOf('Content-Type') === -1) {
Expand All @@ -234,7 +236,7 @@ class Sniffer extends EventEmitter {

const httpr = r.split('\r\n')
try {
return { ts: ts, eth: eth, ip: ip, tcp: tcp, payload: this.parseHTTP(httpr), raw: r }
return { ts: ts, eth: eth, ip: ip, tcp: tcp, payload: this.parseHTTP(httpr, rBuffer), raw: r }
} catch (err) {
this.error(err)
return false
Expand All @@ -259,7 +261,26 @@ class Sniffer extends EventEmitter {
return ipArr
}

parseHTTP (headers) {
findFileSignature (arr, val, val2, val3) {
let indexes = []
for (let i = 0; i < arr.length; i++) {
if (arr[i] === val) {
indexes.push(i)
}
}
// Look for the first three decimal values of the image file signature
// If found, convert to base64
for (let j = 0; j < indexes.length; j++) {
if (arr[indexes[j] + 1] === val2) {
if (arr[indexes[j] + 2] === val3) {
const sliced = arr.slice(indexes[j]).toString('base64')
return sliced
}
}
}
}

parseHTTP (headers, buffer) {
const packet = {}
packet.http = true
packet.host = ''
Expand Down Expand Up @@ -303,10 +324,26 @@ class Sniffer extends EventEmitter {
// packet.contentType = ''
// }
// headers.pop()
const lastline = headers.splice(headers.length - 2, headers.length - 1)
packet.payload = lastline
if (buffer.indexOf('Content-Type: image') !== -1) {
if (buffer.indexOf('png') !== -1) {
const fileSignature = [137, 80, 78]
packet.payload = this.findFileSignature(buffer, fileSignature[0], fileSignature[1], fileSignature[2])
}
if (buffer.indexOf('jpeg') !== -1) {
const fileSignature = [255, 216, 255]
packet.payload = this.findFileSignature(buffer, fileSignature[0], fileSignature[1], fileSignature[2])
}
if (buffer.indexOf('gif') !== -1) {
const fileSignature = [71, 73, 70]
packet.payload = this.findFileSignature(buffer, fileSignature[0], fileSignature[1], fileSignature[2])
}
} else {
const lastline = headers.splice(headers.length - 1)
packet.payload = lastline
}
return packet
}

}

export default new Sniffer()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^2.0.1",
"mocha": "^3.0.2",
"node-sass": "^4.5.0",
"node-sass": "^4.9.0",
"require-dir": "^0.3.0",
"sass-loader": "^6.0.3",
"spectron": "^3.4.0",
Expand Down