Anyproxy Intercept

Anyproxy is an intercept proxy. I used it to inject scripts into pages to assist in web fuzzing.

const AnyProxy = require('./anyproxy/proxy');
const options = {
    port: 8080,
    rule: require('./dfkt_rule'),
    webInterface: {
        enable: true,
        webPort: 8002
    },
    throttle: 10000,
    forceProxyHttps: true,
    wsIntercept: true,
    silent: false
};
const proxyServer = new AnyProxy.ProxyServer(options);

proxyServer.on('ready', () => {
    console.log('ready')
});
proxyServer.on('error', (e) => {
    console.error(e)
});
proxyServer.start();

//when finished
// dfkt_rule
let hooks = {
    beforeSendRequest: [
        function (requestDetail, requestDetailModifications) {
            requestDetailModifications.requestOptions = requestDetail.requestOptions;
            requestDetailModifications.requestOptions.headers['User-Agent'] += ' DFKT/1';
        },
    ],

    beforeSendResponse: [
        function (requestDetail, responseDetail, modifiedResponse) {

            modifiedResponse.response = responseDetail.response;

            console.log(modifiedResponse.response.header);

            if (modifiedResponse.response.body.indexOf('<head>') !== -1) {
                modifiedResponse.response.body = modifiedResponse.response.body.toString().replace('<head>', '<head><script>console.log("dfkt loaded")</script>');
            }
        },
    ],
}


module.exports = {

    summary: 'DFKT rules for web testing',

    * beforeSendRequest(requestDetail) {
        let requestDetailModifications = {};
        for (let hook in hooks.beforeSendRequest) {
            hooks.beforeSendRequest[hook](requestDetail, requestDetailModifications);
        }

        return requestDetailModifications;
    },


    // deal response before send to client
    * beforeSendResponse(requestDetail, responseDetail) {
        let responseDetailModifications = {};
        for (let hook in hooks.beforeSendResponse) {
            hooks.beforeSendResponse[hook](requestDetail, responseDetail, responseDetailModifications);
        }

        return responseDetailModifications;
    },

    // // if deal https request
    // *beforeDealHttpsRequest(requestDetail) {
    //
    // },
    // error happened when dealing requests
    * onError(requestDetail, error) {

    },
    // error happened when connect to https server
    * onConnectError(requestDetail, error) {

    }
};
Last modified August 31, 2024: old content (b79b598)