Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update remote #1

Merged
merged 237 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
237 commits
Select commit Hold shift + click to select a range
d51de6d
Create LICENCE.md
sagarpo Jan 10, 2018
0885c5c
Rename LICENCE.md to LICENSE.md
sagarpo Jan 10, 2018
69744eb
Create LICENSE
sagarpo Jan 10, 2018
f7b517d
Merge pull request #1 from flipkart-incubator/add-license-1
sagarpo Jan 10, 2018
eaef07e
Delete LICENSE.md
sagarpo Jan 10, 2018
9042898
Merge branch 'master' of https://github.com/flipkart-incubator/apiscan
sagarpo Jan 10, 2018
c2c44b3
Bug fix
sagarpo Jan 10, 2018
cdc8071
Delete core.py
sagarpo Jan 10, 2018
197e418
Minor changes
sagarpo Jan 10, 2018
30041df
Minor changes
sagarpo Jan 10, 2018
2379c6c
Merge branch 'master' of https://github.com/flipkart-incubator/apiscan
sagarpo Jan 10, 2018
5bca9b5
Minor changes
sagarpo Jan 10, 2018
6770e2d
Added ConfigParser
sagarpo Jan 11, 2018
7e9ca19
Minor change
sagarpo Jan 11, 2018
c168023
minor change
sagarpo Jan 11, 2018
3f465ef
Core bug fix
sagarpo Jan 11, 2018
368f7fd
Delete apiscan.py
sagarpo Jan 11, 2018
25df0fd
Bug fix
sagarpo Jan 11, 2018
7539de1
Add files via upload
sagarpo Jan 12, 2018
fee1e21
Update README.md
sagarpo Jan 12, 2018
b40dd87
Added report image
sagarpo Jan 12, 2018
84e8892
Bug fix
sagarpo Jan 13, 2018
644044e
Bug fix-DB
sagarpo Jan 14, 2018
a5e33c2
Added Report feature
sagarpo Jan 14, 2018
30e762f
Changed name API to Report
sagarpo Jan 14, 2018
2aca3f5
Bug fix
sagarpo Jan 14, 2018
0f62f28
Delete alerts.py
sagarpo Jan 14, 2018
45fff2a
Delete alert.js
sagarpo Jan 14, 2018
530c305
Delete report.html
sagarpo Jan 14, 2018
0a7e8ca
Added Report
sagarpo Jan 14, 2018
e4f3d17
Bug fix
sagarpo Jan 14, 2018
a80a308
Bug fix
sagarpo Jan 14, 2018
3e98120
DB code changes
sagarpo Jan 14, 2018
003b5ac
Bug fix
sagarpo Jan 26, 2018
ab26dfd
Small changes
sagarpo Jan 31, 2018
6a6d668
Bug fix
sagarpo Feb 1, 2018
3ad57ce
Bug fix
sagarpo Feb 1, 2018
7eb8d00
Login bug fix
sagarpo Feb 1, 2018
6b874e2
bug fix
sagarpo Feb 1, 2018
ac32166
API added
sagarpo Feb 4, 2018
b1b276d
Added API
sagarpo Feb 6, 2018
f4092f6
Added API
sagarpo Feb 6, 2018
e2c02e1
Added API
sagarpo Feb 6, 2018
6e93587
Added API
sagarpo Feb 6, 2018
aec2215
Added API
sagarpo Feb 6, 2018
0eb5888
Added API
sagarpo Feb 6, 2018
bf225dd
Added API
sagarpo Feb 6, 2018
abd737a
Added API
sagarpo Feb 6, 2018
debdd47
API bug fix
sagarpo Feb 14, 2018
767065e
DB update code changes
sagarpo Feb 14, 2018
b06b39a
Bug fix
sagarpo Feb 14, 2018
53ca65f
changes in HELP
sagarpo Feb 14, 2018
cbc7da3
Buf fix
sagarpo Feb 14, 2018
3703fff
Bug fix
sagarpo Feb 15, 2018
f7c156f
Added CORS headeR
sagarpo Feb 16, 2018
c19b14b
Added vulnerabilities
sagarpo Feb 17, 2018
3b4d810
Added scanid feature
sagarpo Feb 18, 2018
258bffc
Added scanid feature
sagarpo Feb 18, 2018
6ddfeef
Added scanid feature
sagarpo Feb 18, 2018
a5c4f71
Bug fix
sagarpo Feb 19, 2018
41403f3
Mongo db bug fix
sagarpo Feb 19, 2018
603cd92
Bug fix
sagarpo Feb 19, 2018
60de72f
Added scanid feature
sagarpo Feb 19, 2018
0e7f946
Added scanid feature
sagarpo Feb 19, 2018
b31f69c
ZAP bug fix
sagarpo Feb 19, 2018
e6b6efa
Added __init__ file
sagarpo Feb 19, 2018
3d054c3
Bug fix
sagarpo Feb 24, 2018
b5fc00a
Bug fix - ZAP
sagarpo Feb 24, 2018
38e7ab4
Bug fix
sagarpo Feb 24, 2018
35d4073
DB bug fix
sagarpo Feb 24, 2018
71fc3fc
Bug fix - Linux
sagarpo Feb 25, 2018
a3a9e6a
Removed git
sagarpo Feb 25, 2018
249be7c
Added scanid API
sagarpo Mar 9, 2018
725da97
New dashboard
sagarpo Mar 9, 2018
2cf87e7
Removed content file
sagarpo Mar 9, 2018
cf1e1b0
Removed test files
sagarpo Mar 9, 2018
fc65c22
Removed old dashboard
sagarpo Mar 9, 2018
2d6188d
Scanid API change
sagarpo Mar 13, 2018
d11ad51
Added table for recent scans
sagarpo Mar 13, 2018
a20a4b7
New feature
sagarpo Mar 13, 2018
d8a0c67
JWT attack module
sagarpo Mar 14, 2018
960981d
Added jwt_brute
sagarpo Mar 15, 2018
385afaa
Added jwt_brute
sagarpo Mar 15, 2018
081f8f4
Changes in JWT alert
sagarpo Mar 15, 2018
26a5830
Added pyjwt
sagarpo Mar 15, 2018
94eb9b0
Added SQLI module
sagarpo Mar 16, 2018
3f02b3a
Added SQLI module
sagarpo Mar 16, 2018
506975a
Removed comment
sagarpo Mar 16, 2018
b071a2e
Added SQLI support
sagarpo Mar 16, 2018
a0c39d4
Added auto start sqlmap
sagarpo Mar 17, 2018
158b78e
Chaged log directory
sagarpo Mar 18, 2018
01e9381
Delete auth.pyc
sagarpo Mar 18, 2018
ce47416
Minor changes
sagarpo Mar 19, 2018
20d299a
Moved CSRF param names to config file
sagarpo Mar 19, 2018
66f2d84
Removed extra lines
sagarpo Mar 19, 2018
d7ced89
Added csrf param names in config file
sagarpo Mar 19, 2018
5f1ab07
Merge pull request #2 from flipkart-incubator/dev
prajal Mar 20, 2018
270e3fb
Added XSS module
sagarpo Mar 21, 2018
c7435cd
changes in xss_get_method function
sagarpo Mar 21, 2018
5ac7fb2
Added XSS module
sagarpo Mar 21, 2018
01f8112
Code changes
sagarpo Mar 21, 2018
1611d2e
changes in xss_http_headers function
sagarpo Mar 22, 2018
d6da358
changes in log file
sagarpo Mar 23, 2018
e1cb808
file name change
sagarpo Mar 23, 2018
1926661
Delete apiscan.py
sagarpo Mar 23, 2018
6da9036
name changed from apiscan to astra
sagarpo Mar 23, 2018
0d1388f
Merge branch 'dev' of https://github.com/flipkart-incubator/Astra int…
sagarpo Mar 23, 2018
350a324
Name changed from apiscan to astra
sagarpo Mar 23, 2018
ea2033d
Added description for JWT, SQLi, XSS
sagarpo Mar 23, 2018
7b48dd5
XSS module changes
sagarpo Mar 24, 2018
3d62b63
Added XSS payloads
sagarpo Mar 24, 2018
adf6025
Minor changes in xss_post_method function
sagarpo Mar 25, 2018
5f6fdd0
Minor changes in xss_post_method function
sagarpo Mar 25, 2018
154a721
Added logger
sagarpo Mar 25, 2018
3eee84e
Update README.md
sagarpo Mar 25, 2018
335dbb9
Update README.md
sagarpo Mar 25, 2018
85111d7
Update README.md
sagarpo Mar 25, 2018
679bfde
Update README.md
sagarpo Mar 25, 2018
c17318c
Update README.md
sagarpo Mar 25, 2018
77a178f
Update README.md
sagarpo Mar 25, 2018
1702804
Update README.md
sagarpo Mar 25, 2018
edf6910
Update README.md
sagarpo Mar 25, 2018
f30aec1
Merge pull request #4 from flipkart-incubator/dev
prajal Mar 26, 2018
f14af54
Added XSS module
sagarpo Mar 26, 2018
d839330
Merge pull request #6 from flipkart-incubator/dev
prajal Mar 26, 2018
3080e53
XSS - Bug fix
sagarpo Mar 27, 2018
0560865
Update xss.tx
sagarpo Mar 27, 2018
1cb732d
Merge pull request #7 from flipkart-incubator/dev
prajal Mar 28, 2018
8ebf7ac
Added scan status
sagarpo Mar 29, 2018
a4857dc
minor change
sagarpo Mar 29, 2018
d8f32b3
Merge pull request #8 from flipkart-incubator/dev
prajal Mar 31, 2018
07e0900
Create images
sagarpo Mar 31, 2018
ae6f2d0
Delete images
sagarpo Mar 31, 2018
bc31e43
Add files via upload
sagarpo Mar 31, 2018
294d197
Update README.md
sagarpo Mar 31, 2018
62a97db
Add files via upload
sagarpo Mar 31, 2018
ee12148
Update README.md
sagarpo Mar 31, 2018
730a825
Update README.md
sagarpo Mar 31, 2018
e5bfad0
Update README.md
sagarpo Mar 31, 2018
5d64ef3
Add files via upload
sagarpo Mar 31, 2018
876d52d
Update README.md
sagarpo Mar 31, 2018
40f8193
Add files via upload
sagarpo Mar 31, 2018
8a9f4c6
Update README.md
sagarpo Mar 31, 2018
563d832
Update README.md
sagarpo Mar 31, 2018
658457d
Add files via upload
sagarpo Mar 31, 2018
81e0560
Update README.md
sagarpo Mar 31, 2018
8d9c6ab
Update README.md
sagarpo Apr 3, 2018
d515cf1
Web interface changes
sagarpo Apr 4, 2018
9defc29
Merge branch 'dev' of https://github.com/flipkart-incubator/Astra int…
sagarpo Apr 4, 2018
f01fe71
Added open redirection module
sagarpo Apr 4, 2018
0edadff
Open redirection Payload
sagarpo Apr 4, 2018
438d059
Merge pull request #9 from flipkart-incubator/dev
prajal Apr 5, 2018
83f39d1
Added flask dependency
sagarpo Apr 5, 2018
049ca94
Merge pull request #10 from flipkart-incubator/dev
sagarpo Apr 5, 2018
530c996
Update README.md
sagarpo Apr 5, 2018
e7cd5f9
Update README.md
sagarpo Apr 5, 2018
184fc57
Update property file
sagarpo Apr 5, 2018
7d410aa
Merge branch 'dev' of https://github.com/flipkart-incubator/Astra int…
sagarpo Apr 5, 2018
4ca56d0
Update README.md
sagarpo Apr 5, 2018
dfe9f8f
Update db file
sagarpo Apr 5, 2018
ae00e12
UI bug fix
sagarpo Apr 5, 2018
aef2029
Update README file
sagarpo Apr 6, 2018
56b3164
Update README file
sagarpo Apr 6, 2018
e4f6037
Merge pull request #15 from flipkart-incubator/dev
sagarpo Apr 7, 2018
e316e29
Connection handle if Mongo not istalled
gajjar8055 Apr 9, 2018
46ac8dd
Bug fix
sagarpo Apr 10, 2018
acf89c3
Merge pull request #21 from flipkart-incubator/dev
prajal Apr 10, 2018
b7b44f9
Merge pull request #23 from gajjar8055/master
sagarpo Apr 13, 2018
5ce87d1
Minor changes
sagarpo Apr 13, 2018
695bde0
Merge branch 'dev' of https://github.com/flipkart-incubator/Astra int…
sagarpo Apr 13, 2018
9297238
Minor changes
sagarpo Apr 13, 2018
57a163f
Merge pull request #26 from flipkart-incubator/dev
ankurbhargava87f Apr 16, 2018
32f4ddb
Update README.md
sagarpo Apr 22, 2018
804b8b3
Added installation docs for astra
sagarpo Apr 23, 2018
0e84d5e
Merge pull request #29 from flipkart-incubator/dev
sagarpo Apr 23, 2018
3b3140f
Added docs for usage, credits, roadmap
sagarpo Apr 24, 2018
8b7e1ec
Merge pull request #31 from flipkart-incubator/dev
sagarpo Apr 24, 2018
64c88ac
Update README.md
sagarpo Apr 25, 2018
5c35e44
Merge pull request #32 from flipkart-incubator/dev
prajal Apr 26, 2018
e5a6b78
Update README.md
sagarpo Apr 26, 2018
d8c169a
Merge pull request #33 from flipkart-incubator/dev
prajal Apr 26, 2018
9acacc0
Minor changes
sagarpo May 3, 2018
101fea9
Merge pull request #35 from flipkart-incubator/dev
prajal May 4, 2018
482f2ee
add Docker support
disenchant May 4, 2018
28f4714
Update README.md
sagarpo May 4, 2018
6efed9e
Fix typo on roadmap.md
royingantaginting May 7, 2018
9dcc741
Merge pull request #43 from royingantaginting/patch-1
sagarpo May 7, 2018
3784f5a
Merge pull request #37 from disenchant/master
prajal May 9, 2018
0490dac
Added Docker support for GUI
mohangcsm May 14, 2018
82ef1e5
Merge pull request #45 from flipkart-incubator/dev
sagarpo May 14, 2018
1714b51
README.md file updated
mohangcsm May 15, 2018
9e75a0d
README.md file updated
mohangcsm May 15, 2018
44f22f2
README.md file updated
mohangcsm May 15, 2018
e772f99
Merge pull request #46 from flipkart-incubator/dev
prajal May 15, 2018
3d917de
Update sendrequest.py
sagarpo May 17, 2018
ec1d8ae
Update sendrequest.py
sagarpo May 17, 2018
b4878f7
Merge pull request #48 from flipkart-incubator/dev
prajal May 17, 2018
6257df4
Update installation.md
sagarpo May 17, 2018
2a3a624
Bug fix - Broken Auth
sagarpo Jul 8, 2018
98231c5
Bug fix - Broken Auth
sagarpo Jul 8, 2018
3160793
Merge pull request #52 from flipkart-incubator/dev
prajal Jul 9, 2018
b223d44
Bug fix and minor code changes
sagarpo Jul 21, 2018
5ebacec
Merge pull request #55 from flipkart-incubator/dev
prajal Jul 23, 2018
03fe1d4
Auto Login detection improvement
sagarpo Jul 25, 2018
7de0a2b
Config file changes
sagarpo Jul 25, 2018
0238311
Auto-login improvement
sagarpo Jul 25, 2018
317b705
Merge pull request #56 from flipkart-incubator/dev
prajal Jul 27, 2018
07021c1
CLI improvement
sagarpo Jul 27, 2018
2597894
Merge pull request #57 from flipkart-incubator/dev
prajal Jul 27, 2018
8304a11
Added XXE module
sagarpo Aug 1, 2018
dbcde00
XXE payload
sagarpo Aug 1, 2018
d2f0a29
Merge pull request #58 from flipkart-incubator/dev
prajal Aug 1, 2018
9bb6e87
Added CRLF module
Aug 1, 2018
6c0c96f
CRLF module
Aug 1, 2018
cf99055
CRLF module
Aug 1, 2018
be52b90
Merge pull request #59 from flipkart-incubator/dev
prajal Aug 1, 2018
3772d92
Update README.md
prajal Aug 1, 2018
6e5fed8
XXE bug fix
sagarpo Sep 25, 2018
f4001b5
XXE bug fix
sagarpo Sep 28, 2018
8de13b3
Merge pull request #65 from flipkart-incubator/dev
prajal Oct 1, 2018
973a0a4
adding robots.txt file
mohangcsm Oct 5, 2018
3fa84ca
Merge pull request #66 from flipkart-incubator/dev
sagarpo Oct 5, 2018
9f954c7
CI/CD integration support
sagarpo Nov 23, 2018
e42839a
CI/CD integration support
sagarpo Nov 23, 2018
a2a5fbe
CI/CD integration support
sagarpo Nov 23, 2018
e203487
Merge pull request #75 from flipkart-incubator/dev
prajal Nov 23, 2018
c39bd56
UI changes
sagarpo Nov 24, 2018
b462d34
Merge pull request #76 from flipkart-incubator/dev
prajal Nov 28, 2018
d6bf17f
Added security-headers-missing module that checks for various securit…
harsh-groverfk Dec 5, 2018
04d7c45
Merge pull request #78 from flipkart-incubator/dev
sagarpo Dec 5, 2018
04e87ff
Update scan.property
sagarpo Dec 5, 2018
49dc646
Update scan.property
sagarpo Dec 5, 2018
8240f1a
Merge pull request #80 from flipkart-incubator/dev
sagarpo Dec 5, 2018
0215354
Update README.md
sagarpo Dec 10, 2018
94016d6
Update README.md
sagarpo Dec 10, 2018
3b9dcdd
Update README.md
sagarpo Dec 10, 2018
7d0f211
Merge pull request #83 from flipkart-incubator/dev
sagarpo Dec 10, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.dockerignore
Dockerfile
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
*.log

Empty file added API/__init__.py
Empty file.
55 changes: 0 additions & 55 deletions API/alerts.py

This file was deleted.

285 changes: 285 additions & 0 deletions API/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
import ast
import os
import json
import sys
import hashlib
import time
import json
import threading
import logging
import requests
import socket
import urlparse
import re

from dbconnection import db_connect
from scanstatus import check_scan_status, scan_status

sys.path.append('../')

from flask import Flask, render_template, send_from_directory
from flask import Response, make_response
from flask import request
from flask import Flask
from flask import jsonify
from pymongo import MongoClient
from pymongo.errors import ServerSelectionTimeoutError



from utils.vulnerabilities import alerts
#from utils.sendemail import send_email
from jinja2 import utils
from utils.email_cron import send_email_notification


if os.getcwd().split('/')[-1] == 'API':
from astra import scan_single_api, scan_postman_collection


app = Flask(__name__, template_folder='../Dashboard/templates', static_folder='../Dashboard/static')


class ServerThread(threading.Thread):

def __init__(self):
threading.Thread.__init__(self)

def run(self):
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
app.run(host='0.0.0.0', port= 8094)


db_object = db_connect()
global db
db = db_object.apiscan


############################# Start scan API ######################################
def generate_hash():
# Return md5 hash value of current timestmap
scanid = hashlib.md5(str(time.time())).hexdigest()
return scanid

def xss_filter(data):
data = str(data)
# Filter special chars to prevent XSS
filterd_data = data.replace("<","&lt;").replace(">","&gt;")
try:
filterd_data = ast.literal_eval(filterd_data)
except:
pass

return filterd_data

# Start the scan and returns the message
@app.route('/scan/', methods = ['POST'])
def start_scan():
scanid = generate_hash()
content = request.get_json()
try:
name = content['appname']
url = str(content['url'])
headers = str(content['headers'])
body = str(content['body'])
method = content['method']
api = "Y"
scan_status = scan_single_api(url, method, headers, body, api, scanid)
if scan_status is True:
# Success
msg = {"status" : scanid}
try:
db.scanids.insert({"scanid" : scanid, "name" : name, "url" : url})
except:
print "Failed to update DB"
else:
msg = {"status" : "Failed"}

except:
msg = {"status" : "Failed"}

return jsonify(msg)


@app.route('/scan/scanids/', methods=['GET'])
def fetch_scanids():
scanids = []
records = db.scanids.find({})
if records:
for data in records:
data.pop('_id')
try:
data = ast.literal_eval(json.dumps(data))
scan_status = check_scan_status(data)
if data['scanid']:
if data['scanid'] not in scanids:
url = xss_filter(data['url'])
scanids.append({"scanid" : data['scanid'], "name" : xss_filter(data['name']), "url" : url, "scan_status" : scan_status})
except:
pass

return jsonify(scanids)

############################# Alerts API ##########################################

# Returns vulnerbilities identified by tool
def fetch_records(scanid):
# Return alerts identified by the tool
vul_list = []
records = db.vulnerabilities.find({"scanid":scanid})
if records:
for data in records:
if data['req_body'] == None:
data['req_body'] = "NA"

data.pop('_id')
try:
data = ast.literal_eval(json.dumps(data))
except Exception as e:
print "Falied to parse",e

try:
if data['id'] == "NA":
all_data = {'url' : data['url'], 'impact' : data['impact'], 'name' : data['name'], 'req_headers' : data['req_headers'], 'req_body' : data['req_body'], 'res_headers' : data['res_headers'], 'res_body' : data['res_body'], 'Description' : data['Description'], 'remediation' : data['remediation']}
vul_list.append(all_data)

if data['id']:
for vul in alerts:
if data['id'] == vul['id']:
#print "response body",data['req_headers'],type(data['req_headers'])
all_data = {
'url' : xss_filter(data['url']),
'impact' : data['impact'],
'name' : xss_filter(data['alert']),
'req_headers' : data['req_headers'],
'req_body' : xss_filter(data['req_body']),
'res_headers' : xss_filter(data['res_headers']),
'res_body' : xss_filter(data['res_body']),
'Description' : vul['Description'],
'remediation' : vul['remediation']
}
vul_list.append(all_data)
break

except:
pass

return vul_list

@app.route('/alerts/<scanid>', methods=['GET'])
def return_alerts(scanid):
result = fetch_records(scanid)
resp = jsonify(result)
resp.headers["Access-Control-Allow-Origin"] = "*"
return resp

#############################Dashboard#########################################

@app.route('/', defaults={'page': 'scan.html'})
@app.route('/<page>')
def view_dashboard(page):
return render_template('{}'.format(page))

def start_server():
app.run(host='0.0.0.0', port= 8094)


############################Postman collection################################

def postman_collection_download(url):
# Download postman collection from URL
postman_req = requests.get(url,allow_redirects=True, verify=False)
try:
filename = url[url.rfind("/")+1:]+"_"+generate_hash()
open("../Files/"+filename, 'wb').write(postman_req.content)
return "../Files/"+filename
except:
return False


def verify_email(email):
# credit : www.scottbrady91.com
match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email)
return match


@app.route('/scan/postman/', methods = ['POST'])
def scan_postman():
content = request.get_json()
try:
# mandatory inputs
appname = content['appname']
postman_url = content['postman_url']
env_type = content['env_type']
if "email" in content.keys():
email_verify_result = verify_email(content['email'])
if email_verify_result == None:
# Not a valid email id
email = "NA"
else:
email = content['email']
else:
email = "NA"

try:
# IP address param is optional.
url = "NA"
if "ip" in content.keys():
url = content['ip']
if urlparse.urlparse(url).scheme == "http" or urlparse.urlparse(url).scheme == "https":
ip = urlparse.urlparse(url).netloc
socket.inet_aton(ip)
ip_result = 1

else:
ip_result = 0
except:
print "Missing Arugument or invalid IP address!"
ip_result = 0


result = postman_collection_download(postman_url)

if result is False:
msg = {"status" : "Failed to Download Postman collection"}
return msg
else:
try:
scan_id = generate_hash()
db.scanids.insert({"scanid" : scan_id, "name" : appname, "url" : postman_url,"env_type": env_type, "url" : url,"email" : email})
if ip_result == 1:
scan_result = scan_postman_collection(result,scan_id,url)
else:
scan_result = scan_postman_collection(result,scan_id)
except:
#Failed to update the DB
pass

if scan_result == True:
# Update the email notification collection
db.email.insert({"email" : email, "scanid" : scan_id, "to_email" : email, "email_notification" : 'N'})
msg = {"status" : "Success", "scanid" : scan_id}
else:
msg = {"status" : "Failed!"}


except:
msg = {"status" "Failed. Application name and postman URL is required!"}

return jsonify(msg)

def main():
if os.getcwd().split('/')[-1] == 'API':
start_server()
else:
thread = ServerThread()
thread.daemon = True
thread.start()


@app.route('/robots.txt', methods=['GET'])
def robots():
return send_from_directory(app.static_folder, "robots.txt")

main()
25 changes: 25 additions & 0 deletions API/dbconnection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os

from pymongo import MongoClient
from pymongo.errors import ServerSelectionTimeoutError


# Mongo DB connection
def db_connect():
maxSevSelDelay = 1
try:
mongo_host = 'localhost'
mongo_port = 27017

if 'MONGO_PORT_27017_TCP_ADDR' in os.environ :
mongo_host = os.environ['MONGO_PORT_27017_TCP_ADDR']

if 'MONGO_PORT_27017_TCP_PORT' in os.environ:
mongo_port = int(os.environ['MONGO_PORT_27017_TCP_PORT'])

client = MongoClient(mongo_host, mongo_port, serverSelectionTimeoutMS=maxSevSelDelay)
client.server_info()
return client

except ServerSelectionTimeoutError as err:
exit("Failed to connect to MongoDB.")
Loading