Permalink
Browse files

Initial commit

  • Loading branch information...
braktech committed Jul 18, 2011
0 parents commit 8aa7bd1a68e59cbfb3d3f2847e23480bccf71073
Showing with 1,803 additions and 0 deletions.
  1. +674 −0 COPYING
  2. +165 −0 COPYING.LESSER
  3. +19 −0 LICENSE
  4. +57 −0 README
  5. +24 −0 xdpdf.sln
  6. +36 −0 xdpdf/Properties/AssemblyInfo.cs
  7. +42 −0 xdpdf/app.config
  8. +644 −0 xdpdf/xdpdf.cs
  9. +81 −0 xdpdf/xdpdf.csproj
  10. +28 −0 xdpdf/xdpdfSettings.cs
  11. +33 −0 xdpdf/xdpdfSettings.settings
674 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
19 LICENSE
@@ -0,0 +1,19 @@
/******************************************************************************
* copyright : 2011 by Daniel Brakensiek *
* email : daniel@braktech.com *
******************************************************************************/
/******************************************************************************
* xdpdf is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* xdpdf is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public *
* License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with xdpdf. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************/
57 README
@@ -0,0 +1,57 @@
Exchange Defend: PDF (xdpdf) is designed to quickly and transparently render inert potentially malicious parts of a PDF document traversing a Microsoft Exchange server. Whenever it changes a PDF document, it will advise the recipient of the email and keep a copy for administrative review if necessary.
xdpdf works in the following way:
1. It detects a PDF
2. It scans the PDF for potentially undesirable keywords
3. If a keyword is matched, xdpdf will:
a) copy the PDF to an administrator-specified location
b) overwrite the first two bytes of the keyword, preventing execution by the PDF reader
c) notify the user, instructing them to contact their mail administrator if they require the original document
xdpdf is highly configurable. It has multiple log levels, as well as allowing administrative configuration of log and quarantine directories. In addition, the administrator can specify if xdpdf should believe the attachment extension or MIME-type supplied by Exchange, or perform speedy PDF detection on all incoming attachments.
=== System Requirements ===
Microsoft Exchange Server 2010 SP1
.NET Framework 3.5
Note: xdpdf will work on Exchange Server 2010 without SP1 or Exchange Server 2007, however the DLL will likely need to be recompiled against the local versions of Microsoft.Exchange.Data.Common and Microsoft.Exchange.Data.Transport
=== Installation ===
1) Copy xdpdf.dll and xdpdf.config to a directory on the mail server
2) Set configuration options, creating the LogPath and QuarantinePath directories
3) In the Exchange Management Shell on the Exchange server, run 'Install-TransportAgent -Name xdpdf -AssemblyPath drive:\path\to\dll\xdpdf.dll> -TransportAgentFactory xdpdf.xdpdfFactory'
4) In the Exchange Management Shell on the Exchange server, run 'Enable-TransportAgent -Identity xdpdf'
5) In the Exchange Management Shell on the Exchange server, run 'Restart-Service MSExchangeTransport'
6) Monitor LogPath for log files, and QuarantinePath for quarantined files
=== Configuration Change ===
1) In the Exchange Management Shell on the Exchange server, run 'Disable-TransportAgent -Identity xdpdf'
2) In the Exchange Management Shell on the Exchange server, run 'Restart-Service MSExchangeTransport'
3) Make changes to the configuration file
4) In the Exchange Management Shell on the Exchange server, run 'Enable-TransportAgent -Identity xdpdf'
5) In the Exchange Management Shell on the Exchange server, run 'Restart-Service MSExchangeTransport'
=== Uninstallation ===
1) In the Exchange Management Shell on the Exchange server, run 'Disable-TransportAgent -Identity xdpdf'
2) In the Exchange Management Shell on the Exchange server, run 'Uninstall-TransportAgent -Identity xdpdf'
3) In the Exchange Management Shell on the Exchange server, run 'Restart-Service MSExchangeTransport'
4) Delete xdpdf files as desired
=== Configuration ===
The configuration file contains the following settings:
Logging [True|False] : Enable or disable logging globally
Loglevel [0 - 2] : Specify the log level:
: 0) Log only malicious PDFs
: 1) Log start, end and PDF processing details for each email
: 2) Verbose; detailed logging (recommended for testing purposes only)
LogPath [drive:\path] : Path to the log directory. It should already exist.
: xdpdf will create one log file per day within this directory
QuarantinePath [drive:\path] : Path to the quarantine directory. It should already exist.
: xdpdf will create one subdirectory per email containing a potentially malicious PDF, and place the unmodified PDF within.
Keywords [string list] : Keywords should be of the form '/Keyword', noting the leading slash and case correctness according to the PDF spec
ScanAllAttachments [True|False] : If True, xdpdf will use its internal PDF file magic. If False, it will believe the file extension or MIME type supplied by Exchange.
=== Implementation Notes ===
Given the potential volume of files being scanned in 'ScanAllAttachments' mode, it has been designed to be as fast and lightweight as possible. It will read the first 1024 bytes of a file, and attempt to locate the bytes "%PDF" within - this is the extent of PDF file magic according to the spec. During testing on a 2 x 2.6GHz core VM with 4gb of memory, Exchange could not measure the time it took to scan non-PDF files - it considered the entire process took place within the same millisecond. If you run in ScanAllAttachments mode at log level 2, you will be able to see the metrics for your own server; of course you should do this in a testing environment. On the other hand, you may decide to take the risk of misidentified PDF files getting through in exchange for not scanning all files.
xdpdf was deliberately designed to be as quick and thorough as possible. This means that it makes no attempt to understand the structure or content of the file; rather it simply looks for the specified keywords (whether obfuscated or not), and renders inert those it finds. It is entirely possible it will encounter the keyword strings within document content (either plain text or encoded images etc), especially for the shorter keywords such as '/AA' and '/JS'. This is the main reason for keeping a copy of the original PDF - during testing, 21 PDFs from 7950 I tested (around 5.4gb worth) rendered incorrectly once they had been modified by xdpdf. The burden would be on the end user to notify the mail administrator, and the mail administrator to use the log and original file to make a decision on the safety of the PDF, before passing it on to the end user. Note that around a third of the testing PDFs were modified by xdpdf, and the vast majority displayed correctly following this.
@@ -0,0 +1,24 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xdpdf", "xdpdf\xdpdf.csproj", "{A13A9935-8538-4494-853F-C24DECDFA065}"
EndProject
Global
GlobalSection(MercurialSourceControlSolutionProperties) = preSolution
SolutionIsControlled = True
SolutionBindings = <Solution Location In Database>
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A13A9935-8538-4494-853F-C24DECDFA065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A13A9935-8538-4494-853F-C24DECDFA065}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A13A9935-8538-4494-853F-C24DECDFA065}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A13A9935-8538-4494-853F-C24DECDFA065}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("xDefend PDF")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("xDefend PDF")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("79623db6-22d8-487b-b6e4-0b45993e3373")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="xdpdf.xdpdfSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<xdpdf.xdpdfSettings>
<setting name="Logging" serializeAs="String">
<value>True</value>
</setting>
<setting name="LogPath" serializeAs="String">
<value>C:\agent_tests\pdf detect</value>
</setting>
<setting name="QuarantinePath" serializeAs="String">
<value>C:\agent_tests\pdf detect\HAZDAT raw pdfs</value>
</setting>
<setting name="Keywords" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>/JS</string>
<string>/JavaScript</string>
<string>/AA</string>
<string>/OpenAction</string>
<string>/JBIG2Decode</string>
<string>/RichMedia</string>
<string>/Launch</string>
</ArrayOfString>
</value>
</setting>
<setting name="ScanAllAttachments" serializeAs="String">
<value>True</value>
</setting>
<setting name="LogLevel" serializeAs="String">
<value>2</value>
</setting>
</xdpdf.xdpdfSettings>
</userSettings>
</configuration>
Oops, something went wrong.

0 comments on commit 8aa7bd1

Please sign in to comment.