├── requirements.txt ├── test └── test_pdf.pdf ├── .flake8 ├── .github └── workflows │ └── pylint.yml ├── pyproject.toml ├── .pre-commit-config.yaml ├── .gitignore ├── README.md ├── src └── ScrapPY.py └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | scipy==1.14.0 2 | pandas==2.2.2 3 | PyPDF2==3.0.1 4 | textract==1.6.5 5 | -------------------------------------------------------------------------------- /test/test_pdf.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RoseSecurity/ScrapPY/HEAD/test/test_pdf.pdf -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | extend-ignore = E203 3 | exclude = 4 | .git, 5 | __pycache__ 6 | max-complexity = 10 7 | -------------------------------------------------------------------------------- /.github/workflows/pylint.yml: -------------------------------------------------------------------------------- 1 | name: Pylint 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | python-version: ["3.8", "3.9", "3.10"] 11 | steps: 12 | - uses: actions/checkout@v4 13 | - name: Set up Python ${{ matrix.python-version }} 14 | uses: actions/setup-python@v5 15 | with: 16 | python-version: ${{ matrix.python-version }} 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install pylint 21 | - name: Analysing the code with pylint 22 | run: | 23 | pylint $(git ls-files '*.py') 24 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "poetry.core.masonry.api" 3 | requires = ["poetry-core"] 4 | 5 | # https://peps.python.org/pep-0621/ 6 | [tool.poetry] 7 | authors = ["RoseSecurity 4 | 5 |

6 | 7 | ScrapPY is a Python utility for scraping manuals, documents, and other sensitive PDFs to generate targeted wordlists that can be utilized by offensive security tools to perform brute force, forced browsing, and dictionary attacks. ScrapPY performs word frequency, entropy, and metadata analysis, and can run in full output modes to craft custom wordlists for targeted attacks. The tool dives deep to discover keywords and phrases leading to potential passwords or hidden directories, outputting to a text file that is readable by tools such as Hydra, Dirb, and Nmap. Expedite initial access, vulnerability discovery, and lateral movement with ScrapPY! 8 | 9 | # Demo: 10 | 11 | https://user-images.githubusercontent.com/72598486/201235531-6b037daf-d1f3-4d33-b256-8411e3a0b3da.mov 12 | 13 | # Install: 14 | 15 | Download Repository: 16 | 17 | ``` 18 | $ mkdir ScrapPY 19 | $ cd ScrapPY/ 20 | $ sudo git clone https://github.com/RoseSecurity/ScrapPY.git 21 | ``` 22 | 23 | Install Dependencies: 24 | 25 | ``` 26 | $ python3 -m venv venv 27 | $ source .venv/bin/activate 28 | $ pip3 install -r requirements.txt 29 | ``` 30 | 31 | # ScrapPY Usage: 32 | 33 | ``` 34 | usage: ScrapPY.py [-h] [-f FILE] [-m {word-frequency,full,metadata,entropy}] [-o OUTPUT] 35 | ``` 36 | 37 | 38 | Output metadata of document: 39 | 40 | ``` 41 | $ python3 ScrapPY.py -f example.pdf -m metadata 42 | ``` 43 | 44 | Output top 100 frequently used keywords to a file name ```Top_100_Keywords.txt```: 45 | 46 | ``` 47 | $ python3 ScrapPY.py -f example.pdf -m word-frequency -o Top_100_Keywords.txt 48 | ``` 49 | 50 | Output all keywords to default ScrapPY.txt file: 51 | 52 | ``` 53 | $ python3 ScrapPY.py -f example.pdf 54 | ``` 55 | 56 | Output top 100 keywords with highest entropy rating: 57 | 58 | ``` 59 | $ python3 ScrapPY.py -f example.pdf -m entropy 60 | ``` 61 | 62 | ScrapPY Output: 63 | 64 | ``` 65 | # ScrapPY outputs the ScrapPY.txt file or specified name file to the directory in which the tool was ran. To view the first fifty lines of the file, run this command: 66 | 67 | $ head -50 ScrapPY.txt 68 | 69 | # To see how many words were generated, run this command: 70 | 71 | $ wc -l ScrapPY.txt 72 | ``` 73 | 74 | # Integration with Offensive Security Tools: 75 | 76 | Easily integrate with tools such as Dirb to expedite the process of discovering hidden subdirectories: 77 | 78 | ``` 79 | root@RoseSecurity:~# dirb http://192.168.1.123/ /root/ScrapPY/ScrapPY.txt 80 | 81 | ----------------- 82 | DIRB v2.21 83 | By The Dark Raver 84 | ----------------- 85 | 86 | START_TIME: Fri May 16 13:41:45 2014 87 | URL_BASE: http://192.168.1.123/ 88 | WORDLIST_FILES: /root/ScrapPY/ScrapPY.txt 89 | 90 | ----------------- 91 | 92 | GENERATED WORDS: 4592 93 | 94 | ---- Scanning URL: http://192.168.1.123/ ---- 95 | ==> DIRECTORY: http://192.168.1.123/vi/ 96 | + http://192.168.1.123/programming (CODE:200|SIZE:2726) 97 | + http://192.168.1.123/s7-logic/ (CODE:403|SIZE:1122) 98 | ==> DIRECTORY: http://192.168.1.123/config/ 99 | ==> DIRECTORY: http://192.168.1.123/docs/ 100 | ==> DIRECTORY: http://192.168.1.123/external/ 101 | ``` 102 | 103 | Utilize ScrapPY with Hydra for advanced brute force attacks: 104 | 105 | ``` 106 | root@RoseSecurity:~# hydra -l root -P /root/ScrapPY/ScrapPY.txt -t 6 ssh://192.168.1.123 107 | Hydra v7.6 (c)2013 by van Hauser/THC & David Maciejak - for legal purposes only 108 | 109 | Hydra (http://www.thc.org/thc-hydra) starting at 2014-05-19 07:53:33 110 | [DATA] 6 tasks, 1 server, 1003 login tries (l:1/p:1003), ~167 tries per task 111 | [DATA] attacking service ssh on port 22 112 | ``` 113 | 114 | Enhance Nmap scripts with ScrapPY wordlists: 115 | 116 | ``` 117 | nmap -p445 --script smb-brute.nse --script-args userdb=users.txt,passdb=ScrapPY.txt 192.168.1.123 118 | ``` 119 | 120 | ## Future Development: 121 | 122 | - [x] Allow for custom output file naming and increased verbosity 123 | - [x] Integrate different modes of operation including word frequency analysis 124 | - [x] Allow for metadata analysis 125 | - [x] Search for high-entropy data 126 | - [ ] Prepare packaging for `homebrew` installation 127 | - [ ] Search for path-like data 128 | - [ ] Implement image OCR to enumerate data from images in PDFs 129 | - [ ] Allow for processing of multiple PDFs 130 | 131 | -------------------------------------------------------------------------------- /src/ScrapPY.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from scipy.stats import entropy 4 | from collections import Counter 5 | from datetime import datetime 6 | import pandas as pd 7 | import argparse 8 | import PyPDF2 9 | import textract 10 | import time 11 | import re 12 | import sys 13 | 14 | 15 | # Variables 16 | BLUE = '\033[34m' 17 | RED = '\033[91m' 18 | GREEN = '\033[92m' 19 | NORM = '\x1b[0m' 20 | tag = "@RoseSecurity" 21 | 22 | # Banner 23 | print(BLUE + """ 24 | ______ ______ _ _ 25 | / _____) (_____ \| | | | 26 | ( (____ ____ ____ _____ ____ _____) ) |___| | 27 | \____ \ / ___)/ ___|____ | _ \| ____/|_____ | 28 | _____) | (___| | / ___ | |_| | | _____| | 29 | (______/ \____)_| \_____| __/|_| (_______| 30 | |_| 31 | """ + NORM) 32 | time.sleep(1) 33 | 34 | # Arguments 35 | parser = argparse.ArgumentParser(description='\nScrapPY enumerates documents, manuals, and sensitive PDFs for key phrases and words that can be utilized in dictionary and brute force attacks. These keywords are outputted to a text file (ScrapPY.txt in the directory which the tool was ran from)that can be read by tools such as Hydra, Dirb, and other offensive security tools for initial access and lateral movement.\t' + GREEN + tag + NORM) 36 | parser.add_argument('-f','--file', help='PDF input file') 37 | parser.add_argument('-m', '--mode', choices=['word-frequency', 'full', 'metadata', 'entropy'], help='Modes of operation: full - All keywords, word-frequency - 100 most frequently used keywords, metadata - Title, author, and extracted metadata, entropy - 100 most random keywords, potentially disclosing password hashes or hardcoded keys', default='full') 38 | parser.add_argument('-o', '--output', help='Name of file to output') 39 | args = parser.parse_args() 40 | 41 | def read_file(): 42 | # Open provided file 43 | global common_words 44 | pdf_file = open(args.file, 'rb') 45 | read_pdf = PyPDF2.PdfFileReader(pdf_file) 46 | page_nums = int(read_pdf.numPages) 47 | 48 | # Loop through each page and convert to text 49 | loop_count = 0 50 | page_text = " " 51 | 52 | while loop_count < page_nums: 53 | page_obj = read_pdf.getPage(loop_count) 54 | loop_count += 1 55 | page_text += page_obj.extractText() 56 | 57 | # Lowercase each word 58 | page_text = str(page_text.encode('ascii','ignore').lower()) 59 | 60 | # Extracting keywords 61 | keywords = re.findall(r'[a-zA-Z]\w+', page_text) 62 | 63 | # Remove common words 64 | common_words = [ "and", "the", "at", "there", "some", "my", "of", "be", "use", "her", "than", "and", "this", "an", "would", "first", "a", "have", "each", "to", "from", "which", "like", "been", "in", "or", "she", "him", "is", "one", "do", "into", "who", "you", "had", "how", "that", "by", "their", "has", "its", "it", "if", "he", "but", "was", "not", "up", "more", "for", "are", "were", "as", "we", "with", "when", "then", "no", "come", "his", "your", "them", "way", "they", "can", "these", "could", "may", "I", "said", "so" ] 65 | 66 | for word in list(keywords): 67 | if word in common_words: 68 | keywords.remove(word) 69 | return keywords 70 | 71 | def dedup(keywords): 72 | # Deduplicate keywords 73 | unduped_keywords = list(dict.fromkeys(keywords)) 74 | keywords = unduped_keywords 75 | output_file(unduped_keywords) 76 | 77 | def mode(keywords): 78 | if args.mode == "word-frequency": 79 | keyword_count = Counter(keywords) 80 | common_keywords = [] 81 | for word, count in keyword_count.most_common(100): 82 | common_keywords.append(word) 83 | keywords = common_keywords 84 | output_file(keywords) 85 | if args.mode == "metadata": 86 | with open(args.file, 'rb') as pdf_file: 87 | read_pdf = PyPDF2.PdfFileReader(pdf_file) 88 | pdf_info = read_pdf.getDocumentInfo() 89 | author = pdf_info.author 90 | creator = pdf_info.creator 91 | producer = pdf_info.producer 92 | title = pdf_info.title 93 | subject = pdf_info.subject 94 | creation_date = str(pdf_info.creation_date) 95 | print(BLUE + "Title: " + NORM + title) 96 | print(BLUE + "Subject: " + NORM + subject) 97 | print(BLUE + "Author: " + NORM + author) 98 | if creator == producer: 99 | print(BLUE + "Creator: " + NORM + creator) 100 | else: 101 | print(BLUE + "Producer: " + NORM + producer) 102 | print(BLUE + "Creator: " + NORM + creator) 103 | print(BLUE + "Creation Date: " + NORM + creation_date + "\n") 104 | sys.exit(0) 105 | if args.mode == "entropy": 106 | unduped_keywords = list(dict.fromkeys(keywords)) 107 | # Pass deduplicated keywords to byte array function 108 | entropy_conv(unduped_keywords) 109 | else: 110 | dedup(keywords) 111 | 112 | # Convert dedplicated keywords to byte array and pass to entropy calculation function 113 | def entropy_conv(unduped_keywords): 114 | keyword_bytearray_list = [] 115 | for word in unduped_keywords: 116 | keyword_bytearray_list.append(bytearray(word, "utf-8")) 117 | entropy_calc(keyword_bytearray_list) 118 | 119 | def entropy_calc(keyword_bytearray_list): 120 | # Detetmine entropy score 121 | entropy_score = [] 122 | for word in keyword_bytearray_list: 123 | byte_series = pd.Series(word) 124 | entropy_score.append(float(entropy(byte_series.value_counts()))) 125 | # Decode keyword list 126 | keywords_list = [] 127 | for word in keyword_bytearray_list: 128 | keywords_list.append(str(word.decode("utf-8"))) 129 | # Create dictionary of keywords and entropy scores 130 | score_dict = {keywords_list[i]: entropy_score[i] for i in range(len(keywords_list))} 131 | sorted_score_dict = Counter(dict(sorted(score_dict.items(), 132 | key=lambda item: item[1], 133 | reverse=True))) 134 | for key,value in sorted_score_dict.most_common(100): 135 | print( BLUE + "Keyword: " + NORM + key + BLUE + "\t\tEntropy Score: " + NORM + str(value)) 136 | 137 | def output_file(keywords): 138 | # Create output file 139 | if args.output: 140 | with open(args.output, "w+") as file: 141 | for word in (keywords): 142 | file.write('%s\n' %word) 143 | file.close() 144 | print(args.output + " has been created!") 145 | else: 146 | with open("ScrapPY.txt", "w+") as file: 147 | for word in (keywords): 148 | file.write('%s\n' %word) 149 | file.close() 150 | print("ScrapPY.txt has been created!") 151 | 152 | def main(): 153 | # Evaluate arguments 154 | if args.file: 155 | read_keywords = read_file() 156 | mode_keywords = mode(read_keywords) 157 | else: 158 | print(RED + "\nEnter PDF file to scrape or use -h for help menu\n" + NORM) 159 | 160 | main() 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------