Update app.py
Browse files
app.py
CHANGED
|
@@ -8,11 +8,14 @@ import re
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
-
#
|
| 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))
|
|
@@ -20,59 +23,67 @@ def solve_distance(bg_b64, target_b64):
|
|
| 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
|
| 24 |
bg_gray = cv2.cvtColor(bg_img, cv2.COLOR_BGR2GRAY)
|
| 25 |
target_gray = cv2.cvtColor(target_img, cv2.COLOR_BGR2GRAY)
|
| 26 |
|
| 27 |
-
#
|
| 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 |
-
#
|
| 42 |
-
# Kadang butuh rsc_v: 'v5' atau version: 'v5'
|
| 43 |
-
payload_get = {
|
| 44 |
-
'app_id': app_id,
|
| 45 |
-
'public_key': public_key,
|
| 46 |
-
'version': 'v5'
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
headers_rs = {
|
|
|
|
| 50 |
"Origin": "https://99faucet.com",
|
| 51 |
"Referer": "https://99faucet.com/",
|
|
|
|
| 52 |
"Content-Type": "application/x-www-form-urlencoded"
|
| 53 |
}
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
resp_get = await client.post(RS_GET_URL, data=payload_get, headers=headers_rs)
|
| 56 |
data = resp_get.json()
|
| 57 |
|
| 58 |
-
# DEBUG: Jika gagal, kita beri tahu apa isi respon dari RSCaptcha
|
| 59 |
if 'data' not in data or 'tile_image_base64' not in data['data']:
|
| 60 |
return {
|
| 61 |
"status": "error",
|
| 62 |
-
"message": "
|
| 63 |
-
"
|
| 64 |
}
|
| 65 |
|
| 66 |
captcha_key = data['data']['captcha_key']
|
| 67 |
display_y = data['data']['display_y']
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
# 2
|
| 72 |
-
distance = solve_distance(
|
| 73 |
|
| 74 |
-
# 3
|
|
|
|
| 75 |
response_val = f"{distance},{display_y}"
|
|
|
|
| 76 |
verify_payload = {
|
| 77 |
'app_id': app_id,
|
| 78 |
'public_key': public_key,
|
|
@@ -84,17 +95,24 @@ async def bypass(app_id: str, public_key: str):
|
|
| 84 |
resp_verify = await client.post(RS_VERIFY_URL, data=verify_payload, headers=headers_rs)
|
| 85 |
v_data = resp_verify.json()
|
| 86 |
|
|
|
|
|
|
|
| 87 |
if v_data.get('data') == 'ok' or 'result' in v_data:
|
| 88 |
return {
|
| 89 |
"status": "success",
|
| 90 |
"rscaptcha_token": captcha_key,
|
| 91 |
-
"rscaptcha_response": v_data.get('result') or response_val
|
|
|
|
| 92 |
}
|
| 93 |
else:
|
| 94 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
-
return {"status": "error", "message": str(e)}
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
# RSCaptcha API Endpoints
|
| 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 |
+
"""
|
| 17 |
+
Logika AI untuk menghitung jarak geser menggunakan Canny Edge Detection
|
| 18 |
+
"""
|
| 19 |
# Decode Base64 ke OpenCV format
|
| 20 |
bg_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', bg_b64))
|
| 21 |
target_bytes = base64.b64decode(re.sub(r'^data:image/\w+;base64,', '', target_b64))
|
|
|
|
| 23 |
bg_img = cv2.imdecode(np.frombuffer(bg_bytes, np.uint8), cv2.IMREAD_COLOR)
|
| 24 |
target_img = cv2.imdecode(np.frombuffer(target_bytes, np.uint8), cv2.IMREAD_COLOR)
|
| 25 |
|
| 26 |
+
# Preprocessing: Grayscale
|
| 27 |
bg_gray = cv2.cvtColor(bg_img, cv2.COLOR_BGR2GRAY)
|
| 28 |
target_gray = cv2.cvtColor(target_img, cv2.COLOR_BGR2GRAY)
|
| 29 |
|
| 30 |
+
# Canny Edge Detection untuk akurasi tinggi pada puzzle
|
| 31 |
bg_edge = cv2.Canny(bg_gray, 100, 200)
|
| 32 |
target_edge = cv2.Canny(target_gray, 100, 200)
|
| 33 |
|
| 34 |
+
# Template Matching pada hasil Edges
|
| 35 |
res = cv2.matchTemplate(bg_edge, target_edge, cv2.TM_CCOEFF_NORMED)
|
| 36 |
_, _, _, max_loc = cv2.minMaxLoc(res)
|
| 37 |
|
| 38 |
+
# Koordinat X (jarak geser) adalah max_loc[0]
|
| 39 |
return float(max_loc[0])
|
| 40 |
|
| 41 |
+
@app.get("/")
|
| 42 |
+
async def root():
|
| 43 |
+
return {"status": "running", "message": "DAN AI Solver is Ready"}
|
| 44 |
+
|
| 45 |
@app.post("/bypass")
|
| 46 |
+
async def bypass(app_id: str, public_key: str, cookies: str = ""):
|
| 47 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 48 |
try:
|
| 49 |
+
# Headers wajib agar tidak dianggap bot oleh server RSCaptcha
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
headers_rs = {
|
| 51 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
|
| 52 |
"Origin": "https://99faucet.com",
|
| 53 |
"Referer": "https://99faucet.com/",
|
| 54 |
+
"Cookie": cookies, # Meneruskan cookie dari PHP
|
| 55 |
"Content-Type": "application/x-www-form-urlencoded"
|
| 56 |
}
|
| 57 |
|
| 58 |
+
# LANGKAH 1: Ambil Gambar dari RSCaptcha
|
| 59 |
+
payload_get = {
|
| 60 |
+
'app_id': app_id,
|
| 61 |
+
'public_key': public_key,
|
| 62 |
+
'version': 'v5'
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
resp_get = await client.post(RS_GET_URL, data=payload_get, headers=headers_rs)
|
| 66 |
data = resp_get.json()
|
| 67 |
|
|
|
|
| 68 |
if 'data' not in data or 'tile_image_base64' not in data['data']:
|
| 69 |
return {
|
| 70 |
"status": "error",
|
| 71 |
+
"message": "Gagal fetch puzzle (Cookie mungkin invalid atau IP diblokir)",
|
| 72 |
+
"raw_response": data
|
| 73 |
}
|
| 74 |
|
| 75 |
captcha_key = data['data']['captcha_key']
|
| 76 |
display_y = data['data']['display_y']
|
| 77 |
+
master_img = data['data']['master_image_base64']
|
| 78 |
+
tile_img = data['data']['tile_image_base64']
|
| 79 |
|
| 80 |
+
# LANGKAH 2: Hitung Jarak Geser dengan OpenCV
|
| 81 |
+
distance = solve_distance(master_img, tile_img)
|
| 82 |
|
| 83 |
+
# LANGKAH 3: Verifikasi Langsung ke RSCaptcha Server
|
| 84 |
+
# Format response: "x,y" (koordinat horizontal,koordinat vertikal)
|
| 85 |
response_val = f"{distance},{display_y}"
|
| 86 |
+
|
| 87 |
verify_payload = {
|
| 88 |
'app_id': app_id,
|
| 89 |
'public_key': public_key,
|
|
|
|
| 95 |
resp_verify = await client.post(RS_VERIFY_URL, data=verify_payload, headers=headers_rs)
|
| 96 |
v_data = resp_verify.json()
|
| 97 |
|
| 98 |
+
# LANGKAH 4: Kirim hasil final balik ke PHP
|
| 99 |
+
# Beberapa server RSCaptcha mengembalikan 'result' (token terenkripsi)
|
| 100 |
if v_data.get('data') == 'ok' or 'result' in v_data:
|
| 101 |
return {
|
| 102 |
"status": "success",
|
| 103 |
"rscaptcha_token": captcha_key,
|
| 104 |
+
"rscaptcha_response": v_data.get('result') or response_val,
|
| 105 |
+
"distance": distance
|
| 106 |
}
|
| 107 |
else:
|
| 108 |
+
return {
|
| 109 |
+
"status": "fail",
|
| 110 |
+
"message": "Verifikasi RSCaptcha ditolak",
|
| 111 |
+
"details": v_data
|
| 112 |
+
}
|
| 113 |
|
| 114 |
except Exception as e:
|
| 115 |
+
return {"status": "error", "message": f"Server Error: {str(e)}"}
|
| 116 |
|
| 117 |
if __name__ == "__main__":
|
| 118 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|