PDF report with gvm-script error

Hallo,

I’ve been doing some tinkering with using OpenVAS from the CLI through the use of GVM-tools and gvm-script. Most of what I want seems to work but the creation of .pdf reports seems to be “broken”. I’ve used the provided script from the gvm-tools github page (and manuals) gvm-tools/scripts/pdf-report. But this leaves me with the error “Uncorrect padding”. To fix this i’ve used a “filler” to fix the numbers of “=” at the end of the file.

content += “=” * ((4 - len(content) % 4) % 4)

This allows me to be able to create the pdf, but when this has finished the actual pdf is broken (As in, the file is the correct size, but no pdf reader can open it). What I also notice is than when opening the pdf in a HEX editor i’m missing the file signature (25 50 44 46 2d) at the top of the document. (adding this manually does not fix the error)

Is anyone aware of this issue, am I the only one or does some1 know how I could fix this?

Which version of GVM do you use? Did you check if all dependencies for generating the pdf report are installed? Are you able to download the pdf via GSA?

HI, thx for the quick reply

GVM version: 11https://community.greenbone.net/t/gvm-11-stable-initial-release-2019-10-14/3674
GMP version: 9

Downloading from GSA works as it should (Using ubuntu 19.04)

As with dependencies, I do not know what I would need (mainly since I did not find any “special” requirements on the gvm-tools github page). At the moment i’m using the base pdf-report.gmp.py script which uses base64 and pathlib.

Using the gvm-cli tool with:

gvm-cli socket --xml ‘<get_reports report_id=“b9f8a2f2-2969-4ff2-bb3f-52e7765ac4cc” format_id=“c402cc3e-b531-11e1-9163-406186ea4fc5” details=“True”/>’ | grep -oP ‘(?<=</report_format>)[^<]+’|base64 -d > reports/test.pdf

Does generate a proper pdf file.

If you can download the file via GSA all dependencies are fine.

Not sure what’s wrong in pdf-report.py. It should be the same as we are doing in GSA.

I have exact the same problem … Any solution?

So my last solution was not correct.
Nevertheless I fixed this now … see PR for more information.
You may fix your local version or pull it from master when its merged!

1 Like

great job @y0urself … thank you very much … here is my function adapted from your work

import sys
from base64 import b64decode
from pathlib import Path
import datetime
import time

def create_report(tname,reportid):
time1 = datetime.datetime.now()
timestamp=time1.strftime(’%Y-%m-%d_%H_%M’)
pdf_filename = “/tmp/” + tname + “-” + timestamp + “.pdf”
pdf_report_format_id = “c402cc3e-b531-11e1-9163-406186ea4fc5”
response = gmp.get_report(report_id=report_id, report_format_id=pdf_report_format_id)
report_element = response.find(“report”)
content = report_element.find(“report_format”).tail
binary_base64_encoded_pdf = content.encode(‘ascii’)
binary_pdf = b64decode(binary_base64_encoded_pdf)
pdf_path = Path(pdf_filename).expanduser()
pdf_path.write_bytes(binary_pdf)
print(“PDF: " + pdf_filename + " created”)
return pdf_filename