privacy-scan: AppImage squashfs found at the end of the ELF runtime (the runtime contains the magic too); a generic home (/root) is not a term. tools test: 30s timeout (detectTools runs every version command)
This commit is contained in:
parent
e86bcec37c
commit
466742207e
3 changed files with 26 additions and 4 deletions
|
|
@ -5,7 +5,7 @@ import { spawnSync } from 'node:child_process';
|
||||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { collectTerms, kindOf, mask, parseTerms, scan, scanBuffer, type Term } from '../tools/privacy-scan';
|
import { collectTerms, kindOf, mask, parseTerms, scan, scanBuffer, squashfsOffset, type Term } from '../tools/privacy-scan';
|
||||||
|
|
||||||
const T: Term[] = [{ text: 'Quillfeather', short: false }, { text: 'qz', short: true }];
|
const T: Term[] = [{ text: 'Quillfeather', short: false }, { text: 'qz', short: true }];
|
||||||
// home folders are put together at run time, so tools/scrub.ts (which forbids them in the repository) passes
|
// home folders are put together at run time, so tools/scrub.ts (which forbids them in the repository) passes
|
||||||
|
|
@ -64,4 +64,13 @@ describe('privacy scan', () => {
|
||||||
expect(kindOf('storebound_0.1.0_x64-setup.exe', Buffer.from('MZ....Nullsoft Install System'))).toBe('nsis');
|
expect(kindOf('storebound_0.1.0_x64-setup.exe', Buffer.from('MZ....Nullsoft Install System'))).toBe('nsis');
|
||||||
expect(kindOf('storebound-desktop.exe', Buffer.from('MZ'))).toBe('file');
|
expect(kindOf('storebound-desktop.exe', Buffer.from('MZ'))).toBe('file');
|
||||||
});
|
});
|
||||||
|
test('AppImage: the squashfs starts where the ELF runtime ends, not at an "hsqs" constant inside the runtime', () => {
|
||||||
|
const img = Buffer.alloc(0x1000 + 16);
|
||||||
|
img.write('\x7fELF', 0, 'latin1'); img[4] = 2; img[5] = 1;
|
||||||
|
img.writeBigUInt64LE(0xc00n, 0x28); img.writeUInt16LE(64, 0x3a); img.writeUInt16LE(16, 0x3c); // 0xc00 + 64*16 = 0x1000
|
||||||
|
img.write('hsqs', 0x800, 'latin1'); img.write('hsqs', 0x1000, 'latin1');
|
||||||
|
expect(squashfsOffset(img)).toBe(0x1000);
|
||||||
|
const plain = Buffer.alloc(0x900); plain.write('hsqs', 0x800, 'latin1');
|
||||||
|
expect(squashfsOffset(plain)).toBe(0x800);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ describe('local tools (desktop Dependencies screen)', () => {
|
||||||
expect(tools.map(t => t.id)).toEqual(expect.arrayContaining(['ffmpeg', 'ffprobe', 'chrome', 'adb', 'git']));
|
expect(tools.map(t => t.id)).toEqual(expect.arrayContaining(['ffmpeg', 'ffprobe', 'chrome', 'adb', 'git']));
|
||||||
for (const t of tools) if (t.id === 'xcode' || t.id === 'simctl' || t.id === 'adb') expect(t.install.kind).toBe('link');
|
for (const t of tools) if (t.id === 'xcode' || t.id === 'simctl' || t.id === 'adb') expect(t.install.kind).toBe('link');
|
||||||
} finally { rmSync(dir, { recursive: true, force: true }); }
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
||||||
});
|
}, 30_000); // detectTools runs every tool's version command (xcrun, simctl, adb, ...): seconds on a busy Mac
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,18 @@ const sh = (cmd: string[]): string => {
|
||||||
return r.status === 0 ? r.stdout.trim() : '';
|
return r.status === 0 ? r.stdout.trim() : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Where an AppImage's squashfs starts: the end of its ELF runtime (section headers come last), else the first
|
||||||
|
* "hsqs" magic. The runtime itself may contain the magic as a constant, so the ELF end is tried first. */
|
||||||
|
export function squashfsOffset(data: Uint8Array): number {
|
||||||
|
const b = Buffer.from(data.buffer, data.byteOffset, data.length);
|
||||||
|
const isSq = (o: number) => o > 0 && o + 4 <= b.length && b.toString('latin1', o, o + 4) === 'hsqs';
|
||||||
|
if (b.length > 0x40 && b.toString('latin1', 0, 4) === '\x7fELF' && b[4] === 2 && b[5] === 1) {
|
||||||
|
const end = Number(b.readBigUInt64LE(0x28)) + b.readUInt16LE(0x3a) * b.readUInt16LE(0x3c);
|
||||||
|
if (isSq(end)) return end;
|
||||||
|
}
|
||||||
|
return b.indexOf('hsqs', 0x400, 'latin1');
|
||||||
|
}
|
||||||
|
|
||||||
export function parseTerms(text: string): string[] {
|
export function parseTerms(text: string): string[] {
|
||||||
return text.split(/\r?\n/).map(l => l.trim()).filter(l => l && !l.startsWith('#'));
|
return text.split(/\r?\n/).map(l => l.trim()).filter(l => l && !l.startsWith('#'));
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +71,8 @@ export function collectTerms(file: string | null, auto = true): Term[] {
|
||||||
try { user = userInfo().username; } catch { /* no passwd entry */ }
|
try { user = userInfo().username; } catch { /* no passwd entry */ }
|
||||||
add(user, true);
|
add(user, true);
|
||||||
add(basename(homedir()), true);
|
add(basename(homedir()), true);
|
||||||
if (homedir().length > 4) add(homedir(), true);
|
// a generic home (/root in a CI container) is no name, and "/root" is part of ordinary strings (root_certs.cpp)
|
||||||
|
if (homedir().length > 4 && !GENERIC.has(basename(homedir()).toLowerCase())) add(homedir(), true);
|
||||||
const host = hostname().replace(/\.local$/i, '');
|
const host = hostname().replace(/\.local$/i, '');
|
||||||
add(host, true);
|
add(host, true);
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
|
@ -174,7 +187,7 @@ function unpack(path: string, kind: Kind): { dir: string; cleanup: () => void }
|
||||||
if (kind === 'appimage') {
|
if (kind === 'appimage') {
|
||||||
const unsq = which('unsquashfs');
|
const unsq = which('unsquashfs');
|
||||||
const data = readFileSync(path);
|
const data = readFileSync(path);
|
||||||
const off = data.indexOf(Buffer.from('hsqs'), 0x400);
|
const off = squashfsOffset(data);
|
||||||
if (unsq && off > 0) { run([unsq, '-q', '-n', '-d', join(dir, 'root'), '-o', String(off), path]); return { dir: join(dir, 'root'), cleanup }; }
|
if (unsq && off > 0) { run([unsq, '-q', '-n', '-d', join(dir, 'root'), '-o', String(off), path]); return { dir: join(dir, 'root'), cleanup }; }
|
||||||
const z = which('7zz', '7z');
|
const z = which('7zz', '7z');
|
||||||
if (z) { run([z, 'x', '-y', `-o${dir}`, path]); return { dir, cleanup }; }
|
if (z) { run([z, 'x', '-y', `-o${dir}`, path]); return { dir, cleanup }; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue