hacking p2
This commit is contained in:
parent
e5aec8a053
commit
2d5b566da4
13 changed files with 194 additions and 112 deletions
|
@ -128,7 +128,7 @@ namespace ShiftOS.Frontend.Apps
|
|||
|
||||
protected override void OnLayout(GameTime gameTime)
|
||||
{
|
||||
_title.X = 15;
|
||||
/*_title.X = 15;
|
||||
_title.Y = 15;
|
||||
|
||||
_subtitle.X = 15;
|
||||
|
@ -174,7 +174,7 @@ Loot rarity: {_current.Data.LootRarity}
|
|||
|
||||
}
|
||||
}
|
||||
base.OnLayout(gameTime);
|
||||
base.OnLayout(gameTime);*/
|
||||
}
|
||||
|
||||
public class PortView : Control
|
||||
|
@ -198,21 +198,21 @@ Loot rarity: {_current.Data.LootRarity}
|
|||
|
||||
protected override void OnLayout(GameTime gameTime)
|
||||
{
|
||||
_start.Y = (Height - _start.Height) / 2;
|
||||
/*_start.Y = (Height - _start.Height) / 2;
|
||||
_start.X = (Width - _start.Width) - 15;
|
||||
unlocked = _port.Locks.Count > 0;
|
||||
base.OnLayout(gameTime);
|
||||
base.OnLayout(gameTime);*/
|
||||
}
|
||||
|
||||
protected override void OnPaint(GraphicsContext gfx)
|
||||
{
|
||||
gfx.Clear(LoadedSkin.ControlTextColor.ToMonoColor());
|
||||
/*gfx.Clear(LoadedSkin.ControlTextColor.ToMonoColor());
|
||||
gfx.DrawRectangle(1, 1, Width - 2, Height - 2, LoadedSkin.ControlColor.ToMonoColor());
|
||||
gfx.DrawString(_port.Name + " (" + _port.Value + ")", 15, 15, LoadedSkin.ControlTextColor.ToMonoColor(), LoadedSkin.Header3Font);
|
||||
string _status = "Tier: " + _port.Tier.ToString();
|
||||
string lockstatus = (unlocked == true) ? "Unlocked" : $"{_port.Locks.Count} locks";
|
||||
_status += " - " + lockstatus;
|
||||
gfx.DrawString(_status, 15, 15 + LoadedSkin.Header3Font.Height + 5, LoadedSkin.ControlTextColor.ToMonoColor(), LoadedSkin.MainFont);
|
||||
gfx.DrawString(_status, 15, 15 + LoadedSkin.Header3Font.Height + 5, LoadedSkin.ControlTextColor.ToMonoColor(), LoadedSkin.MainFont);*/
|
||||
}
|
||||
|
||||
public event Action<Port> ConnectionStarted;
|
||||
|
|
|
@ -26,6 +26,11 @@ namespace ShiftOS.Frontend
|
|||
return JsonConvert.DeserializeObject<Payload[]>(Properties.Resources.Payloads);
|
||||
}
|
||||
|
||||
public Port[] GetPorts()
|
||||
{
|
||||
return JsonConvert.DeserializeObject<Port[]>(Properties.Resources.Ports);
|
||||
}
|
||||
|
||||
public byte[] GetLootFromResource(string resId)
|
||||
{
|
||||
return new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }; //nyi
|
||||
|
|
|
@ -19,6 +19,33 @@ namespace ShiftOS.Frontend
|
|||
}
|
||||
}
|
||||
|
||||
[Command("lsexploits")]
|
||||
public static void ListAllExploits()
|
||||
{
|
||||
foreach (var exploit in Hacking.AvailableExploits)
|
||||
{
|
||||
Console.WriteLine(exploit.ID + ": " + exploit.FriendlyName);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("lspayloads")]
|
||||
public static void ListAllPayloads()
|
||||
{
|
||||
foreach (var exploit in Hacking.AvailablePayloads)
|
||||
{
|
||||
Console.WriteLine(exploit.ID + ": " + exploit.FriendlyName);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("lsports")]
|
||||
public static void ListAllPorts()
|
||||
{
|
||||
foreach (var exploit in Hacking.AvailablePorts)
|
||||
{
|
||||
Console.WriteLine(exploit.ID + ": " + exploit.FriendlyName);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("describebackable")]
|
||||
[RequiresArgument("id")]
|
||||
public static void DescribeHackable(Dictionary<string, object> args)
|
||||
|
@ -41,6 +68,24 @@ namespace ShiftOS.Frontend
|
|||
Console.WriteLine(hackable.WelcomeMessage);
|
||||
}
|
||||
|
||||
[Command("describeport")]
|
||||
[RequiresArgument("id")]
|
||||
public static void DescribePort(Dictionary<string, object> args)
|
||||
{
|
||||
string id = args["id"].ToString();
|
||||
var port = Hacking.AvailablePorts.FirstOrDefault(x => x.ID == id);
|
||||
if (port == null)
|
||||
{
|
||||
Console.WriteLine("Port not found.");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(port.FriendlyName);
|
||||
Console.WriteLine("------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Port: " + port.Value.ToString());
|
||||
Console.WriteLine("Name: " + port.Name);
|
||||
}
|
||||
|
||||
[Command("inithack")]
|
||||
[RequiresArgument("id")]
|
||||
public static void InitHack(Dictionary<string, object> args)
|
||||
|
|
39
ShiftOS.Frontend/Properties/Resources.Designer.cs
generated
39
ShiftOS.Frontend/Properties/Resources.Designer.cs
generated
|
@ -153,7 +153,7 @@ namespace ShiftOS.Frontend.Properties {
|
|||
/// FriendlyName: "FTP Payload",
|
||||
/// PayloadName: "ftpull"
|
||||
/// EffectiveAgainstFirewall: 1,
|
||||
/// EffectiveAgainstPort: "FileServer",
|
||||
/// EffectiveAgainst: "FileServer",
|
||||
/// }
|
||||
///].
|
||||
/// </summary>
|
||||
|
@ -163,6 +163,43 @@ namespace ShiftOS.Frontend.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to /* ShiftOS Ports data file
|
||||
/// *
|
||||
/// * This file contains information about all ports in the game's campaign.
|
||||
/// *
|
||||
/// */
|
||||
///
|
||||
///[
|
||||
/// {
|
||||
/// FriendlyName: "SMTP mailserver (unencrypted)",
|
||||
/// AttachTo: "EmailServer"
|
||||
/// Value: 25,
|
||||
/// Name: "smtp",
|
||||
/// },
|
||||
/// {
|
||||
/// FriendlyName: "File Transfer Protocol",
|
||||
/// AttachTo: "FileServer"
|
||||
/// Value: 21,
|
||||
/// Name: "ftp",
|
||||
/// },
|
||||
/// {
|
||||
/// FriendlyName: "ShiftSSH server",
|
||||
/// AttachTo: "SSHServer"
|
||||
/// Value: 22,
|
||||
/// Name: "ssh",
|
||||
/// },
|
||||
/// {
|
||||
/// FriendlyName: "MySQL server",
|
||||
/// AttachTo: "Database"
|
||||
/// Val [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
public static string Ports {
|
||||
get {
|
||||
return ResourceManager.GetString("Ports", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [].
|
||||
/// </summary>
|
||||
|
|
|
@ -148,4 +148,7 @@
|
|||
<data name="Payloads" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\resources\payloads.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
<data name="Ports" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\resources\ports.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
</root>
|
|
@ -7,7 +7,7 @@
|
|||
[
|
||||
{
|
||||
FriendlyName: "FTP Exploit",
|
||||
ExploitName: "ftpwn"
|
||||
ExploitName: "ftpwn",
|
||||
EffectiveAgainstPort: "FileServer",
|
||||
}
|
||||
]
|
|
@ -7,8 +7,8 @@
|
|||
[
|
||||
{
|
||||
FriendlyName: "FTP Payload",
|
||||
PayloadName: "ftpull"
|
||||
PayloadName: "ftpull",
|
||||
EffectiveAgainstFirewall: 1,
|
||||
EffectiveAgainstPort: "FileServer",
|
||||
EffectiveAgainst: "FileServer",
|
||||
}
|
||||
]
|
32
ShiftOS.Frontend/Resources/Ports.txt
Normal file
32
ShiftOS.Frontend/Resources/Ports.txt
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ShiftOS Ports data file
|
||||
*
|
||||
* This file contains information about all ports in the game's campaign.
|
||||
*
|
||||
*/
|
||||
|
||||
[
|
||||
{
|
||||
FriendlyName: "SMTP mailserver (unencrypted)",
|
||||
AttachTo: "EmailServer",
|
||||
Value: 25,
|
||||
Name: "smtp",
|
||||
},
|
||||
{
|
||||
FriendlyName: "File Transfer Protocol",
|
||||
AttachTo: "FileServer",
|
||||
Value: 21,
|
||||
Name: "ftp",
|
||||
},
|
||||
{
|
||||
FriendlyName: "ShiftSSH server",
|
||||
AttachTo: "SSHServer",
|
||||
Value: 22,
|
||||
Name: "ssh",
|
||||
},
|
||||
{
|
||||
FriendlyName: "MySQL server",
|
||||
AttachTo: "Database",
|
||||
Value: 3306,
|
||||
Name: "sql",
|
||||
}
|
||||
]
|
|
@ -190,6 +190,7 @@
|
|||
<None Include="Resources\LootInfo.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Resources\Ports.txt" />
|
||||
<Content Include="Resources\Payloads.txt" />
|
||||
<Content Include="Resources\Exploits.txt" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace ShiftOS.Objects
|
|||
public string FriendlyName { get; set; }
|
||||
public string PayloadName { get; set; }
|
||||
public int EffectiveAgainstFirewall { get; set; }
|
||||
public SystemType EffectiveAgainstPort { get; set; }
|
||||
public SystemType EffectiveAgainst { get; set; }
|
||||
public string Dependencies { get; set; }
|
||||
|
||||
public string ID
|
||||
|
|
30
ShiftOS.Objects/Hacking/Port.cs
Normal file
30
ShiftOS.Objects/Hacking/Port.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShiftOS.Objects
|
||||
{
|
||||
public class Port
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string FriendlyName { get; set; }
|
||||
public SystemType AttachTo { get; set; }
|
||||
public int Value { get; set; }
|
||||
|
||||
public string ID
|
||||
{
|
||||
get
|
||||
{
|
||||
return Name.ToLower().Replace(" ", "_");
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -47,6 +47,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EngineShiftnetSubscription.cs" />
|
||||
<Compile Include="Hacking\Port.cs" />
|
||||
<Compile Include="Hacking\Payload.cs" />
|
||||
<Compile Include="Hacking\Exploit.cs" />
|
||||
<Compile Include="Hacking\Hackable.cs" />
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace ShiftOS.Engine
|
|||
private static List<Objects.Hackable> Hackables = new List<Objects.Hackable>();
|
||||
private static List<Objects.Exploit> Exploits = new List<Objects.Exploit>();
|
||||
private static List<Objects.Payload> Payloads = new List<Objects.Payload>();
|
||||
private static List<Objects.Port> Ports = new List<Objects.Port>();
|
||||
private static List<Objects.Loot> Loot = new List<Objects.Loot>();
|
||||
|
||||
public static HackableSystem CurrentHackable { get; private set; }
|
||||
|
@ -40,6 +41,14 @@ namespace ShiftOS.Engine
|
|||
}
|
||||
}
|
||||
|
||||
public static Objects.Port[] AvailablePorts
|
||||
{
|
||||
get
|
||||
{
|
||||
return Ports.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static HackableSystem[] ActiveConnections
|
||||
{
|
||||
get
|
||||
|
@ -85,72 +94,15 @@ namespace ShiftOS.Engine
|
|||
{
|
||||
hsys.MillisecondsCountdown = 0;
|
||||
}
|
||||
hsys.PortsToUnlock = new List<Port>();
|
||||
if (data.SystemType.HasFlag(Objects.SystemType.EmailServer))
|
||||
hsys.PortsToUnlock.Add(new Port
|
||||
{
|
||||
Value = 25,
|
||||
Name = "SMTP mailserver (unencrypted)",
|
||||
Tier = hsys.Data.LockTier,
|
||||
Locks = GetLocks(hsys.Data.LockTier, hsys.Data.FirewallStrength),
|
||||
});
|
||||
if (data.SystemType.HasFlag(Objects.SystemType.FileServer))
|
||||
hsys.PortsToUnlock.Add(new Port
|
||||
{
|
||||
Value = 21,
|
||||
Name = "File Transfer Protocol",
|
||||
Tier = hsys.Data.LockTier,
|
||||
Locks = GetLocks(hsys.Data.LockTier, hsys.Data.FirewallStrength),
|
||||
});
|
||||
if (data.SystemType.HasFlag(Objects.SystemType.SSHServer))
|
||||
hsys.PortsToUnlock.Add(new Port
|
||||
{
|
||||
Value = 22,
|
||||
Name = "ShiftSSH server",
|
||||
Tier = hsys.Data.LockTier,
|
||||
Locks = GetLocks(hsys.Data.LockTier, hsys.Data.FirewallStrength),
|
||||
});
|
||||
if (data.SystemType.HasFlag(Objects.SystemType.Database))
|
||||
hsys.PortsToUnlock.Add(new Port
|
||||
{
|
||||
Value = 3306,
|
||||
Name = "MySQL database",
|
||||
Tier = hsys.Data.LockTier,
|
||||
Locks = GetLocks(hsys.Data.LockTier, hsys.Data.FirewallStrength),
|
||||
});
|
||||
|
||||
hsys.PortsToUnlock = new List<Objects.Port>();
|
||||
foreach(Objects.Port porttocheck in Ports)
|
||||
{
|
||||
if (data.SystemType.HasFlag(porttocheck.AttachTo))
|
||||
hsys.PortsToUnlock.Add(porttocheck);
|
||||
}
|
||||
CurrentHackable = hsys;
|
||||
}
|
||||
|
||||
public static List<PortLock> GetLocks(int tier, int fwallstrength)
|
||||
{
|
||||
var locks = new List<PortLock>();
|
||||
var lckTypes = new List<Type>();
|
||||
foreach(var lck in ReflectMan.Types.Where(x=>x.BaseType == typeof(PortLock)))
|
||||
{
|
||||
var lckAttrib = lck.GetCustomAttributes(false).FirstOrDefault(x => x is LockAttribute) as LockAttribute;
|
||||
if(lckAttrib != null)
|
||||
{
|
||||
if(lckAttrib.Tier == tier)
|
||||
{
|
||||
lckTypes.Add(lck);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lckTypes.Count > 0)
|
||||
{
|
||||
var rnd = new Random();
|
||||
for (int i = 0; i < fwallstrength; i++)
|
||||
{
|
||||
int _typeindex = rnd.Next(lckTypes.Count);
|
||||
var type = (PortLock)Activator.CreateInstance(lckTypes[_typeindex], lckTypes[_typeindex].GetCustomAttributes(false).FirstOrDefault(x => x is LockAttribute));
|
||||
lckTypes.RemoveAt(_typeindex);
|
||||
locks.Add(type);
|
||||
}
|
||||
}
|
||||
return locks;
|
||||
}
|
||||
|
||||
public static void FailHack()
|
||||
{
|
||||
if (CurrentHackable == null)
|
||||
|
@ -170,6 +122,9 @@ namespace ShiftOS.Engine
|
|||
{
|
||||
var @interface = (IHackableProvider)Activator.CreateInstance(type, null);
|
||||
Hackables.AddRange(@interface.GetHackables());
|
||||
Ports.AddRange(@interface.GetPorts());
|
||||
Payloads.AddRange(@interface.GetPayloads());
|
||||
Exploits.AddRange(@interface.GetExploits());
|
||||
var lootinfo = @interface.GetLootInfo();
|
||||
foreach(var loot in lootinfo)
|
||||
{
|
||||
|
@ -183,9 +138,16 @@ namespace ShiftOS.Engine
|
|||
|
||||
var hackable = Hackables.FirstOrDefault(x => Hackables.Where(y => x.SystemName == y.SystemName).Count() > 1);
|
||||
if(hackable != null)
|
||||
{
|
||||
throw new DataConflictException("Data conflict encountered while initiating the hacking engine. Two or more hackables were found with the same hostname \"" + hackable.SystemName + "\". This is a direct violation of the ShiftOS save system and Shiftorium backend.");
|
||||
}
|
||||
var ports = Ports.FirstOrDefault(x => Ports.Where(y => x.Name == y.Name).Count() > 1);
|
||||
if (hackable != null)
|
||||
throw new DataConflictException("Data conflict encountered while initiating the hacking engine. Two or more ports were found with the same name \"" + ports.Name + "\". This is a direct violation of the ShiftOS save system and Shiftorium backend.");
|
||||
var payloads = Payloads.FirstOrDefault(x => Payloads.Where(y => x.PayloadName == y.PayloadName).Count() > 1);
|
||||
if (hackable != null)
|
||||
throw new DataConflictException("Data conflict encountered while initiating the hacking engine. Two or more payloads were found with the same name \"" + payloads.PayloadName + "\". This is a direct violation of the ShiftOS save system and Shiftorium backend.");
|
||||
var exploits = Exploits.FirstOrDefault(x => Exploits.Where(y => x.ExploitName == y.ExploitName).Count() > 1);
|
||||
if (hackable != null)
|
||||
throw new DataConflictException("Data conflict encountered while initiating the hacking engine. Two or more exploits were found with the same name \"" + exploits.ExploitName + "\". This is a direct violation of the ShiftOS save system and Shiftorium backend.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,6 +179,7 @@ namespace ShiftOS.Engine
|
|||
Objects.Hackable[] GetHackables();
|
||||
Objects.Exploit[] GetExploits();
|
||||
Objects.Payload[] GetPayloads();
|
||||
Objects.Port[] GetPorts();
|
||||
Objects.LootInfo[] GetLootInfo();
|
||||
byte[] GetLootFromResource(string resId);
|
||||
}
|
||||
|
@ -224,46 +187,11 @@ namespace ShiftOS.Engine
|
|||
public class HackableSystem
|
||||
{
|
||||
public Objects.Hackable Data { get; set; }
|
||||
public List<Port> PortsToUnlock { get; set; }
|
||||
public List<Objects.Port> PortsToUnlock { get; set; }
|
||||
public bool FirewallCracked { get; set; }
|
||||
public Objects.ShiftFS.Directory Filesystem { get; set; }
|
||||
public double MillisecondsCountdown { get; set; }
|
||||
public bool DoConnectionTimeout { get; set; }
|
||||
public bool IsPwn3d { get; set; }
|
||||
}
|
||||
|
||||
public class Port
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
public int Tier { get; set; }
|
||||
public List<PortLock> Locks { get; set; } //not a hackmud thing i promise
|
||||
}
|
||||
|
||||
public abstract class PortLock
|
||||
{
|
||||
public PortLock(LockAttribute attrib)
|
||||
{
|
||||
Attribute = attrib;
|
||||
}
|
||||
|
||||
public LockAttribute Attribute { get; private set; }
|
||||
|
||||
public abstract bool Evaluate(Dictionary<string, object> args);
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple =false)]
|
||||
public class LockAttribute : Attribute
|
||||
{
|
||||
public LockAttribute(string name, string company, int tier)
|
||||
{
|
||||
Name = name;
|
||||
Company = company;
|
||||
Tier = tier;
|
||||
}
|
||||
|
||||
public int Tier { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Company { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue