zhou12189108 commited on
Commit
452753f
1 Parent(s): 48504a3

Upload 2 files

Browse files
Files changed (2) hide show
  1. api.py +11 -1
  2. hcaptcha_solver.py +3 -4
api.py CHANGED
@@ -1,7 +1,10 @@
 
1
  import os
2
  import asyncio
3
  import time
4
  import multiprocessing
 
 
5
  from flask import Flask, jsonify, request, logging as flog
6
  from flask_limiter.util import get_remote_address
7
  import hcaptcha_solver
@@ -20,6 +23,12 @@ def get_ipaddr():
20
  handler = flog.default_handler
21
 
22
 
 
 
 
 
 
 
23
  def get_token():
24
  default_token = "init_token"
25
  if os.path.exists("token"):
@@ -37,6 +46,7 @@ def check_request(required_data, data):
37
  return False
38
  return True
39
 
 
40
  @app.errorhandler(429)
41
  def rate_limit_exceeded(e):
42
  print(get_remote_address())
@@ -72,7 +82,7 @@ def solver_captcha():
72
  data = request.get_json(force=True, silent=True)
73
  if not check_request(require_data, data):
74
  return jsonify(msg="Unauthorized Request"), 403
75
- return asyncio.run(hcaptcha_solver.bytedance(data["host"], data["site_key"]))
76
 
77
 
78
  app.run(host="0.0.0.0", port=7860)
 
1
+ import hashlib
2
  import os
3
  import asyncio
4
  import time
5
  import multiprocessing
6
+ import uuid
7
+
8
  from flask import Flask, jsonify, request, logging as flog
9
  from flask_limiter.util import get_remote_address
10
  import hcaptcha_solver
 
23
  handler = flog.default_handler
24
 
25
 
26
+ def generate_uuid():
27
+ unique_identifier = str(uuid.uuid4())
28
+ hashed_string = hashlib.sha256(unique_identifier.encode()).hexdigest()
29
+ return hashed_string
30
+
31
+
32
  def get_token():
33
  default_token = "init_token"
34
  if os.path.exists("token"):
 
46
  return False
47
  return True
48
 
49
+
50
  @app.errorhandler(429)
51
  def rate_limit_exceeded(e):
52
  print(get_remote_address())
 
82
  data = request.get_json(force=True, silent=True)
83
  if not check_request(require_data, data):
84
  return jsonify(msg="Unauthorized Request"), 403
85
+ return asyncio.run(hcaptcha_solver.bytedance(data["host"], data["site_key"], generate_uuid()))
86
 
87
 
88
  app.run(host="0.0.0.0", port=7860)
hcaptcha_solver.py CHANGED
@@ -9,7 +9,6 @@ from hcaptcha_challenger.agents import AgentT, Malenia
9
  solver.install(upgrade=True)
10
 
11
  # Save dataset to current working directory
12
- user_data_dir = Path(__file__).parent.joinpath("user_data_dir")
13
  context_dir = user_data_dir.joinpath("context")
14
  tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
15
 
@@ -134,14 +133,14 @@ async def route_continuation(route, request, host, sitekey):
134
  await route.continue_()
135
 
136
 
137
- async def bytedance(host, sitekey):
138
  # playwright install firefox --with-deps
139
  async with async_playwright() as p:
140
  context = await p.firefox.launch_persistent_context(
141
- user_data_dir=context_dir,
142
  headless=True,
143
  locale="en-US"
144
  )
145
  await Malenia.apply_stealth(context)
146
  token = await hit_challenge(context, host, sitekey)
147
- return token
 
9
  solver.install(upgrade=True)
10
 
11
  # Save dataset to current working directory
 
12
  context_dir = user_data_dir.joinpath("context")
13
  tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
14
 
 
133
  await route.continue_()
134
 
135
 
136
+ async def bytedance(host, sitekey, user_data_dirs):
137
  # playwright install firefox --with-deps
138
  async with async_playwright() as p:
139
  context = await p.firefox.launch_persistent_context(
140
+ user_data_dir=Path(__file__).parent.joinpath(user_data_dirs),
141
  headless=True,
142
  locale="en-US"
143
  )
144
  await Malenia.apply_stealth(context)
145
  token = await hit_challenge(context, host, sitekey)
146
+ return token