diff --git a/README.md b/README.md index c9ea2ea..b93fb86 100644 --- a/README.md +++ b/README.md @@ -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) @@ -980,6 +981,36 @@ console.log(err); }) ``` +### Imperva (Incapsula) + +[API method description.](https://2captcha.com/2captcha-api#imperva) + +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 diff --git a/examples/imperva.js b/examples/imperva.js new file mode 100644 index 0000000..089ae7f --- /dev/null +++ b/examples/imperva.js @@ -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); +}) diff --git a/package-lock.json b/package-lock.json index 5fa74cc..acf3f3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@2captcha/captcha-solver", - "version": "1.3.8", + "version": "1.3.9", "license": "MIT", "dependencies": { "node-fetch": "^2.6.1" diff --git a/package.json b/package.json index 220f8bf..8c61c79 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "TSPD", "Basilisk", "Hunt", - "Drag and Drop" + "Drag and Drop", + "Imperva" ], "scripts": { "build": "tsc && node ./dist/index.js", diff --git a/src/structs/2captcha.ts b/src/structs/2captcha.ts index e42bccb..a5d8930 100644 --- a/src/structs/2captcha.ts +++ b/src/structs/2captcha.ts @@ -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 @@ -2814,6 +2824,77 @@ public async dragAndDrop(params: paramsDragAndDrop): Promise { } } +/** + * ### 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} 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 { + 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. * diff --git a/src/utils/checkCaptchaParams.ts b/src/utils/checkCaptchaParams.ts index 4d8b3f9..8345c69 100644 --- a/src/utils/checkCaptchaParams.ts +++ b/src/utils/checkCaptchaParams.ts @@ -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'] @@ -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. @@ -168,6 +169,9 @@ const getRequiredFildsArr = (method: string):Array => { case "drag_drop": requiredFieldsArr = dragAndDropRequiredFields break; + case "incapsula": + requiredFieldsArr = impervaRequiredFields + break; } return requiredFieldsArr } diff --git a/src/utils/renameParams.ts b/src/utils/renameParams.ts index 246e03e..4d2e720 100644 --- a/src/utils/renameParams.ts +++ b/src/utils/renameParams.ts @@ -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) {