From 2d5b566da493c8669d05df2e8004f7ba6a2d29d5 Mon Sep 17 00:00:00 2001 From: william341 Date: Thu, 27 Jul 2017 17:27:31 -0700 Subject: [PATCH] hacking p2 --- ShiftOS.Frontend/Apps/Network.cs | 12 +- ShiftOS.Frontend/Hacking/HackableProvider.cs | 5 + .../Hacking/HackerTestCommands.cs | 45 ++++++ .../Properties/Resources.Designer.cs | 39 +++++- ShiftOS.Frontend/Properties/Resources.resx | 3 + ShiftOS.Frontend/Resources/Exploits.txt | 2 +- ShiftOS.Frontend/Resources/Payloads.txt | 4 +- ShiftOS.Frontend/Resources/Ports.txt | 32 +++++ ShiftOS.Frontend/ShiftOS.Frontend.csproj | 1 + ShiftOS.Objects/Hacking/Payload.cs | 2 +- ShiftOS.Objects/Hacking/Port.cs | 30 ++++ ShiftOS.Objects/ShiftOS.Objects.csproj | 1 + ShiftOS_TheReturn/Hacking.cs | 130 ++++-------------- 13 files changed, 194 insertions(+), 112 deletions(-) create mode 100644 ShiftOS.Frontend/Resources/Ports.txt create mode 100644 ShiftOS.Objects/Hacking/Port.cs diff --git a/ShiftOS.Frontend/Apps/Network.cs b/ShiftOS.Frontend/Apps/Network.cs index 5cbc385..cd67e6a 100644 --- a/ShiftOS.Frontend/Apps/Network.cs +++ b/ShiftOS.Frontend/Apps/Network.cs @@ -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 ConnectionStarted; diff --git a/ShiftOS.Frontend/Hacking/HackableProvider.cs b/ShiftOS.Frontend/Hacking/HackableProvider.cs index 6198b0c..5419030 100644 --- a/ShiftOS.Frontend/Hacking/HackableProvider.cs +++ b/ShiftOS.Frontend/Hacking/HackableProvider.cs @@ -26,6 +26,11 @@ namespace ShiftOS.Frontend return JsonConvert.DeserializeObject(Properties.Resources.Payloads); } + public Port[] GetPorts() + { + return JsonConvert.DeserializeObject(Properties.Resources.Ports); + } + public byte[] GetLootFromResource(string resId) { return new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }; //nyi diff --git a/ShiftOS.Frontend/Hacking/HackerTestCommands.cs b/ShiftOS.Frontend/Hacking/HackerTestCommands.cs index 675356a..a72f267 100644 --- a/ShiftOS.Frontend/Hacking/HackerTestCommands.cs +++ b/ShiftOS.Frontend/Hacking/HackerTestCommands.cs @@ -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 args) @@ -41,6 +68,24 @@ namespace ShiftOS.Frontend Console.WriteLine(hackable.WelcomeMessage); } + [Command("describeport")] + [RequiresArgument("id")] + public static void DescribePort(Dictionary 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 args) diff --git a/ShiftOS.Frontend/Properties/Resources.Designer.cs b/ShiftOS.Frontend/Properties/Resources.Designer.cs index 1d451a1..dfc728e 100644 --- a/ShiftOS.Frontend/Properties/Resources.Designer.cs +++ b/ShiftOS.Frontend/Properties/Resources.Designer.cs @@ -153,7 +153,7 @@ namespace ShiftOS.Frontend.Properties { /// FriendlyName: "FTP Payload", /// PayloadName: "ftpull" /// EffectiveAgainstFirewall: 1, - /// EffectiveAgainstPort: "FileServer", + /// EffectiveAgainst: "FileServer", /// } ///]. /// @@ -163,6 +163,43 @@ namespace ShiftOS.Frontend.Properties { } } + /// + /// 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]";. + /// + public static string Ports { + get { + return ResourceManager.GetString("Ports", resourceCulture); + } + } + /// /// Looks up a localized string similar to []. /// diff --git a/ShiftOS.Frontend/Properties/Resources.resx b/ShiftOS.Frontend/Properties/Resources.resx index 80ed513..0b514f7 100644 --- a/ShiftOS.Frontend/Properties/Resources.resx +++ b/ShiftOS.Frontend/Properties/Resources.resx @@ -148,4 +148,7 @@ ..\resources\payloads.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + ..\resources\ports.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/ShiftOS.Frontend/Resources/Exploits.txt b/ShiftOS.Frontend/Resources/Exploits.txt index 0e0dd64..45b0250 100644 --- a/ShiftOS.Frontend/Resources/Exploits.txt +++ b/ShiftOS.Frontend/Resources/Exploits.txt @@ -7,7 +7,7 @@ [ { FriendlyName: "FTP Exploit", - ExploitName: "ftpwn" + ExploitName: "ftpwn", EffectiveAgainstPort: "FileServer", } ] \ No newline at end of file diff --git a/ShiftOS.Frontend/Resources/Payloads.txt b/ShiftOS.Frontend/Resources/Payloads.txt index 1c7ff2d..1ce0f43 100644 --- a/ShiftOS.Frontend/Resources/Payloads.txt +++ b/ShiftOS.Frontend/Resources/Payloads.txt @@ -7,8 +7,8 @@ [ { FriendlyName: "FTP Payload", - PayloadName: "ftpull" + PayloadName: "ftpull", EffectiveAgainstFirewall: 1, - EffectiveAgainstPort: "FileServer", + EffectiveAgainst: "FileServer", } ] \ No newline at end of file diff --git a/ShiftOS.Frontend/Resources/Ports.txt b/ShiftOS.Frontend/Resources/Ports.txt new file mode 100644 index 0000000..4813496 --- /dev/null +++ b/ShiftOS.Frontend/Resources/Ports.txt @@ -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", + } +] \ No newline at end of file diff --git a/ShiftOS.Frontend/ShiftOS.Frontend.csproj b/ShiftOS.Frontend/ShiftOS.Frontend.csproj index 5f3d18a..eff61a2 100644 --- a/ShiftOS.Frontend/ShiftOS.Frontend.csproj +++ b/ShiftOS.Frontend/ShiftOS.Frontend.csproj @@ -190,6 +190,7 @@ + diff --git a/ShiftOS.Objects/Hacking/Payload.cs b/ShiftOS.Objects/Hacking/Payload.cs index a3800fa..3d191e4 100644 --- a/ShiftOS.Objects/Hacking/Payload.cs +++ b/ShiftOS.Objects/Hacking/Payload.cs @@ -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 diff --git a/ShiftOS.Objects/Hacking/Port.cs b/ShiftOS.Objects/Hacking/Port.cs new file mode 100644 index 0000000..85360a3 --- /dev/null +++ b/ShiftOS.Objects/Hacking/Port.cs @@ -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; + } + } + +} diff --git a/ShiftOS.Objects/ShiftOS.Objects.csproj b/ShiftOS.Objects/ShiftOS.Objects.csproj index 6fa7f79..27b950c 100644 --- a/ShiftOS.Objects/ShiftOS.Objects.csproj +++ b/ShiftOS.Objects/ShiftOS.Objects.csproj @@ -47,6 +47,7 @@ + diff --git a/ShiftOS_TheReturn/Hacking.cs b/ShiftOS_TheReturn/Hacking.cs index ca6c4e8..a691767 100644 --- a/ShiftOS_TheReturn/Hacking.cs +++ b/ShiftOS_TheReturn/Hacking.cs @@ -12,6 +12,7 @@ namespace ShiftOS.Engine private static List Hackables = new List(); private static List Exploits = new List(); private static List Payloads = new List(); + private static List Ports = new List(); private static List Loot = new List(); 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(); - 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(); + foreach(Objects.Port porttocheck in Ports) + { + if (data.SystemType.HasFlag(porttocheck.AttachTo)) + hsys.PortsToUnlock.Add(porttocheck); + } CurrentHackable = hsys; } - public static List GetLocks(int tier, int fwallstrength) - { - var locks = new List(); - var lckTypes = new List(); - 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 PortsToUnlock { get; set; } + public List 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 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 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; } - } }