2021-06-07 14:07:08 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The LibInjection Module
|
|
|
|
================================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the Urls module.
|
|
|
|
|
|
|
|
It tries to identify SQL Injections with libinjection.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import pylibinjection
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from pyfaup.faup import Faup
|
2022-10-25 14:25:19 +00:00
|
|
|
from urllib.parse import unquote
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from modules.abstract_module import AbstractModule
|
|
|
|
from lib.ConfigLoader import ConfigLoader
|
2022-10-25 14:25:19 +00:00
|
|
|
from lib.objects.Items import Item
|
2023-03-30 13:23:41 +00:00
|
|
|
# from lib import Statistics
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
class LibInjection(AbstractModule):
|
|
|
|
"""docstring for LibInjection module."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(LibInjection, self).__init__()
|
|
|
|
|
|
|
|
self.faup = Faup()
|
|
|
|
|
|
|
|
self.redis_logger.info(f"Module: {self.module_name} Launched")
|
|
|
|
|
|
|
|
def compute(self, message):
|
2023-06-22 13:38:04 +00:00
|
|
|
item = self.get_obj()
|
|
|
|
url = message
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
self.faup.decode(url)
|
|
|
|
url_parsed = self.faup.get()
|
2022-10-25 14:25:19 +00:00
|
|
|
# # TODO: # FIXME: remove me
|
2021-06-07 14:07:08 +00:00
|
|
|
try:
|
|
|
|
resource_path = url_parsed['resource_path'].encode()
|
|
|
|
except:
|
|
|
|
resource_path = url_parsed['resource_path']
|
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# # TODO: # FIXME: remove me
|
2021-06-07 14:07:08 +00:00
|
|
|
try:
|
|
|
|
query_string = url_parsed['query_string'].encode()
|
|
|
|
except:
|
|
|
|
query_string = url_parsed['query_string']
|
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
result_path = {'sqli': False}
|
|
|
|
result_query = {'sqli': False}
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
if resource_path is not None:
|
|
|
|
result_path = pylibinjection.detect_sqli(resource_path)
|
2022-10-25 14:25:19 +00:00
|
|
|
# print(f'path is sqli : {result_path}')
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
if query_string is not None:
|
|
|
|
result_query = pylibinjection.detect_sqli(query_string)
|
2022-10-25 14:25:19 +00:00
|
|
|
# print(f'query is sqli : {result_query}')
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
if result_path['sqli'] is True or result_query['sqli'] is True:
|
|
|
|
item_id = item.get_id()
|
|
|
|
print(f"Detected (libinjection) SQL in URL: {item_id}")
|
2022-10-25 14:25:19 +00:00
|
|
|
print(unquote(url))
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
to_print = f'LibInjection;{item.get_source()};{item.get_date()};{item.get_basename()};Detected SQL in URL;{item_id}'
|
|
|
|
self.redis_logger.warning(to_print)
|
|
|
|
|
|
|
|
# Add tag
|
2023-06-22 13:38:04 +00:00
|
|
|
tag = 'infoleak:automatic-detection="sql-injection"'
|
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2021-06-07 14:07:08 +00:00
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# statistics
|
2023-03-30 13:23:41 +00:00
|
|
|
# # # TODO: # FIXME: remove me
|
|
|
|
# try:
|
|
|
|
# tld = url_parsed['tld'].decode()
|
|
|
|
# except:
|
|
|
|
# tld = url_parsed['tld']
|
|
|
|
# if tld is not None:
|
|
|
|
# date = datetime.now().strftime("%Y%m")
|
|
|
|
# Statistics.add_module_tld_stats_by_date(self.module_name, date, tld, 1)
|
2021-06-07 14:07:08 +00:00
|
|
|
|
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
if __name__ == "__main__":
|
2021-06-07 14:07:08 +00:00
|
|
|
module = LibInjection()
|
|
|
|
module.run()
|