From f4e39bb9117a692c543ecf17e79ed98c95ffc70e Mon Sep 17 00:00:00 2001 From: william341 Date: Thu, 27 Jul 2017 19:36:46 -0700 Subject: [PATCH] hacking works like actually it does kindof --- ShiftOS.Frontend/Hacking/HackingCommands.cs | 99 +++++++++++++++++++++ ShiftOS.Frontend/Hacking/PayloadFunc.cs | 24 +++++ ShiftOS.Frontend/Resources/Exploits.txt | 5 ++ ShiftOS.Frontend/Resources/Hackables.txt | 2 +- ShiftOS.Frontend/Resources/Payloads.txt | 6 ++ ShiftOS.Frontend/ShiftOS.Frontend.csproj | 2 + ShiftOS.Frontend/ShiftOS.cs | 4 +- ShiftOS.Objects/Hacking/Payload.cs | 1 + ShiftOS_TheReturn/Hacking.cs | 27 ++++++ 9 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 ShiftOS.Frontend/Hacking/HackingCommands.cs create mode 100644 ShiftOS.Frontend/Hacking/PayloadFunc.cs diff --git a/ShiftOS.Frontend/Hacking/HackingCommands.cs b/ShiftOS.Frontend/Hacking/HackingCommands.cs new file mode 100644 index 0000000..fe9ccbc --- /dev/null +++ b/ShiftOS.Frontend/Hacking/HackingCommands.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.Frontend +{ + class HackingCommands + { + //TODO: Implement firewall cracking + [Command("connect")] + [RequiresArgument("id")] + public static void Connect(Dictionary args) + { + string id = args["id"].ToString(); + var hackable = Hacking.AvailableToHack.FirstOrDefault(x => x.ID == id); + if (hackable == null) + { + Console.WriteLine("[sploitset] device not found on network."); + return; + } + Hacking.InitHack(hackable); + } + + [Command("exploit")] + [RequiresArgument("exploit")] + [RequiresArgument("port")] + public static void Exploit(Dictionary args) + { + if (Hacking.CurrentHackable == null) + { + Console.WriteLine("[sploitset] not connected"); + } + string Port = args["port"].ToString(); + string ExploitName = args["exploit"].ToString(); + var Exploit = Hacking.AvailableExploits.FirstOrDefault(x => x.ID == ExploitName); + if (Exploit == null) + { + Console.WriteLine("[sploitset] invalid exploit."); + return; + } + var ExploitTarget = Hacking.CurrentHackable.PortsToUnlock.FirstOrDefault(x => x.AttachTo == Exploit.EffectiveAgainst); + if (ExploitTarget == null) + { + Console.WriteLine("[sploitset] the connected machine doesn't have that service running."); + return; + } + if (ExploitTarget.Value.ToString() != Port) + { + Console.WriteLine("[sploitset] port not open"); + return; + } + Hacking.CurrentHackable.VectorsUnlocked.Add(ExploitTarget.AttachTo); + Console.WriteLine("[sploitset] exploited service"); + } + + [Command("inject")] + [RequiresArgument("payload")] + public static void InjectPayload(Dictionary args) + { + if (Hacking.CurrentHackable == null) + { + Console.WriteLine("[sploitset] not connected"); + } + string PayloadName = args["payload"].ToString(); + var Payload = Hacking.AvailablePayloads.FirstOrDefault(x => x.ID == PayloadName); + if (Payload == null) + { + Console.WriteLine("[sploitset] invalid payload."); + return; + } + if (!Hacking.CurrentHackable.VectorsUnlocked.Contains(Payload.EffectiveAgainst)) + { + Console.WriteLine("[sploitset] the connected machine doesn't have that service exploited."); + return; + } + PayloadFunc.DoHackFunction(Payload.Function); + Hacking.CurrentHackable.PayloadExecuted.Add(Payload); + Console.WriteLine("[sploitset] injected payload"); + } + + [Command("disconnect")] + public static void Disconnect(Dictionary args) + { + if (Hacking.CurrentHackable == null) + { + Console.WriteLine("[sploitset] not connected"); + } + if (Hacking.CurrentHackable.PayloadExecuted.Count == 0) + { + Hacking.FailHack(); + return; + } + Hacking.FinishHack(); + } + } +} diff --git a/ShiftOS.Frontend/Hacking/PayloadFunc.cs b/ShiftOS.Frontend/Hacking/PayloadFunc.cs new file mode 100644 index 0000000..5252db4 --- /dev/null +++ b/ShiftOS.Frontend/Hacking/PayloadFunc.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.Frontend +{ + class PayloadFunc + { + public static void DoHackFunction(int function) + { + switch (function) + { + default: + break; + case 1: + Hacking.CurrentHackable.DoConnectionTimeout = false; + break; + } + } + } +} diff --git a/ShiftOS.Frontend/Resources/Exploits.txt b/ShiftOS.Frontend/Resources/Exploits.txt index 45b0250..4ad6caf 100644 --- a/ShiftOS.Frontend/Resources/Exploits.txt +++ b/ShiftOS.Frontend/Resources/Exploits.txt @@ -9,5 +9,10 @@ FriendlyName: "FTP Exploit", ExploitName: "ftpwn", EffectiveAgainstPort: "FileServer", + }, + { + FriendlyName: "SSH Exploit", + ExploitName: "sshardline", + EffectiveAgainstPort: "SSHServer", } ] \ No newline at end of file diff --git a/ShiftOS.Frontend/Resources/Hackables.txt b/ShiftOS.Frontend/Resources/Hackables.txt index 1c82394..ca09057 100644 --- a/ShiftOS.Frontend/Resources/Hackables.txt +++ b/ShiftOS.Frontend/Resources/Hackables.txt @@ -11,7 +11,7 @@ Password: "h0ldy0urc0l0ur", PasswordHint: "Prepare to hold your colour...", WelcomeMessage: "Don't make fun of SpamSyndicate web design.", - FirewallStrength: 1, + FirewallStrength: 0, LootRarity: 1, LootAmount: 4, ConnectionTimeoutLevel: 4, diff --git a/ShiftOS.Frontend/Resources/Payloads.txt b/ShiftOS.Frontend/Resources/Payloads.txt index 1ce0f43..bb85d74 100644 --- a/ShiftOS.Frontend/Resources/Payloads.txt +++ b/ShiftOS.Frontend/Resources/Payloads.txt @@ -10,5 +10,11 @@ PayloadName: "ftpull", EffectiveAgainstFirewall: 1, EffectiveAgainst: "FileServer", + }, + { + FriendlyName: "Ping Spam", + PayloadName: "keepalive", + EffectiveAgainstFirewall: 1, + EffectiveAgainst: "SSHServer", } ] \ No newline at end of file diff --git a/ShiftOS.Frontend/ShiftOS.Frontend.csproj b/ShiftOS.Frontend/ShiftOS.Frontend.csproj index eff61a2..8decbc6 100644 --- a/ShiftOS.Frontend/ShiftOS.Frontend.csproj +++ b/ShiftOS.Frontend/ShiftOS.Frontend.csproj @@ -64,8 +64,10 @@ + + diff --git a/ShiftOS.Frontend/ShiftOS.cs b/ShiftOS.Frontend/ShiftOS.cs index 88f009a..866f7f5 100644 --- a/ShiftOS.Frontend/ShiftOS.cs +++ b/ShiftOS.Frontend/ShiftOS.cs @@ -295,7 +295,7 @@ namespace ShiftOS.Frontend { if (Hacking.CurrentHackable.DoConnectionTimeout) { - string str = $"Connection TImeout in {(Hacking.CurrentHackable.MillisecondsCountdown / 1000).ToString("#.##")} seconds."; + string str = $"Timeout in {(Hacking.CurrentHackable.MillisecondsCountdown / 1000).ToString("#.##")} seconds."; var gfx = new GraphicsContext(GraphicsDevice, spriteBatch, 0, 0, UIManager.Viewport.Width, UIManager.Viewport.Height); var measure = gfx.MeasureString(str, SkinEngine.LoadedSkin.HeaderFont); gfx.DrawString(str, 5, (gfx.Height - ((int)measure.Y) - 5), Color.Red, SkinEngine.LoadedSkin.HeaderFont); @@ -310,7 +310,7 @@ namespace ShiftOS.Frontend if (fps <= 20) color = Color.Red; gfxContext.DrawString($@"ShiftOS 1.0 Beta 4 -Copyright (c) 2017 Michael VanOverbeek, Rylan Arbour, RogueAI +Copyright (c) 2017 Michael VanOverbeek, Rylan Arbour, RogueAI, william341 This is an unstable build. FPS: {(fps)} An FPS below 20 can cause glitches in keyboard and mouse handling. It is advised that if you are getting these diff --git a/ShiftOS.Objects/Hacking/Payload.cs b/ShiftOS.Objects/Hacking/Payload.cs index 3d191e4..3ec11b8 100644 --- a/ShiftOS.Objects/Hacking/Payload.cs +++ b/ShiftOS.Objects/Hacking/Payload.cs @@ -12,6 +12,7 @@ namespace ShiftOS.Objects public string PayloadName { get; set; } public int EffectiveAgainstFirewall { get; set; } public SystemType EffectiveAgainst { get; set; } + public int Function { get; set; } public string Dependencies { get; set; } public string ID diff --git a/ShiftOS_TheReturn/Hacking.cs b/ShiftOS_TheReturn/Hacking.cs index a691767..337ac04 100644 --- a/ShiftOS_TheReturn/Hacking.cs +++ b/ShiftOS_TheReturn/Hacking.cs @@ -95,6 +95,8 @@ namespace ShiftOS.Engine hsys.MillisecondsCountdown = 0; } hsys.PortsToUnlock = new List(); + hsys.VectorsUnlocked = new List(); + hsys.PayloadExecuted = new List(); foreach(Objects.Port porttocheck in Ports) { if (data.SystemType.HasFlag(porttocheck.AttachTo)) @@ -109,6 +111,7 @@ namespace ShiftOS.Engine throw new NaughtyDeveloperException("Someone tried to fail a non-existent hack."); if (CurrentHackable.IsPwn3d) throw new NaughtyDeveloperException("A developer tried to un-pwn a pwn3d hackable."); + Console.WriteLine("[sploitset] [FAIL] disconnected - connection terminated by remote machine "); if (!string.IsNullOrWhiteSpace(CurrentHackable.Data.OnHackFailedStoryEvent)) Story.Start(CurrentHackable.Data.OnHackFailedStoryEvent); if (Objects.ShiftFS.Utils.Mounts.Contains(CurrentHackable.Filesystem)) @@ -116,6 +119,28 @@ namespace ShiftOS.Engine CurrentHackable = null; } + public static void EndHack() + { + if (CurrentHackable == null) + throw new NaughtyDeveloperException("Someone tried to end a non-existent hack."); + if (Objects.ShiftFS.Utils.Mounts.Contains(CurrentHackable.Filesystem)) + Objects.ShiftFS.Utils.Mounts.Remove(CurrentHackable.Filesystem); + Console.WriteLine("[sploitset] [FAIL] disconnected for unknown reason"); + CurrentHackable = null; + } + + public static void FinishHack() + { + if (CurrentHackable == null) + throw new NaughtyDeveloperException("Someone tried to finish a non-existent hack."); + if (!string.IsNullOrWhiteSpace(CurrentHackable.Data.OnHackCompleteStoryEvent)) + Story.Start(CurrentHackable.Data.OnHackCompleteStoryEvent); + if (Objects.ShiftFS.Utils.Mounts.Contains(CurrentHackable.Filesystem)) + Objects.ShiftFS.Utils.Mounts.Remove(CurrentHackable.Filesystem); + Console.WriteLine("[sploitset] disconnected with payload applied"); + CurrentHackable = null; + } + public static void Initiate() { foreach(var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IHackableProvider)))) @@ -188,6 +213,8 @@ namespace ShiftOS.Engine { public Objects.Hackable Data { get; set; } public List PortsToUnlock { get; set; } + public List VectorsUnlocked { get; set; } + public List PayloadExecuted { get; set; } public bool FirewallCracked { get; set; } public Objects.ShiftFS.Directory Filesystem { get; set; } public double MillisecondsCountdown { get; set; }