Skip to content

Commit

Permalink
chg: re-implement uwhois module
Browse files Browse the repository at this point in the history
Fix #684
  • Loading branch information
Rafiot committed Aug 19, 2024
1 parent 3a13af7 commit 4e2ed66
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions misp_modules/modules/expansion/whois.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-

import json
try:
from uwhois import Uwhois
except ImportError:
print("uwhois module not installed.")
import socket

misperrors = {'error': 'Error'}
mispattributes = {'input': ['domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}
Expand All @@ -17,7 +14,7 @@
'logo': '',
'requirements': ['uwhois: A whois python library'],
'features': "This module takes a domain or IP address attribute as input and queries a 'Univseral Whois proxy server' to get the correct details of the Whois query on the input value (check the references for more details about this whois server).",
'references': ['https://github.com/rafiot/uwhoisd'],
'references': ['https://github.com/Lookyloo/uwhoisd'],
'input': 'A domain or IP address attribute.',
'output': 'Text describing the result of a whois request for the input value.',
}
Expand All @@ -43,14 +40,21 @@ def handler(q=False):
misperrors['error'] = 'Whois local instance address is missing'
return misperrors

uwhois = Uwhois(request['config']['server'], int(request['config']['port']))

if 'event_id' in request:
return handle_expansion(uwhois, toquery)
return handle_expansion(request['config']['server'], int(request['config']['port']), toquery)


def handle_expansion(w, domain):
return {'results': [{'types': mispattributes['output'], 'values': w.query(domain)}]}
def handle_expansion(server, port, query):
bytes_whois = b''
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((server, port))
sock.sendall(f'{query}\n'.encode())
while True:
data = sock.recv(2048)
if not data:
break
bytes_whois += data
return {'results': [{'types': mispattributes['output'], 'values': bytes_whois.decode()}]}


def introspection():
Expand Down

0 comments on commit 4e2ed66

Please sign in to comment.