Skip to content

Instantly share code, notes, and snippets.

@codeniko
Last active July 26, 2017 21:32
Show Gist options
  • Save codeniko/63456abfc6dd370d461fdbef2644dcab to your computer and use it in GitHub Desktop.
Save codeniko/63456abfc6dd370d461fdbef2644dcab to your computer and use it in GitHub Desktop.
login into yahoo and get cookies
var exec = require('child_process').exec;
var when = require('when');
function login(credentials) {
var whenAuthenticated = when.defer();
var user = credentials.user;
var pass = credentials.pass;
var res = {
user: user,
cookies: undefined
};
console.log('Logging into ' + user);
var cmd = "./login.sh '"+user+"' '"+pass+"'";
exec(cmd, function(error, stdout) {
var cookies = stdout;
if (!error && typeof cookies === 'string' && cookies.indexOf('B=') === 0 && cookies.length > 200) {
cookies = cookies.substring(0, cookies.length - 1); // strip newline at end
res.cookies = cookies;
whenAuthenticated.resolve(res);
return;
}
console.log('Failed to login into ' + user);
console.log('error: ', error);
console.log('output: ', stdout);
success = false;
whenAuthenticated.resolve(res);
});
return whenAuthenticated.promise;
}
#!/bin/bash
user="${1}"
pass="${2}"
COOKIES_FILE=".cookies_${1}"
HIDDEN_FIELDS_FILE=".hiddens_${1}"
USER_AGENT='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36'
rm "${COOKIES_FILE}"
rm "${HIDDEN_FIELDS_FILE}"
curl -s -L -A "${USER_AGENT}" -c "${COOKIES_FILE}" -k 'https://login.yahoo.com/?.src=ym&.intl=us&.lang=en-US' | grep '<input name.\+hidden.\+value="[a-zA-Z0-9./-]\+"' | head -n 3 | tr -s ' ' | cut -d '"' -f 2,6 --output-delimiter '=' > "${HIDDEN_FIELDS_FILE}"
source "${HIDDEN_FIELDS_FILE}"
curl -s -L -b "${COOKIES_FILE}" -A "${USER_AGENT}" -c "${COOKIES_FILE}" -k 'https://login.yahoo.com/?.src=ym&.intl=us&.lang=en-US' -d "username=${user}&passwd=${pass}&.persistent=y&_crumb=${_crumb}&_ts=${_ts}&_format&_uuid=${_uuid}&_seqid=2&otp_channel" > /dev/null
curl -s -L -b "${COOKIES_FILE}" -A "${USER_AGENT}" -c "${COOKIES_FILE}" -k 'https://mail.yahoo.com/' > /dev/null
curl -s -L -b "${COOKIES_FILE}" -A "${USER_AGENT}" -c "${COOKIES_FILE}" -k 'https://search.yahoo.com/' > /dev/null
curl -s -L -b "${COOKIES_FILE}" -A "${USER_AGENT}" -c "${COOKIES_FILE}" -k 'https://index.search.yahoo.com/' > /dev/null
cat "${COOKIES_FILE}" | sed -e '1,4d' | cut -f6,7 --output-delimiter '=' | sed -e 's/$/;/' | xargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment