Skip to content

Commit

Permalink
chg: [improvement] format output + typo const
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Oct 3, 2023
1 parent 5819c70 commit dc4209d
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 78 deletions.
55 changes: 55 additions & 0 deletions ail_typo_squatting/format/output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import yaml

from format.yara import formatYara
from format.regex import formatRegex, formatRegexRetrie
from format.yaml import formatYaml

def formatOutput(format, resultList, domain, pathOutput, givevariations=False, betterRegex=False):
"""
Call different function to create the right format file
"""

if format == "text":
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.txt", "w", encoding='utf-8') as write_file:
for element in resultList:
if givevariations:
write_file.write(f"{element[0]}, {element[1]}\n")
else:
write_file.write(element + "\n")
elif pathOutput == "-":
for element in resultList:
if givevariations:
print(f"{element[0]}, {element[1]}")
else:
print(element)

elif format == "yara":
yara = formatYara(resultList, domain, givevariations)
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.yar", "w", encoding='utf-8') as write_file:
write_file.write(yara)
elif pathOutput == "-":
print(yara)

elif format == "regex":
if betterRegex:
regex = formatRegexRetrie(resultList, givevariations)
else:
regex = formatRegex(resultList, givevariations)
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.regex", "w", encoding='utf-8') as write_file:
write_file.write(regex)
elif pathOutput == "-":
print(regex)

elif format == "yaml":
yaml_file = formatYaml(resultList, domain, givevariations)
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.yml", "w", encoding='utf-8') as write_file:
yaml.dump(yaml_file, write_file)
elif pathOutput == "-":
print(yaml_file)
else:
print(f"Unknown format: {format}. Will use text format instead")
formatOutput("text", resultList, domain, pathOutput, givevariations)
6 changes: 0 additions & 6 deletions ail_typo_squatting/generator/addTld.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def addTld(domain, resultList, verbose, limit, givevariations=False, keeporigina
if verbose:
print(f"{cp}\n")

# if combo:
# return final_treatment(domain, loc_result_list, limit, givevariations, keeporiginal, "addTld")

# resultList = resultList + loc_result_list
# resultList = final_treatment(domain, resultList, limit, givevariations, keeporiginal, "addTld")

return final_treatment(domain, loc_result_list, limit, givevariations, keeporiginal, "addTld")

return resultList
Expand Down
1 change: 0 additions & 1 deletion ail_typo_squatting/generator/changeOrder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Import all the utils
from .utils.generator_functions import *


"""
Original Domain Typosquatted Domain
Expand Down
5 changes: 2 additions & 3 deletions ail_typo_squatting/generator/commonMisspelling.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Import all the utils
from .utils.generator_functions import *
from .utils.get_pathetc import get_path_etc

import json

from .utils.get_pathetc import get_path_etc

pathEtc = get_path_etc()

print(pathEtc)


def commonMisspelling(domain, resultList, verbose, limit, givevariations=False, keeporiginal=False, combo=False):
"""Change a word by is misspellings"""
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions ail_typo_squatting/generator/homoglyph.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Import all the utils
from .utils.generator_functions import *


from .conts.main import *
from .const.main import *

glyphs = const_get_similar_chars()

Expand Down
3 changes: 0 additions & 3 deletions ail_typo_squatting/generator/missingDot.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ def missingDot(domain, resultList, verbose, limit, givevariations=False, keepor
if verbose:
print(f"{cp}\n")

# if combo:
# return final_treatment(domain, loc_result_list, limit, givevariations, keeporiginal, "missingDot")
return final_treatment(domain, loc_result_list, limit, givevariations, keeporiginal, "missingDot")


return resultList
2 changes: 1 addition & 1 deletion ail_typo_squatting/generator/numeralSwap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Import all the utils
from .utils.generator_functions import *
from .conts.main import *
from .const.main import *

numerals = const_get_numeral()

Expand Down
1 change: 0 additions & 1 deletion ail_typo_squatting/generator/subdomain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Import all the utils
from .utils.generator_functions import *


"""
Original Domain Typosquatted Domain
Expand Down
6 changes: 5 additions & 1 deletion ail_typo_squatting/generator/utils/generator_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tldextract

# Import the constants stored in "../const/main.py"
from ..conts.main import *
from ..const.main import *

# The constants
algo_list = const_get_algo_name_list()
Expand Down Expand Up @@ -41,6 +41,7 @@ def globalAppend(loclist):

return r[-1]


def checkResult(resultLoc, resultList, givevariations, algoName=''):
"""
Verify if element in resultLoc not exist in resultList before adding them in resultList
Expand Down Expand Up @@ -75,6 +76,7 @@ def checkResult(resultLoc, resultList, givevariations, algoName=''):

return loc_result_list


def check_valid_domain(domain_extract):
if not domain_extract.suffix:
return("[-] Domain not valid")
Expand All @@ -84,6 +86,7 @@ def check_valid_domain(domain_extract):
return("[-] Only a TLD is identified. Try adding something like 'www.' before your domain.")
return ""


def parse_domain(domain):
domain_extract = tldextract.extract(domain)

Expand All @@ -104,6 +107,7 @@ def parse_domain(domain):

return prefix, domain_extract.domain, domain_extract.suffix


def final_treatment(domain, resultList, limit, givevariations, keeporiginal, algo_name):
""" Final treatment of a variation's function, keep original and name of variations' algorithm """
if not keeporiginal:
Expand Down
4 changes: 2 additions & 2 deletions ail_typo_squatting/generator/wrongTld.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from .utils.generator_functions import *
from .utils.get_pathetc import get_path_etc

pathEtc = get_path_etc()

import pkgutil
from typing import cast

pathEtc = get_path_etc()


"""
Expand Down
61 changes: 4 additions & 57 deletions ail_typo_squatting/typo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Import all the modules

## The public libraries
import os, sys, math, yaml
import os, sys, math

## The local libraries
from generator.conts.main import *
from generator.utils.generator_functions import check_valid_domain
from generator.const.main import *

## The typo generator
from generator.addDash import addDash
Expand All @@ -31,9 +30,7 @@
from generator.wrongSld import wrongSld

## The format function
from format.yara import formatYara
from format.regex import formatRegex, formatRegexRetrie
from format.yaml import formatYaml
from format.output import formatOutput

## The dns resolving function
from dns_local.resolving import dnsResolving # named "dns_local" to avoid conflict with the dns library
Expand All @@ -44,64 +41,14 @@
sys.path.append(get_path_etc())


# Import all the constants of data from the file conts/main.py
# Import all the constants of data from the file const/main.py
# If you wanna add a new algorithm, you have to add it in the list algo_list
numerals = const_get_numeral()
algo_list = const_get_algo_name_list()


## [START] Final treatment

def formatOutput(format, resultList, domain, pathOutput, givevariations=False, betterRegex=False):
"""
Call different function to create the right format file
"""

if format == "text":
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.txt", "w", encoding='utf-8') as write_file:
for element in resultList:
if givevariations:
write_file.write(f"{element[0]}, {element[1]}\n")
else:
write_file.write(element + "\n")
elif pathOutput == "-":
for element in resultList:
if givevariations:
print(f"{element[0]}, {element[1]}")
else:
print(element)

elif format == "yara":
yara = formatYara(resultList, domain, givevariations)
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.yar", "w", encoding='utf-8') as write_file:
write_file.write(yara)
elif pathOutput == "-":
print(yara)

elif format == "regex":
if betterRegex:
regex = formatRegexRetrie(resultList, givevariations)
else:
regex = formatRegex(resultList, givevariations)
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.regex", "w", encoding='utf-8') as write_file:
write_file.write(regex)
elif pathOutput == "-":
print(regex)

elif format == "yaml":
yaml_file = formatYaml(resultList, domain, givevariations)
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.yml", "w", encoding='utf-8') as write_file:
yaml.dump(yaml_file, write_file)
elif pathOutput == "-":
print(yaml_file)
else:
print(f"Unknown format: {format}. Will use text format instead")
formatOutput("text", resultList, domain, pathOutput, givevariations)

def runAll(domain, limit, formatoutput, pathOutput, verbose=False, givevariations=False, keeporiginal=False, all_homoglyph=False):
"""Run all algo on each domain contain in domainList"""

Expand Down

0 comments on commit dc4209d

Please sign in to comment.