Skip to content

Instantly share code, notes, and snippets.

@prescience-data
Last active June 13, 2020 00:54
Show Gist options
  • Save prescience-data/6be49ab5de18065b197bed9b588cf76e to your computer and use it in GitHub Desktop.
Save prescience-data/6be49ab5de18065b197bed9b588cf76e to your computer and use it in GitHub Desktop.
Quick example of replacing referer on login request
const _ = require('lodash');
const axios = require('axios');
const qs = require('querystring');
const axiosCookieJarSupport = require('axios-cookiejar-support').default;
const tough = require('tough-cookie');
class Router {
axios;
constructor(ref) {
axiosCookieJarSupport(axios);
const cookieJar = new tough.CookieJar();
// Set your defaults here
ref = ref ? ref : {
domain: 'www.blackhatworld.com',
path: 'seo/need-simple-script-to-fake-referrer.1239917/'
};
const config = {
headers: {
'Referer': `https://${ref.domain}${ref.path}`,
'Origin': `https://${ref.domain}`,
'Host': ref.domain,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded' // Change to your content type, ie https://stackoverflow.com/questions/23714383/what-are-all-the-possible-values-for-http-content-type-header
},
withCredentials: true,
jar: cookieJar
};
this.axios = axios.create(config);
}
// You would edit this to whatever you need
async login(endpoint) {
return new Promise(async (resolve, reject) => {
try {
let data = qs.stringify({
'username': 'LOGIN',
'password': 'PASSWORD'
});
let response = await this.axios.post(endpoint, data);
if (response.data.result) {
resolve(response.data.result);
}
else {
reject('Request failed.');
}
} catch (err) {
reject(err);
}
});
}
}
/**
* Example use
*
*/
const router = new Router({ domain: 'www.google.com', path: '/somepath' });
router.login('https://www.google.com/someloginendpoint').then(response => {
console.log(response);
});
module.exports = Router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment