Home > OS >  Request HTTP giving binary gibberish results instead of readable text (possible encoding problem?)
Request HTTP giving binary gibberish results instead of readable text (possible encoding problem?)

Time:10-08

Nodejs project that scraps information from a phone web address is returning empty results. When it does the requestHTTP the result that comes off of console.log is something like this>

\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u000b�Wmo�H\u0010�|��\u001f����t���&����q���F�ɇ~�6�B�d��6�z��f�\u0002&\n�U�r\b�=���̳�b[���"\u0013\u000b����6���\f%\u0005/�ze��Z�˔��RQ�;��6�D�D���q��l \u0015/�-�g�Y^\nX�"\u0016�L���B)س��\u0003D�Z†\u000bR�2�0�E\u0016�\rK���!�)\u0007�&��\u0000*\u0005T�T{;�\u0005�eʎ#�\u001d϶��j*j�:B���\u000f�_�8��q�\u000f��#\u0001�!\n��G�.���{c\u001f&\u0001\u0019�\u001d,I�\\u0000\u001a\u0014�\u0016 �C�W \u0001ņǂ��mC��m"��Q[�\�FlOH@\u001e�dJ\tL\u0016T��]�h�\u001c3'�#��\u001dS�\r� \u0003_��o\u001b�\u0018\u0017 \u0016%�\u001c�h\u001a�~�? (it also beeps)

The rawdata became unreadable gibberish, so the rest of the thing doesn't work as it can't pick up the information(I think?)

this is the code causing the problem (I believe)


 
'use strict';

var userConfig = require("../setup_config/setup_config");
const requestHTTP = require("request-promise");

const requestPath = "https://mob.processotelematico.giustizia.it/proxy/index_mobile.php?"

var requestParameters = {
    "version": "2.0.15",
    "platform": "Android 8.1.0",
    "devicename": "USER_UNIQUE_DEVICE_NAME_GOES_HERE",
    "devicewidth": "USER_UNIQUE_DEVICE_WIDTH_GOES_HERE",
    "deviceheight": "USER_UNIQUE_DEVICE_HEIGHT_GOES_HERE",
    "token": "USER_UNIQUE_DEVICE_TOKEN_GOES_HERE",
    "azione": "direttarg_sicid_mobile",
    "registro": "CC",
    "idufficio": "0580910098",
    "numproc": "ID_OF_PROCCESS (CASE_NUMBER)",
    "aaproc": "YEAR",
    "tipoufficio": "1",
    "_": "CURRENT_TIME_IN_MS_GOES_HERE"

};

//get case info from Italy's Giustizia Civile's Server
async function getCase(caseNumber, caseYear){
    let userInfo = userConfig.getUserInfo();
    if(!(userInfo && Array.isArray(userInfo) && userInfo.length == 5)) return {};
    var userUUID = userInfo[0];
    var userToken = userInfo[1]; 
    var userDeviceName = userInfo[2];
    var userDeviceWidth = userInfo[3];
    var userDeviceHeight = userInfo[4];
    console.log(userInfo);

    //populate user related parameters
    requestParameters.uuid = userUUID
    requestParameters.token = userToken

    requestParameters.devicename = userDeviceName;
    requestParameters.devicewidth = userDeviceWidth;
    requestParameters.deviceheight = userDeviceHeight;    

    requestParameters.numproc = caseNumber
    requestParameters.aaproc = caseYear
    requestParameters._ = new Date().getTime()

    //prepare parameters to send
    var fullURL = requestPath   Object.entries(requestParameters).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
    const options = {
        url: fullURL,
        method: 'GET',
        headers: {
            'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; Moto G (5) Build/OPP28.85-19-4-2)',
            'Host': 'mob.processotelematico.giustizia.it',
            'path': '/',
            'Accept': '*/*',
            'Accept-Language': 'en-US',
            'Connection': 'keep-alive',
            'Accept-Encoding':  'gzip, deflate',
            'X-Requested-With': 'it.giustizia.civile'
        }
        
    };

    //make request (get)
    var result = await requestHTTP(options);
    //console.log(result);
    //check if it returned any error signs
    if(checkForErrors(result) == false) return null;
    
    return result;
}

//check if response contains any signs of errors found
function checkForErrors(response){
   //console.log(response)
    if(response.includes("<Errore>") && response.includes("</Errore>")){
        return false; //found error
    }
    return true;
}

module.exports = {
    getCase
};

It seems to me that the part that is causing this problem is in //prepare parameters to send/ where it deals with encodeURIComponent (?) Any ideas, if this is the problem and how to fix this? Thank you.

CodePudding user response:

I fixed it by erasing 'Accept-Encoding': 'gzip, deflate, Apparently by adding this header it disables the built in decompressor of request-promise (something like that).

CodePudding user response:

how did you manage to get userUUID and userToken with mitm? here the traffic is blocked

  • Related