//*********************************************************************
// //
// SQL Power Injector 1.2 Copyright (c) 2006-2007 Francois Larouche //
// //
// Author : francois.larouche@sqlpowerinjector.com //
// Web Site: www.sqlpowerinjector.com //
// //
//*******************************************************************//
using System;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
namespace SQLPowerInjector{
/// <summary>
/// Summary description for Session.
/// </summary>
[XmlRootAttribute("SQL_Power_Injector_Session", Namespace="", IsNullable=false)]
public class Session
{
#region Members
#region Private
private string _sessionName;
private string _fileName;
private DateTime _creationDate;
private bool _useCookie;
private bool _autoDetectEncoding;
private string _loadedUri;
private int _currentSubmitSelectedIndex;
private Database_Type _databaseType;
private Method_Injection _method;
private Technique_Injection _technique;
private bool _replaceSpace;
private bool _waitforDelay;
private byte _delaySecond;
private bool _useTop;
private uint _topValue;
private Type_Injection _typeInjection;
private bool _distinct;
private Type_Parameters_Test _parameterToTestType;
private string _positiveAnswer;
private uint _startingLength;
private uint _startingCount;
private byte _numberThreads;
private int _currentCharacterSetSelectedIndex;
private bool _characterSetCaseSensitive;
private bool _useVariableRange;
private string[] _variableRangeList;
private ArrayList _HtmlForms;
private ArrayList _cookiesInject;
private int _htmlMessageLength;
private string _sqlPositiveInjectionResult;
private bool _trapErrorString;
#endregion
#region Constants
const byte NUMBER_MAX_DELAYSECONDS = 255;
const uint NUMBER_MAX_TOP = 1000000;
const uint STARTING_LENGTH_MAX = 100000000;
const uint STARTING_COUNT_MAX = 100000000;
const byte NUMBER_THREADS_MAX = 50;
const int HTML_MESSAGE_LENGTH_MAX = 100000000;
const int VARIABLE_RANGE_LIST_SIZE_MAX_ARRAY = 100000;
#endregion
#endregion
#region Public Enums
public enum Database_Type
{
SQL_Server = 0,
Oracle = 1,
MySqlUnder411 = 2,
MySql411AndOver = 3,
Sybase = 4,
DB2 = 5
}
public enum Method_Injection
{
POST = 1,
GET = 2
}
public enum Technique_Injection
{
Normal = 1,
Blind = 2
}
public enum Type_Injection
{
Word = 1,
Length = 2,
Count = 3
}
public enum Type_Parameters_Test
{
String = 1,
Cookie = 2
}
#endregion
#region Constructor
public Session()
{
_sessionName = "";
_fileName = "";
_creationDate = DateTime.Now;
_useCookie = true;
_autoDetectEncoding = true;
_loadedUri = "";
_currentSubmitSelectedIndex = 0;
_databaseType = Database_Type.SQL_Server;
_method = Method_Injection.POST;
_technique = Technique_Injection.Normal;
_replaceSpace = false;
_waitforDelay = false;
_delaySecond = 0;
_useTop = false;
_topValue = 1;
_typeInjection = Type_Injection.Word;
_distinct = false;
_parameterToTestType = Type_Parameters_Test.String;
_positiveAnswer = "";
_startingLength = 50;
_startingCount = 100;
_numberThreads = 1;
_currentCharacterSetSelectedIndex = 0;
_characterSetCaseSensitive = false;
_useVariableRange = false;
_HtmlForms = new ArrayList();
_cookiesInject = new ArrayList();
_htmlMessageLength = 255;
_sqlPositiveInjectionResult = "";
_trapErrorString = false;
}
#endregion
#region Public Attributes
[XmlAttributeAttribute(DataType="Name")]
public string SessionName
{
get { return _sessionName; }
set { _sessionName = value; }
}
[XmlIgnoreAttribute()]
public string FileName
{
get { return _fileName; }
set { _fileName = value; }
}
[XmlAttributeAttribute(DataType="date")]
public DateTime CreationDate
{
get { return _creationDate; }
set { _creationDate = value; }
}
public bool UseCookie
{
get { return _useCookie; }
set { _useCookie = value; }
}
public bool AutoDetectEncoding
{
get { return _autoDetectEncoding; }
set { _autoDetectEncoding = value; }
}
public string LoadedUri
{
get { return _loadedUri; }
set { _loadedUri = value; }
}
public int CurrentSubmitSelectedIndex
{
get { return _currentSubmitSelectedIndex; }
set
{
if(value >= 0)
_currentSubmitSelectedIndex = value;
else
_currentCharacterSetSelectedIndex = 0;
}
}
[XmlElementAttribute("DatabaseType", typeof(Database_Type))]
public Database_Type DatabaseType
{
get { return _databaseType; }
set { _databaseType = value; }
}
public Method_Injection Method
{
get { return _method; }
set { _method = value; }
}
public Technique_Injection Technique
{
get { return _technique; }
set { _technique = value; }
}
public bool ReplaceSpace
{
get { return _replaceSpace; }
set { _replaceSpace = value; }
}
public bool WaitforDelay
{
get { return _waitforDelay; }
set { _waitforDelay = value; }
}
public byte DelaySecond
{
get { return _delaySecond; }
set
{
if(value <= NUMBER_MAX_DELAYSECONDS)
_delaySecond = value;
else
_delaySecond = 0;
}
}
public bool UseTop
{
get { return _useTop; }
set { _useTop = value; }
}
public uint TopValue
{
get { return _topValue; }
set
{
if(value <= NUMBER_MAX_TOP)
_topValue = value;
else
_topValue = 1;
}
}
public Type_Injection TypeInjection
{
get { return _typeInjection; }
set { _typeInjection = value; }
}
public bool Distinct
{
get { return _distinct; }
set { _distinct = value; }
}
public Type_Parameters_Test ParametersToTestType
{
get { return _parameterToTestType; }
set { _parameterToTestType = value; }
}
public string PositiveAnswer
{
get { return _positiveAnswer; }
set { _positiveAnswer = value; }
}
public uint StartingLength
{
get { return _startingLength; }
set
{
if(value <= STARTING_LENGTH_MAX)
_startingLength = value;
else
_startingLength = 50;
}
}
public uint StartingCount
{
get { return _startingCount; }
set
{
if(value <= STARTING_COUNT_MAX)
_startingCount = value;
else
_startingCount = 100;
}
}
public byte NumberThreads
{
get { return _numberThreads; }
set
{
if(value <= NUMBER_THREADS_MAX)
_numberThreads = value;
else
_numberThreads = 1;
}
}
public int CurrentCharacterSetSelectedIndex
{
get { return _currentCharacterSetSelectedIndex; }
set
{
if(value >= 0)
_currentCharacterSetSelectedIndex = value;
else
_currentCharacterSetSelectedIndex = 0;
}
}
public bool CharacterSetCaseSensitive
{
get { return _characterSetCaseSensitive; }
set { _characterSetCaseSensitive = value; }
}
public bool UseVariableRange
{
get { return _useVariableRange; }
set { _useVariableRange = value; }
}
[XmlArray ("VariableRangeList"), XmlArrayItem("Variable", typeof(string))]
public string[] VariableRangeList
{
get { return _variableRangeList; }
set { _variableRangeList = value; }
}
[XmlArray ("HtmlForms"), XmlArrayItem("HtmlForm", typeof(HTMLForm))]
public ArrayList HtmlForms
{
get { return _HtmlForms; }
set { _HtmlForms = value; }
}
[XmlArray ("CookieInjects"), XmlArrayItem("CookieInject", typeof(CCookieInject))]
public ArrayList CookiesInject
{
get { return _cookiesInject; }
set { _cookiesInject = value; }
}
public int HtmlMessageLength
{
get { return _htmlMessageLength; }
set
{
if(value <= HTML_MESSAGE_LENGTH_MAX)
_htmlMessageLength = value;
else
_htmlMessageLength = 255;
}
}
public string SqlPositiveInjectionResult
{
get { return _sqlPositiveInjectionResult; }
set { _sqlPositiveInjectionResult = value; }
}
public bool TrapErrorString
{
get { return _trapErrorString; }
set { _trapErrorString = value; }
}
#endregion
public static bool SaveSession(Session SessionToSave, string XMLFileName)
{
bool sessionSavedSuccessfully = false;
sessionSavedSuccessfully = Utilities.SerializeXML(SessionToSave, XMLFileName);
return sessionSavedSuccessfully;
}
public static Session LoadSession(string XMLFileName)
{
return LoadSerializedSession(XMLFileName);
}
private static Session LoadSerializedSession(string XMLFileName)
{
Session loadedSession = new Session();
TextReader txrTextReader = null;
try
{
XmlSerializer xserDocumentSerializer = new XmlSerializer(typeof(Session));
txrTextReader = new StreamReader(XMLFileName);
loadedSession = (Session)xserDocumentSerializer.Deserialize(txrTextReader);
}
catch(InvalidOperationException ex)
{
throw(new MyException(ex.Message, ex.InnerException));
}
catch(Exception ex)
{
throw(ex);
}
finally
{
//Make sure to close the file even if an exception is raised...
if (txrTextReader != null)
txrTextReader.Close();
}
return loadedSession;
}
}
}
|