From cae3848490577e29e5047bd13e7990ed3d498e36 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 14 May 2023 22:37:00 +0200 Subject: [PATCH] LOGGED! --- bin/twitter.ml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bin/twitter.ml b/bin/twitter.ml index 1fd31b1..c1e3c4e 100644 --- a/bin/twitter.ml +++ b/bin/twitter.ml @@ -58,19 +58,23 @@ let rec _inject_password session_id creds try_count = send_keys session_id input creds.password; Unix.sleep 1; send_keys session_id input Keys.return; - Unix.sleep 5 + Unix.sleep 3 | None -> () ;; let inject_password session_id creds = _inject_password session_id creds 1 -let inject_2fa _session_id secret _entry = - let _code = +let inject_2fa session_id secret input = + let code = match secret with | Some seed -> Twostep.TOTP.code ~secret:seed () | None -> raise (Any "No TOTP code given, but TOTP required") in - () + (* Insert 2FA code *) + send_keys session_id input code; + Unix.sleep 1; + send_keys session_id input Keys.return; + Unix.sleep 5 ;; let login_twitter ctx username password secret = @@ -83,10 +87,15 @@ let login_twitter ctx username password secret = (* Find password input *) inject_password ctx.session_id creds; (* Detection of 2FA *) - match find ctx.session_id (XPath "XPATH_TOTP") with - | [] -> () + match + find + ctx.session_id + (XPath + "/html/body/div[1]/div/div/div[1]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[2]/label/div/div[2]/div/input") + with + | [] -> print_endline "Don't use 2FA input as input not found" | _ as l -> if List.length l > 1 - then raise (Any "Too many element found as the username input") + then raise (Any "Too many element found as 2FA input") else inject_2fa ctx.session_id secret (List.nth l 0) ;;