Skip to content

Commit

Permalink
Merge pull request #3232 from dipsylala/semgrep-9301
Browse files Browse the repository at this point in the history
Checks for ProcessStartInfo instantiator
  • Loading branch information
kurt-r2c authored Jan 25, 2024
2 parents 7d69825 + 64c8bcd commit 327afd7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
60 changes: 60 additions & 0 deletions csharp/lang/security/injections/os-command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,65 @@ public void RunConstantAppWithArgs(string args)
// ok: os-command-injection
var process = Process.Start(processStartInfo);
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = args
}
};

// ruleid: os-command-injection
process.Start();
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "constant",
Arguments = arguments
}
};

// ruleid: os-command-injection
process.Start();
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = "constant"
}
};

// ruleid: os-command-injection
process.Start();
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "constant",
Arguments = "constant"
}
};

// ok: os-command-injection
process.Start();
}
}
}
19 changes: 19 additions & 0 deletions csharp/lang/security/injections/os-command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,22 @@ rules:
- pattern: |
Process.Start($PSINFO);
- focus-metavariable: $PSINFO
- patterns:
- pattern-inside: |
Process $PROC = new Process()
{
StartInfo = new ProcessStartInfo()
{
...
}
};
...
- pattern-either:
- pattern-inside: |
FileName = $ARG;
...
- pattern-inside: |
Arguments = $ARG;
...
- pattern: |
$PROC.Start();

0 comments on commit 327afd7

Please sign in to comment.