|
| 1 | +from defectdojo_api import defectdojo |
| 2 | +from random import randint |
| 3 | +import os |
| 4 | +from datetime import datetime, timedelta |
| 5 | + |
| 6 | +""" |
| 7 | +Imports test data into Defect DefectDojo |
| 8 | +""" |
| 9 | + |
| 10 | +# Setup DefectDojo connection information |
| 11 | +host = 'http://localhost:8000' |
| 12 | +api_key = os.environ['DOJO_API_KEY'] |
| 13 | +user = 'admin' |
| 14 | + |
| 15 | +""" |
| 16 | +#Optionally, specify a proxy |
| 17 | +proxies = { |
| 18 | + 'http': 'http://localhost:8080', |
| 19 | + 'https': 'http://localhost:8080', |
| 20 | +} |
| 21 | +#proxies=proxies |
| 22 | +""" |
| 23 | + |
| 24 | +# Instantiate the DefectDojo api wrapper |
| 25 | +dd = defectdojo.DefectDojoAPI(host, api_key, user, debug=False) |
| 26 | + |
| 27 | +user_id = 1 #Default user |
| 28 | + |
| 29 | +def create_finding_data(product_id, engagement_id, test_id): |
| 30 | + cwe = [352, 22, 676, 863, 134, 759, 798] |
| 31 | + cwe_desc = ['Cross-Site Request Forgery (CSRF)', 'Improper Limitation of a Pathname to a Restricted Directory (\'Path Traversal\')', |
| 32 | + 'Use of Potentially Dangerous Function', 'Incorrect Authorization', 'Uncontrolled Format String', |
| 33 | + 'Use of a One-Way Hash without a Salt', 'Use of Hard-coded Credentials'] |
| 34 | + severity=['Low','Medium','High', 'Critical'] |
| 35 | + user_id = 1 |
| 36 | + finding_date = datetime.now() |
| 37 | + finding_date = finding_date+timedelta(days=randint(-30,0)) |
| 38 | + finding_cwe = randint(0,6) |
| 39 | + |
| 40 | + finding = dd.create_finding(cwe_desc[finding_cwe], cwe_desc[finding_cwe], severity[randint(0,3)], |
| 41 | + cwe[finding_cwe], finding_date.strftime("%Y-%m-%d"), product_id, engagement_id, test_id, user_id, |
| 42 | + "None", "true", "true", "References") |
| 43 | + |
| 44 | +def create_load_data(product_name, product_desc, file=None, file_test_type=None): |
| 45 | + # Create a product |
| 46 | + prod_type = 1 #1 - Research and Development, product type |
| 47 | + print "Creating product: " + product_name |
| 48 | + product = dd.create_product(product_name, product_desc, prod_type) |
| 49 | + if product.success: |
| 50 | + # Get the product id |
| 51 | + product_id = product.id() |
| 52 | + |
| 53 | + # Create an engagement |
| 54 | + start_date = datetime.now() |
| 55 | + end_date = start_date+timedelta(days=randint(2,8)) |
| 56 | + |
| 57 | + print "Creating engagement: " + "Intial " + product_name + " Engagement" |
| 58 | + engagement = dd.create_engagement("Intial " + product_name + " Engagement", product_id, user_id, |
| 59 | + "In Progress", start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d")) |
| 60 | + engagement_id = engagement.id() |
| 61 | + |
| 62 | + # Create some tests |
| 63 | + print "Creating tests" |
| 64 | + |
| 65 | + #Load scanner test data |
| 66 | + if file is not None: |
| 67 | + print "Loading scanner results from scanner export" |
| 68 | + dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 69 | + upload_scan = dd.upload_scan(engagement_id, "Burp Scan", dir_path + file, |
| 70 | + "true", "01/11/2016", "API") |
| 71 | + |
| 72 | + i = 0 |
| 73 | + while i < 6: |
| 74 | + test_type = i+1 #Select some random tests |
| 75 | + environment = randint(1,6) #Select random environments |
| 76 | + test = dd.create_test(engagement_id, test_type, environment, |
| 77 | + start_date.strftime("%Y-%m-%d"), start_date.strftime("%Y-%m-%d")) |
| 78 | + test_id = test.id() |
| 79 | + |
| 80 | + f = 0 |
| 81 | + f_max = randint(4,10) |
| 82 | + while f < f_max: |
| 83 | + # Load findings |
| 84 | + create_finding_data(product_id, engagement_id, test_id) |
| 85 | + f = f + 1 |
| 86 | + |
| 87 | + i = i + 1 |
| 88 | + else: |
| 89 | + print product.message |
| 90 | + |
| 91 | +##### Create Products, Engagements and Tests ######## |
| 92 | +create_load_data("BodgeIt", "Product description.", "../tests/scans/Bodgeit-burp.xml", "Burp Scan") |
| 93 | +create_load_data("A CRM App", "Product description.") |
| 94 | +create_load_data("An Engineering Application", "Product description.") |
| 95 | +create_load_data("A Marketing Site", "Product description.") |
0 commit comments