|
| 1 | +import Re2 from "re2"; |
| 2 | +import { surroundWithGroups } from "../../regexHandler"; |
| 3 | +import { Detector, ScanResult } from "../../types/detector"; |
| 4 | +import { httpClient } from "../../util"; |
| 5 | + |
| 6 | +const keywords: string[] = ["facebook", "meta"]; |
| 7 | +const regexGroup: string = surroundWithGroups(keywords); |
| 8 | +const secretPattern: Re2 = new Re2( |
| 9 | + `${regexGroup}\\b([A-Za-z0-9]{32})\\b`, |
| 10 | + "gi" |
| 11 | +); |
| 12 | +const idPattern: Re2 = new Re2(`${regexGroup}\\b([0-9]{15,18})\\b`, "gi"); |
| 13 | + |
| 14 | +const scan = async ( |
| 15 | + verify: boolean | undefined, |
| 16 | + data: string |
| 17 | +): Promise<ScanResult | null> => { |
| 18 | + const secretPatternMatches = data.matchAll(secretPattern); |
| 19 | + const idPatternMatches = data.matchAll(idPattern); |
| 20 | + let result: ScanResult = { detectorType: "Facebook OAuth", verified: false }; |
| 21 | + |
| 22 | + for (const match of idPatternMatches) { |
| 23 | + if (match.length !== 2) continue; |
| 24 | + const idMatch = match[1].trim(); |
| 25 | + |
| 26 | + result.rawValue = idMatch; |
| 27 | + result.position = match.index; |
| 28 | + |
| 29 | + for (const secretMatch of secretPatternMatches) { |
| 30 | + if (secretMatch.length !== 2) continue; |
| 31 | + |
| 32 | + const secretMatchValue = secretMatch[1].trim(); |
| 33 | + if (verify) { |
| 34 | + try { |
| 35 | + await httpClient.get( |
| 36 | + `https://graph.facebook.com/me?access_token=${idMatch}|${secretMatchValue}` |
| 37 | + ); |
| 38 | + |
| 39 | + result.verified = true; |
| 40 | + } catch (error) {} |
| 41 | + } |
| 42 | + return result; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + return null; |
| 47 | +}; |
| 48 | + |
| 49 | +const detectorType = "FACEBOOK_OAUTH_DETECTOR"; |
| 50 | + |
| 51 | +export const FacebookOAuthDetector: Detector = { |
| 52 | + scan, |
| 53 | + keywords, |
| 54 | + detectorType, |
| 55 | +}; |
0 commit comments