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
14 changes: 13 additions & 1 deletion Command Injection/OSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ public class OsInjection : ControllerBase
[HttpGet("{binFile}")]
public string os(string binFile)
{
// Restrict to safe binaries in specific directory
string safeDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin");
string safeName = Path.GetFileName(binFile); // Strip any path components
string fullPath = Path.Combine(safeDir, safeName);

// Whitelist of allowed executables
string[] allowedBinaries = new[] { "safe1.exe", "safe2.exe" };
if (!allowedBinaries.Contains(safeName))
{
throw new UnauthorizedAccessException("Binary not in whitelist");
}

Process p = new Process();
p.StartInfo.FileName = binFile; // Noncompliant
p.StartInfo.FileName = fullPath;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
Expand Down