-
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.
Merge pull request #40 from WSE-research/35-mysql-support-in-docker
35 mysql support in docker
- Loading branch information
Showing
6 changed files
with
107 additions
and
22 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
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 |
---|---|---|
@@ -1,27 +1,37 @@ | ||
version: '3.4' | ||
|
||
# networks: | ||
# amivulnerable: | ||
|
||
# services: | ||
# amivulnerable: | ||
# networks: | ||
# - amivulnerable | ||
# container_name: api | ||
# image: amivulnerable:latest | ||
# build: | ||
# context: . | ||
# dockerfile: AmIVulnerable/Dockerfile | ||
# ports: | ||
# - "8080:80" | ||
# - "8443:443" | ||
|
||
services: | ||
amivulnerable_db: | ||
container_name: MySqlDbAmIVulnerable | ||
image: mysql:8.0.2 | ||
environment: | ||
- MYSQL_ROOT_PASSWORD=cvecve | ||
- MYSQL_DATABASE=cve | ||
- MYSQL_USER=u | ||
- MYSQL_PASSWORD=p | ||
- MYSQL_ALLOW_EMPTY_PASSWORD=1 | ||
volumes: | ||
- db_volume:/var/lib/mysql | ||
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql:ro | ||
restart: on-failure | ||
healthcheck: | ||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] | ||
timeout: 20s | ||
retries: 10 | ||
ports: | ||
- 3306:3306 | ||
command: --default-authentication-plugin=mysql_native_password | ||
|
||
amivulnerable: | ||
container_name: api | ||
container_name: ApiAmIVulnerable | ||
build: | ||
context: . | ||
dockerfile: AmIVulnerable/Dockerfile | ||
ports: | ||
- 8080:80 | ||
- 8443:443 | ||
depends_on: | ||
- amivulnerable_db | ||
|
||
volumes: | ||
db_volume: |
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,21 @@ | ||
CREATE TABLE cve.cve ( | ||
cve_number VARCHAR(15) PRIMARY KEY NOT NULL, | ||
designation VARCHAR(100) NOT NULL, | ||
version_affected TEXT NOT NULL | ||
); | ||
|
||
INSERT INTO cve (cve_number, designation, version_affected) | ||
VALUES ('CVE-2016-582384','dummy 1','< 1.0.3'), | ||
('CVE-2019-482384','dummy 5a','< 3.0.3'), | ||
('CVE-2019-182384','dummy 21a','< 2.4.3'), | ||
('CVE-2019-284384','dummy 5a','< 1.5.3'), | ||
('CVE-2019-588384','dummy 31a','< 2.0.3'), | ||
('CVE-2019-587384','dummy r23v','< 6.0.3'), | ||
('CVE-2019-582984','dummy v123','< 1.4.3'), | ||
('CVE-2019-582784','dummy 5a','< 1.4.6'), | ||
('CVE-2019-582344','dummy 5v123','< 1.1.12'), | ||
('CVE-2019-582383','dummy v123a','< 2.1.3'), | ||
('CVE-2019-582387','dummy 5v14 143a','< 7.8.3'), | ||
('CVE-2018-312397','dummy 2','> 1.5.6'); | ||
|
||
CREATE INDEX idx_designation ON cve (designation); |