seishun / node-steam

Interface directly with Steam servers from Node.js
MIT License
1k stars 180 forks source link

Steam Guard code always needed instead of sentry file #404

Closed Dipricyn closed 7 years ago

Dipricyn commented 7 years ago

I have tried different approaches of using the sentry file in exchange for the Steam Guard code but I can't get it to work no matter what I try. I created a test script but I always get EResult: 85 which is AccountLoginDeniedNeedTwoFactor.

var log = require("./log"), Steam = require("steam"), steamClient = new Steam.SteamClient(), steamUser = new Steam.SteamUser(
        steamClient), crypto = require("crypto"), steamGC = new Steam.SteamGameCoordinator(steamClient, 730);

function getSHA1(bytes) {
    var shasum = crypto.createHash('sha1');
    shasum.end(bytes);
    return shasum.read();
}

var logOnOptions = {
        account_name : 'USERNAME',
        password : 'PASSWORD',
        two_factor_code: null, //not needed for login using sentry file
    };
var sentry;
try {
    sentry = fs.readFileSync('sentry');
    if(sentry){
        logOnOptions.sha_sentryfile = getSHA1(sentry);
        log.log("sentry file loaded");
    }else{
        log.log("Empty sentry file.");
    }
} catch (e) {
    log.log("Error loading sentry: " + e);
}

var steamClient = new Steam.SteamClient();
var steamUser = new Steam.SteamUser(steamClient);

steamClient.connect();
steamClient.on('connected', function() {
    steamUser.logOn(logOnOptions);
});

steamClient.on('logOnResponse', function(logonResp) {
    if (logonResp.eresult === Steam.EResult.OK) {
        log.log('Logged in!');
    }else{
        log.log("Eresult: "+logonResp.eresult);
    }
});

steamClient.on('servers', function(servers) {
    fs.writeFile('servers', JSON.stringify(servers));
});

steamUser.on('updateMachineAuth', function(sentry, callback) {
    fs.writeFileSync('sentry', sentry.bytes);
    log.log("Updated machine auth.");
    callback({
        sha_file : getSHA1(sentry.bytes),
        eresult : Steam.EResult.OK,
    });
});

I can confirm that steam servers send the same sentry file at the updateMachineAuth event which I already have. How can I log in using the sentry file?

alex7kom commented 7 years ago

Sentry file can't be used if 2FA is enabled. See also #390

seishun commented 7 years ago

What @Alex7Kom said.

You're welcome to add this information to the wiki.

scholtzm commented 7 years ago

It's actually mentioned in there: https://github.com/seishun/node-steam/wiki/Protobufs#cmsgclientlogon

edit. Went ahead and added a short clarification.

seishun commented 7 years ago

Maybe it would be useful to mention the meanings of some eresult values under CMsgClientLogonResponse as well.

Dipricyn commented 7 years ago

Just out of curiousity: how does the Steam client login at my PC? I have 2FA enabled and I automatically get logged in on system startup. Seems like the sentry file is used there.

seishun commented 7 years ago

I'd guess it uses login_key. You can use NetHook2 to find out.

scholtzm commented 7 years ago

Yep, valid username + login_key combo will bypass the need for 2FA code.

yesworld commented 4 years ago

Yep, valid username + login_key combo will bypass the need for 2FA code.

Please give an example of how this can be used, thank you.

scholtzm commented 4 years ago

@yesworld I would suggest implementing automated logins using 2FA which you will need anyway if you want a truly automated bot.