Skip to content

Commit

Permalink
basic site
Browse files Browse the repository at this point in the history
  • Loading branch information
cobbr committed Apr 27, 2019
1 parent a89170a commit 43f8c8a
Show file tree
Hide file tree
Showing 92 changed files with 44,509 additions and 80 deletions.
1 change: 0 additions & 1 deletion Covenant/.dockerignore
@@ -1,5 +1,4 @@
**/bin/
**/obj/
**/out/
Dockerfile*
**/*.trx
Expand Down
Expand Up @@ -19,7 +19,7 @@

namespace Covenant.Controllers
{
[Authorize]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api")]
public class CovenantUserApiController : Controller
Expand Down Expand Up @@ -141,7 +141,7 @@ public ActionResult<CovenantUserLoginResult> Login([FromBody] CovenantUserLogin

// POST api/users
// Create a User
[Authorize(Policy = "RequireAdministratorRole")]
[Authorize(Policy = "RequireJwtBearerRequireAdministratorRole")]
[HttpPost("users", Name = "CreateUser")]
[ProducesResponseType(typeof(CovenantUser), 201)]
public ActionResult<CovenantUser> CreateUser([FromBody] CovenantUserLogin login)
Expand Down
Expand Up @@ -12,7 +12,7 @@

namespace Covenant.Controllers
{
[Authorize]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/credentials")]
public class CredentialApiController : Controller
Expand Down
Expand Up @@ -15,8 +15,8 @@

namespace Covenant.Controllers
{
[Authorize]
[ApiController]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/events")]
public class EventApiController : Controller
{
Expand Down
Expand Up @@ -20,8 +20,8 @@

namespace Covenant.Controllers
{
[Authorize]
[ApiController]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/grunts")]
public class GruntApiController : Controller
{
Expand Down
Expand Up @@ -14,8 +14,8 @@

namespace Covenant.Controllers
{
[Authorize]
[ApiController]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/grunttasks")]
public class GruntTaskApiController : Controller
{
Expand Down
Expand Up @@ -20,8 +20,8 @@

namespace Covenant.Controllers
{
[Authorize]
[ApiController]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api")]
public class GruntTaskingApiController : Controller
{
Expand Down Expand Up @@ -344,27 +344,35 @@ public ActionResult<GruntTasking> CreateGruntTasking(int id, [FromBody] GruntTas
[HttpPut("grunts/{id}/taskings/{tid}", Name = "EditGruntTasking")]
public ActionResult<GruntTasking> EditGruntTasking(int id, int tid, [FromBody] GruntTasking gruntTasking)
{
Console.WriteLine("EditGruntTasking");
Grunt grunt = _context.Grunts.FirstOrDefault(G => G.Id == id);
if (grunt == null)
{
Console.WriteLine($"NotFound - Grunt with id: {id}");
return NotFound($"NotFound - Grunt with id: {id}");
}
Console.WriteLine("1");
GruntTasking updatingGruntTasking = _context.GruntTaskings.FirstOrDefault(GT => grunt.Id == GT.GruntId && tid == GT.Id);
if (updatingGruntTasking == null)
{
Console.WriteLine($"NotFound - GruntTasking with id: {tid}");
return NotFound($"NotFound - GruntTasking with id: {tid}");
}
Console.WriteLine("2");
GruntTask gruntTask = _context.GruntTasks.FirstOrDefault(G => G.Id == gruntTasking.TaskId);
if (gruntTask == null)
{
Console.WriteLine($"NotFound - GruntTask with id: {gruntTasking.TaskId}");
return NotFound($"NotFound - GruntTask with id: {gruntTasking.TaskId}");
}
Console.WriteLine("3");
GruntTask DownloadTask = _context.GruntTasks.FirstOrDefault(GT => GT.Name == "Download");
if (DownloadTask == null)
{
Console.WriteLine($"NotFound - GruntTask DownloadTask");
return NotFound($"NotFound - GruntTask DownloadTask");
}

Console.WriteLine("4");
List<CapturedCredential> capturedCredentials = CapturedCredential.ParseCredentials(gruntTasking.GruntTaskOutput);
foreach (CapturedCredential cred in capturedCredentials)
{
Expand Down Expand Up @@ -405,8 +413,10 @@ public ActionResult<GruntTasking> EditGruntTasking(int id, int tid, [FromBody] G
}
else if (gruntTasking.Type == GruntTaskingType.Connect)
{
Console.WriteLine("Connect Type");
if (originalStatus == GruntTaskingStatus.Tasked)
{
Console.WriteLine("og tasked");
// Check if this Grunt was already connected
string hostname = gruntTasking.GruntTaskingMessage.Message.Split(",")[0];
string pipename = gruntTasking.GruntTaskingMessage.Message.Split(",")[1];
Expand Down Expand Up @@ -443,12 +453,14 @@ public ActionResult<GruntTasking> EditGruntTasking(int id, int tid, [FromBody] G
}
else
{
Console.WriteLine("change to progressed");
// If not already connected, the Grunt is going to stage, set status to Progressed
newStatus = GruntTaskingStatus.Progressed;
}
}
else if (originalStatus == GruntTaskingStatus.Progressed)
{
Console.WriteLine("og progressed");
// Connecting Grunt has staged, add as Child
string hostname = gruntTasking.GruntTaskingMessage.Message.Split(",")[0];
string pipename = gruntTasking.GruntTaskingMessage.Message.Split(",")[1];
Expand Down
Expand Up @@ -12,7 +12,7 @@

namespace Covenant.Controllers
{
[Authorize]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/indicators")]
public class IndicatorApiController : Controller
Expand Down
Expand Up @@ -14,8 +14,8 @@

namespace Covenant.Controllers
{
[Authorize]
[ApiController]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/launchers")]
public class LauncherApiController : Controller
{
Expand Down Expand Up @@ -127,7 +127,7 @@ public ActionResult<BinaryLauncher> GenerateBinaryHostedFileLauncher(HostedFile
return launcher;
}

// PUT api/launchers/powershell
// PUT api/launchers/binary
// <summary>
// Edit BinaryLauncher
// </summary>
Expand Down
Expand Up @@ -21,7 +21,7 @@

namespace Covenant.Controllers
{
[Authorize]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/listeners")]
public class ListenerApiController : Controller
Expand Down Expand Up @@ -118,7 +118,7 @@ public ActionResult<Listener> GetListener(int id)
// Edit a Listener
// </summary>
[HttpPut(Name = "PutListener")]
public ActionResult<Listener> PutHttpListener([FromBody] Listener listener)
public ActionResult<Listener> PutListener([FromBody] Listener listener)
{
Listener savedListener = _context.Listeners.FirstOrDefault(L => L.Id == listener.Id);
if (savedListener == null)
Expand Down Expand Up @@ -233,11 +233,8 @@ public ActionResult<HttpListener> CreateHttpListener([FromBody] HttpListener lis
{
return listener;
}
else
{
Profile profile = _context.Profiles.FirstOrDefault(HP => HP.Id == 1);
listener = new HttpListener(httpType.Id, profile.Id);
}
Profile profile = _context.Profiles.FirstOrDefault(HP => HP.Id == 1);
listener = new HttpListener(httpType.Id, profile.Id);

// Append capital letter to appease Password complexity requirements, get rid of warning output
string covenantListenerUsername = Utilities.CreateSecureGuid().ToString();
Expand Down Expand Up @@ -407,7 +404,7 @@ public ActionResult<HostedFile> CreateHostedFile(int id, [FromBody] HostedFile h
{
hostFileRequest = listener.HostFile(hostFileRequest);
}
catch
catch (Exception)
{
return BadRequest($"BadRequest - Error hosting file at: {hostFileRequest.Path}");
}
Expand Down
Expand Up @@ -12,7 +12,7 @@

namespace Covenant.Controllers
{
[Authorize]
[Authorize(Policy = "RequireJwtBearer")]
[ApiController]
[Route("api/profiles")]
public class ProfileApiController : Controller
Expand Down
Expand Up @@ -3,25 +3,24 @@
// License: GNU GPLv3

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Security.Cryptography;

using Microsoft.Rest;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json;

using Covenant.API;
using Covenant.API.Models;
using Covenant.Core;
using Encrypt = Covenant.Core.Encryption;
using Covenant.Models.Listeners;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Rest;
using Newtonsoft.Json;
using Encrypt = Covenant.Core.Encryption;

namespace Covenant.Controllers
{
[AllowAnonymous]
public class HttpListenerController : Controller
{
private readonly HttpListenerContext _context;
Expand Down Expand Up @@ -245,7 +244,7 @@ private ActionResult PostTask(API.Models.Grunt egressGrunt, API.Models.Grunt tar
// Invalid task response. This happens on post-register write
return NotFound();
}
GruntTasking gruntTasking = CovenantClient.ApiGruntsByIdTaskingsGet(targetGrunt.Id ?? default).FirstOrDefault(T => T.Name == TaskName);
GruntTasking gruntTasking = CovenantClient.ApiGruntsByIdTaskingsDetailGet(targetGrunt.Id ?? default).FirstOrDefault(T => T.Name == TaskName);
if (gruntTasking == null || targetGrunt.Id != gruntTasking.GruntId)
{
// Invalid taskname. May not be legitimate Grunt request, respond NotFound
Expand Down Expand Up @@ -340,6 +339,7 @@ private ActionResult PostStage0(API.Models.Grunt egressGrunt, API.Models.Grunt t
{
return NotFound();
}
connectTasking = this.CovenantClient.ApiGruntsByIdTaskingsByTidDetailGet(connectTasking.GruntId ?? default, connectTasking.Id ?? default);
realTargetGrunt.Hostname = connectTasking.GruntTaskingMessage.Message.Split(",")[0];
this.CovenantClient.ApiGruntsPut(realTargetGrunt.ToModel());
connectTasking.Status = GruntTaskingStatus.Completed;
Expand Down
47 changes: 47 additions & 0 deletions Covenant/Controllers/ViewControllers/CovenantUserController.cs
@@ -0,0 +1,47 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;

using Microsoft.Rest;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

using Covenant.Core;
using Covenant.API;
using Covenant.API.Models;

namespace Covenant.Controllers
{
[Authorize]
public class CovenantUserController : Controller
{
private readonly CovenantAPI _client;

public CovenantUserController(IConfiguration configuration)
{
X509Certificate2 covenantCert = new X509Certificate2(Common.CovenantPublicCertFile);
HttpClientHandler clientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, errors) =>
{
return cert.GetCertHashString() == covenantCert.GetCertHashString();
}
};
_client = new CovenantAPI(
new Uri("https://localhost:7443"),
new TokenCredentials(configuration["CovenantToken"]),
clientHandler
);
}

// GET: /users/
public async Task<IActionResult> Index()
{
return View(await _client.ApiUsersGetAsync());
}
}
}
51 changes: 51 additions & 0 deletions Covenant/Controllers/ViewControllers/CredentialController.cs
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Rest;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;

using Covenant.Core;
using Covenant.API;
using Covenant.API.Models;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Covenant.Controllers
{
[Authorize]
public class CredentialController : Controller
{
private readonly CovenantAPI _client;

public CredentialController(IConfiguration configuration)
{
X509Certificate2 covenantCert = new X509Certificate2(Common.CovenantPublicCertFile);
HttpClientHandler clientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, errors) =>
{
return cert.GetCertHashString() == covenantCert.GetCertHashString();
}
};
_client = new CovenantAPI(
new Uri("https://localhost:7443"),
new TokenCredentials(configuration["CovenantToken"]),
clientHandler
);
}

// GET: /credential/
public async Task<IActionResult> Index()
{
ViewBag.PasswordCredentials = await _client.ApiCredentialsPasswordsGetAsync();
ViewBag.HashCredentials = await _client.ApiCredentialsHashesGetAsync();
ViewBag.TicketCredentials = await _client.ApiCredentialsTicketsGetAsync();
return View(await _client.ApiCredentialsGetAsync());
}
}
}
21 changes: 21 additions & 0 deletions Covenant/Controllers/ViewControllers/EventController.cs
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Covenant.Controllers
{
[Authorize]
public class EventController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
}
}

0 comments on commit 43f8c8a

Please sign in to comment.