/// <summary>
        /// Parses Credentials from a file into a usable data structure
        /// </summary>
        /// <param name="fileFormat">Format of CSV-File</param>
        /// <param name="stringTable">String table</param>
        /// <returns>A list of parsed Credentials</returns>
        public IEnumerable <Credential> ParseCredentialsFromFile(CSVFileFormat fileFormat, List <List <string> > stringTable)
        {
            List <Credential> credentials = new List <Credential>();

            for (int index = 1; index < stringTable.Count; index++)
            {
                if (stringTable[index].All(x => string.IsNullOrEmpty(x)))
                {
                    continue;
                }

                Dictionary <Credential.UserDataType, string> dictionary =
                    new Dictionary <Credential.UserDataType, string>();

                foreach (string dataType in stringTable[0])
                {
                    int column = stringTable[0].IndexOf(dataType);
                    KeyValuePair <Credential.UserDataType, string>?keyValuePair =
                        ParseUserDataType(fileFormat, dataType, stringTable[index][column]);

                    if (keyValuePair != null)
                    {
                        dictionary.Add(keyValuePair.GetValueOrDefault().Key, keyValuePair.GetValueOrDefault().Value);
                    }
                }

                if (dictionary.Count != 0)
                {
                    credentials.Add(new Credential(dictionary));
                }
            }

            return(credentials);
        }
        /// <summary>
        /// Gets the HTTP content type header associated with the given CSVFile format
        /// </summary>
        /// <returns>The type string</returns>
        /// <param name="csvfileFormat">CSVFile Format</param>
        public static string ContentTypeString(this CSVFileFormat csvfileFormat)
        {
            if (!s_formatContentTypes.TryGetValue(csvfileFormat, out string contentType))
            {
                return(null);
            }

            return(contentType);
        }
        /// <summary>
        /// Parses a UserDataType and data into a KeyValuePair
        /// </summary>
        /// <param name="fileFormat">File Format</param>
        /// <param name="userDataType">UserDataType like LoginName or Password</param>
        /// <param name="data">Value</param>
        /// <returns>Null if information could not be parsed. Else a valid KeyValuePair</returns>
        public KeyValuePair <Credential.UserDataType, string>?ParseUserDataType(
            CSVFileFormat fileFormat,
            string userDataType,
            string data)
        {
            Credential.UserDataType?dataType = null;

            if (fileFormat == CSVFileFormat.KeePass)
            {
                switch (userDataType)
                {
                case "Account":
                    dataType = Credential.UserDataType.Title;
                    break;

                case "Login Name":
                    dataType = Credential.UserDataType.Email;
                    break;

                case "Password":
                    dataType = Credential.UserDataType.Password;
                    break;

                case "Web Site":
                    dataType = Credential.UserDataType.Website;
                    break;

                case "Comments":
                    dataType = null;
                    break;

                default:
                    throw new ArgumentException(
                              "This UserDataType is invalid in a '{0}' file!",
                              fileFormat.ToString());
                }
            }
            else if (fileFormat == CSVFileFormat.Dashlane)
            {
                throw new NotSupportedException("Dashlane is not supported yet!");
            }

            if (dataType == null)
            {
                return(null);
            }

            return(new KeyValuePair <Credential.UserDataType, string>(dataType.GetValueOrDefault(), data));
        }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:HostpitalAllocation.Providers.CSVFile.Interface.HttpCSVFileStream"/> class.
 ///
 /// </summary>
 /// <param name="formFile">Form file.</param>
 /// <param name="format">Format.</param>
 private HttpCSVFileStream(IFormFile formFile, CSVFileFormat format)
 {
     _httpFileStream = formFile;
     Format          = format;
 }
示例#5
0
        /// <summary>
        /// Read/Update the content of the file
        /// </summary>
        /// <returns>true if successful</returns>
        /// <exception cref="FormatException">Airodump-ng CSV format unknown</exception>
        public override bool Read()
        {
            // Reset parsing status
            this.ParseSuccess = false;

            // Get the content of the file
            string[] content = this.getStrippedFileContent();

            // Get file format
            this._fileFormat = this.getFormat(content);

            if (this._fileFormat == CSVFileFormat.Unknown)
            {
                throw new FormatException("Airodump-ng CSV format unknown");
            }

            // Parse AP ...
            int i = 2; // Start at line 3 (skipping header)
            for (; i < content.Length && !string.IsNullOrEmpty(content[i]); i++) 
            {
                string [] splitted = content[i].Split(',');

                switch (this._fileFormat)
                {
                    case CSVFileFormat.v0X:
                        if (splitted.Length < 11)
                        {
                            continue;
                        }
                        break;

                    case CSVFileFormat.v1X:
                        if (splitted.Length < 15)
                        {
                            continue;
                        }
                        break;
                }
                AccessPoint ap = new AccessPoint();
                ap.BSSID = splitted[0].Trim();
                ap.FirstTimeSeen = this.parseDateTime(splitted[1]);
                ap.LastTimeSeen = this.parseDateTime(splitted[2]);
                ap.Channel = int.Parse(splitted[3].Trim());
                ap.MaxRate = double.Parse(splitted[4].Trim());
                ap.Privacy = splitted[5].Trim();

                switch (this._fileFormat)
                {
                    case CSVFileFormat.v0X:
                        ap.Power = int.Parse(splitted[6].Trim());
                        ap.Beacons = long.Parse(splitted[7].Trim());
                        ap.DataFrames = ulong.Parse(splitted[8].Trim());
                        ap.IP = splitted[9].Replace(" ", "");
                        ap.ESSID = splitted[10].Substring(1); // TODO: Improve it because it may contain a ','
                        ap.ESSIDLength = (byte)ap.ESSID.Length;
                        break;

                    case CSVFileFormat.v1X:
                        ap.Cipher = splitted[6].Trim();
                        ap.Authentication = splitted[7].Trim();
                        ap.Power = int.Parse(splitted[8].Trim());
                        ap.Beacons = long.Parse(splitted[9].Trim());
                        ap.DataFrames = ulong.Parse(splitted[10].Trim());
                        ap.IP = splitted[11].Replace(" ", "");
                        ap.ESSIDLength = byte.Parse(splitted[12].Trim());
                        ap.ESSID = splitted[13].Substring(1); // TODO: Improve it because it may contain a ','
                        ap.Key = splitted[14];
                        break;
                }

                // Add AP to the list
                this.addAccessPoint(ap);
            }

            // ... Parse stations

            i += 2; // Skip station header
            for (; i < content.Length && !string.IsNullOrEmpty(content[i]); i++)
            {
                string[] splitted = content[i].Split(',');

                // Skip to the next if not long enough
                if (splitted.Length < 6)
                {
                    continue;
                }

                // Parse station information
                Station sta = new Station();
                sta.StationMAC = splitted[0].Trim();
                sta.FirstTimeSeen = this.parseDateTime(splitted[1]);
                sta.LastTimeSeen = this.parseDateTime(splitted[2]);
                sta.Power = int.Parse(splitted[3].Trim());
                sta.NbPackets = ulong.Parse(splitted[4].Trim());
                sta.BSSID = splitted[5].Trim();

                // Get probed ESSID list
                if (splitted.Length > 6 && splitted[6] != "")
                {
                    List<string> list = new List<string>();
                    for (int j = 6; j < splitted.Length; j++)
                    {
                        // There's always a whitespace character before
                        list.Add(splitted[j].Substring(1));
                    }
                    sta.ProbedESSIDsList = list.ToArray();
                }
                else
                {
                    sta.ProbedESSIDs = string.Empty;
                }

                // Add station to the list
                this.addStation(sta);
            }

            // Link them together
            this.LinkAPClients();

            // Parsing was successful
            this.ParseSuccess = true;

            return this.ParseSuccess;
        }
示例#6
0
        /// <summary>
        /// Read/Update the content of the file
        /// </summary>
        /// <returns>true if successful</returns>
        /// <exception cref="FormatException">Airodump-ng CSV format unknown</exception>
        public override bool Read()
        {
            // Reset parsing status
            this.ParseSuccess = false;

            // Get the content of the file
            string[] content = this.getStrippedFileContent();

            // Get file format
            this._fileFormat = this.getFormat(content);

            if (this._fileFormat == CSVFileFormat.Unknown)
            {
                throw new FormatException("Airodump-ng CSV format unknown");
            }

            // Parse AP ...
            int i = 2; // Start at line 3 (skipping header)

            for (; i < content.Length && !string.IsNullOrEmpty(content[i]); i++)
            {
                string [] splitted = content[i].Split(',');

                switch (this._fileFormat)
                {
                case CSVFileFormat.v0X:
                    if (splitted.Length < 11)
                    {
                        continue;
                    }
                    break;

                case CSVFileFormat.v1X:
                    if (splitted.Length < 15)
                    {
                        continue;
                    }
                    break;
                }
                AccessPoint ap = new AccessPoint();
                ap.BSSID         = splitted[0].Trim();
                ap.FirstTimeSeen = this.parseDateTime(splitted[1]);
                ap.LastTimeSeen  = this.parseDateTime(splitted[2]);
                ap.Channel       = int.Parse(splitted[3].Trim());
                ap.MaxRate       = double.Parse(splitted[4].Trim());
                ap.Privacy       = splitted[5].Trim();

                switch (this._fileFormat)
                {
                case CSVFileFormat.v0X:
                    ap.Power       = int.Parse(splitted[6].Trim());
                    ap.Beacons     = long.Parse(splitted[7].Trim());
                    ap.DataFrames  = ulong.Parse(splitted[8].Trim());
                    ap.IP          = splitted[9].Replace(" ", "");
                    ap.ESSID       = splitted[10].Substring(1); // TODO: Improve it because it may contain a ','
                    ap.ESSIDLength = (byte)ap.ESSID.Length;
                    break;

                case CSVFileFormat.v1X:
                    ap.Cipher         = splitted[6].Trim();
                    ap.Authentication = splitted[7].Trim();
                    ap.Power          = int.Parse(splitted[8].Trim());
                    ap.Beacons        = long.Parse(splitted[9].Trim());
                    ap.DataFrames     = ulong.Parse(splitted[10].Trim());
                    ap.IP             = splitted[11].Replace(" ", "");
                    ap.ESSIDLength    = byte.Parse(splitted[12].Trim());
                    ap.ESSID          = splitted[13].Substring(1); // TODO: Improve it because it may contain a ','
                    ap.Key            = splitted[14];
                    break;
                }

                // Add AP to the list
                this.addAccessPoint(ap);
            }

            // ... Parse stations

            i += 2; // Skip station header
            for (; i < content.Length && !string.IsNullOrEmpty(content[i]); i++)
            {
                string[] splitted = content[i].Split(',');

                // Skip to the next if not long enough
                if (splitted.Length < 6)
                {
                    continue;
                }

                // Parse station information
                Station sta = new Station();
                sta.StationMAC    = splitted[0].Trim();
                sta.FirstTimeSeen = this.parseDateTime(splitted[1]);
                sta.LastTimeSeen  = this.parseDateTime(splitted[2]);
                sta.Power         = int.Parse(splitted[3].Trim());
                sta.NbPackets     = ulong.Parse(splitted[4].Trim());
                sta.BSSID         = splitted[5].Trim();

                // Get probed ESSID list
                if (splitted.Length > 6 && splitted[6] != "")
                {
                    List <string> list = new List <string>();
                    for (int j = 6; j < splitted.Length; j++)
                    {
                        // There's always a whitespace character before
                        list.Add(splitted[j].Substring(1));
                    }
                    sta.ProbedESSIDsList = list.ToArray();
                }
                else
                {
                    sta.ProbedESSIDs = string.Empty;
                }

                // Add station to the list
                this.addStation(sta);
            }

            // Link them together
            this.LinkAPClients();

            // Parsing was successful
            this.ParseSuccess = true;

            return(this.ParseSuccess);
        }
 /// <summary>
 /// Gets the file extension associated with the given CSVFile format
 /// </summary>
 /// <returns>The extension.</returns>
 /// <param name="csvfileformat">CSVFile format.</param>
 public static string FileExtension(this CSVFileFormat csvfileFormat)
 {
     return("." + csvfileFormat.ToString().ToLower());
 }
 public MemoryCSVFileStream(byte[] csvfileData, DateTime timestamp, CSVFileFormat format)
 {
     _csvfileData = csvfileData;
     TimeStamp    = timestamp;
     Format       = format;
 }