-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
200 lines (170 loc) · 6.85 KB
/
main.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
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
// Copyright Daniel Fonseca Yarochewsky
const { writeFileSync } = require('fs');
const puppeteer = require('puppeteer');
const CDP = require('chrome-remote-interface');
async function getData(browser, fp, iter) {
try {
// create browser connection via WS (local)
let client = await CDP({
target: browser.wsEndpoint(),
local: true,
})
const {
Target,
Debugger
} = client;
const {
targetId
} = await Target.createTarget({
url: 'about:blank',
});
const {
sessionId
} = await Target.attachToTarget({
targetId: targetId,
flatten: true
});
Target.setDiscoverTargets({
discover: true
});
Target.targetCreated(async (p) => {
await Target.setAutoAttach({
autoAttach: true,
flatten: true,
waitForDebuggerOnStart: true
}, sessionId);
})
// run script on target int
Target.attachedToTarget(async (params) => {
await Runtime.evaluate({
awaitPromise: true,
expression: `(() => {
try {
const spoofProperty = (target, property, val) => {
try {
Object.defineProperty(target, property, {
enumerable: false,
configurable: false,
value: val,
writable: false,
});
} catch (error) {}
};
spoofProperty(window.navigator, 'webdriver', false)
window.chrome = {
loadTimes() {
return {};
},
csi: {},
app: {},
};
window.chrome.loadTimes.toString = function () {
return 'function () { [native code] }';
};
spoofProperty(navigator, 'userAgent',${fp.userAgent});
spoofProperty(navigator, 'appVersion', ${fp.appVersion})
spoofProperty(navigator, 'hardwareConcurrency', 8)
spoofProperty(navigator, 'platform', 'MacIntel')
spoofProperty(navigator, 'userAgentData', {
brands: [{
brand: "Not=A?Brand",
version: "99",
},
{
brand: "Chromium",
version: ${fp.agentVersion},
},
]
});
} catch {}
})()
`
}, params.sessionId)
await Runtime.runIfWaitingForDebugger(params.sessionId)
})
const {
ServiceWorker,
Emulation,
Fetch,
IndexedDB,
DOMStorage,
Page,
Runtime,
DOM,
Network,
Storage
} = client;
// activate protocol APIs
await Promise.all([
Fetch.enable({patterns: [{ requestStage: "Response" }]}, sessionId), ServiceWorker.enable(sessionId), IndexedDB.enable(sessionId), DOMStorage.enable(sessionId), Page.enable(sessionId), Runtime.enable(sessionId), DOM.enable(sessionId), Network.enable(sessionId)
]);
Debugger.paused(() => {
Debugger.resume(sessionId)
})
// intercept response to get the data we want in a nice format, instead of dealing with DOM
Fetch.requestPaused(async p => {
if (p.request.url === 'https://creepjs-api.web.app/fp' && p.responseStatusCode) {
const {body, base64Encoded} = await Fetch.getResponseBody({
requestId: p.requestId,
}, sessionId);
if (base64Encoded) {
try {
const j = JSON.parse(atob(body));
console.log("[+] writing data json");
writeFileSync(`out/data_${iter}.json`, JSON.stringify({
"trust_score": j.score,
"has_lied": j.hasLied,
"bot": j.bot,
"fingerprint": j.fingerprint,
}))
} catch {}
}
}
Fetch.continueRequest({
requestId: p.requestId,
}, sessionId)
})
// oof! navigate to the target
await Page.navigate({
url: 'https://abrahamjuliot.github.io/creepjs/'
}, sessionId);
await Page.loadEventFired(sessionId);
await Runtime.evaluate({
expression: 'document.readyState'
}, sessionId);
// wait for everything to settle
await new Promise(resolve => setTimeout(resolve, 10000))
const { data } = await Page.printToPDF({}, sessionId);
console.log("[+] writing data pdf")
writeFileSync(`out/page_${iter}.pdf`, data, 'base64')
} catch {}
}
(async () => {
const browser = await puppeteer.launch({
headless: 'new',
devtools: false,
});
// a few sample spoofing profiles here.
const profiles = [
{
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4298.0 Safari/537.36",
appVersion: "5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4298.0 Safari/537.36",
agentVersion: "88"
},
{
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4298.0 Safari/537.36",
appVersion: "5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4298.0 Safari/537.36",
agentVersion: "89"
},
{
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4298.0 Safari/537.36",
appVersion: "5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4298.0 Safari/537.36",
agentVersion: "91"
}
]
for (let i = 0; i < 3; i++) {
await getData(browser, profiles[i], i)
}
console.log('[+] all done!')
process.exit(0)
})()