简体   繁体   English

如何从命令行启动fiddler作为https代理?

[英]How to start fiddler as a https proxy from command line?

I need to start fiddler automatically to parse https requests. 我需要自动启动fiddler来解析https请求。

How to force fiddler to generate and use a ssl certificate without GUI? 如何强制fiddler生成和使用没有GUI的ssl证书? Does anyone know where fiddler stores its certificate? 有谁知道小提琴手存放证书的地方? Can I generate my own server certificate and set it to fiddler without GUI? 我可以生成自己的服务器证书并在没有GUI的情况下将其设置为fiddler吗?

I can start fiddler in quit mode. 我可以在退出模式下开始提琴手。 I can enable https via registry keys, but fiddler starts without ssl certificate. 我可以通过注册表项启用https,但fiddler在没有ssl证书的情况下启动。 I can create certificate useing makecert.exe, but I don't know how to set it as active certificate for fiddler without UI. 我可以创建使用makecert.exe的证书,但我不知道如何在没有UI的情况下将其设置为fiddler的活动证书。

I'd be very apprciate if anybody helps me to solve it. 如果有人帮助我解决它,我会很高兴。

Nobody helps me, but I've found solution. 没有人帮助我,但我找到了解决方案。

The Solution: 解决方案:

To Enable capturing the https trafic update register's values: 要启用捕获https流量更新寄存器的值:

reg.exe add "HKEY_LOCAL_MACHINE\Software\Microsoft\Fiddler2" /v CaptureCONNECT /t REG_SZ /d True /f
reg.exe add "HKEY_LOCAL_MACHINE\Software\Microsoft\Fiddler2" /v CaptureHTTPS /t REG_SZ /d True /f
reg.exe add "HKEY_LOCAL_MACHINE\Software\Microsoft\Fiddler2" /v IgnoreServerCertErrors /t REG_SZ /d True /f

reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Fiddler2" /v CaptureCONNECT /t REG_SZ /d True /f
reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Fiddler2" /v CaptureHTTPS /t REG_SZ /d True /f
reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Fiddler2" /v IgnoreServerCertErrors /t REG_SZ /d True /f

You need to use custom fiddler's script. 您需要使用自定义fiddler的脚本。 It force fiddler to generate ssl certificate (Please see section main in the script CustomRules.js below). 它强制fiddler生成ssl证书(请参阅下面脚本CustomRules.js中的main部分)。 If you don't add it fiddler will start without ssl certificate. 如果你不添加它,fiddler将在没有ssl证书的情况下启动。

copy /Y /V "<path to file>\CustomRules.js" "%userprofile%\Documents\Fiddler2\Scripts\CustomRules.js"

Note: don't change the destination file name. 注意:请勿更改目标文件名。

When fiddler starts in automaticaly attaches to the socket 127.0.0.1:8888 当fiddler自动启动时连接到套接字127.0.0.1:8888

start "" "%programfiles(x86)%\fiddler2\fiddler.exe" -quiet

The fiddler automatically creates a new ssl certificate. 小提琴手自动创建一个新的ssl证书。 It can be downloaded: 它可以下载:

curl.exe -s -k -o <dst file path> "http://127.0.0.1:8888/FiddlerRoot.cer"

Then you need to add it to Trusted Root Certificates 然后,您需要将其添加到受信任的根证书

certutil -addstore -f "Root" <path to certificate>

Now the fiddelr is started and can capture https trafic useing CustomRules.js. 现在fiddelr已启动,可以捕获使用CustomRules.js的https流量。

Fiddler.bat: Fiddler.bat:

@ECHO OFF

set currentDir=%~dp0
cd "%currentDir%"

set log="%currentDir%\fiddler.log"
set fiddler_custom_script_dir="%userprofile%\Documents\Fiddler2\Scripts\"
set fiddler_result_dir="C:\fiddler\"

echo "Start Fiddler Script" > "%log%"
echo "Current Dir: %currentDir%" >> "%log%"
echo "Update values in the register" >> "%log%"
reg.exe add "HKEY_LOCAL_MACHINE\Software\Microsoft\Fiddler2" /v CaptureCONNECT /t REG_SZ /d True /f >> "%log%"
reg.exe add "HKEY_LOCAL_MACHINE\Software\Microsoft\Fiddler2" /v CaptureHTTPS /t REG_SZ /d True /f >> "%log%"
reg.exe add "HKEY_LOCAL_MACHINE\Software\Microsoft\Fiddler2" /v IgnoreServerCertErrors /t REG_SZ /d True /f >> "%log%"

reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Fiddler2" /v CaptureCONNECT /t REG_SZ /d True /f >> "%log%"
reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Fiddler2" /v CaptureHTTPS /t REG_SZ /d True /f >> "%log%"
reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Fiddler2" /v IgnoreServerCertErrors /t REG_SZ /d True /f >> "%log%"

echo "Create folder for results: %fiddler_result_dir%" >> "%log%"
mkdir "%fiddler_result_dir%" >> "%log%"

echo "Create folder for the custom fiddler's script: %fiddler_custom_script_dir%" >> "%log%"
mkdir "%fiddler_custom_script_dir%" >> "%log%"

echo "Copy fiddler script to  %fiddler_custom_script_dir%" >> "%log%"
copy /Y /V "%currentDir%\CustomRules.js" "%fiddler_custom_script_dir%\CustomRules.js" >> "%log%"

echo "Start fiddler" >> "%log%"
start "" "%programfiles(x86)%\fiddler2\fiddler.exe" -quiet

set cert_path="%currentDir%\FiddlerRoot.cer"
set /a attempt=0

timeout 10 > nul

:get_cert
    set /a attempt+=1
    timeout 1 > nul
    echo "Attempt #%attempt% to download fiddeler's certificate" >> "%log%"
    curl.exe -s -k -o "%cert_path%" "http://127.0.0.1:8888/FiddlerRoot.cer" >> "%log%"
if not exist "%cert_path%" if %attempt% LSS 300 goto get_cert

if not exist "%cert_path%" (
    echo "FAIL. Certificate "%cert_path%" doesn't exist. Cannot set trusted certificate"  >> "%log%"
    exit /b -100
)

set /a attempt=0
echo "Try to add certificate to trusted" >> "%log%"
echo certutil -addstore -f "Root" %cert_path% >> "%log%"
:import_cert
    set /a attempt+=1
    timeout 1 > nul
    echo "Attempt #%attempt% to download fiddeler's certificate" >> "%log%"
    certutil -addstore -f "Root" %cert_path% >> "%log%"
if "%errorlevel%" LSS 0 if %attempt% LSS 3 goto import_cert

echo "End..." >> "%log%"
exit /b 0

CustomRules.js CustomRules.js

import System;
import System.Windows.Forms;
import Fiddler;

/**
 This script must be in the folder C:\Users\<USER>\Documents\Fiddler2\Scripts\CustomRules.js
 */
class Handlers
{
    // The Main() function runs everytime your FiddlerScript compiles
    static function Main() {
        var today: Date = new Date();
        FiddlerObject.StatusText = " CustomRules.js was loaded at: " + today;
        CertMaker.createRootCert();
        //CertMaker.GetRootCertificate().GetPublicKeyString()
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM