-
Notifications
You must be signed in to change notification settings - Fork 0
/
extn.py
34 lines (28 loc) · 1.35 KB
/
extn.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
from burp import IBurpExtender, IHttpListener
import socket
import urllib2
import json
class BurpExtender(IBurpExtender, IHttpListener):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
self._callbacks.setExtensionName("Check ASN")
self._callbacks.registerHttpListener(self)
print("ASN Finder extension loaded.")
def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo):
if not messageIsRequest:
httpService = messageInfo.getHttpService()
host = httpService.getHost()
try:
ip_address = socket.gethostbyname(host)
url = "https://ipinfo.io/{}/json".format(ip_address)
response = urllib2.urlopen(url)
data = json.load(response)
org_name = data.get("org", "N/A").split(' ', 1)[-1]
currentComment = messageInfo.getComment()
newComment = "ASN: {}".format(org_name)
if currentComment:
newComment = "{} | {}".format(currentComment, newComment)
messageInfo.setComment(newComment)
except Exception as e:
print("Error processing IP {}: {}".format(host, e))