c# 批量添加awvs默认扫描

  1 using Newtonsoft.Json;
  2 using Newtonsoft.Json.Linq;
  3 using System;
  4 using System.IO;
  5 using System.Net;
  6 using System.Net.Security;
  7 using System.Security.Cryptography.X509Certificates;
  8 using System.Text;
  9 using System.Windows.Forms;
 10
 11 namespace 批量添加AWVS默认扫描
 12 {
 13     public partial class Form1 : Form
 14     {
 15         public Form1()
 16         {
 17             InitializeComponent();
 18         }
 19
 20         string urls;
 21
 22         private void button1_Click(object sender, EventArgs e)
 23         {
 24             //文件类型过滤
 25             openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
 26             if (openFileDialog1.ShowDialog() == DialogResult.OK)
 27             {
 28                 //得到文件路径全名
 29                 this.textBox1.Text = openFileDialog1.FileName;
 30
 31                 string strfromtxt = File.ReadAllText(this.textBox1.Text, Encoding.GetEncoding("GB2312"));
 32
 33                 urls = strfromtxt;
 34
 35                 string[] ab = strfromtxt.Split(new string[] { "\r\n" }, StringSplitOptions.None);
 36
 37                 MessageBox.Show("共上传" + ab.Length + "个目标");
 38             }
 39         }
 40
 41         public static int GoAwvs(string url, string a)
 42         {
 43             //if (url.IndexOf("443") > 0)
 44             //{
 45             //    url = "https://" + url;
 46             //}
 47             //else
 48             //{
 49             //    url = "http://" + url;
 50             //}
 51
 52             url = "http://" + url;
 53
 54             //固定cooke 目前解决COOKIE获取
 55             string cookie = "ui_session=" + a;
 56             //第一步  获取target_id
 57             string param = "{\"address\":\"" + url + "\",\"description\":\"\",\"criticality\":\"10\"}";
 58
 59             string target_id = GetTarget_id(cookie, param, a);
 60
 61             //string param2 = "{\"target_id\":\"" + target_id + "\",\"profile_id\":\"11111111-1111-1111-1111-111111111113\",\"schedule\":{\"disable\":false,\"start_date\":null,\"time_sensitive\":false},\"ui_session_id\":\"" + cookie + "\"}";
 62             string param2 = "{\"target_id\":\"" + target_id + "\",\"profile_id\":\"11111111-1111-1111-1111-111111111111\",\"schedule\":{\"disable\":false,\"start_date\":null,\"time_sensitive\":false}}";
 63             if (target_id == null)
 64             {
 65                 return 0;
 66             }
 67             else
 68             {
 69                 if (GoScan(cookie, param2, a) == null)
 70                 {
 71                     return 1;
 72                 }
 73                 else
 74                 {
 75                     return 2;
 76                 }
 77
 78             }
 79
 80         }
 81         public static string GetTarget_id(string cookie, string param, string a)
 82         {
 83             try
 84             {
 85                 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 86                 string strURL = "https://localhost:3443/api/v1/targets";
 87                 System.Net.HttpWebRequest request;
 88                 request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
 89                 request.Method = "POST";
 90                 request.Host = "localhost:3443";
 91                 request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";
 92                 request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
 93                 request.Headers.Add("Cookie", cookie);
 94                 request.ContentType = "application/json;charset=UTF-8";
 95                 request.Referer = "https://localhost:3443/";
 96                 request.Headers.Add("X-Auth", a);
 97                 string paraUrlCoded = param;
 98                 byte[] payload;
 99                 payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
100                 request.ContentLength = payload.Length;
101                 Stream writer = request.GetRequestStream();
102                 writer.Write(payload, 0, payload.Length);
103                 writer.Close();
104                 System.Net.HttpWebResponse response;
105                 response = (System.Net.HttpWebResponse)request.GetResponse();
106                 System.IO.Stream s;
107                 s = response.GetResponseStream();
108
109                 string StrDate = "";
110
111                 StreamReader Reader = new StreamReader(s, Encoding.UTF8);
112                 StrDate = Reader.ReadToEnd();
113
114
115
116                 JObject newObj1 = (JObject)JsonConvert.DeserializeObject(StrDate);
117                 return newObj1["target_id"].ToString();
118             }
119             catch (Exception ex)
120             {
121
122                 return null;
123             }
124
125         }
126         public static string GoScan(string cookie, string param, string a)
127         {
128
129             try
130             {
131                 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
132                 string strURL = "https://localhost:3443/api/v1/scans";
133                 System.Net.HttpWebRequest request;
134                 request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
135                 request.Method = "POST";
136                 request.Host = "localhost:3443";
137                 //request.Headers.Add("Connection", "keep-alive");
138                 request.Headers.Add("Origin", "https://localhost:3443");
139                 request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";
140                 request.ContentType = "application/json;charset=UTF-8";
141                 request.Accept = "application/json, text/plain, */*";
142                 request.Headers.Add("X-Auth", a);
143                 request.Referer = "https://localhost:3443/";
144                 request.Headers.Add("Accept-Encoding", "gzip, deflate, br");
145                 request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4");
146                 request.Headers.Add("Cookie", cookie);
147                 string paraUrlCoded = param;
148                 byte[] payload;
149                 payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
150                 request.ContentLength = payload.Length;
151                 Stream writer = request.GetRequestStream();
152                 writer.Write(payload, 0, payload.Length);
153                 writer.Close();
154                 System.Net.HttpWebResponse response;
155                 response = (System.Net.HttpWebResponse)request.GetResponse();
156                 System.IO.Stream s;
157                 s = response.GetResponseStream();
158                 string StrDate = "";
159
160                 StreamReader Reader = new StreamReader(s, Encoding.UTF8);
161                 StrDate = Reader.ReadLine();
162
163
164
165                 return "OK!";
166             }
167             catch (Exception ex)
168             {
169
170                 return null;
171             }
172
173         }
174
175         public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
176         {   // 总是接受
177             return true;
178         }
179
180         private void button2_Click(object sender, EventArgs e)
181         {
182             int a = 0;//创建失败
183             int b = 0;//创建成功,添加扫描失败
184             int c = 0;//创建成功,添加扫描成功
185
186
187
188             if (string.IsNullOrEmpty(urls))
189             {
190                 MessageBox.Show("请先上传URL");
191                 return;
192             }
193             if (string.IsNullOrEmpty(this.textBox2.Text))
194             {
195                 MessageBox.Show("请输入cookie");
196                 return;
197             }
198
199             string[] ab = urls.Split(new string[] { "\r\n" }, StringSplitOptions.None);
200
201             foreach (var item in ab)
202             {
203                 int end = GoAwvs(item, this.textBox2.Text);
204
205                 if (end == 0)
206                 {
207                     a++;
208                 }
209                 else if (end == 1)
210                 {
211                     b++;
212                 }
213                 else if (end == 2)
214                 {
215                     c++;
216                 }
217
218             }
219
220             MessageBox.Show("创建失败" + a + "条," + "创建成功,添加扫描失败" + b + "条," + "创建成功,添加扫描成功" + c + "条");
221
222
223         }
224     }
225 }

原文地址:https://www.cnblogs.com/had3s/p/9755063.html

时间: 2024-11-06 21:41:07

c# 批量添加awvs默认扫描的相关文章

微信jssdk批量添加卡券接口

1)首先是官方接口文档: 1.批量添加卡券接口:https://mp.weixin.qq.com/wiki?action=doc&id=mp1421141115&t=0.08619731531288366&token=&lang=zh_CN#wxkq3 : 2.卡券扩展字段cardExt说明:https://mp.weixin.qq.com/wiki?action=doc&id=mp1421141115&t=0.08619731531288366&t

Lync Server 2010批量添加联系人并同步联系人

最近一直帮助朋友整理Lync Server 2010,总是听他抱怨说微软的Lync不能实现组织结构等方面的联系人列表,其实也不完全没办法实现,早在OCS的年代,OCS利用Restkit tool工具进行添加联系人列表,而到了Lync的时代虽然Restkit Tool工具还在,但是已然无法利用之前的方式进行批量添加联系人了,在网上有人表示利用LyncAddContacts.vbs这个工具进行批量添加,但是所有的文章只是把国外这个作者的写的东西照抄过来并且翻译一下就成为原创发布到网络上,本人觉得现在

struts2文件上传(单文件/批量添加)

单文件上传 1.导入上传需要jar包 2.建立UploadAction file是jsp页面的输入项的name相同,后面的两个属性的名称也是有规律的:(inputName+FileName/ContentType) 1 public class UploadAction extends ActionSupport{ 2 3 private static final long serialVersionUID = 1L; 4 private File file;//上传文件的本身 5 privat

android批量添加联系人

研究生期间就没写过Java代码了,这几天由于想做一个统计网页词频的工具,但是使用C++不是很方便,于是又用Java做了一个小工具.翻开电脑中以前的文件,发现之前还做过一个android中批量添加联系人的工具,瞬间感觉好亲切,也感叹时间过得好快,一眨眼研究生就快要过完了. 记得当初做这个批量添加联系人的工具是刚来读研时,一大堆新同学的手机号码需要添加,班长整理出来同学们的通讯录后就得一个一个输入联系人和号码到手机中,想想这罪可有的受,于是就想能不能让手机直接读取xls格式(Excel格式)的文件到

批量添加-fno-objc-arc

http://syxiaqj.github.io/2014/02/28/bee-learning-1/ 4.批量添加-fno-objc-arc 因为BeeFramework是一个非RAC的框架,现在Xcode5.0以后新建的工程,都默认是ARC工程,所以需要对BeeFramework进行混编处理. framework目录下的所有文件都需要在Build Phases中添加-fno-objc-arc,但是文件非常多,一个个添加,我相信,你会疯掉的.此时,你就需要用到这个小工具:xproj. 解压后,

Android批量添加联系人到通讯录

由于工作上的需要,把数据库中备份的联系人添加到通讯录,一般都有几百条记录,插入一条数据系统默认commit一次,这样效率就降低了,如果把所有的数据都添加进去后再commit效率就不一样,这就需要事务 没有添加事务的方法,每次添加一条记录 /** * 单条添加数据 * * @param contacts * @return */ public boolean add(Tb_contacts contacts) { SQLiteDatabase db = helper.getWritableData

Centos6配置samba服务器并批量添加用户和文件夹

一.需求 局域网内有若干用户,所有用户访问一个共享目录 每个用户在共享目录里有自己的文件夹 每个用户都可以读取其他人的文件夹 每个用户只能对自己的文件夹有写入权限 所有用户都属于filesgroup组 二.环境 服务器:Centos6 主机名:fileserver IP地址:192.168.1.2 用户端IP网段: 192.168.1.0/24 , 192.168.2.0/24 , 172.16.1.0/24 三.配置步骤 1.安装samba,备份原始配置文件,编辑配置文件 [[email pr

在CentOS下使用文件批量添加用户

在CentOS添加用户的方法是多样的,例如,使用useradd.passwd单个添加用户:使用脚本批量添加用 户:使用文件批量导入用户.本节介绍的是使用文件批量导入用户的方法. 环境介绍: [[email protected] ~]# uname -r 3.10.0-327.el7.x86_64 [[email protected] ~]# cat /etc/centos-release CentOS Linux release 7.2.1511 (Core) [[email protected

EF批量添加数据性能慢的问题的解决方案

//EF批量添加数据性能慢的问题的解决方案 public ActionResult BatchAdd() { using (var db = new ToneRoad.CEA.DbContext.DbContext()) { //**********************第一种解决方案 直接使用sql********************** string sqls = ""; for (int i = 0; i < 100000; i++) { sqls += "