-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.py
79 lines (57 loc) · 2.67 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from fastapi import FastAPI
import os
import subprocess
import asyncio
from typing import Optional
import json
# Author: Jubaer
app = FastAPI()
os.environ["GOPATH"] = str(os.getcwd())+"/go/bin/tools"
os.environ["GOBIN"] = str(os.getcwd())+"/go/bin"
subprocess.run(["chmod -R +x "+str(os.getcwd())+"/go/bin/go"], shell=True)
## Local environment (If you don't have go installed or showing errors then try to use this)
subprocess.run([str(os.getcwd())+"/go/bin/go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest"], shell=True)
subprocess.run([str(os.getcwd())+"/go/bin/go install -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest"], shell=True)
## Local environment (If you have go installed already then use this)
# subprocess.run(["go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest"], shell=True)
# subprocess.run(["go install -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest"], shell=True)
@app.get("/api/scanner1/{domain}")
async def subdomain(domain:str):
special_characters = """"!@# $%^&*'()}{[]|\`+?_=,<>/"""
if 'http' in domain:
return "Error Input"
elif len(domain) < 1:
return "Error Input"
elif '.' not in domain:
return "Error Input"
elif 'www.' in domain:
return "Error Input! Please remove WWW"
elif any(c in special_characters for c in domain):
return "Error Input"
out = await asyncio.create_subprocess_shell(str(os.getcwd()) + "/go/bin/subfinder -d " + str(domain),
stdout=subprocess.PIPE)
data = []
output = await out.communicate()
for subs in output[0].decode().split('\n'):
if len(subs) != 0:
data.append(subs)
return {'result':data}
@app.get("/api/scanner2/nuclei")
async def nuclei_scanner(target_name: str, autoscan: bool, tags: Optional[str] = None):
try:
if autoscan == True:
out = subprocess.Popen(str(os.getcwd()) + "/go/bin/nuclei -u " + str(target_name) + " -as -json", shell=True,
stdout=subprocess.PIPE)
else:
# Change the parameters as you require
out = subprocess.Popen(str(os.getcwd()) + "/go/bin/nuclei -u " + str(target_name) + " -json -tags " + str(tags),
shell=True, stdout=subprocess.PIPE)
output = out.communicate()
data = []
for result in output[0].decode().split('\n'):
if len(result) != 0:
output_json = json.loads(result)
data.append(output_json)
return data
except Exception as e:
return {'message': "Error, Please try again!"}