def insert_toc(self): paragraph = self.document.add_paragraph() run = paragraph.add_run() fldChar = OxmlElement('w:fldChar') # creates a new element fldChar.set(qn('w:fldCharType'), 'begin') # sets attribute on element instrText = OxmlElement('w:instrText') instrText.set(qn('xml:space'), 'preserve') # sets attribute on element instrText.text = 'TOC \\o "1-3" \\h \\z \\u' # change 1-3 depending on heading levels you need fldChar2 = OxmlElement('w:fldChar') fldChar2.set(qn('w:fldCharType'), 'separate') # fldChar3 = OxmlElement('w:t') fldChar3 = OxmlElement('w:updateFields') fldChar3.set(qn('w:val'), 'true') # fldChar3.text = "Right-click to update field." fldChar2.append(fldChar3) fldChar4 = OxmlElement('w:fldChar') fldChar4.set(qn('w:fldCharType'), 'end') r_element = run._r r_element.append(fldChar) r_element.append(instrText) r_element.append(fldChar2) r_element.append(fldChar4) p_element = paragraph._p
def set_table_margins(self, tbl, width: dict = None): """ <w:tbl> <w:tblPr> <w:tblStyle w:val="LightShading"/> <w:tblW w:type="auto" w:w="0"/> <w:tblCellMar> <w:left w:type="dxa" w:w="63"/> <w:right w:type="dxa" w:w="63"/> </w:tblCellMar> <w:tblLook w:firstColumn="1" w:firstRow="1" w:lastColumn="0" w:lastRow="0" w:noHBand="0" w:noVBand="1" w:val="04A0"/> </w:tblPr> """ # noqa # 67 = Cm(0.11) ...? if width is None: width = dict(left=67, right=67) margins = OxmlElement('w:tblCellMar') for side, w in width.items(): margin = OxmlElement(f'w:{side}') margin.set(qn('w:w'), str(w)) margin.set(qn('w:type'), 'dxa') margins.append(margin) tbl._tbl.tblPr.append(margins)
def add_url_hyperlink(paragraph, url: str, text: str): """Add URL hyperlink in docx report. Adapted from https://stackoverflow.com/a/47666747/906385 Args: paragraph: a docx paragraph object url (str): The URL text (str): The text to display """ # This gets access to the document.xml.rels file and gets a new relation id value part = paragraph.part r_id = part.relate_to(url, constants.RELATIONSHIP_TYPE.HYPERLINK, is_external=True) # Create the w:hyperlink tag and add needed values hyperlink = OxmlElement("w:hyperlink") hyperlink.set(qn("r:id"), r_id) # Create a w:r element and a new w:rPr element new_run = OxmlElement("w:r") rPr = OxmlElement("w:rPr") # Join all the xml elements together add add the required text to the w:r element new_run.append(rPr) new_run.text = text hyperlink.append(new_run) # Create a new Run object and add the hyperlink into it run = paragraph.add_run() run._r.append(hyperlink) # A workaround for the lack of a hyperlink style (doesn't go purple after using the link) # Delete this if using a template that has the hyperlink style in it run.font.color.theme_color = dml.MSO_THEME_COLOR_INDEX.HYPERLINK run.font.underline = True
def set_vert_cell_direction(cell): # https://github.com/python-openxml/python-docx/issues/55 tc = cell._tc tcPr = tc.tcPr textDirection = OxmlElement('w:textDirection') textDirection.set(qn('w:val'), 'btLr') tcPr.append(textDirection)
def set_row_height(row): tr = row._tr trPr = tr.get_or_add_trPr() trHeight = OxmlElement('w:trHeight') trHeight.set(qn('w:val'), "250") trHeight.set(qn('w:hRule'), "atLeast") trPr.append(trHeight)
def set_cant_split(self, row): tr = row._tr trPr = tr.get_or_add_trPr() tblHeader = OxmlElement('w:cantSplit') tblHeader.set(qn('w:val'), "true") trPr.append(tblHeader) return row
def cellStyle(self, cells, background): self.make_rows_bold(cells) for cell in cells: tcPr = cell._tc.get_or_add_tcPr() tcVAlign = OxmlElement("w:shd") tcVAlign.set(qn("w:fill"), background) tcPr.append(tcVAlign)
def set_row_height(row, heightv): # https://stackoverflow.com/questions/37532283/python-how-to-adjust-row-height-of-table-in-docx tr = row._tr trPr = tr.get_or_add_trPr() trHeight = OxmlElement('w:trHeight') trHeight.set(qn('w:val'), str(heightv)) trHeight.set(qn('w:hRule'), "atLeast") trPr.append(trHeight)
def set_shade_cell(cell, shade): tcpr = cell._tc.get_or_add_tcPr( ) # récupération de lélément XML correspondant à la cellule tcvalign = OxmlElement( "w:shd") # création d'un élément XML pour le background tcvalign.set(qn("w:fill"), shade) # set de la valeur de la vcouleur de fond tcpr.append(tcvalign) # ajout de l'élement XML à la cellule
def add_tbl_border(self, tbl): """Add table bottom border with OxmlElement""" borders = OxmlElement('w:tblBorders') bottom_border = OxmlElement('w:bottom') bottom_border.set(qn('w:val'), 'single') bottom_border.set(qn('w:sz'), '4') borders.append(bottom_border) tbl._tbl.tblPr.append(borders)
def set_cell_color(cell, color): # https://github.com/python-openxml/python-docx/issues/55 tc = cell._tc tcPr = tc.tcPr color_xml = OxmlElement('w:shd') color_xml.set(qn('w:val'), 'clear') # color_xml.set(qn('w:color'), text) color_xml.set(qn('w:fill'), color) tcPr.append(color_xml)
def set_repeat_table_header(row): """ set repeat table row on every new page """ tr = row._tr trPr = tr.get_or_add_trPr() tblHeader = OxmlElement('w:tblHeader') tblHeader.set(qn('w:val'), "true") trPr.append(tblHeader) return row
def autofit_table_window(self, tbl): """ <w:tbl> <w:tblPr> <w:tblW w:type="pct" w:w="5000"/> """ width = OxmlElement('w:tblW') width.set(qn('w:type'), 'pct') width.set(qn('w:w'), '5000') tbl._tbl.tblPr.append(width)
def indent_table(table, indent): # noinspection PyProtectedMember tbl_pr = table._element.xpath( 'w:tblPr') # récupération de l'élément XML de la table if tbl_pr: e = OxmlElement( 'w:tblInd') # création d'un element XML pour l'indentation e.set(qn('w:w'), str(indent)) # set de la valeur e l'indentation e.set(qn('w:type'), 'dxa') # type de l'indentation tbl_pr[0].append(e) # ajout de l'elment XML à celui de la table
def set_cell_vertical_alignment(cell, align="center"): try: tc = cell._tc tcPr = tc.get_or_add_tcPr() tcValign = OxmlElement('w:vAlign') tcValign.set(qn('w:val'), align) tcPr.append(tcValign) return True except: traceback.print_exc() return False
def set_cell_color(self, cell, bg=None, text=None): """Set table cell bg and text color""" cell_pr = cell._element.tcPr cl_shading = OxmlElement('w:shd') if bg: cl_shading.set(qn('w:fill'), bg) if text: cl_shading.set(qn('w:color'), text) cell_pr.append(cl_shading)
def shade_cells(cells, shade): """Gives background color to the inputted cells of a table in a .docx file. :param cells: The cells which you want to be colored. It could be a full row, such as the header row. :type cells: list :param shade: HEX color code like: "#f3f3f3" (grey) :type shade: str """ for cell in cells: tcPr = cell._tc.get_or_add_tcPr() tcVAlign = OxmlElement("w:shd") tcVAlign.set(qn("w:fill"), shade) tcPr.append(tcVAlign)
def generate_pw_toc(document): global gl_font_size add_simple_par(document, "", gl_font_size, align=docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER, bold=False, breakpar=True) document.add_heading("Spis treści", 1) paragraph = document.add_paragraph() run = paragraph.add_run() fldChar = OxmlElement('w:fldChar') # creates a new element fldChar.set(qn('w:fldCharType'), 'begin') # sets attribute on element instrText = OxmlElement('w:instrText') instrText.set(qn('xml:space'), 'preserve') # sets attribute on element instrText.text = 'TOC \\o "1-2" \\h \\z \\u' # change 1-3 depending on heading levels you need fldChar2 = OxmlElement('w:fldChar') fldChar2.set(qn('w:fldCharType'), 'separate') fldChar3 = OxmlElement('w:t') fldChar3.text = "Kliknij prawym klawiszem myszki, aby zaktualizować spis treści." fldChar2.append(fldChar3) fldChar4 = OxmlElement('w:fldChar') fldChar4.set(qn('w:fldCharType'), 'end') r_element = run._r r_element.append(fldChar) r_element.append(instrText) r_element.append(fldChar2) r_element.append(fldChar4) p_element = paragraph._p
def insert_horizontal_border(paragraph: Paragraph): """ Add an horizontal border under a paragraph. Args: paragraph: Paragraph under which you want to add an horizontal border. """ # access to XML paragraph element <w:p> and its properties p = paragraph._p pPr = p.get_or_add_pPr() # create new XML element and insert it to the paragraph element pBdr = OxmlElement('w:pBdr') pPr.insert_element_before( pBdr, 'w:shd', 'w:tabs', 'w:suppressAutoHyphens', 'w:kinsoku', 'w:wordWrap', 'w:overflowPunct', 'w:topLinePunct', 'w:autoSpaceDE', 'w:autoSpaceDN', 'w:bidi', 'w:adjustRightInd', 'w:snapToGrid', 'w:spacing', 'w:ind', 'w:contextualSpacing', 'w:mirrorIndents', 'w:suppressOverlap', 'w:jc', 'w:textDirection', 'w:textAlignment', 'w:textboxTightWrap', 'w:outlineLvl', 'w:divId', 'w:cnfStyle', 'w:rPr', 'w:sectPr', 'w:pPrChange') # create new XML element, set its properties and add it to the pBdr element bottom = OxmlElement('w:bottom') bottom.set(qn('w:val'), 'single') bottom.set(qn('w:sz'), '6') bottom.set(qn('w:space'), '1') bottom.set(qn('w:color'), 'auto') pBdr.append(bottom)
def add_table_of_contents(document, label='Table of Contents'): document.add_heading(label, level=1) paragraph = document.add_paragraph() run = paragraph.add_run() fldChar = OxmlElement('w:fldChar') # creates a new element fldChar.set(qn('w:fldCharType'), 'begin') # sets attribute on element instrText = OxmlElement('w:instrText') instrText.set(qn('xml:space'), 'preserve') # sets attribute on element instrText.text = r'TOC \o "1-3" \h \z \u' # change 1-3 depending on heading levels you need fldChar2 = OxmlElement('w:fldChar') fldChar2.set(qn('w:fldCharType'), 'separate') fldChar3 = OxmlElement('w:t') fldChar3.text = "Right-click to update field." fldChar2.append(fldChar3) fldChar4 = OxmlElement('w:fldChar') fldChar4.set(qn('w:fldCharType'), 'end') r_element = run._r r_element.append(fldChar) r_element.append(instrText) r_element.append(fldChar2) r_element.append(fldChar4) p_element = paragraph._p return document
def add_fig_caption(self, paragraph): """Add figure caption to image with auto updating numbers - User must select all (cmd/ctrl + A), then F9 to update fig captions""" run = paragraph.add_run() r = run._r fldChar = OxmlElement('w:fldChar') fldChar.set(qn('w:fldCharType'), 'begin') r.append(fldChar) instrText = OxmlElement('w:instrText') instrText.text = ' SEQ Figure \* ARABIC' # noqa r.append(instrText) fldChar = OxmlElement('w:fldChar') fldChar.set(qn('w:fldCharType'), 'end') r.append(fldChar)
def add_hyperlink(paragraph, text, url): part = paragraph.part r_id = part.relate_to(url, RELATIONSHIP_TYPE.HYPERLINK, is_external=True) hyperlink = OxmlElement("w:hyperlink") hyperlink.set(qn("r:id"), r_id, ) new_run = OxmlElement("w:r") rPr = OxmlElement("w:rPr") new_run.append(rPr) new_run.text = text hyperlink.append(new_run) r = paragraph.add_run() r._r.append(hyperlink) r.font.color.theme_color = MSO_THEME_COLOR_INDEX.HYPERLINK r.font.underline = True return hyperlink
def set_repeat_table_header(row): """Sets property 'repeat header row on every new page' of table. :param row: Header row :type row: [type] :return: Row :rtype: [type] """ tr = row._tr trPr = tr.get_or_add_trPr() tblHeader = OxmlElement('w:tblHeader') tblHeader.set(qn('w:val'), "true") trPr.append(tblHeader) return row
def set_row_height(table, begin, end, ratio): # 表格元素、起始行、终止行、行占原图比例 try: for row in range(begin, end): row = table.rows[row] tr = row._tr trPr = tr.get_or_add_trPr() trHeight = OxmlElement('w:trHeight') trHeight.set(qn('w:val'), str(int( ratio * 13000))) # 13000为在纸张21.5*27.9cm, 上下距离25.4mm时页面设置最大值 # trHeight.set(qn('w:val'), str(30)) # 强制最小 根据cell内容自适应 trHeight.set(qn('w:hRule'), "atLeast") trPr.append(trHeight) except Exception as ex: print('set_row_height', ex)
def set_cell_border(cell: _Cell, **kwargs): """ Set the border of a cell. Usage example: set_cell_border(cell, top={"sz": 12, "val": "single", "color": "#FF0000", "space": "0"}, # top border bottom={"sz": 12, "color": "#00FF00", "val": "single"}, # bottom border start={"sz": 24, "val": "dashed", "shadow": "true"}, # left border end={"sz": 12, "val": "dashed"} # right border ) Available attributes can be found here: http://officeopenxml.com/WPtableBorders.php Args: cell: Cell with borders to be changed. """ # access to XML element <w:tc> and its properties tc = cell._tc tcPr = tc.get_or_add_tcPr() # check for tag existence, if none found, then create one tcBorders = tcPr.first_child_found_in("w:tcBorders") if tcBorders is None: tcBorders = OxmlElement('w:tcBorders') tcPr.append(tcBorders) # list over all available tags for edge in ('start', 'top', 'end', 'bottom', 'insideH', 'insideV'): edge_data = kwargs.get(edge) if edge_data: tag = 'w:{}'.format(edge) # check for tag existence, if none found, then create one element = tcBorders.find(qn(tag)) if element is None: element = OxmlElement(tag) tcBorders.append(element) # looks like order of attributes is important for key in ["sz", "val", "color", "space", "shadow"]: if key in edge_data: element.set(qn('w:{}'.format(key)), str(edge_data[key]))
def __add_image_from_url(self, cell, image_url): margins = ['top', 'start', 'bottom', 'end'] margin_size = '0' tc = cell._tc tcPr = tc.get_or_add_tcPr() tcMar = OxmlElement('w:tcMar') for margin in margins: node = OxmlElement('w:%s' % margin) node.set(qn('w:w'), margin_size) node.set(qn('w:type'), 'dxa') tcMar.append(node) tcPr.append(tcMar) img_width = Mm(40) image = self.__get_image_from_url(image_url) paragraph = cell.paragraphs[0] run = paragraph.add_run() run.add_picture(image, width=img_width) return True
def add_page_number(run: Run): """ Add the page number to a paragraph. Args: run: Run in which the page number will be added. """ # access to XML run element <w:r> r = run._r # create new XML elements, set their attributes and add them to the run element # so that the page number correspond to a real page number fldChar1 = OxmlElement('w:fldChar') fldChar1.set(qn('w:fldCharType'), 'begin') r.append(fldChar1) instrText = OxmlElement('w:instrText') instrText.set(qn('xml:space'), 'preserve') instrText.text = 'PAGE' r.append(instrText) fldChar2 = OxmlElement('w:fldChar') fldChar2.set(qn('w:fldCharType'), 'end') r.append(fldChar2)
def add_hyperlink(paragraph, url, text, color='0000FF', underline=True): """ places a hyperlink within a paragraph object """ part = paragraph.part r_id = part.relate_to(url, RELATIONSHIP_TYPE.HYPERLINK, is_external=True) hyperlink = OxmlElement('w:hyperlink') hyperlink.set( qn('r:id'), r_id, ) new_run = OxmlElement('w:r') rPr = OxmlElement('w:rPr') if color is not None: c = OxmlElement('w:color') c.set(qn('w:val'), color) rPr.append(c) if not underline: u = OxmlElement('w:u') u.set(qn('w:val'), 'none') rPr.append(u) # Join all the xml elements together add add the required text to the w:r element new_run.append(rPr) new_run.text = text hyperlink.append(new_run) paragraph._p.append(hyperlink) return hyperlink
def add_hyperlink_into_run(paragraph, run, i, url): runs = paragraph.runs if i is None: for i, runi in enumerate(runs): if run.text == runi.text: break # This gets access to the document.xml.rels file and gets a new relation id value part = paragraph.part r_id = part.relate_to(url, docx.opc.constants.RELATIONSHIP_TYPE.HYPERLINK, is_external=True) # Create the w:hyperlink tag and add needed values hyperlink = OxmlElement('w:hyperlink') hyperlink.set(docx.oxml.shared.qn('r:id'), r_id, ) hyperlink.append(run._r) # see above comment about insert # paragraph._p.insert(i+1, hyperlink) paragraph._p.append(hyperlink) i += 1 while i < len(runs): paragraph._p.append(runs[i]._r) i += 1
def add_hyperlink(paragraph, url, text, font_name=None, underline_hyperlink=True, indent=0, color=True): """ A function that places a hyperlink within a paragraph object. :param paragraph: The paragraph we are adding the hyperlink to. :param url: A string containing the required url :param text: The text displayed for the url :return: A Run object containing the hyperlink """ # This gets access to the document.xml.rels file and gets a new relation id value part = paragraph.part r_id = part.relate_to(url, RT.HYPERLINK, is_external=True) # Create the w:hyperlink tag and add needed values hyperlink = OxmlElement('w:hyperlink') hyperlink.set( qn('r:id'), r_id, ) hyperlink.set(qn('w:history'), '1') # Create a w:r element new_run = OxmlElement('w:r') # Create a new w:rPr element rPr = OxmlElement('w:rPr') # Create a w:rStyle element, note this currently does not add the hyperlink style as its not in # the default template, I have left it here in case someone uses one that has the style in it rStyle = OxmlElement('w:rStyle') rStyle.set(qn('w:val'), 'Hyperlink') # Join all the xml elements together add add the required text to the w:r element rPr.append(rStyle) new_run.append(rPr) new_run.text = text hyperlink.append(new_run) # Create a new Run object and add the hyperlink into it r = paragraph.add_run() r.font.name = font_name r._r.append(hyperlink) # A workaround for the lack of a hyperlink style (doesn't go purple after using the link) # Delete this if using a template that has the hyperlink style in it if color: r.font.color.theme_color = MSO_THEME_COLOR_INDEX.HYPERLINK r.font.underline = underline_hyperlink return r
def addMetadata(p, text): # colored small text r = p.add_run(text) rPr = r._r.get_or_add_rPr() rStyle = OxmlElement('w:color') rStyle.set(qn('w:val'), '888888') rPr.insert(0, rStyle) rStyle = OxmlElement('w:sz') rStyle.set(qn('w:val'), '18') rPr.insert(0, rStyle) rStyle = OxmlElement('w:szCs') rStyle.set(qn('w:val'), '18') rPr.insert(1, rStyle)
def new(cls, nsptagname_str, cx, cy): elm = OxmlElement(nsptagname_str) elm.set('cx', str(cx)) elm.set('cy', str(cy)) return elm
def run(self, \ args, \ report_directory, \ lookup, whois_result, \ dns_result, \ google_result, \ shodan_result, \ paste_scrape_result, \ theharvester_result, \ webscrape_result, \ cred_result, \ pyfoca_result): for l in lookup: print('[+] Starting OSINT report for '.format(l)) self.document = docx.Document() #add logo self.document.add_picture('./resources/logo.png', height=Inches(1.25)) #add domain cover info paragraph = self.document.add_paragraph() run_paragraph = paragraph.add_run('%s' % l) font = run_paragraph.font font.name = 'Arial' font.size = Pt(28) font.color.rgb = RGBColor(0x00, 0x00, 0x00) #add cover info paragraph = self.document.add_paragraph() run_paragraph = paragraph.add_run('Open Source Intelligence Report\n\n\n\n\n\n\n\n\n\n\n') font = run_paragraph.font font.name = 'Arial' font.size = Pt(26) font.color.rgb = RGBColor(0xe9, 0x58, 0x23) paragraph = self.document.add_paragraph() run_paragraph = paragraph.add_run('Generated on: %s' % self.today) font = run_paragraph.font font.name = 'Arial' font.size = Pt(16) font.color.rgb = RGBColor(0x00, 0x00, 0x00) #page break for cover page self.document.add_page_break() #add intro text on intropage heading = self.document.add_heading() run_heading = heading.add_run('Executive Summary') font = run_heading.font font.name = 'Arial' font.size = Pt(20) font.color.rgb = RGBColor(0xe9, 0x58, 0x23) paragraph = self.document.add_paragraph() run_paragraph = paragraph.add_run('\nThis document contains information about network, technology, and people associated with the assessment targets. The information was obtained by programatically querying various free or low cost Internet data sources.\n') font = run_paragraph.font font.name = 'Arial' font.size = Pt(11) run_paragraph = paragraph.add_run('\nThese data include information about the network, technology, and people associated with the targets.\n') font = run_paragraph.font font.name = 'Arial' font.size = Pt(11) run_paragraph = paragraph.add_run('\nSpecific data sources include: whois, domain name system (DNS) records, Google dork results, and data from recent compromises such as LinkedIn. Other sources include results from Shodan, document metadata from theHarvester and pyFoca, as well as queries to Pastebin, Github, job boards, etc. \n') font = run_paragraph.font font.name = 'Arial' font.size = Pt(11) #page break for cover page self.document.add_page_break() heading = self.document.add_heading() run_heading = heading.add_run('Table of Contents') font = run_heading.font font.bold = True font.name = 'Arial' font.size = Pt(20) font.color.rgb = RGBColor(0x0, 0x0, 0x0) #TOC https://github.com/python-openxml/python-docx/issues/36 paragraph = self.document.add_paragraph() run = paragraph.add_run() font.name = 'Arial' font.size = Pt(11) fldChar = OxmlElement('w:fldChar') # creates a new element fldChar.set(qn('w:fldCharType'), 'begin') # sets attribute on element instrText = OxmlElement('w:instrText') instrText.set(qn('xml:space'), 'preserve') # sets attribute on element instrText.text = 'TOC \o "1-3" \h \z \u' # change 1-3 depending on heading levels you need fldChar2 = OxmlElement('w:fldChar') fldChar2.set(qn('w:fldCharType'), 'separate') fldChar3 = OxmlElement('w:t') fldChar3.text = "Right-click to update field." fldChar2.append(fldChar3) fldChar4 = OxmlElement('w:fldChar') fldChar4.set(qn('w:fldCharType'), 'end') r_element = run._r r_element.append(fldChar) r_element.append(instrText) r_element.append(fldChar2) r_element.append(fldChar4) p_element = paragraph._p #page break for toc self.document.add_page_break() if cred_result is not None: print('[+] Adding credential dump results to report') #header heading = self.document.add_heading(level=3) run_heading = heading.add_run('Credentials found from recent compromises (LinkedIn, Adobe, etc.) related to: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) paragraph = self.document.add_paragraph() for c in cred_result: run_paragraph = paragraph.add_run(''.join(c)) font = run_paragraph.font font.name = 'Arial' font.size = Pt(11) self.document.add_page_break() #add whois data with header and break after end if whois_result is not None: print('[+] Adding whois results to report') #header heading = self.document.add_heading(level=3) run_heading = heading.add_run('Whois Data for: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) #content paragraph = self.document.add_paragraph() for line in whois_result: if ':' in line: run_paragraph = paragraph.add_run(''.join(line)+'\n') font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #add dns data with header and break after end if dns_result is not None: print('[+] Adding DNS results to report') #header heading = self.document.add_heading(level=3) run_heading = heading.add_run('Domain Name System Data for: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) #content paragraph = self.document.add_paragraph() for d in dns_result: run_paragraph = paragraph.add_run('\n'.join(d)) font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #google dork output if google_result is not None: print('[+] Adding google dork results to report') #header heading = self.document.add_heading(level=3) run_heading = heading.add_run('Google Dork Results for: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) #content paragraph = self.document.add_paragraph() for r in google_result: run_paragraph = paragraph.add_run(''.join(r+'\n')) font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #harvester output if theharvester_result is not None: print('[+] Adding theHarvester results to report') #header heading = self.document.add_heading(level=3) run_heading = heading.add_run('theHarvester Results for: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) #content paragraph = self.document.add_paragraph() for h in theharvester_result: run_paragraph = paragraph.add_run(''.join(h)) #set font stuff font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #pastebin scrape output if paste_scrape_result is not None: print('[+] Adding pastebin scrape results to report') heading = self.document.add_heading(level=3) run_heading = heading.add_run('Pastebin URLs for %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) paragraph = self.document.add_paragraph() self.document.add_paragraph(paste_scrape_result) font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #general scrape output if webscrape_result is not None: print('[+] Adding website scraping results to report') #header heading = self.document.add_heading(level=3) run_heading = heading.add_run('Website Scraping Results for %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) #content paragraph = self.document.add_paragraph() for sr in webscrape_result: for line in sr: run_paragraph = paragraph.add_run(line) font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #pyfoca results if pyfoca_result is not None: print('[+] Adding pyfoca results to report') heading = self.document.add_heading(level=3) run_heading = heading.add_run('pyFoca Results for: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) paragraph = self.document.add_paragraph() for fr in pyfoca_result: run_paragraph = paragraph.add_run(''.join(str(fr).strip(("\\ba\x00b\n\rc\fd\xc3")))) font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) self.document.add_page_break() #shodan output if shodan_result is not None: heading = self.document.add_heading(level=3) run_heading = heading.add_run('Shodan Results for: %s' % l) font = run_heading.font font.name = 'Arial' font.color.rgb = RGBColor(0xe9, 0x58, 0x23) paragraph = self.document.add_paragraph() for shr in shodan_result: try: run_paragraph = paragraph.add_run(str(shr).strip(("\\ba\x00b\n\rc\fd\xc3"))) #set font stuff font = run_paragraph.font font.name = 'Arial' font.size = Pt(10) except: print ('probably an encoding error...') continue print('[+] Writing file: ./reports/{}/OSINT_{}_.docx'.format(l, l)) #saves to ./reports/domain.com/OSINT_domain.com_.docx self.document.save(report_directory+'{}/OSINT_{}_.docx'.format(l, l))
def new(cls, nsptagname_str, shape_id, name): elt = OxmlElement(nsptagname_str) elt.set('id', str(shape_id)) elt.set('name', name) return elt
def new(cls, nsptagname_str, x, y): elm = OxmlElement(nsptagname_str) elm.set('x', str(x)) elm.set('y', str(y)) return elm
def new(cls, prst): prstGeom = OxmlElement('a:prstGeom') prstGeom.set('prst', prst) return prstGeom
def new(cls, rId): blip = OxmlElement('a:blip') blip.set(qn('r:embed'), rId) return blip
def new(cls, uri, pic): graphicData = OxmlElement('a:graphicData') graphicData.set('uri', uri) graphicData.append(pic) return graphicData