Update app.py
Browse files
app.py
CHANGED
|
@@ -3,61 +3,65 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
import httpx
|
| 5 |
import uvicorn
|
| 6 |
-
import re
|
| 7 |
import base64
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 11 |
RS_GET_URL = "https://rscaptcha.com/captcha/v5/get"
|
| 12 |
RS_VERIFY_URL = "https://rscaptcha.com/captcha/v5/verify"
|
| 13 |
|
| 14 |
-
def
|
| 15 |
-
# Decode Base64
|
| 16 |
bg_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', bg_b64))
|
| 17 |
target_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', target_b64))
|
| 18 |
|
| 19 |
bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
|
| 20 |
target_img = cv2.imdecode(np.frombuffer(target_bytes, np.uint8), cv2.IMREAD_COLOR)
|
| 21 |
|
| 22 |
-
# Edge Detection
|
| 23 |
bg_gray = cv2.cvtColor(bg_img, cv2.COLOR_BGR2GRAY)
|
| 24 |
target_gray = cv2.cvtColor(target_img, cv2.COLOR_BGR2GRAY)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
_, _, _, max_loc = cv2.minMaxLoc(res)
|
|
|
|
| 30 |
return float(max_loc[0])
|
| 31 |
|
| 32 |
@app.post("/bypass")
|
| 33 |
-
async def
|
| 34 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 35 |
try:
|
| 36 |
-
# 1
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
'version': 'v5'
|
| 41 |
-
})
|
| 42 |
-
data = get_res.json()
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
captcha_key = data['data']['captcha_key']
|
| 45 |
display_y = data['data']['display_y']
|
| 46 |
|
| 47 |
-
# 2
|
| 48 |
-
distance =
|
| 49 |
-
data['data']['tile_image_base64'])
|
| 50 |
|
| 51 |
-
# 3
|
| 52 |
-
#
|
| 53 |
response_val = f"{distance},{display_y}"
|
| 54 |
|
| 55 |
-
|
| 56 |
-
'app_id':
|
| 57 |
-
'public_key':
|
| 58 |
-
'version':
|
| 59 |
-
'token':
|
| 60 |
-
'response':
|
| 61 |
}
|
| 62 |
|
| 63 |
headers = {
|
|
@@ -65,18 +69,19 @@ async def bypass_rscaptcha(app_id: str, public_key: str):
|
|
| 65 |
"Referer": "https://99faucet.com/"
|
| 66 |
}
|
| 67 |
|
| 68 |
-
|
| 69 |
-
v_data =
|
| 70 |
|
|
|
|
| 71 |
if v_data.get('data') == 'ok':
|
| 72 |
return {
|
| 73 |
"status": "success",
|
| 74 |
"rscaptcha_token": captcha_key,
|
| 75 |
-
"rscaptcha_response": v_data.get('result') or v_data
|
| 76 |
}
|
| 77 |
else:
|
| 78 |
return {"status": "fail", "details": v_data}
|
| 79 |
-
|
| 80 |
except Exception as e:
|
| 81 |
return {"status": "error", "message": str(e)}
|
| 82 |
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import httpx
|
| 5 |
import uvicorn
|
|
|
|
| 6 |
import base64
|
| 7 |
+
import re
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
# Konfigurasi RSCaptcha
|
| 12 |
RS_GET_URL = "https://rscaptcha.com/captcha/v5/get"
|
| 13 |
RS_VERIFY_URL = "https://rscaptcha.com/captcha/v5/verify"
|
| 14 |
|
| 15 |
+
def solve_distance(bg_b64, target_b64):
|
| 16 |
+
# Decode Base64 ke OpenCV format
|
| 17 |
bg_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', bg_b64))
|
| 18 |
target_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', target_b64))
|
| 19 |
|
| 20 |
bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
|
| 21 |
target_img = cv2.imdecode(np.frombuffer(target_bytes, np.uint8), cv2.IMREAD_COLOR)
|
| 22 |
|
| 23 |
+
# Preprocessing: Grayscale & Canny Edge Detection
|
| 24 |
bg_gray = cv2.cvtColor(bg_img, cv2.COLOR_BGR2GRAY)
|
| 25 |
target_gray = cv2.cvtColor(target_img, cv2.COLOR_BGR2GRAY)
|
| 26 |
|
| 27 |
+
# Gunakan Canny untuk akurasi gila
|
| 28 |
+
bg_edge = cv2.Canny(bg_gray, 100, 200)
|
| 29 |
+
target_edge = cv2.Canny(target_gray, 100, 200)
|
| 30 |
+
|
| 31 |
+
# Template Matching
|
| 32 |
+
res = cv2.matchTemplate(bg_edge, target_edge, cv2.TM_CCOEFF_NORMED)
|
| 33 |
_, _, _, max_loc = cv2.minMaxLoc(res)
|
| 34 |
+
|
| 35 |
return float(max_loc[0])
|
| 36 |
|
| 37 |
@app.post("/bypass")
|
| 38 |
+
async def bypass(app_id: str, public_key: str):
|
| 39 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 40 |
try:
|
| 41 |
+
# Langkah 1: Ambil Gambar dari RSCaptcha
|
| 42 |
+
payload_get = {'app_id': app_id, 'public_key': public_key, 'version': 'v5'}
|
| 43 |
+
resp_get = await client.post(RS_GET_URL, data=payload_get)
|
| 44 |
+
data = resp_get.json()
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
if 'data' not in data:
|
| 47 |
+
return {"status": "error", "message": "Gagal ambil puzzle dari RSCaptcha"}
|
| 48 |
+
|
| 49 |
captcha_key = data['data']['captcha_key']
|
| 50 |
display_y = data['data']['display_y']
|
| 51 |
|
| 52 |
+
# Langkah 2: Hitung Jarak Geser dengan AI
|
| 53 |
+
distance = solve_distance(data['data']['master_image_base64'], data['data']['tile_image_base64'])
|
|
|
|
| 54 |
|
| 55 |
+
# Langkah 3: Verifikasi Langsung ke RSCaptcha
|
| 56 |
+
# Response format: "x,y"
|
| 57 |
response_val = f"{distance},{display_y}"
|
| 58 |
|
| 59 |
+
verify_payload = {
|
| 60 |
+
'app_id': app_id,
|
| 61 |
+
'public_key': public_key,
|
| 62 |
+
'version': 'v5',
|
| 63 |
+
'token': captcha_key,
|
| 64 |
+
'response': response_val
|
| 65 |
}
|
| 66 |
|
| 67 |
headers = {
|
|
|
|
| 69 |
"Referer": "https://99faucet.com/"
|
| 70 |
}
|
| 71 |
|
| 72 |
+
resp_verify = await client.post(RS_VERIFY_URL, data=verify_payload, headers=headers)
|
| 73 |
+
v_data = resp_verify.json()
|
| 74 |
|
| 75 |
+
# Langkah 4: Kembalikan hasil ke PHP
|
| 76 |
if v_data.get('data') == 'ok':
|
| 77 |
return {
|
| 78 |
"status": "success",
|
| 79 |
"rscaptcha_token": captcha_key,
|
| 80 |
+
"rscaptcha_response": v_data.get('result') or v_data.get('data_response') or response_val
|
| 81 |
}
|
| 82 |
else:
|
| 83 |
return {"status": "fail", "details": v_data}
|
| 84 |
+
|
| 85 |
except Exception as e:
|
| 86 |
return {"status": "error", "message": str(e)}
|
| 87 |
|