Skip to content

Commit f760b72

Browse files
committed
Improved processing and removed missing import
1 parent 3c81200 commit f760b72

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

find_compromised_secrets.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ They were doubly-Base64 encoded, so we need to spot Base64 strings and decode th
1010
import { Octokit } from "@octokit/rest";
1111
import fs from "fs";
1212
import AdmZip from "adm-zip";
13-
import { findSecretsInLines, base64Regex } from "./find_compromised_secrets_helper.js";
13+
import { findSecretsInLines } from "./find_compromised_secrets_helper.js";
1414

1515
// Initialize Octokit with a personal access token
1616
const octokit = new Octokit({
@@ -59,8 +59,9 @@ async function main() {
5959
const args = process.argv.slice(2);
6060

6161
if (args.length > 0) {
62+
const script_name = process.argv[1].split("/").pop();
6263
console.error(
63-
"Usage: node find_compromised_secrets.js < <input file>"
64+
`Usage: node ${script_name} < <SLJSON input file>`
6465
);
6566
return;
6667
}

find_compromised_secrets_helper.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11

22
// base64 strings were used to leak the secrets
33
export const base64Regex1 =
4-
/^(?:[A-Za-z0-9+/]{4}){16,}(?:[A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)\s*$/;
4+
/^SW[A-Za-z0-9+/]{2}(?:[A-Za-z0-9+/]{4}){15,}(?:[A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)\s*$/;
55

66
export const base64Regex2 =
7-
/^(?:[A-Za-z0-9+/]{4}){10,}(?:[A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)\s*$/;
7+
/^I[A-Za-z0-9+/]{3}(?:[A-Za-z0-9+/]{4}){9,}(?:[A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)\s*$/;
88

99
export function findSecretsInLines(lines) {
1010
const secrets = [];
11+
12+
let foundSecrets = false;
1113

1214
for (const line of lines) {
1315
if (line == "") {
1416
continue;
1517
}
1618

19+
// separate the timestamp from the data
1720
const data = line.split(" ").slice(1).join(" ");
1821

1922
if (data == undefined) {
@@ -23,6 +26,10 @@ export function findSecretsInLines(lines) {
2326

2427
const match = base64Regex1.exec(data);
2528
if (!match) {
29+
// stop processing the log after the first line that does not match the regex, if we already found secrets
30+
if (foundSecrets) {
31+
break
32+
}
2633
continue;
2734
}
2835
const secret = match[0];
@@ -43,6 +50,7 @@ export function findSecretsInLines(lines) {
4350
try {
4451
const jsonDecoded = JSON.parse("{" + decoded + "}");
4552
if (Object.keys(jsonDecoded).length > 0) {
53+
foundSecrets = true;
4654
secrets.push(jsonDecoded);
4755
}
4856
} catch (error) {

0 commit comments

Comments
 (0)