From 545718ad93ed812d7c2bd0df4b4f55c51efc52dc Mon Sep 17 00:00:00 2001 From: KnYL3R Date: Sun, 26 May 2024 16:58:08 +0200 Subject: [PATCH 1/4] added endpoint, bad json --- .../Controllers/GitController.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs index b9c8562..ca41dec 100644 --- a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs +++ b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs @@ -1,10 +1,13 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.CodeAnalysis.CSharp; using Modells; using MySql.Data.MySqlClient; using Newtonsoft.Json; using SerilogTimings; using System.Data; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json.Nodes; using System.Text.RegularExpressions; using CM = System.Configuration.ConfigurationManager; @@ -31,7 +34,7 @@ public GitController(IConfiguration configuration) { /// /// [HttpPost] - [Route("cloneRepo")] + [Route("repository")] public async Task CloneRepoToAnalyze([FromBody] RepoObject repoObject) { if (repoObject.RepoUrl is null) { return BadRequest(); @@ -71,6 +74,28 @@ public async Task CloneRepoToAnalyze([FromBody] RepoObject repoOb } } + /// Gets designation and tag of all Repositories that have been cloned + /// Return all designations and tags of repos + [HttpGet] + [Route("allrepositories")] + public async Task GetRepositories() { + DataTable repositoryQuery = ExecuteMySqlCommand($"" + + $"SELECT * " + + $"FROM cve.repositories;"); + + if (repositoryQuery.Rows.Count == 0) { + return NoContent(); + } + //var repositoryQueryJson = new { + // foreach(DataRow row in repositoryQuery.Rows) { + + // } + // repositoryQuery + //}; + + return Ok(System.Text.Json.JsonSerializer.Serialize(repositoryQuery)); + } + /// /// [HttpPost] From 3e6f39664b63bbd503c44e167c50e3640f066425 Mon Sep 17 00:00:00 2001 From: Kretchen001 <83697846+Kretchen001@users.noreply.github.com> Date: Sun, 26 May 2024 17:04:07 +0200 Subject: [PATCH 2/4] Update GitController.cs - Returntype to implicite json over List return --- .../Controllers/GitController.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs index ca41dec..7e4d09f 100644 --- a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs +++ b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs @@ -4,6 +4,7 @@ using MySql.Data.MySqlClient; using Newtonsoft.Json; using SerilogTimings; +using System; using System.Data; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -86,14 +87,19 @@ public async Task GetRepositories() { if (repositoryQuery.Rows.Count == 0) { return NoContent(); } - //var repositoryQueryJson = new { - // foreach(DataRow row in repositoryQuery.Rows) { - - // } - // repositoryQuery - //}; - - return Ok(System.Text.Json.JsonSerializer.Serialize(repositoryQuery)); + + List list = []; + foreach (DataRow row in repositoryQuery.Rows) { + list.Add(new { + guid = row["guid"], + repoUrl = row["repoUrl"], + repoOwner = row["repoOwner"], + repoDesignation = row["repoDesignation"], + tag = row["tag"] + }); + } + + return Ok(list); } /// From 7ff53807cbdbea93ad949af7b80a2c96e8bd5d9e Mon Sep 17 00:00:00 2001 From: KnYL3R Date: Sun, 26 May 2024 17:20:24 +0200 Subject: [PATCH 3/4] changed comment --- code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs index 7e4d09f..b57b1a7 100644 --- a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs +++ b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs @@ -75,8 +75,8 @@ public async Task CloneRepoToAnalyze([FromBody] RepoObject repoOb } } - /// Gets designation and tag of all Repositories that have been cloned - /// Return all designations and tags of repos + /// Gets guid, tag, ... of all Repositories that have been cloned + /// Return all data of repos [HttpGet] [Route("allrepositories")] public async Task GetRepositories() { From 59331b2c764419aa6cbd95636f47d271193f14fc Mon Sep 17 00:00:00 2001 From: KnYL3R Date: Sun, 26 May 2024 17:40:13 +0200 Subject: [PATCH 4/4] removed unused imports --- code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs index b57b1a7..2578992 100644 --- a/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs +++ b/code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs @@ -1,14 +1,10 @@ using Microsoft.AspNetCore.Mvc; -using Microsoft.CodeAnalysis.CSharp; using Modells; using MySql.Data.MySqlClient; using Newtonsoft.Json; using SerilogTimings; -using System; using System.Data; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json.Nodes; using System.Text.RegularExpressions; using CM = System.Configuration.ConfigurationManager;