Skip to content
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
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Examples of API requests for different captcha types are available on the [JavaS
- [Basilisk](#basilisk)
- [Hunt](#hunt)
- [Drag and Drop](#drag-and-drop)
- [Imperva (Incapsula)](#imperva-incapsula)
- [Other methods](#other-methods)
- [goodReport](#goodreport)
- [badReport](#badreport)
Expand Down Expand Up @@ -980,6 +981,36 @@ console.log(err);
})
```

### Imperva (Incapsula)

<sup>[API method description.](https://2captcha.com/2captcha-api#imperva)</sup>

Cookie-based method for automatic solving of Imperva (Incapsula) captcha. Returns cookies that can be used to access the target page.

Required parameters: `pageurl`, `incapsulaScriptUrl`, `incapsulaCookies`, `proxy`, `proxytype`.

**Important:** a proxy is required for this captcha type. Some parameters are generated dynamically and may differ with each load of a page protected by Imperva (Incapsula).

The result (`data`) is an object. The cookies from `data.domains` must be passed to the target site. If `data.headers["User-Agent"]` is present, use the same User-Agent in requests to the site.

```js
solver.imperva({
pageurl: "https://example.com/login",
incapsulaScriptUrl: "/_Incapsula_Resource?SWUDNSAI=31&xinfo=1",
incapsulaCookies: "visid_incap_123456=sample; incap_ses_123_123456=sample",
reese84UrlEndpoint: "https://example.com/_Incapsula_Resource?reese84=1",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
proxy: "login:password@1.2.3.4:8080",
proxytype: "HTTP"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

## Other methods

### goodReport
Expand Down
20 changes: 20 additions & 0 deletions examples/imperva.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

solver.imperva({
pageurl: "https://micropact.co.henry.ga.us/MagistrateCourtsCMWS/",
incapsulaScriptUrl: "/_Incapsula_Resource?SWJIYLWA=719d34d31c8e3a6e6fffd425f7e032f3",
incapsulaCookies: "visid_incap_2705870=vgmigpy2QGOqNJZc8KM/jo8d12oAAAAAQUIPAAAAAABqX D/H/MsR3nFhvJcxDlO; incap_ses_1021_2705870=yu3CZ8I9KyLXl1KCJ1IrDo8d12oAAAAAt/QGabcviDNe9aI4O/eiDg==",
// reese84UrlEndpoint: "https://example.com/_Incapsula_Resource?reese84=1",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
proxy: "ub6900fef552505bc-zone-custom-region-ca-session-jUrtu0yco-sessTime-120:ubbT@eu.proxy.2captcha.com:2334",
proxytype: "HTTP"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"TSPD",
"Basilisk",
"Hunt",
"Drag and Drop"
"Drag and Drop",
"Imperva"
],
"scripts": {
"build": "tsc && node ./dist/index.js",
Expand Down
81 changes: 81 additions & 0 deletions src/structs/2captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ export interface paramsDragAndDrop {
pingback?: string,
}

export interface paramsImperva {
pageurl: string,
incapsulaScriptUrl: string,
incapsulaCookies: string,
proxy: string,
proxytype: string,
userAgent?: string,
reese84UrlEndpoint?: string,
}

/**
* An object containing properties of the captcha solution.
* @typedef {Object} CaptchaAnswer
Expand Down Expand Up @@ -2814,6 +2824,77 @@ public async dragAndDrop(params: paramsDragAndDrop): Promise<CaptchaAnswer> {
}
}

/**
* ### Solves Imperva (Incapsula) Captcha
*
* Cookie-based method for automatic solving of Imperva (Incapsula) captcha.
* [Read more about Imperva (Incapsula) captcha](https://2captcha.com/2captcha-api#imperva).
*
* **Important:** a proxy is required for this captcha type. Some parameters are generated dynamically
* and may differ with each load of a page protected by Imperva (Incapsula).
*
* @param {{ pageurl, incapsulaScriptUrl, incapsulaCookies, proxy, proxytype, userAgent, reese84UrlEndpoint }} params Parameters Imperva (Incapsula) Captcha as an object.
* @param {string} params.pageurl The full URL of the page with the captcha.
* @param {string} params.incapsulaScriptUrl The URL or path of the Incapsula script, for example `/_Incapsula_Resource?...`.
* @param {string} params.incapsulaCookies Incapsula cookies from the site before solving the task.
* @param {string} params.proxy Proxy in format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
* @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
* @param {string} params.userAgent Optional. The browser User-Agent used to open the page.
* @param {string} params.reese84UrlEndpoint Optional. The Reese84 endpoint, if required for a specific site.
*
* @returns {Promise<CaptchaAnswer>} The result from the solve. `data` is an object with cookies in `data.domains` that must be passed to the target site.
* If `data.headers["User-Agent"]` is present, use the same User-Agent in requests to the site.
* @throws APIError
*
* @example
* solver.imperva({
* pageurl: "https://example.com/login",
* incapsulaScriptUrl: "/_Incapsula_Resource?SWUDNSAI=31&xinfo=1",
* incapsulaCookies: "visid_incap_123456=sample; incap_ses_123_123456=sample",
* reese84UrlEndpoint: "https://example.com/_Incapsula_Resource?reese84=1",
* userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
* proxy: "login:password@1.2.3.4:8080",
* proxytype: "HTTP"
* })
* .then((res) => {
* console.log(res);
* })
* .catch((err) => {
* console.log(err);
* })
*/
public async imperva(params: paramsImperva): Promise<CaptchaAnswer> {
params = renameParams(params)

checkCaptchaParams(params, "incapsula")

const payload = {
...this.defaultPayload,
...params,
method: "incapsula",
};

const response = await fetch(this.in, {
body: JSON.stringify(payload),
method: "post",
headers: { "Content-Type": "application/json" }
})
const result = await response.text()

let data;
try {
data = JSON.parse(result)
} catch {
throw new APIError(result)
}

if (data.status == 1) {
return this.pollResponse(data.request)
} else {
throw new APIError(data.request)
}
}

/**
* Reports a captcha as correctly solved.
*
Expand Down
6 changes: 5 additions & 1 deletion src/utils/checkCaptchaParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Captcha methods for which parameter checking is available
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid',
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd', 'basilisk', 'hunt', 'drag_drop']
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd', 'basilisk', 'hunt', 'drag_drop', 'incapsula']

// Names of required fields that must be contained in the parameters captcha
const recaptchaRequiredFields = ['pageurl','googlekey']
Expand Down Expand Up @@ -43,6 +43,7 @@ const tspdRequiredFields = ['pageurl', 'tspd_cookie', 'html_page_base64',
const basiliskRequiredFields = ['pageurl', 'sitekey']
const huntRequiredFields = ['pageurl', 'api_get_lib']
const dragAndDropRequiredFields = ['body', 'images']
const impervaRequiredFields = ['pageurl', 'incapsula_script_url', 'incapsula_cookies', 'proxy', 'proxytype']

/**
* Getting required arguments for a captcha.
Expand Down Expand Up @@ -168,6 +169,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
case "drag_drop":
requiredFieldsArr = dragAndDropRequiredFields
break;
case "incapsula":
requiredFieldsArr = impervaRequiredFields
break;
}
return requiredFieldsArr
}
Expand Down
7 changes: 6 additions & 1 deletion src/utils/renameParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export default function renameParams(params: any) {

// TSPD
"tspdCookie": "tspd_cookie",
"htmlPageBase64": "html_page_base64"
"htmlPageBase64": "html_page_base64",

// Imperva (Incapsula)
"incapsulaScriptUrl": "incapsula_script_url",
"incapsulaCookies": "incapsula_cookies",
"reese84UrlEndpoint": "reese84_url_endpoint"
}

for(let key in params) {
Expand Down