|
| 1 | +import sys |
| 2 | + |
| 3 | +try: |
| 4 | + from datetime import datetime |
| 5 | + import os |
| 6 | + import openpyxl |
| 7 | + from openpyxl.styles import Font |
| 8 | + from colorama import Fore, Style |
| 9 | + import sqlite3 |
| 10 | +except ImportError as e: |
| 11 | + print(Fore.RED + "Import error appeared. Reason: {}".format(e) + Style.RESET_ALL) |
| 12 | + sys.exit() |
| 13 | + |
| 14 | +sys.path.append('service') |
| 15 | + |
| 16 | +import db_processing as db |
| 17 | +import files_processing as fp |
| 18 | + |
| 19 | +def create_report(short_domain, url, case_comment, data_array, report_info_array): |
| 20 | + try: |
| 21 | + ip = data_array[0] |
| 22 | + res = data_array[1] |
| 23 | + subdomains_amount = data_array[4] |
| 24 | + subdomain_mails = data_array[6] |
| 25 | + subdomain_ip = data_array[8] |
| 26 | + issuer = data_array[9] |
| 27 | + subject = data_array[10] |
| 28 | + notBefore = data_array[11] |
| 29 | + notAfter = data_array[12] |
| 30 | + commonName = data_array[13] |
| 31 | + serialNumber = data_array[14] |
| 32 | + mx_records = data_array[15] |
| 33 | + robots_txt_result = data_array[16] |
| 34 | + sitemap_xml_result = data_array[17] |
| 35 | + sitemap_links_status = data_array[18] |
| 36 | + web_servers = data_array[19] |
| 37 | + cms = data_array[20] |
| 38 | + programming_languages = data_array[21] |
| 39 | + web_frameworks = data_array[22] |
| 40 | + analytics = data_array[23] |
| 41 | + javascript_frameworks = data_array[24] |
| 42 | + ports = data_array[25] |
| 43 | + hostnames = data_array[26] |
| 44 | + cpes = data_array[27] |
| 45 | + tags = data_array[28] |
| 46 | + vulns = data_array[29] |
| 47 | + common_socials = data_array[31] |
| 48 | + total_socials = data_array[32] |
| 49 | + casename = report_info_array[0] |
| 50 | + db_casename = report_info_array[1] |
| 51 | + db_creation_date = report_info_array[2] |
| 52 | + report_folder = report_info_array[3] |
| 53 | + ctime = report_info_array[4] |
| 54 | + dorking_status = data_array[30] |
| 55 | + dorking_results = data_array[35] |
| 56 | + parsed_links = data_array[33] |
| 57 | + subdomain_urls = data_array[34] |
| 58 | + |
| 59 | + robots_filepath = report_folder + '//01-robots.txt' |
| 60 | + sitemap_filepath = report_folder + '//02-sitemap.txt' |
| 61 | + os.makedirs(report_folder, exist_ok=True) |
| 62 | + |
| 63 | + wb = openpyxl.Workbook() |
| 64 | + sheet_names = [ |
| 65 | + "GENERAL INFO", |
| 66 | + "WHOIS", |
| 67 | + "SOCIAL MEDIAS", |
| 68 | + "SUBDOMAINS", |
| 69 | + "DNS SCAN", |
| 70 | + "SSL CERTIFICATE", |
| 71 | + "INTERNETDB SEARCH", |
| 72 | + "WEBSITE TECHNOLOGIES", |
| 73 | + "SITEMAP LINKS", |
| 74 | + "DORKING RESULTS" |
| 75 | + ] |
| 76 | + sheet = wb.active |
| 77 | + sheet.title = sheet_names[0] |
| 78 | + for name in sheet_names[1:]: |
| 79 | + wb.create_sheet(title=name) |
| 80 | + bold_font = Font(bold=True) |
| 81 | + |
| 82 | + ws = wb['GENERAL INFO'] |
| 83 | + for col in ['1', '2', '3', '4', '5', '6', '7']: |
| 84 | + cell = f"A{col}" |
| 85 | + ws[cell].font = bold_font |
| 86 | + ws.column_dimensions['A'].width = 45 |
| 87 | + ws.column_dimensions['B'].width = 60 |
| 88 | + ws['A1'] = 'SUBDOMAINS FOUND' |
| 89 | + ws['A2'] = 'SOCIAL MEDIAS FOUND' |
| 90 | + ws['A3'] = 'ROBOTS EXTRACTED?' |
| 91 | + ws['A4'] = 'SITEMAP.XML EXTRACTED?' |
| 92 | + ws['A5'] = 'SITEMAP.XML LINKS EXTRACTED?' |
| 93 | + ws['A6'] = 'DORKING STATUS' |
| 94 | + ws['A7'] = 'REPORT CREATION TIME' |
| 95 | + ws['B1'] = subdomains_amount |
| 96 | + ws['B2'] = total_socials |
| 97 | + ws['B3'] = robots_txt_result |
| 98 | + ws['B4'] = sitemap_xml_result |
| 99 | + ws['B5'] = sitemap_links_status |
| 100 | + ws['B6'] = dorking_status |
| 101 | + ws['B7'] = ctime |
| 102 | + |
| 103 | + ws = wb['WHOIS'] |
| 104 | + for col in ['1', '2', '3', '4', '5', '6', '7', '8']: |
| 105 | + cell = f"A{col}" |
| 106 | + ws[cell].font = bold_font |
| 107 | + ws.column_dimensions['A'].width = 45 |
| 108 | + ws.column_dimensions['B'].width = 60 |
| 109 | + ws['A1'] = 'SHORT DOMAIN' |
| 110 | + ws['A2'] = 'URL' |
| 111 | + ws['A3'] = 'IP ADDRESS' |
| 112 | + ws['A4'] = 'REGISTRAR' |
| 113 | + ws['A5'] = 'CREATION DATE' |
| 114 | + ws['A6'] = 'EXPIRATION DATE' |
| 115 | + ws['A7'] = 'NAME SERVERS' |
| 116 | + ws['A8'] = 'ORGANIZATION NAME' |
| 117 | + ws['B1'] = short_domain |
| 118 | + ws['B2'] = url |
| 119 | + ws['B3'] = ip |
| 120 | + ws['B4'] = res['registrar'] |
| 121 | + ws['B5'] = res['creation_date'] |
| 122 | + ws['B6'] = res['expiration_date'] |
| 123 | + ws['B7'] = ', '.join(res['name_servers']) |
| 124 | + ws['B8'] = res['org'] |
| 125 | + |
| 126 | + ws = wb['SOCIAL MEDIAS'] |
| 127 | + for col in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']: |
| 128 | + cell = f"{col}1" |
| 129 | + ws[cell].font = bold_font |
| 130 | + ws.column_dimensions[col].width = 70 |
| 131 | + tw_links = common_socials['Twitter'] |
| 132 | + inst_links = common_socials['Instagram'] |
| 133 | + tg_links = common_socials['Telegram'] |
| 134 | + tt_links = common_socials['TikTok'] |
| 135 | + li_links = common_socials['LinkedIn'] |
| 136 | + vk_links = common_socials['VKontakte'] |
| 137 | + yt_links = common_socials['YouTube'] |
| 138 | + wc_links = common_socials['WeChat'] |
| 139 | + ok_links = common_socials['Odnoklassniki'] |
| 140 | + fb_links = common_socials['Facebook'] |
| 141 | + ws['A1'] = 'FACEBOOK' |
| 142 | + ws['B1'] = 'TWITTER' |
| 143 | + ws['C1'] = 'INSTAGRAM' |
| 144 | + ws['D1'] = 'TELEGRAM' |
| 145 | + ws['E1'] = 'TIKTOK' |
| 146 | + ws['F1'] = 'LINKEDIN' |
| 147 | + ws['G1'] = 'VKONTAKTE' |
| 148 | + ws['H1'] = 'YOUTUBE' |
| 149 | + ws['I1'] = 'ODNOKLASSNIKI' |
| 150 | + ws['J1'] = 'WECHAT' |
| 151 | + |
| 152 | + for i in range(len(fb_links)): |
| 153 | + ws[f"A{i + 2}"] = fb_links[i] |
| 154 | + for i in range(len(tw_links)): |
| 155 | + ws[f"B{i + 2}"] = tw_links[i] |
| 156 | + for i in range(len(inst_links)): |
| 157 | + ws[f"C{i + 2}"] = inst_links[i] |
| 158 | + for i in range(len(tg_links)): |
| 159 | + ws[f"D{i + 2}"] = tg_links[i] |
| 160 | + for i in range(len(tt_links)): |
| 161 | + ws[f"E{i + 2}"] = tt_links[i] |
| 162 | + for i in range(len(li_links)): |
| 163 | + ws[f"F{i + 2}"] = li_links[i] |
| 164 | + for i in range(len(vk_links)): |
| 165 | + ws[f"G{i + 2}"] = vk_links[i] |
| 166 | + for i in range(len(yt_links)): |
| 167 | + ws[f"H{i + 2}"] = yt_links[i] |
| 168 | + for i in range(len(ok_links)): |
| 169 | + ws[f"I{i + 2}"] = ok_links[i] |
| 170 | + for i in range(len(wc_links)): |
| 171 | + ws[f"J{i + 2}"] = wc_links[i] |
| 172 | + |
| 173 | + ws = wb['SUBDOMAINS'] |
| 174 | + for col in ['A', 'B', 'C']: |
| 175 | + cell = f"{col}1" |
| 176 | + ws[cell].font = bold_font |
| 177 | + ws.column_dimensions[col].width = 70 |
| 178 | + ws['A1'] = 'FOUNDED SUBDOMAINS' |
| 179 | + ws['B1'] = 'SUBDOMAIN IP ADDRESSES (NOT CORRELATED)' |
| 180 | + ws['C1'] = 'SUBDOMAIN EMAILS (NOT CORRELATED)' |
| 181 | + try: |
| 182 | + for i in range(len(subdomain_urls)): |
| 183 | + ws[f"A{i + 2}"] = str(subdomain_urls[i]) |
| 184 | + for i in range(len(subdomain_ip)): |
| 185 | + ws[f"B{i + 2}"] = str(subdomain_ip[i]) |
| 186 | + for i in range(len(subdomain_mails)): |
| 187 | + ws[f"C{i + 2}"] = str(subdomain_mails[i]) |
| 188 | + except Exception as e: |
| 189 | + print(Fore.RED + "Error appeared when writing some information about subdomains in XLSX file. Reason: {}".format(e)) |
| 190 | + pass |
| 191 | + |
| 192 | + ws = wb['DNS SCAN'] |
| 193 | + for col in ['1', '2']: |
| 194 | + cell = f"A{col}" |
| 195 | + ws[cell].font = bold_font |
| 196 | + ws.column_dimensions['A'].width = 45 |
| 197 | + ws.column_dimensions['B'].width = 60 |
| 198 | + ws['A1'] = 'NAME SERVERS' |
| 199 | + ws['A2'] = 'MX ADDRESSES' |
| 200 | + ws['B1'] = ', '.join(res['name_servers']) |
| 201 | + ws['B2'] = mx_records |
| 202 | + |
| 203 | + ws = wb['SSL CERTIFICATE'] |
| 204 | + for col in ['1', '2', '3', '4', '5', '6']: |
| 205 | + cell = f"A{col}" |
| 206 | + ws[cell].font = bold_font |
| 207 | + ws.column_dimensions['A'].width = 45 |
| 208 | + ws.column_dimensions['B'].width = 60 |
| 209 | + ws['A1'] = 'ISSUER' |
| 210 | + ws['A2'] = 'SUBJECT' |
| 211 | + ws['A3'] = 'NOT BEFORE' |
| 212 | + ws['A4'] = 'NOT AFTER' |
| 213 | + ws['A5'] = 'CERTIFICATE NAME' |
| 214 | + ws['A6'] = 'CERTIFICATE SERIAL NUMBER' |
| 215 | + ws['B1'] = issuer |
| 216 | + ws['B2'] = subject |
| 217 | + ws['B3'] = notBefore |
| 218 | + ws['B4'] = notAfter |
| 219 | + ws['B5'] = commonName |
| 220 | + ws['B6'] = serialNumber |
| 221 | + |
| 222 | + ws = wb['INTERNETDB SEARCH'] |
| 223 | + for col in ['1', '2', '3', '4']: |
| 224 | + cell = f"A{col}" |
| 225 | + ws[cell].font = bold_font |
| 226 | + ws['I1'].font = bold_font |
| 227 | + ws.column_dimensions['A'].width = 45 |
| 228 | + ws.column_dimensions['B'].width = 60 |
| 229 | + ws['A1'] = 'OPEN PORTS' |
| 230 | + ws['A2'] = 'HOSTNAMES' |
| 231 | + ws['A3'] = 'TAGS' |
| 232 | + ws['A4'] = 'CPEs' |
| 233 | + ws['I1'] = 'POTENTIAL VULNERABILITIES' |
| 234 | + ws['B1'] = str(ports) |
| 235 | + ws['B2'] = str(hostnames) |
| 236 | + ws['B3'] = str(tags) |
| 237 | + ws['B4'] = str(cpes) |
| 238 | + for i in range(len(vulns)): |
| 239 | + ws[f"I{i + 2}"] = str(vulns[i]) |
| 240 | + |
| 241 | + ws = wb['WEBSITE TECHNOLOGIES'] |
| 242 | + for col in ['1', '2', '3', '4', '5', '6']: |
| 243 | + cell = f"A{col}" |
| 244 | + ws[cell].font = bold_font |
| 245 | + ws.column_dimensions['A'].width = 45 |
| 246 | + ws.column_dimensions['B'].width = 60 |
| 247 | + ws['A1'] = 'WEB SERVERS' |
| 248 | + ws['A2'] = 'CMS' |
| 249 | + ws['A3'] = 'USED PROGRAMMING LANGUAGES' |
| 250 | + ws['A4'] = 'USED WEB FRAMEWORKS' |
| 251 | + ws['A5'] = 'ANALYTICS SERVICE' |
| 252 | + ws['A6'] = 'USED JAVASCRIPT FRAMEWORKS' |
| 253 | + ws['B1'] = str(web_servers) |
| 254 | + ws['B2'] = str(cms) |
| 255 | + ws['B3'] = str(programming_languages) |
| 256 | + ws['B4'] = str(web_frameworks) |
| 257 | + ws['B5'] = str(analytics) |
| 258 | + ws['B6'] = str(javascript_frameworks) |
| 259 | + |
| 260 | + ws = wb['SITEMAP LINKS'] |
| 261 | + ws.column_dimensions['A'].width = 80 |
| 262 | + for i in range(len(parsed_links)): |
| 263 | + ws[f"A{i + 1}"] = str(parsed_links[i]) |
| 264 | + |
| 265 | + ws = wb['DORKING RESULTS'] |
| 266 | + ws.column_dimensions['A'].width = 80 |
| 267 | + for i in range(len(dorking_results)): |
| 268 | + ws[f"A{i + 1}"] = str(dorking_results[i]) |
| 269 | + |
| 270 | + report_file = report_folder + "//" + casename |
| 271 | + wb.save(report_file) |
| 272 | + print(Fore.GREEN + "Report for {} case was created at {}".format(''.join(short_domain), ctime) + Style.RESET_ALL) |
| 273 | + robots_content, sitemap_content, sitemap_links_content, dorking_content = fp.get_db_columns(report_folder) |
| 274 | + xlsx_blob = fp.get_blob(report_file) |
| 275 | + db.insert_blob('XLSX', xlsx_blob, db_casename, db_creation_date, case_comment, robots_content, sitemap_content, sitemap_links_content, dorking_content) |
| 276 | + except Exception as e: |
| 277 | + print(Fore.RED + 'Unable to create XLSX report. Reason: {}'.format(e)) |
0 commit comments