Esempio n. 1
0
        public void MoveFile(string dir, string desdir, TaskFileiInfo tfi)
        {
            DirectoryInfo di = new DirectoryInfo(dir);

            desdir = Path.Combine(desdir, di.Name);
            tfi.TaskInfofilepath = desdir;
            try
            {
                if (!Directory.Exists(dir))
                {
                    ILog.log.Error($"{dir}文件路径不存在");
                    return;
                }

                di.MoveTo(desdir);

                ILog.log.Debug($"把{dir}拷贝到{desdir }");
                //压缩文件中除了 json和task 文件其他的文件保存在 zipDIc 字典中  key value
                DirectoryInfo des = new DirectoryInfo(desdir);
                foreach (FileInfo f in des.GetFiles())
                {
                    if (Path.GetExtension(f.FullName) != ".json" && Path.GetExtension(f.FullName) != ".task")
                    {
                        tfi.filepath.filepath = f.FullName;
                        tfi.filepath.filename = f.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                ILog.log.Error($"错误信息:{ex }");
                Directory.Delete(desdir);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 读取解压的文件夹
        /// </summary>
        private void ReadCompression(string compressionPath, string scoreDir)
        {
            DirectoryInfo root = new DirectoryInfo(compressionPath);
            TaskFileiInfo tfi  = new TaskFileiInfo();
            ZipClass      zc   = new ZipClass();

            ILog.log.Debug("开始读取文件夹内的文件");
            foreach (FileInfo f in root.GetFiles())
            {
                if (Path.GetExtension(f.FullName) == ".json")
                {
                    tfi.jsdata = ReadJson(f.FullName);
                }
                else if (Path.GetExtension(f.FullName) == ".task")
                {
                    tfi.taskinfo = ReadTask(f.FullName);
                }
                else if (Path.GetExtension(f.FullName) != ".json" && Path.GetExtension(f.FullName) != ".task")
                {
                    zc.filename  = f.Name;
                    zc.filepath  = f.FullName;
                    tfi.filepath = zc;
                }
            }
            DataClassification(tfi);
            MoveFile(compressionPath, scoreDir, tfi);
        }
Esempio n. 3
0
        private void DeleteFile(TaskFileiInfo key, Dictionary <TaskFileiInfo, JObject> JsonData)
        {
            if (XmlData.IsDelete == true)//要删除文件
            {
                switch (key.DealResult)
                {
                case ApiStatus.success:
                    Directory.Delete(key.TaskInfofilepath, true);
                    JsonData.Remove(key);
                    break;

                case ApiStatus.fail:
                    Directory.Move(key.TaskInfofilepath, this.te.errorfile);
                    JsonData.Remove(key);
                    break;

                case ApiStatus.unknown:

                    break;

                default:
                    break;
                }
            }
            else//不删除完成的文件
            {
                switch (key.DealResult)
                {
                case ApiStatus.success:
                    //Directory.Move(key.TaskInfofilepath, this.te.tempfile);
                    JsonData.Remove(key);
                    break;

                case ApiStatus.fail:
                    Directory.Move(key.TaskInfofilepath, this.te.errorfile);
                    JsonData.Remove(key);
                    break;

                case ApiStatus.unknown:

                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 4
0
        public TaskFileiInfo IsSuccess(string result, TaskFileiInfo key, TaskFileiInfo tfi)
        {
            JObject jo = (JObject)JsonConvert.DeserializeObject(result);

            if (!jo.ContainsKey("msg")) //返回成功
            {
                if (jo["status"].ToString() == "success")
                {
                    key = tfi;
                }
            }
            else if (jo["msg"].ToString() == "用户信息已过期") //返回用户信息过期
            {
                GetCookie();                            //用户信息过期不用删除
            }
            else
            {
                key = tfi;
            }
            mm.WriteFile(result, tfi);
            return(key);
        }
Esempio n. 5
0
        private void DataClassification(TaskFileiInfo tfi)
        {
            switch (tfi.taskinfo.tasktype.type)
            {
            case "1":
                if (!StaticDataObject.AddData.ContainsKey(tfi))
                {
                    StaticDataObject.AddData.Add(tfi, tfi.jsdata);
                }
                break;

            case "2":
                if (!StaticDataObject.DeleteData.ContainsKey(tfi))
                {
                    StaticDataObject.DeleteData.Add(tfi, tfi.jsdata);
                }
                break;

            case "3":
                if (!StaticDataObject.UpdateData.ContainsKey(tfi))
                {
                    StaticDataObject.UpdateData.Add(tfi, tfi.jsdata);
                }
                break;

            case "4":
                if (!StaticDataObject.SelectData.ContainsKey(tfi))
                {
                    StaticDataObject.SelectData.Add(tfi, tfi.jsdata);
                }
                break;

            default:
                break;
            }
            ILog.log.Debug($"写入文件到集合中去{tfi.jsdata}");
        }
Esempio n. 6
0
        /// <summary>
        /// 读取api返回的信息 处理后进行第二次的上传文件
        /// 此函数用于增加漏洞
        /// </summary>
        public string ReadResultDeal(string result, string filePath, TaskFileiInfo taskid)
        {
            var res = "";

            try
            {
                JObject job = (JObject)JsonConvert.DeserializeObject(result);
                //重要的得到id 和文件名
                string status = job["status"].ToString();
                if (status == "success")
                {
                    ILog.log.Debug($"上传第一次数据返回的信息:{job}");
                    string id       = job["data"]["id"].ToString();
                    string filename = job["data"]["evilfile"].ToString().Trim('/');//evilfile   "file_a22e624b-6b38-4b8a-8c66-cba4d95c747a.7z"
                    filename = filename.Replace("_", "__");
                    string data = string.Format("id={0}&evilfile={1}", id, filename);
                    string aa   = filename.Split('_')[2].ToString() + "=";
                    filePath = string.Format("{0}" + filePath, aa);
                    string updateApi = wa.updateApi;
                    string url       = updateApi.Replace("table", "exploit");
                    string newUrl    = url.Replace("id", id);
                    res = HttpHleper.PostExploit(newUrl, data, filePath, DCookieContainer);
                }
                else
                {
                    ILog.log.Debug($"上传文件之前的发送json给api返回的是失败的状态:{result}");
                    taskid.DealResult = ApiStatus.fail;
                }
            }
            catch (Exception ex)
            {
                ILog.log.Error($"错误信息:{ex}====ReadResultDeal中处理出现了问题");
                taskid.DealResult = ApiStatus.fail;
            }
            return(res);
        }
Esempio n. 7
0
        public void WriteFile(string result, TaskFileiInfo tfi)
        {
            JObject jo = (JObject)JsonConvert.DeserializeObject(result);

            if (!System.IO.Directory.Exists(this.OutFilePath))
            {
                System.IO.Directory.CreateDirectory(this.OutFilePath);
            }

            if (tfi.taskinfo.tasktype.type == "2")
            {
                var DataFile = Path.Combine(this.OutFilePath, Guid.NewGuid().ToString() + ".gmpt_deletetask");
                using (StreamWriter sw = new StreamWriter(DataFile))
                {
                    string errorinfo;
                    string status;
                    string datatime = "captime:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);


                    if (jo.ContainsKey("status"))
                    {
                        if (jo["status"].ToString() == "success")
                        {
                            status    = "status:" + "3";
                            errorinfo = "errorinfo:" + "NULL";
                        }
                        else
                        {
                            status    = "status:" + "2";
                            errorinfo = "errorinfo:" + "返回信息失败";
                        }
                        sw.WriteLine(status);
                        sw.WriteLine(errorinfo);
                    }

                    string taskid = "taskid:" + tfi.taskinfo.taskid;
                    sw.WriteLine(datatime);
                    sw.WriteLine(taskid);
                }
            }
            else
            {
                var DataFile = Path.Combine(this.OutFilePath, Guid.NewGuid().ToString() + ".gmpt_task");
                using (StreamWriter sw = new StreamWriter(DataFile))
                {
                    string errorinfo;
                    string status;
                    if (jo.ContainsKey("status"))
                    {
                        if (jo["status"].ToString() == "success")
                        {
                            status    = "status:" + "3";
                            errorinfo = "errorinfo:" + "NULL";
                        }
                        else
                        {
                            status    = "status:" + "2";
                            errorinfo = "errorinfo:" + "返回信息失败";
                        }
                        sw.WriteLine(status);
                        sw.WriteLine(errorinfo);
                    }
                    else if (jo.ContainsKey("msg"))
                    {
                        status    = "status:" + "2";
                        errorinfo = "errorinfo:" + "用户信息已过期";
                        sw.WriteLine(status);
                        sw.WriteLine(errorinfo);
                    }
                    if (jo.ContainsKey("id"))
                    {
                        string gmptid = null;

                        gmptid = "gmptid:" + jo["id"].ToString();

                        sw.WriteLine(gmptid);
                    }
                    //时间
                    string datatime = "captime:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
                    sw.WriteLine(datatime);
                    //taskid
                    string taskid = "taskid:" + tfi.taskinfo.taskid;
                    sw.WriteLine(taskid);

                    string data = "data:" + tfi.taskinfo.dataid;
                    sw.WriteLine(data);
                    string type = null;
                    switch (tfi.taskinfo.tasktype.table)
                    {
                    case "1":
                        type = "type:" + "gmpt_server";
                        break;

                    case "2":
                        type = "type:" + "gmpt_exploit";
                        break;

                    case "3":
                        type = "type:" + "gmpt_worktime";
                        break;
                    }
                    sw.WriteLine(type);
                    sw.Close();
                }
            }
        }
Esempio n. 8
0
        public void UpdatePostApi(Dictionary <TaskFileiInfo, JObject> JsonData)
        {
            if (JsonData.Count != 0)
            {
                TaskFileiInfo key       = null;
                string        updateApi = null;
                string        id        = null;
                string        result    = null;
                foreach (var item in JsonData)
                {
                    id        = item.Value["id"].ToString();
                    updateApi = wa.updateApi;

                    switch (item.Key.taskinfo.tasktype.table)
                    {
                    case "1":
                        updateApi = updateApi.Replace("table", "server");
                        updateApi = updateApi.Replace("id", id);
                        result    = HttpHleper.PostUrl(updateApi, item.Value.ToString(), DCookieContainer);
                        if (ResultIsSuccess(result) == true)
                        {
                            ILog.log.Debug($"{updateApi}请求成功返回的信息{result}");
                            item.Key.DealResult = ApiStatus.success;
                        }
                        else
                        {
                            ILog.log.Debug($"{updateApi}请求失败返回的信息{result}");
                            item.Key.DealResult = ApiStatus.fail;
                        }
                        break;

                    case "2":
                        updateApi = updateApi.Replace("table", "exploit");
                        updateApi = updateApi.Replace("id", id);
                        result    = HttpHleper.PostUrl(updateApi, item.Value.ToString(), DCookieContainer);
                        if (ResultIsSuccess(result) == true)
                        {
                            if (item.Key.filepath.filepath != null)
                            {
                                result = ReadResultDeal(result, item.Key.filepath.filepath, item.Key);
                                if (ResultIsSuccess(result) == true)
                                {
                                    ILog.log.Debug($"{updateApi}请求成功返回的信息{result}");
                                    item.Key.DealResult = ApiStatus.success;
                                }
                                else
                                {
                                    ILog.log.Debug($"{updateApi}请求失败返回的信息{result}");
                                    item.Key.DealResult = ApiStatus.fail;
                                }
                            }
                        }
                        else
                        {
                            ILog.log.Debug($"{updateApi}请求失败返回的信息{result}");
                            item.Key.DealResult = ApiStatus.fail;
                        }
                        break;

                    case "3":
                        updateApi = updateApi.Replace("table", "worktime");
                        updateApi = updateApi.Replace("id", id);
                        result    = HttpHleper.PostUrl(updateApi, item.Value.ToString(), DCookieContainer);
                        if (ResultIsSuccess(result) == true)
                        {
                            ILog.log.Debug($"{updateApi}请求成功返回的信息{result}");
                            item.Key.DealResult = ApiStatus.success;
                        }
                        else
                        {
                            ILog.log.Debug($"{updateApi}请求失败返回的信息{result}");
                            item.Key.DealResult = ApiStatus.fail;
                        }
                        break;

                    default:
                        break;
                    }


                    if (result != null)
                    {
                        key = IsSuccess(result, key, item.Key);
                    }
                }
                if (key != null)
                {
                    DeleteFile(key, JsonData);
                }
            }
        }
Esempio n. 9
0
//----------------------------------------------------------------------------
        #region  api请求相关的函数
        public void AddPostApi(Dictionary <TaskFileiInfo, JObject> JsonData)
        {
            if (JsonData.Count != 0)
            {
                string        addApi = null;
                TaskFileiInfo key    = null;
                string        result = null;
                foreach (var item in JsonData)
                {
                    addApi = wa.addApi;
                    switch (item.Key.taskinfo.tasktype.table)
                    {
                    case "1":
                        addApi = addApi.Replace("table", "server");
                        result = HttpHleper.PostMoths(addApi, item.Value, null, DCookieContainer);
                        if (ResultIsSuccess(result) == true)
                        {
                            ILog.log.Debug($"{addApi}请求成功返回的信息{result}");
                            item.Key.DealResult = ApiStatus.success;
                        }
                        else
                        {
                            ILog.log.Debug($"{addApi}请求失败返回的信息{result}");
                            item.Key.DealResult = ApiStatus.fail;
                        }

                        break;

                    case "2":
                        addApi = addApi.Replace("table", "exploit");
                        ILog.log.Trace($"===urls地址======================={addApi}=============================");
                        result = HttpHleper.PostUrl(addApi, item.Value.ToString(), DCookieContainer);

                        if (ResultIsSuccess(result) == true)
                        {
                            if (item.Key.filepath.filepath != null)
                            {
                                result = ReadResultDeal(result, item.Key.filepath.filepath, item.Key);
                                if (ResultIsSuccess(result) == true)
                                {
                                    ILog.log.Debug($"{addApi}请求成功返回的信息{result}");
                                    item.Key.DealResult = ApiStatus.success;
                                }
                                else
                                {
                                    ILog.log.Debug($"{addApi}请求失败返回的信息{result}");
                                    item.Key.DealResult = ApiStatus.fail;
                                }
                            }
                        }
                        else
                        {
                            ILog.log.Debug($"{addApi}请求失败返回的信息{result}");
                            item.Key.DealResult = ApiStatus.fail;
                        }

                        break;

                    case "3":
                        addApi = addApi.Replace("table", "worktime");
                        result = HttpHleper.PostUrl(addApi, item.Value.ToString(), DCookieContainer);
                        if (ResultIsSuccess(result) == true)
                        {
                            ILog.log.Debug($"{addApi}请求成功返回的信息{result}");
                            item.Key.DealResult = ApiStatus.success;
                        }
                        else
                        {
                            ILog.log.Debug($"{addApi}请求失败返回的信息{result}");
                            item.Key.DealResult = ApiStatus.fail;
                        }
                        break;

                    default:
                        break;
                    }

                    if (result != null)
                    {
                        //这里返回key 的信息无论成功是否都删除
                        key = IsSuccess(result, key, item.Key);
                    }
                }
                if (null != key)
                {
                    DeleteFile(key, JsonData);
                }
            }
        }