This commit is contained in:
lhodges1 2023-09-12 03:39:00 +10:00
parent e475d49bf0
commit 81f379730b
8 changed files with 145 additions and 1 deletions

View file

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace server.Database.Entity.Report
{
public interface IReport
{
/// <summary>
/// Inserts the report into the database.
/// </summary>
void InsertReport();
}
}

View file

@ -0,0 +1,26 @@
using server.Database.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace server.Database.Entity.Report
{
public class IllegalHandleOperationEntity : ReportIllegalHandleOperation, IReport
{
private readonly ModelContext _modelContext;
public UserEntity UserEntity { get; set; }
public IllegalHandleOperationEntity(ModelContext modelContext)
{
UserEntity = new UserEntity(modelContext);
_modelContext = modelContext;
}
public void InsertReport()
{
_modelContext.ReportIllegalHandleOperation.Add(this);
}
}
}

View file

@ -0,0 +1,21 @@
using server.Database.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace server.Database.Entity.Report
{
public class Report
{
private readonly ModelContext _modelContext;
public UserEntity UserEntity { get; set; }
public Report(ModelContext modelContext)
{
UserEntity = new UserEntity(modelContext);
_modelContext = modelContext;
}
}
}

View file

@ -27,6 +27,11 @@ namespace server.Database.Entity
return _modelContext.Users.Any(u => u.Steam64Id == Steam64Id && u.IsBanned);
}
public User GetUserBySteamId(ulong steamId)
{
return _modelContext.Users.First(u => u.Steam64Id == steamId);
}
public bool CheckIfUsersHardwareExists()
{
List<HardwareConfiguration> hardwareConfigurations = _modelContext.HardwareConfiguration

View file

@ -15,6 +15,7 @@ namespace server.Database.Model
public ulong Steam64Id { get; set; }
public bool IsBanned { get; set; }
public virtual ICollection<HardwareConfiguration> HardwareConfigurations { get; set; }
public virtual ICollection<ReportIllegalHandleOperation> ReportIllegalHandleOperations { get; set; }
}
public class HardwareConfiguration
@ -25,4 +26,15 @@ namespace server.Database.Model
public string DeviceDrive0Serial { get; set; }
public string MotherboardSerial { get; set; }
}
public class ReportIllegalHandleOperation
{
public int ReportId { get; set; }
public virtual User User { get; set; }
public int IsKernelHandle { get; set; }
public uint ProcessId { get; set; }
public uint ThreadId { get; set; }
public uint DesiredAccess { get; set; }
public string ProcessName { get; set; }
}
}

View file

@ -13,6 +13,8 @@ namespace server.Database.Model
public DbSet<User> Users { get; set; }
public DbSet<HardwareConfiguration> HardwareConfiguration { get; set; }
public DbSet<ReportIllegalHandleOperation> ReportIllegalHandleOperation { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=localhost;userid=root;password=root;database=ac_db");
@ -55,6 +57,32 @@ namespace server.Database.Model
entity.HasOne(d => d.User)
.WithMany(f => f.HardwareConfigurations);
});
modelBuilder.Entity<ReportIllegalHandleOperation>(entity =>
{
entity.HasKey(e => e.ReportId);
entity.Property(e => e.ReportId)
.UseMySQLAutoIncrementColumn(entity.Property(e => e.ReportId).Metadata.Name);
entity.Property(e => e.IsKernelHandle)
.IsRequired();
entity.Property(e => e.ProcessId)
.IsRequired();
entity.Property(e => e.ThreadId)
.IsRequired();
entity.Property(e => e.DesiredAccess)
.IsRequired();
entity.Property(e => e.ProcessName)
.IsRequired();
entity.HasOne(d => d.User)
.WithMany(f => f.ReportIllegalHandleOperations);
});
}
}
}

View file

@ -1,4 +1,7 @@
using Serilog;
using server.Database.Entity;
using server.Database.Entity.Report;
using server.Database.Model;
using server.Types.ClientReport;
using System;
using System.Collections.Generic;
@ -117,5 +120,38 @@ namespace server.Message
SetResponsePacketData(1);
return true;
}
unsafe public void HandleReportIllegalHandleOperation()
{
OPEN_HANDLE_FAILURE_REPORT report = Helper.BytesToStructure<OPEN_HANDLE_FAILURE_REPORT>(_buffer, sizeof(PACKET_HEADER));
_logger.Information("ProcessName: {0}, ProcessID: {1:x}, ThreadId: {2:x}, DesiredAccess{3:x}",
report.ProcessName,
report.ProcessId,
report.ThreadId,
report.DesiredAccess);
using (var context = new ModelContext())
{
/*
* This doesn't seem to be the most optimal way to do this, but it works..
* Maybe look into it further at somepoint..
*/
UserEntity user = new UserEntity(context);
var newReport = new IllegalHandleOperationEntity(context)
{
User = user.GetUserBySteamId(this._packetHeader.steam64_id),
IsKernelHandle = report.IsKernelHandle,
ProcessId = report.ProcessId,
ThreadId = report.ThreadId,
DesiredAccess = report.DesiredAccess,
ProcessName = report.ProcessName
};
newReport.InsertReport();
context.SaveChanges();
}
}
}
}

View file

@ -99,7 +99,7 @@ namespace server
public uint ThreadId;
public uint DesiredAccess;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string processName;
public string ProcessName;
}
}