Rust Os Command Injection
Description
This detector identifies OS command injection vulnerabilities in Rust applications using the Actix Web framework. Command injection occurs when user-controlled data is passed to system command execution functions without proper sanitization, allowing attackers to execute arbitrary commands on the server.
Detection Strategy
• Scan Rust source code files that import the 'actix_web' library or any module with 'actix_web' prefix
• Identify calls to vulnerable command execution functions including Command::new(), shell argument functions, and shell args functions
• Flag locations where these command execution functions are called with potentially unsafe parameters that could allow user input to be interpreted as system commands
Vulnerable code example
use actix_web::{web, HttpResponse};
use std::collections::HashMap;
use std::process::Command;
async fn ping(query: web::Query<HashMap<String, String>>) -> HttpResponse {
let host = query.get("host").unwrap();
// VULNERABLE: user input passed to shell command via sh -c...✅ Secure code example
use actix_web::{web, HttpResponse};
use std::collections::HashMap;
use std::process::Command;
async fn ping(query: web::Query<HashMap<String, String>>) -> HttpResponse {
let host = query.get("host").unwrap();
// SAFE: arguments passed separately to fixed binary, no shell invoked...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.