Skip to content

Commit

Permalink
chg: [output Path] no display if no output path is pass
Browse files Browse the repository at this point in the history
Useful for ail-typo-website, to avoid lot of print during dns resolving
  • Loading branch information
DavidCruciani committed Sep 22, 2022
1 parent 57158fd commit b7cb33d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ail-typo-squatting can be install with poetry. If you don't have poetry installe
~~~bash
$ poetry install
$ poetry shell
$ ail-typo-squatting -h
$ cd ail-typo-squatting
$ python typo.py -h
~~~

## pip installation
Expand Down Expand Up @@ -160,7 +161,7 @@ for domain in domainList:
# Sample output
There's 4 format possible for the output file:
There's **4 format** possible for the output file:

- text
- yara
Expand All @@ -169,7 +170,7 @@ There's 4 format possible for the output file:



For text file, each line is a variation.
For **Text** file, each line is a variation.

````
ail-project.org
Expand All @@ -191,7 +192,7 @@ aiil-project.org



For Yara file, each rule is a variation.
For **Yara** file, each rule is a variation.

~~~~
rule ail-project_org {
Expand All @@ -217,15 +218,15 @@ rule ail-project_org {



For regex file, each variations is transform into regex and concatenate with other to do only one big regex.
For **Regex** file, each variations is transform into regex and concatenate with other to do only one big regex.

~~~~
ail\-project\.org|il\-project\.org|al\-project\.org|ai\-project\.org|ailproject\.org|ail\-roject\.org|ail\-poject\.org|ail\-prject\.org|ail\-proect\.org|ail\-projct\.org|ail\-projet\.org|ail\-projec\.org
~~~~



For sigma file, each variations are list under `variations` key.
For **Sigma** file, each variations are list under `variations` key.

~~~~
title: ail-project.org
Expand Down Expand Up @@ -287,6 +288,8 @@ each keys are variations and may have a field "ip" if the domain name have been
}
````



# List of algorithms used


Expand Down Expand Up @@ -315,6 +318,7 @@ each keys are variations and may have a field "ip" if the domain name have been
| Subdomain | These typos are created by placing a dot in the domain name in order to create subdomain. Example: google.com becomes goo.gle.com |



# Acknowledgment

![](./img/cef.png)
Expand Down
54 changes: 31 additions & 23 deletions ail_typo_squatting/typo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,12 +1051,15 @@ def runAll(domain, limit, formatoutput, pathOutput, verbose=False):
return resultList


def dnsResolving(resultList, domain, pathOutput):
def dnsResolving(resultList, domain, pathOutput, verbose=False):
"""Do a dns resolving on each variations and then create a json"""

import dns.name
import dns.resolver
print("[+] Dns Resolving...")

if verbose:
print("[+] Dns Resolving...")

domain_resolve = dict()

for result in resultList:
Expand All @@ -1079,11 +1082,11 @@ def dnsResolving(resultList, domain, pathOutput):
else:
domain_resolve[result]['NotExist'] = False

if not pathOutput == "-":
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}_resolve.json", "w", encoding='utf-8') as write_json:
json.dump(domain_resolve, write_json, indent=4)
else:
sys.stdout.write(json.dumps(domain_resolve))
elif pathOutput == '-':
print(json.dumps(domain_resolve), flush=True)

return domain_resolve

Expand Down Expand Up @@ -1138,34 +1141,37 @@ def formatOutput(format, resultList, domain, pathOutput):
"""

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

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

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

elif format == "yaml":
yaml_file = formatYaml(resultList, domain)
if not pathOutput == "-":
if pathOutput and not pathOutput == "-":
with open(f"{pathOutput}/{domain}.yml", "w", encoding='utf-8') as write_file:
yaml.dump(yaml_file, write_file)
else:
sys.stdout.write(yaml)
elif pathOutput == "-":
print(yaml_file)



Expand All @@ -1178,7 +1184,7 @@ def formatOutput(format, resultList, domain, pathOutput):
parser.add_argument("-dn", "--domainName", nargs="+", help="list of domain name")
parser.add_argument("-fdn", "--filedomainName", help="file containing list of domain name")

parser.add_argument("-o", "--output", help="path to ouput location", required=True)
parser.add_argument("-o", "--output", help="path to ouput location")
parser.add_argument("-fo", "--formatoutput", help="format for the output file, yara - regex - yaml - text. Default: text")

parser.add_argument("-dnsr", "--dnsresolving", help="resolve all variation of domain name to see if it's up or not", action="store_true")
Expand Down Expand Up @@ -1221,7 +1227,7 @@ def formatOutput(format, resultList, domain, pathOutput):

pathOutput = args.output

if not pathOutput == "-":
if pathOutput and not pathOutput == "-":
try:
os.makedirs(pathOutput)
except:
Expand Down Expand Up @@ -1249,19 +1255,21 @@ def formatOutput(format, resultList, domain, pathOutput):
# the option for all algo to run is selected
if args.all:
for domain in domainList:
print(f"\n\t[*****] {domain} [*****]")
if pathOutput:
print(f"\n\t[*****] {domain} [*****]")

resultList = runAll(domain, limit, formatoutput, pathOutput, verbose)

if args.dnsresolving:
dnsResolving(resultList, domain, pathOutput)
dnsResolving(resultList, domain, pathOutput, verbose)

resultList = list()

# The user select sepcial algo but not all
else:
for domain in domainList:
print(f"\n\t[*****] {domain} [*****]")
if pathOutput:
print(f"\n\t[*****] {domain} [*****]")

if args.characteromission:
resultList = characterOmission(domain, resultList, verbose, limit)
Expand Down Expand Up @@ -1340,6 +1348,6 @@ def formatOutput(format, resultList, domain, pathOutput):
if args.dnsresolving:
domain_resolve = dict()

dnsResolving(resultList, domain, pathOutput)
dnsResolving(resultList, domain, pathOutput, verbose)

resultList = list()

0 comments on commit b7cb33d

Please sign in to comment.