Dataset Viewer
Auto-converted to Parquet Duplicate
file_id
large_stringlengths
24
46
skeleton
large_stringlengths
306
120k
skeleton_masked
large_stringlengths
306
120k
skeleton_chars
int64
306
120k
skeleton_tokens_est
int64
76
30k
was_truncated
bool
2 classes
file_size
int64
306
76.9M
n_obj
int64
1
33.2k
n_endobj
int64
3
33.2k
n_stream
int64
0
32.8k
n_xref
int64
0
34
n_startxref
int64
0
17
n_trailer
int64
0
17
n_objstm
int64
0
312
n_eof
int64
0
17
n_images
int64
0
24.2k
n_distinct_names
int64
8
32.8k
max_dict_depth
int64
1
170
printable_frac
float64
0.08
1
entropy_file
float64
1.27
8
entropy_largest_stream
float64
0
8
largest_stream_bytes
int64
0
10.1M
compression_ratio
float64
0
2.86
binary_streams_dropped
int64
0
32.8k
n_pages
int64
0
1.18k
page_text_chars
int64
0
3.13M
parses_ok
bool
2 classes
markers_in_file
large_stringclasses
17 values
markers_in_skeleton
large_stringclasses
19 values
payload_pos_frac
float64
0
1
index
int64
0
1.2k
source_file
large_stringlengths
36
48
injection_type
large_stringclasses
13 values
framework
large_stringclasses
10 values
base_payload
large_stringclasses
5 values
variant_used
large_stringlengths
6
292
insertion_strategy
large_stringclasses
4 values
obfuscation_strategy
large_stringclasses
7 values
seed
int64
42
42
timestamp
large_stringdate
2026-07-19 07:34:39
2026-07-25 14:28:17
is_injected
bool
2 classes
payload_retained
bool
1 class
payload_window
large_stringlengths
306
3k
cluster
int32
0
5
cross_site_scripting_OWASP_0004.pdf
"%PDF-1.7 % \n127 0 obj <</Linearized 1/L 414218/O 129/E 338305/N 6/T 411562/H [ 2236 703]>> endob(...TRUNCATED)
"%PDF-1.7 % \n127 0 obj <</Linearized 1/L 414218/O 129/E 338305/N 6/T 411562/H [ 2236 703]>> endob(...TRUNCATED)
120,000
30,000
true
414,402
224
224
71
4
2
2
0
2
7
296
3
0.45097
7.932606
7.989339
70,979
0.289574
24
6
20,996
true
cross_site_scripting
cross_site_scripting
0.846984
4
12851f0053449570257ff3dfe552621a8dd63d53.pdf
cross_site_scripting
OWASP
WICAR
Safe_WICAR-BROWSER-TEST-PAYLOAD-CALC-EXE
before_trailer
null
42
2026-07-19T07:36:25.609623
true
true
"s humanit)21 (arios.)]TJ\n-1.031 -1.636 Td\n(\\225)Tj\n/Span<</ActualText<FEFF0009>>> BDC \n( )Tj\n(...TRUNCATED)
4
cross_site_scripting_OWASP_0007.pdf
"%PDF-1.4 % \n49 0 obj <</Linearized 1/L 244325/O 51/E 132968/N 5/T 243230/H [ 856 370]>> endobj\n(...TRUNCATED)
"%PDF-1.4 % \n49 0 obj <</Linearized 1/L 244325/O 51/E 132968/N 5/T 243230/H [ 856 370]>> endobj\n(...TRUNCATED)
48,020
12,005
false
244,510
77
77
31
4
2
2
0
2
6
186
3
0.414801
7.849449
7.746165
94,757
0.196393
15
5
8,011
true
cross_site_scripting
cross_site_scripting
0.000601
7
1dcf57a5007b56254583423ba31107d22459bccf.pdf
cross_site_scripting
OWASP
WICAR
Safe_WICAR_Browser-Test-Payload-Calc-Exe
after_first_endobj
null
42
2026-07-19T07:38:11.679370
true
true
"%PDF-1.4 % \n49 0 obj <</Linearized 1/L 244325/O 51/E 132968/N 5/T 243230/H [ 856 370]>> endobj\n(...TRUNCATED)
2
cross_site_scripting_OWASP_0024.pdf
"%PDF-1.5 \n% \n1 0 obj \n<</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 9 0 R/MarkInfo<<(...TRUNCATED)
"%PDF-1.5 \n% \n1 0 obj \n<</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 9 0 R/MarkInfo<<(...TRUNCATED)
9,177
2,294
false
5,841
14
14
3
4
2
2
1
2
0
77
3
0.750043
6.836111
7.878419
1,680
1.571135
1
1
836
true
cross_site_scripting
cross_site_scripting
0.029276
24
2KQDEYIMQDVT2DUARRCJV5HEUYY2HO7H.pdf
cross_site_scripting
OWASP
EICAR
X5O!p%@ap[4\pzX54(p^)7Cc)7}$eIcAr-StAnDAnD-AntiViRUs-tEsT-fIlE!$h+h*
after_first_endobj
null
42
2026-07-19T07:49:54.773882
true
true
"%PDF-1.5 \n% \n1 0 obj \n<</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 9 0 R/MarkInfo<<(...TRUNCATED)
1
cross_site_scripting_OWASP_0028.pdf
"%PDF-1.4\n% \n1 0 obj\n<<\n/Type/ExtGState\n/SM 0.001\n/OPM 1\n>>\nendobj\n2 0 obj\n<<\n/Width 73(...TRUNCATED)
"%PDF-1.4\n% \n1 0 obj\n<<\n/Type/ExtGState\n/SM 0.001\n/OPM 1\n>>\nendobj\n2 0 obj\n<<\n/Width 73(...TRUNCATED)
84,715
21,178
false
556,015
139
139
63
4
2
2
0
2
31
299
2
0.418253
7.973096
7.943141
35,473
0.152361
48
12
82,182
true
cross_site_scripting
cross_site_scripting
0.999691
28
2RE7KOL5KV5FFCUG6CYUVEFF4KIUZN2V.pdf
cross_site_scripting
OWASP
EICAR
x5O!P%@ap[4\Pzx54(p^)7Cc)7}eIcar-standard-Antivirus-Test-File!$H+H*
before_final_eof
null
42
2026-07-19T07:52:28.023700
true
true
"xap:ModifyDate>\n <xap:MetadataDate>2008-01-03T20:19:48-08:00</xap:MetadataDate>\n </rdf:Descri(...TRUNCATED)
3
cross_site_scripting_OWASP_0047.pdf
"%PDF-1.4 % \n12 0 obj <</Linearized 1/L 12309/O 14/E 5404/N 2/T 12022/H [ 556 200]>> endobj \nx(...TRUNCATED)
"%PDF-1.4 % \n12 0 obj <</Linearized 1/L 12309/O 14/E 5404/N 2/T 12022/H [ 556 200]>> endobj \nx(...TRUNCATED)
14,246
3,561
false
12,512
25
25
4
4
2
2
0
2
0
95
2
0.789802
6.249081
2.965503
3,823
1.138587
1
2
5,838
true
cross_site_scripting
cross_site_scripting
0.987132
47
37WOUPCWLZGR4AFDBNNHKUHNTVLYXVLD.pdf
cross_site_scripting
OWASP
AMTSO
safeTestFile_AMTSO-POTENTIALLY-UNWANTED-TEST-NOT-DANGEROUS
before_final_eof
null
42
2026-07-19T08:02:06.654831
true
true
"iption>\n <rdf:Description rdf:about=\"\"\n xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n (...TRUNCATED)
3
cross_site_scripting_OWASP_0118.pdf
"%PDF-1.5\n3 0 obj\n<</Type /Page\n/Parent 1 0 R\n/Resources 2 0 R\n/Contents 4 0 R>>\nendobj\n4 0 o(...TRUNCATED)
"%PDF-1.5\n3 0 obj\n<</Type /Page\n/Parent 1 0 R\n/Resources 2 0 R\n/Contents 4 0 R>>\nendobj\n4 0 o(...TRUNCATED)
40,728
10,182
false
240,646
21
21
7
2
1
1
0
1
0
102
5
0.477461
7.806088
7.99605
148,325
0.169244
4
1
659
true
cross_site_scripting
cross_site_scripting
0.999007
118
5LSCLZ4YEU5LZUAPARZB6QKKYSPSLW26.pdf
cross_site_scripting
OWASP
EICAR
X5O!p%@aP[4\pZx54(p^)7Cc)7}$eIcAr-StAndArD-AntiViRus-tEsT-fIlE!$h+h*
before_trailer
null
42
2026-07-19T10:09:53.868033
true
true
"/CMap defineresource pop\nend\nend\nendstream\nendobj\n16 0 obj\n<</Registry (Adobe)\n/Ordering (UC(...TRUNCATED)
5
cross_site_scripting_OWASP_0122.pdf
"%PDF-1.4\n% \n3 0 obj\n<</Filter[/ASCII85Decode/LZWDecode]/Length 11377>>stream\nJ.RTgcqqMC<&m5e`(...TRUNCATED)
"%PDF-1.4\n% \n3 0 obj\n<</Filter[/ASCII85Decode/LZWDecode]/Length 11377>>stream\nJ.RTgcqqMC<&m5e`(...TRUNCATED)
55,278
13,819
false
205,917
65
65
10
4
2
2
0
2
0
552
12
0.866733
6.653127
3.825873
51,668
0.268448
1
1
8,452
true
cross_site_scripting
cross_site_scripting
0.055959
122
5WEKPBBWFKF47XDYW5QBC36KFVBYJFE5.pdf
cross_site_scripting
OWASP
RANSIM
Safe_RANSIM-KNOWBE4-ENCRYPTION-SIMULATION-TEST-NOT-REAL_Safe
after_first_endobj
null
42
2026-07-19T10:11:25.390296
true
true
".rDY)&a5mJ9'Zu]3k \nRY`\\4qR:6qW9N5\\)FMbpScMI]K4nXXgFP6^d`ZL8R:)m(66\">si5(U9^n)9m84<l9 \nJ1H:LK!Y(...TRUNCATED)
4
cross_site_scripting_OWASP_0136.pdf
"%PDF-1.6\n% \n14 0 obj\n<< /Type /Page /Parent 1 0 R /LastModified (D:20150607184823-06'00') /Res(...TRUNCATED)
"%PDF-1.6\n% \n14 0 obj\n<< /Type /Page /Parent 1 0 R /LastModified (D:20150607184823-06'00') /Res(...TRUNCATED)
61,846
15,461
false
783,935
31
31
11
2
1
1
0
1
2
261
2
0.413524
7.960671
7.993997
361,230
0.078892
6
1
1,459
true
cross_site_scripting
cross_site_scripting
0.999596
136
6AVXT3OLPGYVAG7L4CBYJHXLAXJE4V6F.pdf
cross_site_scripting
OWASP
EICAR
X5O!p%@AP[4\PZX54(P^)7Cc)7}$eIcAr-StAndArD-AntiViRus-tEsT-fIlE!$h+h*
before_trailer
null
42
2026-07-19T10:19:59.010499
true
true
"df:li>\n <rdf:li rdf:parseType=\"Resource\">\n <pdfaProperty:category>internal</pdfaProperty:ca(...TRUNCATED)
3
cross_site_scripting_OWASP_0159.pdf
"%PDF-1.5\n% \n2 0 obj\n<<\n/Type /Catalog\n/Pages 4 0 R\n/Dests 5 0 R\n/Version /1#2E5\n>>\nendob(...TRUNCATED)
"%PDF-1.5\n% \n2 0 obj\n<<\n/Type /Catalog\n/Pages 4 0 R\n/Dests 5 0 R\n/Version /1#2E5\n>>\nendob(...TRUNCATED)
30,589
7,647
false
278,419
31
31
28
1
1
0
1
1
8
100
1
0.370194
7.910191
7.746168
94,758
0.109867
15
4
6,463
true
cross_site_scripting
cross_site_scripting
0.000506
159
7096e75ab6e07bb7950205a526f70af2024a802a.pdf
cross_site_scripting
OWASP
WICAR
Wicar_Browser_Test_Payload_Calc_Exe_Safe
after_first_endobj
null
42
2026-07-19T10:37:29.938031
true
true
"%PDF-1.5\n% \n2 0 obj\n<<\n/Type /Catalog\n/Pages 4 0 R\n/Dests 5 0 R\n/Version /1#2E5\n>>\nendob(...TRUNCATED)
2
cross_site_scripting_OWASP_0233.pdf
"%PDF-1.6 % \n1052 0 obj <</Linearized 1/L 149211/O 1055/E 6972/N 38/T 128122/H [ 653 517]>> endob(...TRUNCATED)
"%PDF-1.6 % \n1052 0 obj <</Linearized 1/L 149211/O 1055/E 6972/N 38/T 128122/H [ 653 517]>> endob(...TRUNCATED)
120,000
30,000
true
149,425
135
135
51
4
2
2
10
2
0
152
6
0.576443
7.453943
3.161149
4,312
0.803078
2
38
80,754
true
cross_site_scripting
cross_site_scripting
0.001004
233
AVFIBOSLNYG5BBP2JOV3MOBAFZDYN7DP.pdf
cross_site_scripting
OWASP
EICAR
EiCaR-Standard-Antivirus-Test-FileX5O!P%@AP[4\PZX54(P^)7CC)7}$H+H*
after_first_endobj
null
42
2026-07-23T07:27:04.222255
true
true
"%PDF-1.6 % \n1052 0 obj <</Linearized 1/L 149211/O 1055/E 6972/N 38/T 128122/H [ 653 517]>> endob(...TRUNCATED)
2
End of preview. Expand in Data Studio

Injected PDFs - EDA and Evaluation Corpus

This repository holds the exploratory data analysis for a project on detecting harmless-but-real attack payloads injected into PDF files, together with the dataset that analysis produced.

The project has two halves, both in the notebook Final_project_V7_EDA.ipynb:

Question Input
Part 1 Is our synthetic corpus a stand-in for real malware, or is it something else? The published CIC feature table (11,126 x 34)
Part 2 Is our corpus a usable measuring instrument, and what does a model actually have to do to pass it? The 1,100 raw PDF files

Part 2 exports Datasets/synthetic_corpus_part2_clustered.parquet, the dataset the model evaluation stage runs on.


The data

Two tables are read directly from Cyber-security-final-project/Generated_Injected_PDFs_HARMLESS:

  • combined (11,126 x 34) - one row per PDF, described by 32 structural features. It holds two different populations:
    • source = "Real" - 10,025 real PDFs from CIC-Evasive-PDFMal2022;
    • source = "Synthetic" - 1,100 PDFs we generated ourselves by injecting harmless payloads.
  • manifest (1,100 x 11) - the ground truth for the synthetic half: which payload went into which file, where, and how it was obfuscated.

Target: Class (Malicious / Benign). Grouping variable: source (Real / Synthetic).

The payloads come from standard, deliberately harmless malware test corpora - EICAR (221 files), WICAR (255), AMTSO (215) and RANSIM (209). They do no damage, but they are the exact strings and structures the security industry uses to check that a scanner works.


Part 1 - How similar is the synthetic malware to the real thing?

Step 1 - Cleaning the feature table

The raw table looks almost perfect and is not. Five repairs were needed before any analysis:

  1. Column names. A typo (Fine name), spaces inside names, and three competing naming conventions. All renamed to snake_case.
  2. pdf_size was in different units in each half - kilobytes for the real files, bytes for the synthetic ones, a factor of roughly 3,000. Rescaled to bytes.
  3. 147 cells contained the extraction tool's crash message, written into the CSV as if it were data (pdfid.py, bytes[endHeader], (most). Given their own -2 sentinel.
  4. 638 cells used a 29(2) notation - a count and a second measurement crammed into one text cell. Parsed out, so every measurement column became a proper integer column.
  5. metadata_size was not a byte size at all on the synthetic side. Voided to <NA> rather than repaired.

The important finding of this step is about missing values. The file declares only 74 NaN out of ~378,000 cells. In reality 15,016 cells carry a sentinel instead of a measurement, across every one of the 30 feature columns - and they are not spread evenly:

Group Share of rows hit by an extraction failure
Real - Malicious 27.2%
Real - Benign 0.8%
Synthetic 0%

The extraction tool breaks specifically on malformed malicious PDFs - and malicious PDFs are often deliberately malformed to defeat parsers. This is informative missingness: the fact that a value is missing is itself a clue about the class. Tempting to exploit, but a model that learns "extraction failed, therefore malicious" has learned about our tool, not about malware. The sentinels were converted to NaN and kept out of the statistics.

Outliers were detected but not removed. The IQR rule flags 4-19% of rows, but in the real half those rows are the most class-informative in the table, and they point both ways: files with an extreme js count are 91.3% malicious, files with an extreme obj count only 5.1%, against a 55.4% base rate. Deleting them would have destroyed the signal, and destroyed it asymmetrically.

Step 2 - Comparing the two corpora

Graph 1 - How is the data composed?

Composition of the dataset by source and class

The dataset is dominated by the real data: 10,025 real files (90%) against 1,100 synthetic ones (10%), so any statistic on the pooled table is really a statistic about the real half. The class balance also differs sharply - the real half is close to balanced at 55.4/44.6, the synthetic half is deliberately skewed at 81.8/18.2. Every graph from here on separates the two.

Graph 2 - Do the two sources measure the same thing?

File size distribution by source, log axis

This is the check on the unit fix. Before rescaling the two distributions were two separate humps roughly 2,900x apart - not because the files differ, but because one half was recorded in kilobytes and the other in bytes. After the fix they overlap across most of their range.

One real difference survives, and it is a believable one: the real files have a median of 38 KB against 107 KB for the synthetic files, about 2.8x. We injected payloads into full-length documents, whereas the CIC corpus contains a large population of very small files. Note the log scale - size data is almost always log-normal, which is also why the median is the honest summary here and not the mean.

Graph 3 - Which features separate Malicious from Benign?

Boxplots of four structural features, by class, in each half

In the real data, malicious PDFs are structurally much simpler than benign ones - 47 objects vs 10, 19 streams vs 2, 2 pages vs 1. That is the opposite of the intuitive guess: a weaponised PDF is a nearly empty shell whose only job is to carry the payload, while a genuine document carries fonts, images and text.

In the synthetic data the same four boxes are effectively identical - 32.5 vs 35 objects, 12 vs 12 streams, 2 vs 2 pages. Our injection did not change the host document's structure, because we started from ordinary complete PDFs and added a small payload to them.

Graph 4 - Correlations between features and the target

Correlation heatmaps, real and synthetic

The real panel contains genuine signal: open_action +0.52, stream -0.39, startxref -0.38, obj -0.26. The signs tell a coherent story - an instruction that runs something the moment the file opens is associated with malice, while everything measuring document richness is associated with benignity.

The synthetic panel is almost blank in the target row. Its strongest correlation is keyword_embedded_file at 0.167 - weaker than the sixth strongest feature on the real side.

Graph 5 - Does the synthetic data behave like the real data?

Scatter plot of two features, coloured by class, in each half

In the real panel the two classes form two visibly different clouds - benign files spread up and to the right (many objects, many streams), malicious files bunch into the bottom-left corner. In the synthetic panel the two clouds sit directly on top of each other.

The flag table makes the gap explicit: js is present in 71.8% of real malicious files but only 19.8% of synthetic malicious ones, and open_action in 51.4% vs 17.9%. Conversely launch and keyword_embedded_file are more common in our files (8.9% and 26.4%) than in real malware (2.3% and 8.1%) - because those are the payload types our generator favoured.

Graph 6 - Every feature ranked by its correlation with the target

Ranked feature correlations, real vs synthetic

This is the compact statement of Part 1's main result. The blue bars form a clear staircase; the orange bars are nearly flat. More importantly, the two rankings do not merely weaken - they disagree. open_action is the best real predictor at +0.52 and -0.07 on the synthetic side: the sign is reversed. A rule taken from one corpus points the wrong way on the other.

Graph 7 - UMAP: the final test of similarity

UMAP of all 29 structural features, coloured by source

Given all features at once and no labels at all, UMAP still sorts the two corpora apart.

  • The relationship is containment, not overlap. The real corpus spreads across the whole map in dozens of thin filaments; the synthetic corpus sits in one compact band covering roughly a fifth of the occupied area.
  • The synthetic corpus is 9.9% of the data, so if the two were interchangeable a synthetic file's neighbours would be about 9.9% synthetic. Instead 77.9% are - an eightfold enrichment - and 39.1% of synthetic files have no real file at all among their 20 nearest neighbours.

Part 1 conclusion - two corpora, two different notions of "malicious"

Built around real (CIC) malware Built around synthetic injected PDFs
What it keys on Global document shape Presence of a specific injected artefact
Top features open_action +0.52, stream -0.39, startxref -0.38 keyword_embedded_file 0.17, launch 0.13, xfa 0.12
Strength of signal Strong - up to 0.52 Weak - nothing above 0.17
Implicit rule "Malicious files are small and structurally simple, with one automatic trigger" "Malicious files contain one extra object that clean files do not"
Region of the UMAP map Spread across the whole map One compact island, ~1/5 of the area

The reason is not statistical but procedural. Real malware is authored - built minimally from scratch to carry a payload. Our files were injected - ordinary complete documents with a payload added, so the host structure barely moved. The two corpora encode two different threat models.

Why that makes the synthetic corpus the right thing to evaluate on

That difference is usually described as a limitation. For an evaluation it is the entire point.

1. The payloads are largely invisible to the CIC feature vocabulary.

mean flags raised share raising zero flags
Real - Malicious 2.2 16.6%
Synthetic - Malicious 1.0 37.3%
Real - Benign 0.3 77.3%
Synthetic - Benign 0.3 69.5%

37.3% of our injected files raise no CIC flag at all - more than double the evasion rate of real malware. A flag-counting scanner of the kind these features describe would pass them straight through.

2. They are nonetheless genuinely dangerous. Every payload comes from a standard malware test corpus - harmless by design, but functionally an attack in every respect except the damage.

3. Real scanners do detect them. While transferring the corpus from Google Drive, every object_action_injection file (80 of them) was blocked by Google's malware scanner - independent confirmation from a production security system that these files are not inert props.

So the corpus is provably malicious to a production scanner while remaining largely invisible to the structural feature set the academic benchmark is built on. That gap is what makes it useful.

The variety is graded, which is what makes it a measuring instrument

900 injected files built from 337 distinct attack configurations, varying along five axes at once: 12 attack families, 9 source frameworks, 550 payload variants, 3 insertion points, 6 obfuscation strategies - and 1,045 distinct host documents for 1,100 files, so a model cannot succeed by memorising the container.

Counting CIC flags per family splits the corpus cleanly in two:

families flags raised % raising zero flags
Loud javascript_injection, object_action_injection, ransomware_simulation, shellcode_embedded_exe, polyglot_file, xfa_acroform_injection 1.2 - 2.3 avg 0%
Silent dde_template_injection, ssrf, llm_prompt_injection, cross_site_scripting, uri_redirect_phishing, steganographic_payload 0.2 - 0.3 avg 71 - 81%

The loud families check that a model has basic competence; the silent families are the real test. Because both are in one corpus, a model's score profile across families is informative in a way a single average is not.

What this corpus can and cannot establish. It can measure evasion resistance and compare models fairly, since every model faces the identical 1,100 files. It cannot stand in for a general accuracy claim on real-world PDFs - the host documents cover about a fifth of the UMAP map.


Part 2 - Preparing the corpus for evaluation

Part 1 ended on a negative result, and that result has a direct consequence: the CIC feature table is the wrong input for Part 2. If the features cannot see the payload, no analysis of those features can tell us whether the corpus is varied enough to test a model on. So Part 2 goes back to the 1,100 actual PDF files and builds its own table from them.

Step 1 - Designing the extraction

A PDF is a binary container of numbered objects, most of them compressed. Three choices had to be made, and each one can quietly delete the payload - so each was measured rather than guessed, on a random sample of 60 injected files.

Probe 1 - where is the payload? after_first_endobj puts it a median of 0.2% into the file; before_trailer and before_final_eof put it at a median of 99.8%. 40 of 60 payloads are past the halfway mark. Keeping only the start of each file would have silently deleted about two thirds of the ground truth - and the dataset would still have looked perfectly healthy.

Probes 2 and 3 - what about the compressed streams? Throwing the stream bodies away destroys 22 of 60 payloads, because many injections sit inside streams. Decompressing first keeps 60 of 60. The payloads were never missing; they were compressed.

This is Part 1's lesson in a different form: there, the feature vocabulary had no column for the payload; here, a naive text extractor cannot see it because it sits behind a decompression step. In both cases the data looks clean and the information is simply gone.

Step 2-3 - The extractor, and its verification

The design that follows: keep a head and a tail window (never just the head), decompress streams and keep the text, replace a body with a placeholder only when it is genuinely binary. The result is a skeleton - the structure and readable content of the PDF with the binary bulk removed, roughly what a security analyst would look at.

Check Result
Rows, columns, manifest join 1,100 x 42, every file_id unique, ground truth on every row
Payload retention 900 / 900 - and in all 900 the marker found matches the type the manifest says was injected
Files over the 120,000-char budget 144 (13.1%), payload retention among them still 100%
Brand strings (EICAR, AMTSO, ...) before masking 869 files
Brand strings after masking 0 - while all 900 structural markers survive
Files that no longer parse as PDFs 2 (kept, flagged in parses_ok)
Extraction time 722 seconds for 815 MB

The masking matters: skeleton_masked removes the give-away brand name without removing the attack, which is what will let us tell "the model recognised a famous test string" apart from "the model understood the PDF".

Step 4 - Descriptive statistics

The entire class of defect that dominated Part 1 is gone: zero declared missing values and zero negative values across all 21 numeric features. Part 1 needed five subsections to repair 15,016 sentinel cells written by the CIC tool; here there is no tool between us and the bytes. The data quality problems in Part 1 were a property of that feature table, not of PDF data in general.

The skew is still extreme (12 of 21 features above 10), so medians remain the honest summary. But only one feature has a median of zero, against 18 of 30 in Part 1 - the first numerical sign that we are measuring something different.

Three near-duplicate column pairs were found and one member of each dropped, leaving 18 features: n_obj ~ n_endobj (r = 1.000, a well-formed PDF closes every object it opens), n_startxref ~ n_eof (0.997, both count revisions), and n_images ~ binary_streams_dropped (0.991, an artefact of our own extraction). Left alone, all three would have silently given object count, revision count and image count double weight in every distance calculation downstream.

Step 5 - Is there enough variety?

Graph 1 - Coverage

Attack type x insertion position coverage grid

All 36 cells of the 12 attack types x 3 insertion positions grid are populated, from 15 files to 33. No attack type was only ever tried in one position, so a model cannot score well by being good at spotting objects appended at the end of a file.

Graph 2 - Composition

Source framework composition per attack type

Each of the 12 types draws on exactly two frameworks. That rules out the worst problem - where "detecting ssrf" would really mean "detecting the one framework it came from" - but two is a thin margin, and this is the corpus's one real limitation.

Graph 3 - Spread within each type

Carrier diversity and payload position spread within each type

This is where the corpus earns its keep:

  • distinct_carriers equals the file count for every single type - no carrier document is ever reused across all 900 injected files.
  • Carrier size varies by a factor of 21x to 281x within a type.
  • pos_iqr is 1.0 for every type: the interquartile range of the payload's relative position covers the whole file, in every category.

But the same fact carries a warning. If every file sits in its own unique carrier, the differences between files are mostly differences between carrier documents, and the payload is a small addition on top.

Step 6 - Embedding and mapping the corpus

UMAP at whole-document scope vs payload-window scope

The same vectoriser, run at two scopes, measured by neighbourhood purity - out of each file's 20 nearest neighbours, what share share its injection type? Random baseline: 8.9%.

Scope Share of text used Neighbourhood purity
Whole document (TF-IDF) 100% 12.1% - barely above chance
Payload window (TF-IDF) 4.5% 42.0% - almost five times baseline
Payload window (neural embedding) 4.5% 30.8%

So the signal is real, and it is local. The payload is a genuine and very distinctive signal occupying about one twentieth of the text, and averaging over the whole document drowns it.

Two consequences:

  • For Part 1's argument, this is confirmation. The CIC features were not unlucky - any whole-document summary, hand-built counters or learned embeddings alike, will miss a small local change. They were the wrong kind of instrument.
  • For the evaluation, this defines the task. Testing a model here is a needle-in-a-haystack detection problem, not a document classification problem: find a few hundred suspicious characters inside a hundred thousand characters of ordinary PDF.

Step 7 - How many natural groups does the corpus have?

Three algorithms, because each defines "a cluster" differently and they fail differently. All run on the 384-dimensional payload-window embeddings, not on the 2-D UMAP coordinates - UMAP deliberately distorts large distances, so clustering its output would describe the picture rather than the data.

KMeans inertia elbow and silhouette Agglomerative silhouette and dendrogram DBSCAN k-distance curve and eps sweep

Chosen: KMeans with k = 6, taken from the inertia elbow rather than the silhouette peak. In 384 dimensions the silhouette rewards any tight little blob, so a split that isolates a few outliers and leaves everything else in one lump can win it.

  • Agglomerative (average linkage, cosine) forms one long chain: wherever the tree is cut, one cluster holds nearly the whole corpus (65.1% at its own elbow) plus a handful of slivers. Those small clusters are outliers being peeled off, not groups.
  • DBSCAN never clusters most of the data. The embeddings sit at roughly uniform cosine distance, so the k-distance curve has no real knee; at the best eps most files come back labelled noise, and a slightly larger eps collapses everything into one cluster.

KMeans at k = 6 is the only setting that gives a balanced split with 0% of files unassigned.

Step 8 - The clustering, and what it actually found

Payload-window UMAP coloured by KMeans cluster

The clustering is well behaved. It is simply not clustering on the payload.

Six clusters of 116-275 files, largest holding 25.0%, nothing unassigned. The profile table shows what they are made of:

cluster 1 cluster 4 cluster 3 cluster 2 cluster 0
file_size 64,917 79,706 81,300 92,135 176,378
n_obj 23 29 34 46 109
skeleton_chars 13,870 21,547 22,845 36,515 72,520
n_pages 2 2 2 3 6

Every row rises steadily left to right. The clusters are sorting PDFs by document size and structural complexity, not by attack. entropy_file (7.72-7.81) and printable_frac (0.46-0.50) barely move at all - the byte-level character of the files is the same, only their scale differs.

Agreement with our design is almost zero: ARI +0.025, NMI 0.046. There are two small, explicable departures: cluster 3 is 98.1% injected and holds three times its share of llm_prompt_injection - the one attack type whose payload is ordinary written instructions rather than PDF syntax, so the one a sentence embedding is best placed to notice - while clusters 1 and 4 are where the clean files gather.

Part 2 conclusion

  1. The data quality problems of Part 1 came from the CIC feature table, not from PDF data. Reading the files ourselves gave zero missing values and zero sentinels.
  2. The corpus is genuinely varied where it matters: all 36 coverage cells filled, no carrier document ever reused, carrier sizes spanning 21x-281x within every type, payload positions spanning the whole file.
  3. The one real limitation is framework breadth - two frameworks per attack type. The corpus varies the shape of the attack far more than the style of the payload.
  4. The payload is a small, local change taking up about 4.5% of the text: 12.1% neighbourhood purity over the whole document against 42.0% in the payload window, on an 8.9% baseline.
  5. The corpus varies mostly by carrier, not by injection, and this is a property we want:
    • a model cannot score well by picking up a generator artefact, because the strongest signal available is document size, which is unrelated to the label by construction;
    • any model that does recover injection type is demonstrably doing something the representation cannot do unaided - the unsupervised floor is measured at ARI 0.025, and that is the number later results must be read against;
    • cluster is therefore a control variable, not a finding. If a model's accuracy tracks cluster, we will know it is tracking document size rather than doing security reasoning.

Repository contents

Final_project_V7_EDA.ipynb                       Parts 1 and 2, end to end
Datasets/
  synthetic_corpus_part2_clustered.parquet       the Part 2 dataset (1,100 x 44)
  synthetic_corpus_part2_clustered.csv           same, for tools that cannot read parquet
images/                                          the 15 figures reproduced above

Dataset columns

Group Columns Purpose
A - text for the model skeleton, skeleton_masked, skeleton_chars, skeleton_tokens_est, was_truncated what a model is asked to judge
B - numeric features the 18 surviving features measured from the file - sizes, counts, entropy, dictionary depth, image and page counts the EDA, the maps, the clustering
C - ground truth and QA manifest columns, markers_in_file, markers_in_skeleton, payload_retained, payload_pos_frac, parses_ok scoring, and proof the extraction is honest
D - clustering cluster the Step 8 control variable

The two marker columns are stored as |-joined strings so that both file formats round-trip.

Loading

from datasets import load_dataset
ds = load_dataset("<your-username>/<your-repo>", split="train")

# or straight to pandas
import pandas as pd
df = pd.read_parquet("Datasets/synthetic_corpus_part2_clustered.parquet")

Reproducing

The notebook runs top to bottom. Part 2's extraction cell needs the 1,100 raw PDFs from the source dataset repo and takes roughly 12 minutes. SEED = 42 throughout, so the quoted numbers are reproducible.

pandas  numpy  matplotlib  seaborn  scikit-learn  scipy
umap-learn  sentence-transformers  pymupdf  pyarrow

Safety note

Every payload in this corpus is drawn from a public, deliberately harmless security test corpus (EICAR, WICAR, AMTSO, RANSIM). These are the standard inert files used to verify that a scanner is working. Nothing here executes a real attack or causes damage. The corpus exists to evaluate detection, and some files will still be flagged by antivirus software - that is the intended behaviour of those test strings.

Citation

The real half of the Part 1 comparison is the CIC-Evasive-PDFMal2022 dataset from the Canadian Institute for Cybersecurity, University of New Brunswick.

Downloads last month
-