Example #1
0
 public static void RemapVanillaPort(this Hacknet.Computer comp, int selectedPort, int remap)
 {
     if (remap == 0)
     {
         comp.PortRemapping.Remove(selectedPort);
     }
     else if (comp.PortRemapping.ContainsKey(selectedPort))
     {
         comp.PortRemapping[selectedPort] = remap;
     }
     else if (comp.GetDisplayPortNumberFromCodePort(selectedPort) != remap)
     {
         comp.PortRemapping.Add(selectedPort, remap);
     }
 }
Example #2
0
        public static SSLPortExe GenerateInstanceOrNullFromArguments(string[] args, Rectangle location, object osObj, Computer target)
        {
            OS operatingSystem = (OS)osObj;

            if (args.Length < 4)
            {
                operatingSystem.write("--------------------------------------");
                operatingSystem.write("SSLTrojan " + LocaleTerms.Loc("ERROR: Not enough arguments!"));
                operatingSystem.write(LocaleTerms.Loc("Usage:") + " SSLTrojan [" + LocaleTerms.Loc("PortNum") + "] [-" + LocaleTerms.Loc("option") + "] [" + LocaleTerms.Loc("option port num") + "]");
                operatingSystem.write(LocaleTerms.Loc("Valid Options:") + " [-s (SSH)] [-f (FTP)] [-w (HTTP)] [-r (RTSP)]");
                operatingSystem.write("--------------------------------------");
                return((SSLPortExe)null);
            }
            try
            {
                Convert.ToInt32(args[1]);
                int                int32_1 = Convert.ToInt32(args[3]);
                string             str     = args[2].ToLower();
                SSLPortExe.SSLMode mode    = SSLPortExe.SSLMode.SSH;
                switch (str)
                {
                case "-s":
                    mode = SSLPortExe.SSLMode.SSH;
                    break;

                case "-f":
                    mode = SSLPortExe.SSLMode.FTP;
                    break;

                case "-w":
                    mode = SSLPortExe.SSLMode.Web;
                    break;

                case "-r":
                    mode = SSLPortExe.SSLMode.RTSP;
                    break;

                default:
                    str = (string)null;
                    break;
                }
                if (str == null)
                {
                    operatingSystem.write("--------------------------------------");
                    operatingSystem.write("SSLTrojan " + string.Format(LocaleTerms.Loc("Error: Mode {0} is invalid."), (object)args[2]));
                    operatingSystem.write(LocaleTerms.Loc("Valid Options:") + " [-s (SSH)] [-f (FTP)] [-w (HTTP)] [-r (RTSP)]");
                    operatingSystem.write("--------------------------------------");
                    return((SSLPortExe)null);
                }
                int  num  = -1;
                bool flag = false;
                switch (mode)
                {
                case SSLPortExe.SSLMode.SSH:
                    flag = target.isPortOpen(22);
                    num  = target.GetDisplayPortNumberFromCodePort(22);
                    break;

                case SSLPortExe.SSLMode.FTP:
                    flag = target.isPortOpen(21);
                    num  = target.GetDisplayPortNumberFromCodePort(21);
                    break;

                case SSLPortExe.SSLMode.Web:
                    flag = target.isPortOpen(80);
                    num  = target.GetDisplayPortNumberFromCodePort(80);
                    break;

                case SSLPortExe.SSLMode.RTSP:
                    flag = target.isPortOpen(554);
                    num  = target.GetDisplayPortNumberFromCodePort(554);
                    break;
                }
                if (!flag)
                {
                    operatingSystem.write("--------------------------------------");
                    operatingSystem.write("SSLTrojan " + LocaleTerms.Loc("Error: Target bypass port is closed!"));
                    return((SSLPortExe)null);
                }
                int int32_2;
                try
                {
                    int32_2 = Convert.ToInt32(int32_1);
                }
                catch (FormatException ex)
                {
                    operatingSystem.write("--------------------------------------");
                    operatingSystem.write("SSLTrojan " + string.Format(LocaleTerms.Loc("Error: Invalid tunnel port number : \"{0}\""), (object)int32_1));
                    return((SSLPortExe)null);
                }
                if (int32_2 == num)
                {
                    return(new SSLPortExe(location, operatingSystem, mode));
                }
                operatingSystem.write("--------------------------------------");
                operatingSystem.write("SSLTrojan " + string.Format(LocaleTerms.Loc("Error: Tunnel port number {0} does not match expected service \"{1}"), (object)int32_2, (object)str));
                return((SSLPortExe)null);
            }
            catch (Exception ex)
            {
                operatingSystem.write("SSLTrojan " + LocaleTerms.Loc("Error:"));
                operatingSystem.write(ex.Message);
                return((SSLPortExe)null);
            }
        }
Example #3
0
        private void doProbeDisplay()
        {
            Rectangle rectangle = Rectangle.Empty;
            Computer  computer  = this.os.connectedComp == null ? this.os.thisComputer : this.os.connectedComp;

            if (computer.proxyActive)
            {
                rectangle = this.bounds;
                ++rectangle.X;
                ++rectangle.Y;
                rectangle.Width  -= 2;
                rectangle.Height -= 2;
                PatternDrawer.draw(rectangle, 0.8f, Color.Transparent, this.os.superLightWhite, this.os.ScreenManager.SpriteBatch);
            }
            if (Button.doButton(299999, this.bounds.X + (this.bounds.Width - 50), this.bounds.Y + this.y, 27, 27, "<-", new Color?()))
            {
                this.command = "connect";
            }
            this.spriteBatch.DrawString(GuiData.font, LocaleTerms.Loc("Open Ports"), new Vector2((float)this.x, (float)this.y), Color.White);
            this.y += 40;
            this.spriteBatch.DrawString(GuiData.smallfont, computer.name + " @" + computer.ip, new Vector2((float)this.x, (float)this.y), Color.White);
            this.y += 30;
            int    num   = Math.Max(computer.portsNeededForCrack + 1, 0);
            string str   = string.Concat((object)num);
            bool   flag1 = num > 100;

            if (flag1)
            {
                if (this.invioableSecurityCacheString == null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (int index = 0; index < str.Length; ++index)
                    {
                        stringBuilder.Append(Utils.getRandomChar());
                    }
                    this.invioableSecurityCacheString = stringBuilder.ToString();
                }
                else
                {
                    this.invioabilityCharChangeTimer -= (float)this.os.lastGameTime.ElapsedGameTime.TotalSeconds;
                    if ((double)this.invioabilityCharChangeTimer <= 0.0)
                    {
                        StringBuilder stringBuilder = new StringBuilder(this.invioableSecurityCacheString);
                        stringBuilder[Utils.random.Next(stringBuilder.Length)] = Utils.random.NextDouble() > 0.3 ? Utils.getRandomNumberChar() : Utils.getRandomChar();
                        this.invioableSecurityCacheString = stringBuilder.ToString();
                        this.invioabilityCharChangeTimer  = 0.025f;
                    }
                }
                str = this.invioableSecurityCacheString;
            }
            this.spriteBatch.DrawString(GuiData.smallfont, LocalizedFileLoader.SafeFilterString(LocaleTerms.Loc("Open Ports Required for Crack:")) + " " + str, new Vector2((float)this.x, (float)this.y), flag1 ? Color.Lerp(Color.Red, this.os.brightLockedColor, Utils.randm(0.5f) + 0.5f) : this.os.highlightColor);
            this.y += 40;
            if (flag1)
            {
                rectangle.X      = this.bounds.X + 2;
                rectangle.Y      = this.y;
                rectangle.Width  = this.bounds.Width - 4;
                rectangle.Height = 110;
                this.DrawInvioabilityEffect(rectangle);
                this.y += rectangle.Height + 10;
            }
            if (computer.hasProxy)
            {
                rectangle.X      = this.x;
                rectangle.Y      = this.y;
                rectangle.Width  = this.bounds.Width - 10;
                rectangle.Height = 40;
                PatternDrawer.draw(rectangle, 1f, computer.proxyActive ? this.os.topBarColor : Color.Lerp(this.os.unlockedColor, Color.Black, 0.2f), computer.proxyActive ? this.os.shellColor * 0.3f : this.os.unlockedColor, this.os.ScreenManager.SpriteBatch);
                if (computer.proxyActive)
                {
                    rectangle.Width = (int)((double)rectangle.Width * (1.0 - (double)computer.proxyOverloadTicks / (double)computer.startingOverloadTicks));
                    this.spriteBatch.Draw(Utils.white, rectangle, Color.Black * 0.5f);
                }
                this.spriteBatch.DrawString(GuiData.smallfont, computer.proxyActive ? LocaleTerms.Loc("Proxy Detected") : LocaleTerms.Loc("Proxy Bypassed"), new Vector2((float)(this.x + 4), (float)(this.y + 2)), Color.Black);
                this.spriteBatch.DrawString(GuiData.smallfont, computer.proxyActive ? LocaleTerms.Loc("Proxy Detected") : LocaleTerms.Loc("Proxy Bypassed"), new Vector2((float)(this.x + 3), (float)(this.y + 1)), computer.proxyActive ? Color.White : this.os.highlightColor);
                this.y += 60;
            }
            if (computer.firewall != null)
            {
                rectangle.X      = this.x;
                rectangle.Y      = this.y;
                rectangle.Width  = this.bounds.Width - 10;
                rectangle.Height = 40;
                bool flag2 = !computer.firewall.solved;
                PatternDrawer.draw(rectangle, 1f, flag2 ? this.os.topBarColor : Color.Lerp(this.os.unlockedColor, Color.Black, 0.2f), flag2 ? this.os.shellColor * 0.3f : this.os.unlockedColor, this.os.ScreenManager.SpriteBatch);
                this.spriteBatch.DrawString(GuiData.smallfont, flag2 ? LocaleTerms.Loc("Firewall Detected") : LocaleTerms.Loc("Firewall Solved"), new Vector2((float)(this.x + 4), (float)(this.y + 2)), Color.Black);
                this.spriteBatch.DrawString(GuiData.smallfont, flag2 ? LocaleTerms.Loc("Firewall Detected") : LocaleTerms.Loc("Firewall Solved"), new Vector2((float)(this.x + 3), (float)(this.y + 1)), flag2 ? Color.White : this.os.highlightColor);
                this.y += 60;
            }
            Vector2 zero = Vector2.Zero;

            rectangle.X      = this.x + 1;
            rectangle.Width  = 420;
            rectangle.Height = 41;
            Vector2 position = new Vector2((float)(rectangle.X + rectangle.Width - 36), (float)(rectangle.Y + 7));

            this.x += 10;
            for (int index = 0; index < computer.ports.Count; ++index)
            {
                rectangle.Y = this.y + 4;
                position.Y  = (float)(rectangle.Y + 4);
                this.spriteBatch.Draw(Utils.white, rectangle, (int)computer.portsOpen[index] > 0 ? this.os.unlockedColor : this.os.lockedColor);
                this.spriteBatch.Draw((int)computer.portsOpen[index] > 0 ? this.openLockSprite : this.lockSprite, position, Color.White);
                string  text1     = "Port#: " + (object)computer.GetDisplayPortNumberFromCodePort(computer.ports[index]);
                Vector2 vector2_1 = GuiData.font.MeasureString(text1);
                this.spriteBatch.DrawString(GuiData.font, text1, new Vector2((float)this.x, (float)(this.y + 3)), Color.White);
                string  text2     = " - " + PortExploits.services[computer.ports[index]];
                Vector2 vector2_2 = GuiData.smallfont.MeasureString(text2);
                float   scale     = Math.Min(1f, (float)((double)rectangle.Width - (double)vector2_1.X - 50.0) / vector2_2.X);
                this.spriteBatch.DrawString(GuiData.smallfont, text2, new Vector2((float)this.x + vector2_1.X, (float)(this.y + 4)), Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.8f);
                this.y += 45;
            }
        }
Example #4
0
        private static int AttemptExeProgramExecution(OS os, string[] p)
        {
            Computer target            = os.connectedComp != null ? os.connectedComp : os.thisComputer;
            Folder   folder            = os.thisComputer.files.root.searchForFolder("bin");
            int      indexOfExeProgram = ProgramRunner.GetFileIndexOfExeProgram(p[0], (object)folder);
            bool     flag   = indexOfExeProgram == int.MaxValue;
            int      index1 = -1;
            int      index2 = -1;

            if (indexOfExeProgram < 0)
            {
                return(-1);
            }
            string exeFileData = (string)null;
            string exeName     = (string)null;

            if (!flag)
            {
                exeFileData = folder.files[indexOfExeProgram].data;
                for (int index3 = 0; index3 < PortExploits.exeNums.Count; ++index3)
                {
                    int exeNum = PortExploits.exeNums[index3];
                    if (PortExploits.crackExeData[exeNum].Equals(exeFileData) || PortExploits.crackExeDataLocalRNG[exeNum].Equals(exeFileData))
                    {
                        exeName = PortExploits.cracks[exeNum].Replace(".exe", "").ToLower();
                        index2  = exeNum;
                        break;
                    }
                }
                if (exeName == "ftpsprint")
                {
                    int num;
                    index2 = num = 21;
                    if (exeFileData == PortExploits.crackExeData[211] || exeFileData == PortExploits.crackExeDataLocalRNG[211])
                    {
                        index1 = 211;
                    }
                }
            }
            else
            {
                exeName = p[0].Replace(".exe", "").ToLower();
                if (exeName == "notes")
                {
                    exeFileData = PortExploits.crackExeData[8];
                }
                if (exeName == "tutorial")
                {
                    exeFileData = PortExploits.crackExeData[1];
                }
            }
            if (exeName == null)
            {
                return(-1);
            }
            int targetPort = -1;
            int codePort   = -1;

            if (!flag && PortExploits.needsPort[index2])
            {
                if (p.Length > 1)
                {
                    try
                    {
                        int int32 = Convert.ToInt32(p[1]);
                        int num   = int32;
                        codePort = target.GetCodePortNumberFromDisplayPort(int32);
                        if (num == codePort)
                        {
                            int numberFromCodePort = target.GetDisplayPortNumberFromCodePort(codePort);
                            if (codePort != numberFromCodePort)
                            {
                                codePort = -1;
                            }
                        }
                    }
                    catch (FormatException ex)
                    {
                        codePort = -1;
                    }
                }
                else
                {
                    if (exeName == "ssltrojan")
                    {
                        SSLPortExe.GenerateInstanceOrNullFromArguments(p, Rectangle.Empty, (object)os, target);
                        return(0);
                    }
                    os.write(LocaleTerms.Loc("No port number Provided"));
                    return(0);
                }
            }
            if (!flag && PortExploits.needsPort[index2])
            {
                try
                {
                    for (int index3 = 0; index3 < target.ports.Count; ++index3)
                    {
                        if (target.ports[index3] == codePort)
                        {
                            targetPort = target.ports[index3];
                            break;
                        }
                    }
                }
                catch
                {
                    os.write(LocaleTerms.Loc("No port number Provided"));
                    return(0);
                }
                if (targetPort == -1)
                {
                    os.write(LocaleTerms.Loc("Target Port is Closed"));
                    return(0);
                }
                if (index1 <= -1)
                {
                    index1 = targetPort;
                }
                if (index1 == 211 && targetPort != 21 || exeFileData != PortExploits.crackExeData[index1] && exeFileData != PortExploits.crackExeDataLocalRNG[index1])
                {
                    os.write(LocaleTerms.Loc("Target Port running incompatible service for this executable"));
                    return(0);
                }
            }
            os.launchExecutable(exeName, exeFileData, targetPort, p, p[0]);
            return(1);
        }