Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions BIGIP_decode_cookie.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
#!/usr/bin/python
#!/usr/bin/python3

# example string: BIGip<ervername>110536896.20480.0000
# example string: BIGipServer<servername>=110536896.20480.0000

import struct
import sys
import re

if len(sys.argv) != 2:
print "Usage: %s cookie" % sys.argv[0]
exit(1)
print(f"Usage: {sys.argv[0]} cookie")
sys.exit(1)

cookie = sys.argv[1]
print "\n[*] Cookie to decode: %s\n" % cookie

(cookie_name, cookie_value) = cookie.split('=')

pool = re.search('^BIGipServer([.\w\.]*)', cookie_name)

(host, port, end) = cookie_value.split('.')

(a, b, c, d) = [ord(i) for i in struct.pack("<I", int(host))]

(e) = [ord(e) for e in struct.pack("<H", int(port))]
port = "0x%02X%02X" % (e[0],e[1])

print "[*] Pool name: %s" % (pool.group(1))
print "[*] Decoded IP and Port: %s.%s.%s.%s:%s\n" % (a,b,c,d, int(port,16))
print(f"\n[*] Cookie to decode: {cookie}\n")

# Split cookie
if '=' not in cookie:
print("[!] Invalid cookie format. Expected name=value")
sys.exit(1)

(cookie_name, cookie_value) = cookie.split('=', 1)

# Extract pool name
pool = re.search(r'^BIGipServer([\w\.]*)', cookie_name)
if not pool:
print("[!] Invalid BIGipServer cookie name")
sys.exit(1)

# Split value
try:
host, port, end = cookie_value.split('.')
except ValueError:
print("[!] Invalid cookie value format. Expected host.port.end")
sys.exit(1)

# Decode IP
packed_ip = struct.pack("<I", int(host))
a, b, c, d = packed_ip

# Decode port
packed_port = struct.pack("<H", int(port))
p1, p2 = packed_port
port_hex = "0x%02X%02X" % (p1, p2)
decoded_port = int(port_hex, 16)

print(f"[*] Pool name: {pool.group(1)}")
print(f"[*] Decoded IP and Port: {a}.{b}.{c}.{d}:{decoded_port}\n")