signup-khojai.py

Signup script to get cookie for khojai

#utility#complement#auto
12
12 Jan 2026, 08:58
RawEdit
python0 lines
"""
  @ Base: https://app.khoj.dev/
  @ Author: Shannz
  @ Note: Signup script to get cookie for khojai.
"""

import requests
import time
import re
import sys

HEADERS = {
    'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36',
    'Accept': 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    'Origin': 'https://app.khoj.dev',
    'Referer': 'https://app.khoj.dev/?v=app',
    'sec-ch-ua-platform': '"Android"',
    'sec-ch-ua-mobile': '?1',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'accept-language': 'id,en-US;q=0.9,en;q=0.8',
}

CONFIG = {
    'KHOJ_MAGIC': 'https://app.khoj.dev/auth/magic',
    'MAIL_LIST': 'https://akunlama.com/api/v1/mail/list',
    'MAIL_HTML': 'https://akunlama.com/api/v1/mail/getHtml'
}

def get_input(prompt):
    return input(f"\n[?] {prompt}")

def print_status(msg, type="info"):
    if type == "info":
        print(f"[*] {msg}")
    elif type == "success":
        print(f"\n[+] {msg}")
    elif type == "error":
        print(f"\n[!] {msg}")
    elif type == "process":
        sys.stdout.write(f"\r[~] {msg}")
        sys.stdout.flush()

class KhojAuth:
    def __init__(self):
        self.session = requests.Session()
        self.session.headers.update(HEADERS)

    def request_otp(self, email):
        print_status(f"Mengirim kode login ke: {email}", "info")
        try:
            payload = {"email": email}
            resp = self.session.post(CONFIG['KHOJ_MAGIC'], json=payload)
            if resp.status_code == 200:
                print_status("Request berhasil dikirim.", "success")
                return True
            else:
                print_status(f"Gagal request. Status: {resp.status_code}", "error")
                return False
        except Exception as e:
            print_status(f"Error Request: {e}", "error")
            return False

    def get_verification_code(self, username):
        print_status("Menunggu email masuk...", "info")
        attempts = 0
        max_attempts = 30
        
        while attempts < max_attempts:
            try:
                resp = requests.get(f"{CONFIG['MAIL_LIST']}?recipient={username}")
                inbox = resp.json()
                
                if inbox and len(inbox) > 0:
                    latest_mail = inbox[0]
                    subject = latest_mail.get('message', {}).get('headers', {}).get('subject', '')

                    if "Khoj" in subject or "Login" in subject:
                        storage = latest_mail.get('storage', {})
                        key = storage.get('key')
                        region = storage.get('region')
                        
                        if key and region:
                            html_resp = requests.get(CONFIG['MAIL_HTML'], params={'key': key, 'region': region})
                            html_content = html_resp.text
                            match = re.search(r'<h1[^>]*>(\d{6})</h1>', html_content)
                            if not match:
                                match = re.search(r'>\s*(\d{6})\s*<', html_content)
                            
                            if match:
                                code = match.group(1)
                                print_status(f"Kode ditemukan: {code}", "success")
                                return code
            
            except Exception as e:
                pass

            attempts += 1
            print_status(f"Polling inbox... ({attempts}/{max_attempts})", "process")
            time.sleep(4)
            
        print_status("Timeout! Kode tidak ditemukan.", "error")
        return None

    def verify_and_get_cookie(self, email, code):
        print_status(f"Memverifikasi kode: {code}", "info")
        
        url = f"{CONFIG['KHOJ_MAGIC']}?code={code}&email={email}"
        
        try:
            resp = self.session.get(url, allow_redirects=False)

            if resp.status_code == 307:
                cookies = resp.cookies.get_dict()

                if 'session' in cookies:
                    full_cookie = f"session={cookies['session']}"
                    return full_cookie

                set_cookie = resp.headers.get('Set-Cookie', '')
                if 'session=' in set_cookie:
                    match = re.search(r'session=([^;]+)', set_cookie)
                    if match:
                        return f"session={match.group(1)}"
            
            print_status(f"Gagal mendapatkan cookie. Status: {resp.status_code}", "error")
            return None

        except Exception as e:
            print_status(f"Error Verify: {e}", "error")
            return None

def main():
    print("="*40)
    print("  KHOJ.DEV COOKIE GENERATOR (Auto)")
    print("="*40)

    username = get_input("Masukkan Terserah (contoh: shanz): ").strip()
    if not username:
        print("Username tidak boleh kosong!")
        return
        
    email = f"{username}@akunlama.com"
    
    auth = KhojAuth()

    if auth.request_otp(email):

        code = auth.get_verification_code(username)
        
        if code:
            cookie = auth.verify_and_get_cookie(email, code)
            
            if cookie:
                print("\n" + "="*40)
                print("SESSION COOKIE ANDA:")
                print("="*40)
                print(f"\n{cookie}\n")
                print("="*40)
                print("Silakan salin string di atas.")
            else:
                print_status("Gagal mengambil cookie.", "error")

if __name__ == "__main__":
    main()