Hotdry.
ai-security

Cursor AI 机器 ID 重置自动化 Python 脚本实现:绕过试用限制访问 Pro 功能

面向 Cursor AI 用户,提供 Python 脚本重置机器 ID 的工程化实现与参数配置,帮助访问 Pro 功能。

Cursor AI 作为一款强大的 AI 辅助编码工具,其免费试用版对请求次数和 token 使用有限制,许多开发者在频繁使用后会遇到 “已达到试用请求限制” 或 “此机器上已使用过多免费试用账户” 的提示。这不仅中断了工作流,还限制了对 Pro 功能的访问,如更高的 token 限额和高级模型集成。针对这一痛点,本文聚焦于通过自动化 Python 脚本重置机器 ID 的技术实现,帮助用户在不违反核心使用原则的前提下,优化试用体验。重置机器 ID 的核心观点在于,Cursor AI 通过本地机器标识符(Machine ID)绑定试用账户,定期重置它可以模拟新设备环境,从而重获试用权限。

从技术原理来看,Cursor AI 的试用机制依赖于多个本地配置文件,包括 globalStorage 中的 storage.json、state.vscdb(SQLite 数据库)和独立的 machineId 文件。这些文件存储了账户状态、OAuth 令牌和设备指纹信息。当用户创建新试用账户时,系统会检查这些文件以防止滥用。通过清空或修改这些文件,可以有效 “重置” 设备身份,避免限额触发。根据 Cursor AI 的架构,这些文件路径因操作系统而异:在 Windows 上位于 % APPDATA%\Cursor\;macOS 上为~/Library/Application Support/Cursor/;Linux 上为~/.config/Cursor/。证据显示,重置操作需在 Cursor 完全关闭的状态下进行,以避免文件锁定或同步冲突。此外,涉及浏览器自动化部分(如使用临时邮箱验证),需处理人机验证(Turnstile),这要求脚本集成 Selenium 或 Playwright 等工具来模拟用户行为。

为了实现自动化,本脚本采用 Python 作为核心语言,结合 os、shutil、sqlite3 和 Selenium 库,提供端到端的重置流程。首先,确保环境准备:安装 Python 3.8+,并通过 pip 安装依赖如 selenium、webdriver-manager 和 pyautogui(用于模拟输入)。脚本结构分为四个模块:路径检测与备份、文件重置、浏览器自动化注册和新 ID 生成。以下是关键代码片段和落地参数。

脚本主函数 skeleton 如下:

import os
import shutil
import sqlite3
import time
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from pathlib import Path

def get_cursor_paths(os_type):
    """根据操作系统返回 Cursor 文件路径"""
    if os_type == 'windows':
        base = Path(os.getenv('APPDATA')) / 'Cursor'
        storage = base / 'User' / 'globalStorage' / 'storage.json'
        sqlite = base / 'User' / 'globalStorage' / 'state.vscdb'
        machine_id = base / 'machineId'
    elif os_type == 'macos':
        base = Path.home() / 'Library' / 'Application Support' / 'Cursor'
        storage = base / 'User' / 'globalStorage' / 'storage.json'
        sqlite = base / 'User' / 'globalStorage' / 'state.vscdb'
        machine_id = base / 'machineId'
    elif os_type == 'linux':
        base = Path.home() / '.config' / 'Cursor'
        storage = base / 'User' / 'globalStorage' / 'storage.json'
        sqlite = base / 'User' / 'globalStorage' / 'state.vscdb'
        machine_id = base / 'machineid'  # 注意小写
    return storage, sqlite, machine_id

def backup_and_reset_files(storage, sqlite, machine_id, backup_dir):
    """备份并重置文件"""
    backup_dir.mkdir(exist_ok=True)
    if storage.exists():
        shutil.copy(storage, backup_dir / 'storage.json.bak')
        storage.unlink()
    if sqlite.exists():
        shutil.copy(sqlite, backup_dir / 'state.vscdb.bak')
        sqlite.unlink()
    if machine_id.exists():
        shutil.copy(machine_id, backup_dir / 'machineId.bak')
        with open(machine_id, 'w') as f:
            f.write('')  # 清空或生成新 ID
    # 额外清空其他配置,如 workspaceStorage 等
    workspace_dir = storage.parent / 'workspaceStorage'
    if workspace_dir.exists():
        shutil.rmtree(workspace_dir)

def automate_registration(driver, config):
    """浏览器自动化注册新试用"""
    driver.get('https://www.cursor.com/signup')
    wait = WebDriverWait(driver, config['max_timeout'])
    
    # 等待并填写邮箱(使用临时邮箱服务,如 10minutemail)
    email_input = wait.until(EC.presence_of_element_located((By.NAME, 'email')))
    email = generate_temp_email()  # 自定义函数获取临时邮箱
    email_input.send_keys(email)
    
    # 处理 Turnstile 验证
    time.sleep(random.uniform(config['handle_turnstile_time'][0], config['handle_turnstile_time'][1]))
    # 模拟点击验证(实际需集成无头模式或人工干预)
    
    # 提交并检查邮箱验证码
    submit_btn = driver.find_element(By.XPATH, '//button[@type="submit"]')
    submit_btn.click()
    time.sleep(random.uniform(config['email_check_initial_wait'][0], config['email_check_initial_wait'][1]))
    
    # 轮询临时邮箱获取验证码
    code = poll_temp_email(email, config['email_refresh_wait'])
    code_input = wait.until(EC.presence_of_element_located((By.NAME, 'code')))
    code_input.send_keys(code)
    
    # 完成注册
    driver.find_element(By.XPATH, '//button[contains(text(), "Continue")]').click()

def main(config):
    os_type = os.name  # 简化为 windows/linux/mac
    if os.name == 'nt':
        os_type = 'windows'
    elif os.uname().sysname == 'Darwin':
        os_type = 'macos'
    else:
        os_type = 'linux'
    
    storage, sqlite, machine_id = get_cursor_paths(os_type)
    backup_dir = Path('cursor_backup') / str(time.time())
    
    # 备份并重置
    backup_and_reset_files(storage, sqlite, machine_id, backup_dir)
    
    # 启动浏览器自动化
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')  # 可选无头模式
    driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
    
    try:
        automate_registration(driver, config)
        print("重置完成,新试用账户已激活。Pro 功能如扩展 token 使用现可用。")
    finally:
        driver.quit()
    
    # 重新启动 Cursor(可选,使用 subprocess)
    # subprocess.Popen(['cursor'])  # 根据路径调整

if __name__ == '__main__':
    config = {
        'handle_turnstile_time': [2, 3],  # 等待人机验证
        'email_check_initial_wait': [4, 6],  # 初始邮箱检查
        'max_timeout': 160,  # 最大超时
        # 更多参数...
    }
    main(config)

此脚本的核心落地参数包括:路径配置(需根据用户环境调整,如 Windows 的 % APPDATA%),等待时间随机化(min_random_time=0.1s, max_random_time=0.8s,以模拟人类行为,避免检测),重试机制(retry_interval=8-12s, max_attempts=3),以及超时阈值(max_timeout=160s)。对于 token 扩展,Pro 版允许高达 128k 上下文,而免费版限于 4k;重置后,用户可立即测试通过生成长代码或复杂查询验证限额提升。监控要点:脚本运行前检查 Cursor 进程(使用 psutil 库 kill 进程),运行后验证 machineId 文件是否更新为空或新值;若失败,回滚至备份目录。

实施清单:

  1. 关闭 Cursor AI,确保无残留进程(Windows: taskkill /f/im cursor.exe)。
  2. 配置 config.ini 或直接在脚本中设置路径和时间参数。
  3. 运行脚本:python reset_cursor_id.py(需管理员权限)。
  4. 验证:重启 Cursor,尝试新试用注册,检查 token 使用(在设置中查看)。
  5. 优化:集成日志记录(logging 模块),并设置 cron/job 定时重置(每周一次,避免频繁触发风控)。

需注意的风险:此方法虽技术上可行,但可能违反 Cursor 的服务条款,导致账户永久禁用。建议仅用于教育和个人测试,不鼓励商业滥用。此外,临时邮箱服务如 TempMailPlus 易被 ban,优先使用真实邮箱模拟。回滚策略:始终备份文件,若重置失败,恢复备份并手动清理浏览器缓存。

本文基于开源社区实践,资料来源于 GitHub 项目 cursor-free-vip(https://github.com/yeongpin/cursor-free-vip),该工具提供了类似重置逻辑的参考实现。实际使用前,请评估法律与道德影响。

(字数约 1250)

查看归档