-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest.py
39 lines (29 loc) · 1.02 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import yaml
import unittest
import requests
import re
import PyPDF3
import urllib.request
class WaterLeak(unittest.TestCase):
with open(os.path.join(os.path.dirname(__file__), "flag"), "r") as f:
SNYK_FLAG = yaml.safe_load(f)
def test_flag_is_valid(self):
# URL of PDF to read
pdf_url = "https://ctf-web-content.s3.ap-southeast-2.amazonaws.com/Secret.pdf"
tmp_file = "/tmp/tmp.pdf"
# Download PDF from URL
urllib.request.urlretrieve(pdf_url, tmp_file)
# Open PDF file
with open(tmp_file, "rb") as pdf_file:
# Create PDF reader object
pdf_reader = PyPDF3.PdfFileReader(pdf_file)
# Loop through all pages
for page_num in range(pdf_reader.numPages):
# Get page object
page = pdf_reader.getPage(page_num)
# Extract text from page
text = page.extractText()
self.assertIn(self.SNYK_FLAG,text)
if __name__ == "__main__":
unittest.main()