using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.DirectoryServices;
using System.Xml;
namespace VulnerableApp
{
public class Vulnerabilities
{
public void SqlInjection(string userId)
{
var conn = new SqlConnection("Server=localhost;Database=test;");
var cmd = new SqlCommand();
cmd.Connection = conn;
var reader = cmd.ExecuteReader("SELECT * FROM users WHERE id = " + userId);
}
public void CommandInjection(string userInput)
{
Process.Start(userInput);
}
public void UnsafeDeserialization(Stream stream)
{
var formatter = new BinaryFormatter();
var obj = formatter.Deserialize(stream);
}
public async void Ssrf(string url)
{
var client = new HttpClient();
var response = await client.GetAsync(url);
}
public void PathTraversal(string userPath)
{
var content = File.ReadAllText(userPath);
var reader = new StreamReader(userPath);
var exists = File.Exists(userPath);
var stream = new FileStream(userPath, FileMode.Open);
}
public void WeakCrypto()
{
var md5 = MD5.Create();
var sha1 = SHA1.Create();
var des = DES.Create();
}
public void HardcodedSecrets()
{
string password = "SuperSecret123";
string apiKey = "sk-1234567890abcdef";
string connectionString = "Server=prod;Password=hunter2;";
}
public void XxeVulnerability(string xmlInput)
{
var doc = new XmlDocument();
doc.LoadXml(xmlInput);
}
public void LdapInjection(string username)
{
var searcher = new DirectorySearcher();
searcher.Filter = "(uid=" + username + ")";
}
public void ConfigureCors(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin();
});
});
}
}
}