Source Code Detection Regex

Source Code Detection

Language specific

COBOL

Make sure that engine threshold is set to > 3 ID, we need at least 4 or more matches to be considered a COBOL program.

IDENTIFICATION DIVISION\.

PROCEDURE DIVISION\.

FILE-CONTROL\.

ENVIRONMENT DIVISION\.

DATA DIVISION\.

PROGRAM-ID\.

WORKING-STORAGE SECTION\.

FILE SECTION\.

SQL

Set engine to greater than zero given the nature of SQL code

[sS][eE][lL][eE][cC][tT]( |\n)+[_a-zA-Z0-9.*, ]+[fF][rR][oO][mM]( |\n)+[_a-zA-Z0-9.]

[dD][eE][lL][eE][tT][eE][ ]+[fF][rR][oO][mM][ ]+[_a-zA-Z0-9][ ]*

[iI][nN][sS][eE][rR][tT][ ]+[iI][nN][tT][oO][ ]+[_a-zA-Z0-9]+[ ]+[vV][aA][lL][uU][eE][sS][ ]*

[cC][rR][eE][aA][tT][eE][ ]+(([tT][aA][bB][lL][eE])|([dD][aA][tTa][bB][aA][sS][eE])|([iI][nN][dD][eE][xX]))[ ]+

[aA][lL][tT][eE][rR][ ]+(([tT][aA][bB][lL][eE])|([dD][aA][tTa][bB][aA][sS][eE])|([iI][nN][dD][eE][xX]))[ ]+

[dD][rR][oO][pP][ ]+(([tT][aA][bB][lL][eE])|([dD][aA][tTa][bB][aA][sS][eE])|([iI][nN][dD][eE][xX]))[ ]+

[gG][rR][oO][uU][pP][ ]+[bB][yY]

[oO][rR][dD][eE][rR][ ]+[bB][yY]

PL/SQL

Make sure that engine threshold is set to > 3 ID, we need atleast 4 or more matches to be considered a PL/SQL script.

DECLARE[ ]*

BEGIN[ ]*

END;

[a-zA-Z][a-zA-Z0-9]*;

C# (C-Sharp)

Make sure that engine threshold is set to > 3 ID, we need atleast 4 or more matches to be considered a C# program.

using[ ]+[a-zA-Z0-9.]+[ ]*;

namespace[ ]+[a-zA-Z0-9]+[ ]*\{

class[ ]+[a-zA-Z0-9]+[ ]+\{

String.Format\(.+\)[ ]*;

Console.Write\(.+\)[ ]*;

Console.WriteLn\(.+\)[ ]*;

Javascript

Make sure that engine threshold is set to > 3 ID, we need at least 4 or more matches to be considered Javascript code.

[a-zA-Z][a-zA-Z0-9]*\(.*\);{0,1}\n{0,1}.*

[a-zA-Z][a-zA-Z0-9]*\.length

[a-zA-Z][a-zA-Z0-9]*\.forEach

function +[a-zA-Z0-9]+[ ]*\(.*\n*.*\)

var +[a-zA-Z0-9]+ *= *\b

console.log\(.*\)

Swift

Make sure that engine threshold is set to > 3 ID, we need at least 4 or more matches to be considered swift code.

Resolution\(\)

struct +[a-zA-Z0-9]+ *\{

let +[a-zA-Z0-9]+ *= *.*

var +[a-zA-Z0-9]+ *= *.*

[a-zA-Z][a-zA-Z0-9]* *(===|!==) *.*

func +[a-zA-Z0-9]+\(.*\)


Copyright 2007-2021 ZSCALER, INC.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1 Like