简体   繁体   English

如何在.NET Core的PDF文档中找到Java脚本?

[英]How to find Java Script in PDF document in .NET Core?

I need to implement on the server side(.NET Core) the ability to check the PDF document for the presence of Java Scripts.我需要在服务器端(.NET Core)实现检查 PDF 文档是否存在 Java 脚本的能力。 If there is a script there, then I need to inform user about it.如果那里有脚本,那么我需要通知用户。 Is it possible to do this without using paid libraries?是否可以在不使用付费图书馆的情况下做到这一点? I will be grateful for any ideas.我将不胜感激任何想法。

Cross platform poppler utils is the simplest to use, There is no guarantee any means will find deliberately obscured JavaScript跨平台 poppler utils 是最简单易用的,不保证任何手段都会发现故意遮挡 JavaScript

pdfinfo -js filename.pdf

will output as plain text any standard embedded JavaScript, thus if the text looks obscured you can be forewarned of an oddity.将 output 作为纯文本嵌入任何标准 JavaScript,因此如果文本看起来模糊不清,您可以预先警告有异常。

A common PDF with normal /JavaScript entry will show up by simple plain text search.带有普通/JavaScript条目的常见 PDF 将通过简单的纯文本搜索显示。

for suspect or compressed file objects a simple extension is to use a pdf decompressor (Internal streams must be decompressed if required to show up any content as plain text) and text search for the /JavaScript marker as here for example:-对于可疑或压缩的文件对象,一个简单的扩展是使用 pdf 解压缩器(如果需要将任何内容显示为纯文本,则必须解压缩内部流)和文本搜索/JavaScript标记,例如:-

<</S/JavaScript/JS(\n\r\n\r\n// T

However an article about say PDF exploitation could legitimately contain this text然而,一篇关于 PDF 漏洞利用的文章可以合法地包含此文本
Td [(/JavaScript)]TJ

and it is easy for JS to self-edit at run time so this would not be detected in such a simple manner /JavaScr##69pt并且 JS 很容易在运行时进行自我编辑,因此不会以这种简单的方式检测到/JavaScr##69pt

You may find of interest page 4 of https://web.archive.org/web/20150421225342if_/http://cs.gmu.edu:80/~astavrou/research/Daiping_dsn14.pdf您可能会发现感兴趣的第 4 页https://web.archive.org/web/20150421225342if_/http://cs.gmu.edu:80/~astavrou/research/Daiping_dsn14.pdf

For a similar question (aimed at PHP) with variable answers see Find malicious PDF files using PHP validation?对于具有可变答案的类似问题(针对 PHP),请参阅Find malicious PDF files using PHP validation?

use PDFsharp and MigraDoc, it is free to use as it is open source ( http://www.pdfsharp.net/Licensing.ashx )使用 PDFsharp 和 MigraDoc,可以免费使用,因为它是开源的 ( http://www.pdfsharp.net/Licensing.ashx )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM