Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
fix issue #11; apikeys are refreshed when tasks are invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
David Garcia committed Feb 6, 2020
1 parent d5a2a5e commit 2947e91
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions server/plugins/abuseipdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def do(self):
@celery_app.task
def abuseipdb(ip, plugin_name, project_id, resource_id, resource_type):
try:
API_KEY = KeyRing().get("abuseipdb")
if not API_KEY:
print("No API key...!")
return None
Expand Down
2 changes: 1 addition & 1 deletion server/plugins/binaryedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def do(self):
@celery_app.task
def binaryedge(plugin_name, project_id, resource_id, resource_type, ip):
try:

API_KEY = KeyRing().get("binaryedge")
if not API_KEY:
print("No API key...!")
return {}
Expand Down
5 changes: 5 additions & 0 deletions server/plugins/botscout.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def do(self):

def botscout_ip(ip):
try:
API_KEY = KeyRing().get("botscout")
if not API_KEY:
print("No API key...!")
return None

URL = f"http://botscout.com/test/?ip={ip}&key={API_KEY}&format=xml"
response = urllib.request.urlopen(URL).read()
return response
Expand Down
4 changes: 4 additions & 0 deletions server/plugins/diario.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ def do(self):
def old_diario(document_hash):
result = {"is_document": False}
try:
APP_ID = KeyRing().get("diario-appid")
if not APP_ID:
print("No App ID key...!")
return None

SECRET_KEY = KeyRing().get("diario-secret")
if not SECRET_KEY:
print("No secret key...!")
return None
Expand All @@ -92,10 +94,12 @@ def old_diario(document_hash):
def diario(plugin_name, project_id, resource_id, resource_type, document_hash):
result = {"is_document": False}
try:
APP_ID = KeyRing().get("diario-appid")
if not APP_ID:
print("No App ID key...!")
return None

SECRET_KEY = KeyRing().get("diario-secret")
if not SECRET_KEY:
print("No secret key...!")
return None
Expand Down
13 changes: 9 additions & 4 deletions server/plugins/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
RESOURCE_TARGET = [ResourceType.IPv4]

# Plugin Metadata {a description, if target is actively reached and name}
PLUGIN_DESCRIPTION = "Use a GeoIP service to geolocate an IP address"
PLUGIN_API_KEY = False
PLUGIN_DESCRIPTION = "Use IpStack service to geolocate an IP address"
PLUGIN_API_KEY = True
PLUGIN_IS_ACTIVE = False
PLUGIN_NAME = "geoip"
PLUGIN_AUTOSTART = True
PLUGIN_DISABLE = False

API_KEY = KeyRing().get("ipstack")
API_KEY = KeyRing().get("geoip")


class Plugin:
description = PLUGIN_DESCRIPTION
is_active = PLUGIN_IS_ACTIVE
name = PLUGIN_NAME
api_key = PLUGIN_API_KEY
api_doc = ""
api_doc = "https://ipstack.com/signup/free"
autostart = PLUGIN_AUTOSTART
apikey_in_ddbb = bool(API_KEY)

Expand Down Expand Up @@ -56,6 +56,11 @@ def do(self):
@celery_app.task
def geoip(plugin_name, project_id, resource_id, resource_type, ip):
try:
API_KEY = KeyRing().get("geoip")
if not API_KEY:
print("No API key...!")
return None

URL = f"http://api.ipstack.com/{ip}?access_key={API_KEY}&format=1"
response = urllib.request.urlopen(URL).read()
result = json.loads(response)
Expand Down
1 change: 1 addition & 0 deletions server/plugins/haveibeenpwned.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def breach_detail_filler(sites):
@celery_app.task
def haveibeenpwned(plugin_name, project_id, resource_id, resource_type, email):
try:
API_KEY = KeyRing().get("haveibeenpwned")
if not API_KEY:
print("No API key...!")
return None
Expand Down
1 change: 1 addition & 0 deletions server/plugins/hunterio.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def do(self):

def send_request(url):
try:
API_KEY = KeyRing().get("hunterio")
if not API_KEY:
print("No API key...!")
return None
Expand Down
4 changes: 3 additions & 1 deletion server/plugins/maltiverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from tasks.tasks import celery_app
from server.plugins.plugin_base import finishing_task

# Maltiverse does not need api key in some operations
# Keeping this if they change their mind in a future
MALTIVERSE_EMAIL = KeyRing().get("maltiverse_email")
MALTIVERSE_PASS = KeyRing().get("maltiverse_pass")

Expand All @@ -33,7 +35,7 @@

# Plugin Metadata {a description, if target is actively reached and name}
PLUGIN_DESCRIPTION = "Search indicators of compromise or something related"
PLUGIN_API_KEY = True
PLUGIN_API_KEY = False
PLUGIN_IS_ACTIVE = False
PLUGIN_NAME = "maltiverse"
PLUGIN_AUTOSTART = False
Expand Down
10 changes: 10 additions & 0 deletions server/plugins/onyphe.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def do(self):

def onyphe_threatlist(ip):
try:
API_KEY = KeyRing().get("onyphe")
if not API_KEY:
print("No API key...!")
return None

URL = f"https://www.onyphe.io/api/threatlist/{ip}?apikey={API_KEY}"
response = urllib.request.urlopen(URL).read()
response = json.loads(response)
Expand All @@ -76,6 +81,11 @@ def onyphe_threatlist(ip):

def onyphe_synscan(ip):
try:
API_KEY = KeyRing().get("onyphe")
if not API_KEY:
print("No API key...!")
return None

URL = f"https://www.onyphe.io/api/synscan/{ip}?apikey={API_KEY}"
response = urllib.request.urlopen(URL).read()
return response
Expand Down
5 changes: 5 additions & 0 deletions server/plugins/otx.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def do(self):

def otx_iocs_file(file_hash, section):
try:
API_KEY = KeyRing().get("otx")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -105,6 +106,7 @@ def otx_iocs_file(file_hash, section):

def otx_iocs_url(url, section):
try:
API_KEY = KeyRing().get("otx")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -134,6 +136,7 @@ def otx_iocs_url(url, section):

def otx_iocs_hostname(hostname, section):
try:
API_KEY = KeyRing().get("otx")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -164,6 +167,7 @@ def otx_iocs_hostname(hostname, section):

def otx_iocs_ipv4(ip, section):
try:
API_KEY = KeyRing().get("otx")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -193,6 +197,7 @@ def otx_iocs_ipv4(ip, section):

def otx_iocs_ipv6(ip, section):
try:
API_KEY = KeyRing().get("otx")
if not API_KEY:
print("No API key...!")
return None
Expand Down
1 change: 1 addition & 0 deletions server/plugins/pastebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_key_from_paste_key(item):

def pastebin_get_results(results):
try:
API_KEY = KeyRing().get("pastebin")
if not API_KEY:
raise Exception("No API_KEY for pastebin")

Expand Down
2 changes: 2 additions & 0 deletions server/plugins/phishtank.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def do(self):

def phishtank_check(url):
try:
API_KEY = KeyRing().get("phishtank")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -146,6 +147,7 @@ def phishtank_tech_details(phish_id):

URL_main = f"https://www.phishtank.com/phish_detail.php?phish_id={phish_id}"

API_KEY = KeyRing().get("phishtank")
if not API_KEY:
print("No API key...!")
return None
Expand Down
7 changes: 4 additions & 3 deletions server/plugins/pulsedive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
## Function OK
def pulsedive_get_ioc_byvalue(param):
try:
API_KEY = KeyRing().get("pulsedive")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -59,6 +60,7 @@ def pulsedive_get_ioc_byvalue(param):
# {'success': 'Added indicator to queue.', 'qid': 98643407}
def pulsedive_analyze(domain):
try:
API_KEY = KeyRing().get("pulsedive")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -97,6 +99,7 @@ def pulsedive_analyze(domain):
# In progress. API response ok but results not found always. Review!
def pulsedive_getreport(qid):
try:
API_KEY = KeyRing().get("pulsedive")
if not API_KEY:
print("No API key...!")
return None
Expand Down Expand Up @@ -125,9 +128,7 @@ def pulsedive_getreport(qid):


@celery_app.task
def pulsedive_task(
plugin_name, project_id, resource_id, resource_type, domain_or_hash
):
def pulsedive_task(plugin_name, project_id, resource_id, resource_type, domain_or_hash):
try:
resource_type = ResourceType(resource_type)
if resource_type == ResourceType.DOMAIN or resource_type == ResourceType.HASH:
Expand Down
4 changes: 4 additions & 0 deletions server/plugins/shodan.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ def do(self):
@celery_app.task
def shodan(plugin_name, project_id, resource_id, resource_type, ip):
try:
API_KEY = KeyRing().get("shodan")

if not API_KEY:
print("No API key...!")
return None

URL = "https://api.shodan.io/shodan/host/{ip}?key={API_KEY}"

response = {}
ipinfo = requests.get(URL.format(**{"ip": ip, "API_KEY": API_KEY}))
if not ipinfo.status_code == 200:
Expand Down
6 changes: 6 additions & 0 deletions server/plugins/tacyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def do(self):
def tacyt(plugin_name, project_id, resource_id, resource_type, apk_hash):
application = None
try:
APP_ID = KeyRing().get("tacyt-appid")
SECRET_KEY = KeyRing().get("tacyt-secret")

if not APP_ID or not SECRET_KEY:
print("APP_ID o SECRET_KEY in database")

api = tacytsdk.TacytApp(APP_ID, SECRET_KEY)
search = api.search_apps(query=apk_hash, outfields=__OUT_FIELDS)

Expand Down
1 change: 1 addition & 0 deletions server/plugins/verifymail.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def do(self):
@celery_app.task
def verifymail(plugin_name, project_id, resource_id, resource_type, email):
try:
API_KEY = KeyRing().get("verify-email")
if not API_KEY:
print("No API key...!")
return None
Expand Down
1 change: 1 addition & 0 deletions server/plugins/virustotal.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def do(self):
@celery_app.task
def virustotal(plugin_name, project_id, resource_id, resource_type, target):
try:
API_KEY = KeyRing().get("virustotal")
if not API_KEY:
print("No API key...!")
return None
Expand Down
1 change: 1 addition & 0 deletions server/plugins/vt_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def do(self):
@celery_app.task
def vt_domain(plugin_name, project_id, resource_id, resource_type, target):
try:
API_KEY = KeyRing().get("virustotal")
if not API_KEY:
print("No API key...!")
return None
Expand Down

0 comments on commit 2947e91

Please sign in to comment.