Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Command Injection/OSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public class OsInjection : ControllerBase
public string os(string binFile)
{
Process p = new Process();
p.StartInfo.FileName = binFile; // Noncompliant
string allowedPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "allowed_binaries", binFile));
if (!allowedPath.StartsWith(Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "allowed_binaries"))))
throw new UnauthorizedAccessException("Access to the specified binary is not allowed.");
if (!File.Exists(allowedPath))
throw new FileNotFoundException("Binary not found.");
p.StartInfo.FileName = allowedPath;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
Expand Down