-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCommandInjection.cs
More file actions
57 lines (49 loc) · 1.72 KB
/
CommandInjection.cs
File metadata and controls
57 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Data.SqlClient;
using System.Diagnostics;
namespace System.Web.UI.WebControls
{
public class TextBox
{
public string Text { get; set; }
public string InnerHtml { get; set; }
}
}
namespace Test
{
using System.Web.UI.WebControls;
using System.Web;
using System.Diagnostics;
class CommandInjection
{
TextBox categoryTextBox;
public void WebCommandInjection()
{
// BAD: Reading from textbox, then using that in the arguments and file name
string userInput = categoryTextBox.Text;
Process.Start("foo.exe" + userInput, "/c " + userInput);
ProcessStartInfo startInfo = new ProcessStartInfo(userInput, userInput);
Process.Start(startInfo);
ProcessStartInfo startInfoProps = new ProcessStartInfo();
startInfoProps.FileName = userInput;
startInfoProps.Arguments = userInput;
startInfoProps.WorkingDirectory = userInput;
Process.Start(startInfoProps);
}
public void StoredCommandInjection()
{
using (SqlConnection connection = new SqlConnection(""))
{
connection.Open();
SqlCommand customerCommand = new SqlCommand("SELECT * FROM customers", connection);
SqlDataReader customerReader = customerCommand.ExecuteReader();
while (customerReader.Read())
{
// BAD: Read from database, and use it to directly execute a command
Process.Start("foo.exe", "/c " + customerReader.GetString(1));
}
customerReader.Close();
}
}
}
}