-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demo Controller for MySql Connection to intern db
https://localhost:8443/api/MySqlConnection/checkReachable Link for check the reachable
- Loading branch information
1 parent
1b9cab2
commit 37cb832
Showing
4 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
code/AmIVulnerable/AmIVulnerable/Controllers/MySqlConnectionController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using MySql.Data.MySqlClient; | ||
using SerilogTimings; | ||
using System.Data; | ||
|
||
namespace AmIVulnerable.Controllers { | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class MySqlConnectionController : ControllerBase { | ||
|
||
private readonly IConfiguration Configuration; | ||
|
||
public MySqlConnectionController(IConfiguration configuration) { | ||
Configuration = configuration; | ||
} | ||
|
||
[HttpGet, Route("checkReachable")] | ||
public IActionResult PingWithDb() { | ||
using (Operation.Time("TaskDuration")) { | ||
try { | ||
MySqlConnection c = new MySqlConnection(Configuration["ConnectionStrings:cvedb"]); | ||
|
||
MySqlCommand cmd = new MySqlCommand("SELECT * FROM cve", c); | ||
|
||
c.Open(); | ||
MySqlDataReader reader = cmd.ExecuteReader(); | ||
DataTable dataTable = new DataTable(); | ||
dataTable.Load(reader); | ||
reader.Close(); | ||
c.Close(); | ||
|
||
string r = ""; | ||
foreach (DataRow row in dataTable.Rows) { | ||
foreach (object? item in row.ItemArray) { | ||
r += item; | ||
} | ||
} | ||
|
||
return Ok(r); | ||
} | ||
catch (Exception ex) { | ||
return BadRequest(ex.ToString()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters