private async Task handleGetInfo(HttpProcessor p) { var info = await MyInfo.Fetch(api.getConsole()); p.writeSuccess(); await p.outputStream.WriteLineAsync(info.Json.ToString()); }
public override void Set(IConfig cfg, vhAPI api) { Pause = () => { hackTimer.Change(0, Timeout.Infinite); cfg.logger.Log("*** Stopping IPAttack"); }; Resume = () => { Set(cfg, api); cfg.logger.Log("*** Resuming IPAttack"); }; if (hackTimer != null) { hackTimer.Dispose(); hackTimer = null; } config = cfg; Period = cfg.ipAttackPolling; var console = api.getConsole(); hackTimer = new Timer(async(o) => await timerCallback(o), new object[] { cfg, api, console }, TimeSpan.Zero, Period); safeScan = cfg.safeScan; InternalPause = () => { if (hackTimer != null) { cfg.logger.Log("*** PAUSING IP ATTACK"); hackTimer.Change(TimeSpan.Zero, pause); } }; InternalResume = () => { if (hackTimer != null) { cfg.logger.Log("*** RESUMING IP ATTACK"); hackTimer.Change(TimeSpan.Zero, Period); } }; }
public void Init(IConfig cfg, IConfigParser parser) { config = cfg; configParser = parser; try { var builder = new vhAPIBuilder().useConfig(cfg); api = builder.getAPI(); timerInfo = new Timer((o) => { var info = MyInfo.Fetch(api.getConsole()).Result; lock (this) { jsonInfo = info.Json; } }, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); } catch (Exception exc) { config.logger.Log($"Error creating vhAPI: {exc.Message}"); } }
public override void Set(IConfig cfg, vhAPI api) { upd = new Update(cfg); Pause = () => { hackTimer.Change(0, Timeout.Infinite); cfg.logger.Log("*** STOPPING IP SCANNER"); }; Resume = () => { Set(cfg, api); cfg.logger.Log("*** RESUMING IP SCANNER"); }; if (hackTimer != null) { hackTimer.Dispose(); hackTimer = null; } config = cfg; var console = api.getConsole(); Period = cfg.ipScannerPolling; InternalPause = () => { if (hackTimer != null) { cfg.logger.Log("*** PAUSING IP SCANNER"); hackTimer.Change(TimeSpan.Zero, pause); } }; InternalResume = () => { if (hackTimer != null) { cfg.logger.Log("*** RESUMING IP SCANNER"); hackTimer.Change(TimeSpan.Zero, Period); } }; hackTimer = new Timer(async(o) => { //// TEST: skip during contest //if (vhUtils.IsContestRunning()) // return; // if not on upgrade we'll skip attack if (!vhUtils.IsContestRunning() && UpgradeMgr.Instance.CurStatus != UpgradeMgr.Status.Upgrade) { return; } if (!Monitor.TryEnter(localSemaphore)) { return; } // wait a random bit Thread.Sleep(rand.Next(0, (int)Period.TotalSeconds / 5) * 1000); try { // first make a search for new ips to hack var img = await console.FindHostsAndAttack(); // then looks in the syslog if there's some ips that needs to be pwn3d if (MyInfo.LastUpdInfo != null // if contest running we don't attack syslog cause we don't know if they're watched && !vhUtils.IsContestRunning()) { var myIp = MyInfo.LastUpdInfo.IP; var sysLog = (await upd.getSysLog())["data"] as JArray; foreach (var log in sysLog) { if ((string)log["from"] == myIp) { var newIp = (string)log["to"]; if (newIp != "Anonymous") { IPs dbIp = null; if (!cfg.persistanceMgr.IpExist(newIp)) { var js = await console.ScanIp(newIp); if (js == null) { cfg.logger.Log("********* BLOCKED BY FBI!!! **********"); Log.ContestLogger.Log("ScanIp {0} error: BLOCKED BY FBI!!! ", newIp); return; } dbIp = new IPs(js); cfg.persistanceMgr.AddIp(dbIp); } else { dbIp = cfg.persistanceMgr.GetIp(newIp); } // we'll sit and wait 10 minutes before trying to attack, just to not stir up suspicions... dbIp.LastAttack = DateTime.Now - TimeSpan.FromMinutes(10); cfg.persistanceMgr.UpdateIp(dbIp); } } } } } catch (Exception e) { cfg.logger.Log(e.ToString()); } finally { Monitor.Exit(localSemaphore); } } , null, TimeSpan.Zero, Period); safeScan = cfg.safeScan; }
public IResponse GetResponse(IRequest request) { //var response = request.CreateResponse(HttpStatusCode.OK, "Welcome"); //response.Body = new MemoryStream(); //response.ContentType = "text/plain"; //var buffer = Encoding.UTF8.GetBytes("Hello world"); //response.Body.Write(buffer, 0, buffer.Length); //response.Body.Position = 0; IResponse response = null; var path = request.Uri.LocalPath.ToLower(); var mainPage = $"http://{config.vhServerHost}:{config.vhServerPort}"; if (request.Method == "GET") { if (path == "/hack") { response = request.CreateResponse(HttpStatusCode.OK, "Nack"); } else if (path == "/") { response = request.CreateResponse(HttpStatusCode.OK, "Index"); var htmlTmpl = new StreamReader(File.OpenRead("HTML/index.html")).ReadToEnd(); var template = new Antlr3.ST.StringTemplate(htmlTmpl, typeof(TemplateLexer)); template.SetAttribute("config_form", $"{mainPage}/config_form"); template.SetAttribute("iplist", $"{mainPage}/iplist"); var html = template.ToString(); setResponse(ref response, html); response.ContentType = "text/html"; } else if (path == "/info") { response = request.CreateResponse(HttpStatusCode.OK, "GET Info request"); //var info = MyInfo.Fetch(api.getConsole()).Result; lock (this) { //response.Body = new MemoryStream(); //response.ContentType = "text/json"; //var buffer = Encoding.UTF8.GetBytes(jsonInfo.ToString()); //response.Body.Write(buffer, 0, buffer.Length); //response.Body.Position = 0; setResponse(ref response, jsonInfo.ToString()); } } else if (path == "/config") { response = request.CreateResponse(HttpStatusCode.OK, "GET Config request"); var json = $@" {{ ""waitstep"": ""{config.waitstep}"", ""winchance"": ""{config.winchance}"", ""maxFirewall"": ""{config.maxFirewall}"", ""finishAllFor"": ""{config.finishAllFor}"", ""maxAntivirus"": ""{config.maxAntivirus}"", ""hackIfNotAnonymous"": ""{config.hackIfNotAnonymous}"" ""ipAttackPaused"": ""{config.ipAttackPaused}"" ""ipScannerPaused"": ""{config.ipScannerPaused}"" ""hackBotNetPaused"": ""{config.hackBotNetPaused}"" ""hackTheDevPaused"": ""{config.hackTheDevPaused}"" ""getImgBy"": ""{config.getImgBy}"" }}"; setResponse(ref response, json); } else if (path == "/config_form") { response = request.CreateResponse(HttpStatusCode.OK, "GET Config Form request"); var htmlTmpl = new StreamReader(File.OpenRead("HTML/config.html")).ReadToEnd(); //response.Body = File.OpenRead("HTML/config.html"); var template = new Antlr3.ST.StringTemplate(htmlTmpl, typeof(TemplateLexer)); template.SetAttribute("mainPage", mainPage); template.SetAttribute("waitstep", config.waitstep); template.SetAttribute("winchance", config.winchance); template.SetAttribute("maxFirewall", config.maxFirewall); template.SetAttribute("maxAntivirus", config.maxAntivirus); template.SetAttribute("finishAllFor", config.finishAllFor); template.SetAttribute("hackIfNotAnonymous", config.hackIfNotAnonymous ? "checked" : "uchecked"); template.SetAttribute("ipAttackPaused", config.ipAttackPaused ? "checked" : "uchecked"); template.SetAttribute("ipScannerPaused", config.ipScannerPaused ? "checked" : "uchecked"); template.SetAttribute("hackBotNetPaused", config.hackBotNetPaused ? "checked" : "uchecked"); template.SetAttribute("hackTheDevPaused", config.hackTheDevPaused ? "checked" : "uchecked"); template.SetAttribute("getImgByScore", config.getImgBy == 0 ? "selected" : ""); template.SetAttribute("getImgByReputation", config.getImgBy == 1 ? "selected" : ""); template.SetAttribute("pcOrAttack", config.pcOrAttack); var html = template.ToString(); setResponse(ref response, html); response.ContentType = "text/html"; } else if (path == "/iplist") { var now = DateTime.Now; var ips = config.persistanceMgr.GetIps() .Where(ip => now - ip.LastAttack > TimeSpan.FromHours(1)) .OrderByDescending(ip => ip.Money) .ThenBy(ip => ip.LastAttack) .Take(20); var iplistTpl = new Antlr3.ST.StringTemplate(new StreamReader(File.OpenRead("HTML/iplist.html")).ReadToEnd() , typeof(TemplateLexer)); var sb = new StringBuilder(); var ipTplStr = new StreamReader(File.OpenRead("HTML/iptemplate.html")).ReadToEnd(); foreach (var ip in ips) { var ipTpl = new Antlr3.ST.StringTemplate(ipTplStr, typeof(TemplateLexer)); ipTpl.SetAttribute("ip", ip.IP); ipTpl.SetAttribute("lastUpd", ip.LastUpdate.ToString("ddd dd MMM yyyy hh:mm:ss")); ipTpl.SetAttribute("money", $"{ip.Money:C}"); var s = ipTpl.ToString(); sb.Append(s); } var iplist = sb.ToString(); iplistTpl.SetAttribute("iptable", iplist); iplistTpl.SetAttribute("mainPage", mainPage); response = request.CreateResponse(HttpStatusCode.OK, "GET IP list request"); setResponse(ref response, iplistTpl.ToString()); response.ContentType = "text/html"; } } else if (request.Method == "POST") { if (path == "/config") { try { using (var rd = new StreamReader(request.Body)) { var json = rd.ReadToEnd(); if (request.ContentType == "application/x-www-form-urlencoded") { var dict = System.Web.HttpUtility.ParseQueryString(json); json = new JavaScriptSerializer().Serialize( dict.Keys.Cast <string>() .ToDictionary(k => k, k => dict[k])); } var cfg = JObject.Parse(json); if (cfg["hackIfNotAnonymous"] != null) { if ((string)cfg["hackIfNotAnonymous"] == "on") { cfg["hackIfNotAnonymous"] = "true"; } } if (cfg["ipAttackPaused"] != null) { if ((string)cfg["ipAttackPaused"] == "on") { cfg["ipAttackPaused"] = "true"; IPAttack.Instance.Pause(); } } else { cfg["ipAttackPaused"] = "false"; IPAttack.Instance.Resume(); } if (cfg["ipScannerPaused"] != null) { if ((string)cfg["ipScannerPaused"] == "on") { cfg["ipScannerPaused"] = "true"; IPScanner.Instance.Pause(); } } else { cfg["ipScannerPaused"] = "false"; IPScanner.Instance.Resume(); } if (cfg["hackBotNetPaused"] != null) { if ((string)cfg["hackBotNetPaused"] == "on") { cfg["hackBotNetPaused"] = "true"; HackBotNet.Instance.Pause(); } } else { cfg["hackBotNetPaused"] = "false"; HackBotNet.Instance.Resume(); } if (cfg["hackTheDevPaused"] != null) { if ((string)cfg["hackTheDevPaused"] == "on") { cfg["hackTheDevPaused"] = "true"; HackTheDev.Instance.Pause(); } } else { cfg["hackTheDevPaused"] = "false"; HackTheDev.Instance.Resume(); } if (cfg["getImgBy"] != null) { var val = (int)cfg["getImgBy"]; // 0 = score, 1 = reputation } if (cfg["pcOrAttack"] != null) { config.pcOrAttack = (int)cfg["pcOrAttack"]; } if (configParser != null) { configParser.ParseConfig(cfg); } } response = request.CreateResponse(HttpStatusCode.OK, "POST config request"); response.Redirect($"http://{config.vhServerHost}:{config.vhServerPort}/config_form"); } catch (Exception exc) { response = request.CreateResponse(HttpStatusCode.BadRequest, $"Error parsing content: {exc.Message}"); } } else if (path == "/attackip") { using (var rd = new StreamReader(request.Body)) { var data = rd.ReadToEnd(); var dict = System.Web.HttpUtility.ParseQueryString(data); var ip = dict["ip"]; var action = dict["action"]; if (action == "attack") { var res = api.getConsole().AttackIp(ip).Result; } else if (action == "remove") { config.persistanceMgr.RemoveIp(ip); } response = request.CreateResponse(HttpStatusCode.OK, "POST config request"); response.Redirect($"http://{config.vhServerHost}:{config.vhServerPort}/iplist"); } } } else { config.logger.Log("Only GET and POST method are supported"); response = request.CreateResponse(HttpStatusCode.BadRequest, $"Unsupported method {request.Method}"); } if (response == null) { response = request.CreateResponse(HttpStatusCode.BadRequest, $"Wrong {request.Method} path: {path}"); } return(response); }
public override void Set(IConfig cfg, vhAPI api) { logger = cfg.logger; _api = api; Pause = () => { hackTimer.Change(0, Timeout.Infinite); cfg.logger.Log("*** STOPPING UPGRADE MANAGER"); }; Resume = () => { Set(cfg, api); cfg.logger.Log("*** RESUMING UPGRADE MANAGER"); }; if (hackTimer != null) { hackTimer.Dispose(); hackTimer = null; } var console = api.getConsole(); var upd = new Update(cfg); hackTimer = new Timer( async(o) => { if (!Monitor.TryEnter(localSemaphore)) { return; } try { var info = await MyInfo.Fetch(console); var tasks = await upd.getTasks(); // upgrade botnet PCs anyway await doUpgradePc(info, upd); var curStatus = CurrentStatus(info, tasks); if (curStatus == Status.Idle) { return; } if (curStatus == Status.Upgrade) { await doUpgrade(info, upd, cfg, tasks); } if (curStatus == Status.EndTasks) { await doBoost(info, upd, cfg, tasks); } } catch (Exception e) { cfg.logger.Log(e.ToString()); } finally { Monitor.Exit(localSemaphore); } } , null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); }
public void Init(IConfig config, vhAPI api) { console = api.getConsole(); cfg = config; ProportionalUpgradeStrategy.api = api; }
public override void Set(IConfig cfg, vhAPI api) { Pause = () => { hackTimer.Change(0, Timeout.Infinite); cfg.logger.Log("*** Pausing HackTheDev"); }; Resume = () => { Set(cfg, api); cfg.logger.Log("*** Resuming HackTheDev"); }; InternalPause = () => { if (hackTimer != null) { cfg.logger.Log("*** PAUSING HackTheDev"); hackTimer.Change(TimeSpan.Zero, pause); } }; InternalResume = () => { if (hackTimer != null) { cfg.logger.Log("*** RESUMING HackTheDev"); hackTimer.Change(TimeSpan.Zero, Period); } }; if (hackTimer != null) { hackTimer.Dispose(); hackTimer = null; } var console = api.getConsole(); var lastAttackTm = DateTime.MinValue; hackTimer = new Timer( async(o) => { if (DateTime.Now - lastAttackTm <= TimeSpan.FromHours(1)) { return; } if (!Monitor.TryEnter(this)) { return; } try { var s = await console.AttackIp("127.0.0.1"); if (s == 0) { lastAttackTm = DateTime.Now; } } catch (Exception e) { cfg.logger.Log(e.ToString()); } finally { Monitor.Exit(this); } } , null, TimeSpan.Zero, cfg.hackDevPolling); _chat = new vhChat(cfg, api); _chat.PrivateMessage += async(rule, email, nick, msg) => { System.Console.ForegroundColor = ConsoleColor.Blue; //cfg.logger.Log($"{DateTime.Now} {nick}({rule}): {msg}"); cfg.logger.Log($"VHCHAT - {nick}[{email}]({rule}): {msg}"); System.Console.ResetColor(); // if message from bot try to hack the dev (maybe it has been reset) if (nick == "vHackXTBot") { var s = await console.AttackIp("127.0.0.1"); if (s == 0) { lastAttackTm = DateTime.Now; } } }; _chat.Run(); }