Ryan Ellis
Ryan Ellis

Reputation: 33

How To Rewrite cookie headers in c# fiddler

I have a friend that built me a Browser extension that worked and rerouted a specific file on the network to his desired file. Here is the code in the Browser extension:

if (typeof browser !== 'undefined') {
    chrome = browser
}

var cookievalue = "0"

function createRedirect(target, redirect) {
    
    let rewriteCookieHeader = (e) => {
        for (var header of e.requestHeaders) {
          if (header.name.toLowerCase() === "cookie") {
            header.value = "si=" + cookievalue;
          }
        }
        return {requestHeaders: e.requestHeaders};
    }

    chrome.webRequest.onBeforeSendHeaders.addListener(
        rewriteCookieHeader,
        {urls: [redirect]},
        ["blocking", "requestHeaders"]
    )  
    
    chrome.webRequest.onBeforeRequest.addListener((details) => {
        return { redirectUrl: redirect }
    }, { urls: [ target ] }, ["blocking"])
}

function postJson(url, json) {
    return new Promise(function(resolve, reject) {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                resolve(this.responseText);
            }
        };
        xhttp.onerror = function() {
            reject()
        }
        xhttp.open("POST", url, true);
        xhttp.setRequestHeader("Content-Type", "application/json");
        xhttp.send(JSON.stringify(json));
    })
}

function Tulc(info)
{
    this.trainerId = info.trainerId
    this.url = {}
    this.url.login = info.baseURL + "/login/signin"
    
    this.user = null
    this.setUser = user => this.user = user
    this.getUser = () => this.user
    this.login = password => {
        this.setUser(null)

        var requestInfo = {}
        requestInfo.trainerId = this.trainerId
        requestInfo.password = password

        return new Promise((resolve, reject) => {
            postJson(this.url.login, requestInfo).then((response) => {
                try {
                    response = JSON.parse(response)
                    if (response.status == "success") {
                        this.setUser({name: response.name})
                        cookievalue = response.cookie
                        resolve(this.getUser());
                    } else { reject() }
                } catch (e) {console.log(e); reject()}
            }, () => {
                reject()
            })
        })
    }
}

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.command == "LoginPassword" && request.message) {
        tulc.login(request.message).then((user) => {
            sendResponse(user)
            pocoyo(tulc.getUser())
        }, () => {
            sendResponse()
        })
        return true
    }
    return false
});

function pocoyo(user)
{
    chrome.browserAction.setPopup({popup: "popup/options.html"})
                                                                                                       
   
    
     createRedirect("https://wc-fb-cdn7.kixeye.com/game/game-v7.v59902/WarCommander.js*", "https://www.warcommander.cheatenginebrasil.com.br/scripts/ryan.js")  
                     


}

var tulc = new Tulc({baseURL: "https://www.warcommander.cheatenginebrasil.com.br/tulc/ext"});
chrome.browserAction.setPopup({popup: "popup/login.html"})

Since this is the code in a chrome extension, how can I replicate rewriting cookies and the url properly in c# fiddler? Below is also my updated code with c# Fiddler:

        public void AutoTamperRequestBefore(Session oSession)
        {
            if (oSession.uriContains("WarCommander.js"))
            {
                oSession.fullUrl = "https://nextgenerationhackers.com/uploads/wc/WarCommander.js";
                //oSession.url = "https://nextgenerationhackers.com/uploads/wc/WarCommander.js";
            }
        }
            if (oSession.uriContains("WarCommander.js"))
            {
                oSession.utilDecodeResponse();
                oSession.oResponse.headers.Remove("Set-Cookie");
            }

When I do this, the URL in Fiddler has a Red stop sign on the traffic in the session list as well as the file isn't loaded properly. I believe it has something to do with the ability to rewrite the cookie header that allows it to work in the browser extension. How is this possible via C# for Fiddler?

Upvotes: 0

Views: 54

Answers (0)

Related Questions