-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathonlyfans.js
205 lines (161 loc) · 5.32 KB
/
onlyfans.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
201
202
203
204
/**
This script demonstrates automated signin into Onlyfans account.
Replace constants "anticaptchaAPIKey", "login" and "password" with your own values.
You may need to run the script several times due to incorrect Recaptcha score.
*/
const anticaptcha = require("@antiadmin/anticaptchaofficial");
const pup = require("puppeteer");
const axios = require('axios')
//API key for anti-captcha.com
const anticaptchaAPIKey = 'YOUR_API_KEY_HERE';
//login and password for Onlyfans
const login = 'some@email.com';
const password = 'your_password_here';
const url = 'https://onlyfans.com/';
const sitekeyV3 = '6LcvNcwdAAAAAMWAuNRXH74u3QePsEzTm6GEjx0J';
const sitekeyV2 = '6LddGoYgAAAAAHD275rVBjuOYXiofr1u4pFS5lHn';
let browser = null;
let page = null;
let tokenV2 = null;
let tokenV3 = null;
let encodedPassword = null;
(async () => {
anticaptcha.setAPIKey(anticaptchaAPIKey);
const balance = await anticaptcha.getBalance();
if (balance <= 0) {
console.log('Buy your anticaptcha balance!');
return;
} else {
console.log('API key balance is '+balance+', continuing');
// anticaptcha.shutUp(); //uncomment for silent captcha recognition
}
try {
console.log('opening browser ..');
let options = {
headless: false,
ignoreHTTPSErrors: true,
devtools: true,
args: [
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process'
]
};
console.log(options);
browser = await pup.launch(options);
console.log('creating new page ..');
page = await browser.newPage();
} catch (e) {
failCallback("could not open browser: "+e);
return false;
}
page.on('console', msg => console.log('EVAL LOG:', msg.text()));
await page.setRequestInterception(true);
page.on('request', (request) => {
//abort to replace with out version of this file
if (request.url().indexOf('users/login') !== -1) {
console.log('aborting '+request.url());
encodedPassword = JSON.parse(request.postData())["encodedPassword"];
//extracting headers
const headers = request.headers();
const extractedHeaders = {};
for (const index in headers) {
if (['app-token', 'x-bc', 'sign', 'time'].indexOf(index) !== -1) {
extractedHeaders[index] = headers[index];
}
}
console.log('extracted headers:')
console.log(extractedHeaders);
request.abort();
solveRecaptchaAndLogin(extractedHeaders);
} else {
request.continue();
}
});
console.log("going to "+url);
try {
await page.goto(url, {
waitUntil: "networkidle2"
});
} catch (e) {
console.log("error loading: "+e);
}
await page.type('input[name="email"]', login);
await page.type('input[name="password"]', password);
await delay(2000);
console.log('click submit');
await page.click('form.b-loginreg__form > button.g-btn.m-rounded.m-block.m-lg.mb-0[type="submit"]');
//intercepting call to user/login from here
})();
async function solveRecaptchaAndLogin(headers) {
console.log('Solving Recaptcha Enterprise V2 .. ');
try {
tokenV2 = await anticaptcha.solveRecaptchaV2EnterpriseProxyless(
url,
sitekeyV2,
{
action: "login"
});
} catch (e) {
failCallback("could not solve V2: "+e);
return;
}
console.log("V2 token: ", tokenV2);
console.log('Solving Recaptcha Enterprise V3 .. ');
try {
tokenV3 = await anticaptcha.solveRecaptchaV3Enterprise(
url,
sitekeyV3,
0.9,
"login");
} catch (e) {
failCallback("could not solve V3: "+e);
return;
}
console.log("V3 token: ", tokenV3);
headers['content-type'] = 'application/json; charset=utf-8';
headers['accept'] = 'application/json';
const payLoad = {
"email" : login,
"password" : password,
"e-recaptcha-response" : tokenV3,
"ec-recaptcha-response" : tokenV2,
"encodedPassword" : encodedPassword
};
console.log("Submitting payload:");
console.log(payLoad);
axios.post('https://onlyfans.com/api2/v2/users/login',
payLoad,
{
headers: headers
})
.then(res => {
console.log('Login result:')
console.log(res.data);
if (res.data.userId) {
console.log('cookies:');
console.log(res.headers['set-cookie']);
successCallback()
} else {
failCallback('Recaptcha had low score')
}
})
.catch((error) => {
console.log('Login error: '+error)
failCallback(error)
})
}
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}
function successCallback() {
console.log('Successfully passed test');
console.log('closing browser .. ');
browser.close();
}
function failCallback(code) {
console.log('Failed to pass: '+code);
console.log('closing browser .. ');
browser.close();
}