From e24fadd1ebd7cf58306df5639347d455dedccfce Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 28 Jun 2019 17:28:41 +0200 Subject: [PATCH 1/2] Add ConnectionLoop modification --- TShock.4.OTAPI.sln | 27 ++++++- TShock.Modifications.Bootstrapper/Program.cs | 2 + .../ConnectionLoop.cs | 45 ++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ ...TShock.Modifications.ConnectionLoop.csproj | 72 +++++++++++++++++++ .../packages.config | 6 ++ 6 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 TShock.Modifications.ConnectionLoop/ConnectionLoop.cs create mode 100644 TShock.Modifications.ConnectionLoop/Properties/AssemblyInfo.cs create mode 100644 TShock.Modifications.ConnectionLoop/TShock.Modifications.ConnectionLoop.csproj create mode 100644 TShock.Modifications.ConnectionLoop/packages.config diff --git a/TShock.4.OTAPI.sln b/TShock.4.OTAPI.sln index 65b61b4c7..20a5b84e0 100644 --- a/TShock.4.OTAPI.sln +++ b/TShock.4.OTAPI.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.156 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrariaServerAPI", "TerrariaServerAPI\TerrariaServerAPI.csproj", "{6877506E-ADC6-4142-98A6-79E4FA02855A}" EndProject @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShock.Modifications.SSC", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShock.Modifications.Platform", "TShock.Modifications.Platform\TShock.Modifications.Platform.csproj", "{AC441C8A-EA6B-416F-9961-FA944131AFB6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShock.Modifications.ConnectionLoop", "TShock.Modifications.ConnectionLoop\TShock.Modifications.ConnectionLoop.csproj", "{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -138,8 +140,29 @@ Global {AC441C8A-EA6B-416F-9961-FA944131AFB6}.Release|x64.Build.0 = Release|Any CPU {AC441C8A-EA6B-416F-9961-FA944131AFB6}.Release|x86.ActiveCfg = Release|Any CPU {AC441C8A-EA6B-416F-9961-FA944131AFB6}.Release|x86.Build.0 = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x64.ActiveCfg = Debug|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x64.Build.0 = Debug|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x86.ActiveCfg = Debug|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x86.Build.0 = Debug|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|Any CPU.ActiveCfg = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|Any CPU.Build.0 = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x64.ActiveCfg = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x64.Build.0 = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x86.ActiveCfg = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x86.Build.0 = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|Any CPU.Build.0 = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x64.ActiveCfg = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x64.Build.0 = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x86.ActiveCfg = Release|Any CPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {34CE5BEA-93DE-4029-BD2E-85A2D6AFB362} + EndGlobalSection EndGlobal diff --git a/TShock.Modifications.Bootstrapper/Program.cs b/TShock.Modifications.Bootstrapper/Program.cs index 7dd8e2b60..9dcaee04d 100644 --- a/TShock.Modifications.Bootstrapper/Program.cs +++ b/TShock.Modifications.Bootstrapper/Program.cs @@ -69,6 +69,8 @@ static void Main(string[] args) PackModifications = true }; patcher.Run(); + + Console.ReadKey(); } } } diff --git a/TShock.Modifications.ConnectionLoop/ConnectionLoop.cs b/TShock.Modifications.ConnectionLoop/ConnectionLoop.cs new file mode 100644 index 000000000..72cff00dc --- /dev/null +++ b/TShock.Modifications.ConnectionLoop/ConnectionLoop.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using Mono.Cecil; +using Mono.Cecil.Cil; +using OTAPI.Patcher.Engine; +using OTAPI.Patcher.Engine.Extensions.ILProcessor; +using OTAPI.Patcher.Engine.Modification; +using Terraria; + +namespace TShock.Modifications.ConnectionLoop +{ + /// + /// This modification is used to inject a network check which ensures that the sever does not enter an infinite loop + /// when clients repeatedly connect and disconnect. + /// + public sealed class ConnectionLoop : ModificationBase + { + /// + public override IEnumerable AssemblyTargets => + new[] {"OTAPI, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null"}; + + /// + public override string Description => "Patching connection loop exploit..."; + + /// + public override void Run() + { + var checkBytes = Method(() => Terraria.NetMessage.CheckBytesDirect(0)); + + // Find the proper instruction range => if (i < num2) + var targetInstruction = checkBytes.Body.Instructions.Single(i => + i.OpCode == OpCodes.Blt_S && i.Previous.OpCode == OpCodes.Ldloc_S && + i.Previous.Previous.OpCode == OpCodes.Ldloc_3); + checkBytes.Body.GetILProcessor().InsertAfter(targetInstruction, + new[] + { + Instruction.Create(OpCodes.Ldloc_S, checkBytes.Body.Variables[4]), + Instruction.Create(OpCodes.Ldc_I4_0), + Instruction.Create(OpCodes.Beq_S, targetInstruction.Operand as Instruction) + }.AsEnumerable()); + } + } +} diff --git a/TShock.Modifications.ConnectionLoop/Properties/AssemblyInfo.cs b/TShock.Modifications.ConnectionLoop/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..83ecb647b --- /dev/null +++ b/TShock.Modifications.ConnectionLoop/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TShock.Modifications.ConnectionLoop")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TShock.Modifications.ConnectionLoop")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b466e59a-8a07-46b1-b7c7-33dbc3a0c375")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TShock.Modifications.ConnectionLoop/TShock.Modifications.ConnectionLoop.csproj b/TShock.Modifications.ConnectionLoop/TShock.Modifications.ConnectionLoop.csproj new file mode 100644 index 000000000..4f881f710 --- /dev/null +++ b/TShock.Modifications.ConnectionLoop/TShock.Modifications.ConnectionLoop.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {B466E59A-8A07-46B1-B7C7-33DBC3A0C375} + Library + Properties + TShock.Modifications.ConnectionLoop + TShock.Modifications.ConnectionLoop + v4.5.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll + + + ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll + + + ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll + + + ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\OTAPI.2.0.0.32\lib\net451\OTAPI.dll + + + ..\prebuilt\OTAPI.Patcher.Engine.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TShock.Modifications.ConnectionLoop/packages.config b/TShock.Modifications.ConnectionLoop/packages.config new file mode 100644 index 000000000..bfcd31206 --- /dev/null +++ b/TShock.Modifications.ConnectionLoop/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From d77d2de12122d226e9be1110a069b50a7ca248a5 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 1 Aug 2019 00:23:44 +0200 Subject: [PATCH 2/2] Remove Console.ReadKey() call in order to pass the AV build --- TShock.Modifications.Bootstrapper/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TShock.Modifications.Bootstrapper/Program.cs b/TShock.Modifications.Bootstrapper/Program.cs index 9dcaee04d..7dd8e2b60 100644 --- a/TShock.Modifications.Bootstrapper/Program.cs +++ b/TShock.Modifications.Bootstrapper/Program.cs @@ -69,8 +69,6 @@ static void Main(string[] args) PackModifications = true }; patcher.Run(); - - Console.ReadKey(); } } }