diff options
| author | william341 <[email protected]> | 2017-07-27 17:27:31 -0700 |
|---|---|---|
| committer | william341 <[email protected]> | 2017-07-27 17:27:31 -0700 |
| commit | 2d5b566da493c8669d05df2e8004f7ba6a2d29d5 (patch) | |
| tree | b06f1e9918a929db0c1d457eb9eb73e859115553 | |
| parent | e5aec8a0531fe78dcc881a11b589b5a19338e503 (diff) | |
| download | shiftos_thereturn-2d5b566da493c8669d05df2e8004f7ba6a2d29d5.tar.gz shiftos_thereturn-2d5b566da493c8669d05df2e8004f7ba6a2d29d5.tar.bz2 shiftos_thereturn-2d5b566da493c8669d05df2e8004f7ba6a2d29d5.zip | |
hacking p2
| -rw-r--r-- | ShiftOS.Frontend/Apps/Network.cs | 12 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Hacking/HackableProvider.cs | 5 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Hacking/HackerTestCommands.cs | 45 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Properties/Resources.Designer.cs | 39 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Properties/Resources.resx | 3 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Resources/Exploits.txt | 2 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Resources/Payloads.txt | 4 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Resources/Ports.txt | 32 | ||||
| -rw-r--r-- | ShiftOS.Frontend/ShiftOS.Frontend.csproj | 1 | ||||
| -rw-r--r-- | ShiftOS.Objects/Hacking/Payload.cs | 2 | ||||
| -rw-r--r-- | ShiftOS.Objects/Hacking/Port.cs | 30 | ||||
| -rw-r--r-- | ShiftOS.Objects/ShiftOS.Objects.csproj | 1 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/Hacking.cs | 128 |
13 files changed, 193 insertions, 111 deletions
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<Port> 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<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 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<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) 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", /// } ///]. /// </summary> @@ -164,6 +164,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> public static string Shiftorium { 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 @@ <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>
\ 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 @@ <None Include="Resources\LootInfo.txt" /> </ItemGroup> <ItemGroup> + <Content Include="Resources\Ports.txt" /> <Content Include="Resources\Payloads.txt" /> <Content Include="Resources\Exploits.txt" /> </ItemGroup> 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 @@ </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" /> 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<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,70 +94,13 @@ 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), - }); - - 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) + hsys.PortsToUnlock = new List<Objects.Port>(); + foreach(Objects.Port porttocheck in Ports) { - 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); - } + if (data.SystemType.HasFlag(porttocheck.AttachTo)) + hsys.PortsToUnlock.Add(porttocheck); } - return locks; + CurrentHackable = hsys; } public static void FailHack() @@ -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; } - } } |
