Skip to content

Commit

Permalink
Domains Form added (#1)
Browse files Browse the repository at this point in the history
* added Domains View Form to select Domains to be tested
  • Loading branch information
aviadHCL authored Oct 23, 2023
1 parent 08d708f commit 781b0eb
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 18 deletions.
5 changes: 2 additions & 3 deletions AppScanImportUrls/AppScanImportUrls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="AppScanSDK">
<HintPath>C:\Program Files (x86)\HCL\AppScan Standard\AppScanSDK.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\Program Files (x86)\HCL\AppScan Standard\AppScanSDK.dll</HintPath>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -35,7 +34,7 @@
<PropertyGroup>
<TargetDir>$(TargetDir)$(TargetName)</TargetDir>
</PropertyGroup>
<Exec Command="rd /s /q &quot;$(TargetDir)&quot;&#xD;&#xA;mkdir &quot;$(TargetDir)&quot;&#xD;&#xA;&#xD;&#xA;copy &quot;$(OutputPath)\AppScanImportUrls.dll&quot; &quot;$(TargetDir)\&quot;&#xD;&#xA;copy &quot;$(OutputPath)\info.xml&quot; &quot;$(TargetDir)\&quot;&#xD;&#xA;&#xD;&#xA;del &quot;$(OutputPath)\$(TargetName).zip&quot;&#xD;&#xA;&#xD;&#xA;echo &quot;Note: to build this project, you need to have 7-zip installed (http://www.7-zip.org/)&quot;&#xD;&#xA;&quot;C:\Program Files\7-Zip\7z.exe&quot; a -tzip &quot;$(OutputPath)\$(TargetName).zip&quot; -r &quot;$(TargetDir)&quot;&#xD;&#xA;" />
<Exec Command="rd /s /q &quot;$(TargetDir)&quot;&#xD;&#xA;mkdir &quot;$(TargetDir)&quot;&#xD;&#xA;&#xD;&#xA;copy &quot;$(OutputPath)\AppScanImportUrls.dll&quot; &quot;$(TargetDir)\&quot;&#xD;&#xA;copy &quot;$(OutputPath)\info.xml&quot; &quot;$(TargetDir)\&quot;&#xD;&#xA;&#xD;&#xA;&quot;$(OutputPath)\ExtensionSigner.exe&quot; -s &quot;C:\appscan-standard-import-urls\AppScanImportUrls\Output\AppScanImportUrls&quot;&#xD;&#xA;&#xD;&#xA;del &quot;$(OutputPath)\$(TargetName).zip&quot;&#xD;&#xA;&#xD;&#xA;echo &quot;Note: to build this project, you need to have 7-zip installed (http://www.7-zip.org/)&quot;&#xD;&#xA;&quot;C:\Program Files\7-Zip\7z.exe&quot; a -tzip &quot;$(OutputPath)\$(TargetName).zip&quot; -r &quot;$(TargetDir)&quot;&#xD;&#xA;" />
</Target>

</Project>
90 changes: 90 additions & 0 deletions AppScanImportUrls/DomainsViewForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions AppScanImportUrls/DomainsViewForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace AppScanImportUrls
{
public partial class DomainsViewForm : Form
{
private HashSet<string> _uniqueDomains = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
public List<string> SelectedDomains = new List<string>();

public DomainsViewForm(string filename)
{
InitializeComponent();
// Read URLs from a file and extract unique domains
if (!File.Exists(filename))
{
MessageBox.Show("File not found: " + filename);
return;
}
foreach (var line in File.ReadLines(filename))
{
try
{
Uri uri = new Uri(line);
string domain = uri.Host;
_uniqueDomains.Add(domain);
}
catch (UriFormatException)
{
Console.WriteLine($"Invalid URL: {line}");
}
}

// Populate the ListBox with unique domains
foreach (var domain in _uniqueDomains)
{
DomainsListBox.Items.Add(domain);
}
}


private void button1_Click(object sender, EventArgs e)
{
// Get selected domains from the ListBox
foreach (var item in DomainsListBox.SelectedItems)
{
SelectedDomains.Add(item.ToString());
}

// For debug purpose uncomment the following:
//string selectedDomainsText = string.Join(", ", SelectedDomains);
//MessageBox.Show("Selected domains: " + selectedDomainsText);

DialogResult = DialogResult.OK;
Close();
}

private void DomainsViewForm_Load(object sender, EventArgs e)
{

}

}
}
120 changes: 120 additions & 0 deletions AppScanImportUrls/DomainsViewForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
36 changes: 28 additions & 8 deletions AppScanImportUrls/ImportUrls.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using AppScan;
using AppScan.Configuration;
using AppScan.Extensions;
using AppScan.Scan.Events;

Expand All @@ -26,7 +28,6 @@ public void Load(IAppScan appScan, IAppScanGui appScanGui, string extensionDir)
{
_appScan = appScan;
_appScanGui = appScanGui;

_menuItem = new MenuItem<EventArgs>("Import URLs from file", ImportUrlsDialog);
_appScanGui.ExtensionsMenu.Add(_menuItem);

Expand All @@ -48,17 +49,28 @@ private void ScanOnStateChanged(object sender, StateChangedEventArgs e)
/// <param name="args"></param>
private void ImportUrlsDialog(EventArgs args)
{
string file = "";
using (var form = new ImportUrlsForm())
{
form.chkUseCookies.Enabled = _appScan.Scan.ScanData.Config.SessionManagement.DetectedCookies.Any();

var result = form.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(form.txtFilename.Text))
file = form.txtFilename.Text;
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(file))
{
Uri baseUri = String.IsNullOrWhiteSpace(form.txtBaseUrl.Text) ?
null :
new Uri(form.txtBaseUrl.Text.Trim());
ImportUrlsFromFile(form.txtFilename.Text, baseUri, form.chkUseCookies.Checked);
ImportUrlsFromFile(file, baseUri, form.chkUseCookies.Checked);
}
}

using (var domainsForm=new DomainsViewForm(file))
{
var result = domainsForm.ShowDialog();
if (result == DialogResult.OK)
{
AddDomains(domainsForm.SelectedDomains);
}
}

Expand Down Expand Up @@ -96,13 +108,21 @@ private void ImportExd(XDocument doc)

// Load from memory to AppScan
_appScan.Scan.RequestRecorder.ImportRecordedRequests(stream, false);
_appScan.Scan.RequestRecorder.Analyse();
_appScanGui.RefreshMainFormGui();

}
}


/// <summary>
/// adds the list of domains into AppScan additional servers
/// </summary>
/// <param name="domainsList">the list of domains to be added</param>
public void AddDomains(List<string> domainsList)
{
foreach (var domain in domainsList)
{
_appScan.Scan.ScanData.Config.AdditionalServers.Add(domain);
}
_appScan.Scan.RequestRecorder.Analyse();
_appScanGui.RefreshMainFormGui();
}

public ExtensionVersionInfo GetUpdateData(Edition edition, Version targetAppVersion)
{
Expand Down
Loading

0 comments on commit 781b0eb

Please sign in to comment.