@@ -797,7 +797,7 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
797797 }
798798
799799 Factory::getAgentFactory ()->getDB ()->beginTransaction ();
800- $ hashlist = new Hashlist (null , $ name , $ format , $ hashtype , 0 , $ separator , 0 , $ secret , $ hexsalted , $ salted , $ accessGroup ->getId (), '' , $ brainId , $ brainFeatures , 0 );
800+ $ hashlist = new Hashlist (null , $ name , $ format , $ hashtype , 0 , $ separator , 0 , $ secret , $ hexsalted , $ salted , $ accessGroup ->getId (), '' , $ brainId , $ brainFeatures , 0 , 0 , 0 , 0 , 0 , 0 );
801801 $ hashlist = Factory::getHashlistFactory ()->save ($ hashlist );
802802
803803 $ dataSource = "" ;
@@ -829,34 +829,60 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
829829 Factory::getAgentFactory ()->getDB ()->rollback ();
830830 throw new HttpError ("Hashlist has too many lines! " );
831831 }
832+
832833 $ file = fopen ($ tmpfile , "rb " );
833834 if (!$ file ) {
834835 throw new HttpError ("Failed to open file! " );
835836 }
837+
838+ if ($ format == DHashlistFormat::PLAIN && $ salted ) {
839+ // find out if the file contains a salt separator at all
840+ rewind ($ file );
841+
842+ $ saltSeparatorFound = false ;
843+ while (($ currentLine = fgets ($ file )) !== false ) {
844+ if (strpos ($ currentLine , $ saltSeparator ) !== false ) {
845+ $ saltSeparatorFound = true ;
846+ break ;
847+ }
848+ }
849+
850+ if ($ saltSeparatorFound === false ) {
851+ fclose ($ file );
852+ unlink ($ tmpfile );
853+ Factory::getAgentFactory ()->getDB ()->rollback ();
854+
855+ throw new HttpError ("Salted hashes separator not found at all in the hashlist! Hashlist not created. " );
856+ }
857+ }
858+ else {
859+ $ saltSeparator = "" ;
860+ }
861+
836862 Factory::getAgentFactory ()->getDB ()->commit ();
863+
837864 $ added = 0 ;
838865 $ preFound = 0 ;
866+ $ uploadedTotalLines = 0 ;
867+ $ uploadedEmptyLines = 0 ;
868+ $ uploadedValidHashes = 0 ;
869+ $ uploadedValidHashesWithoutExpectedSalt = 0 ;
870+ $ uploadedInvalidHashes = 0 ;
839871
840872 switch ($ format ) {
841873 case DHashlistFormat::PLAIN :
842- if ($ salted ) {
843- // find out if the first line contains field separator
844- rewind ($ file );
845- $ bufline = stream_get_line ($ file , 1024 );
846- if (strpos ($ bufline , $ saltSeparator ) === false ) {
847- throw new HttpError ("Salted hashes separator not found in file! " );
848- }
849- }
850- else {
851- $ saltSeparator = "" ;
852- }
853874 rewind ($ file );
875+
854876 Factory::getAgentFactory ()->getDB ()->beginTransaction ();
855877 $ values = array ();
856878 $ bufferCount = 0 ;
879+
857880 while (!feof ($ file )) {
858881 $ line = trim (fgets ($ file ));
882+ $ uploadedTotalLines ++;
883+
859884 if (strlen ($ line ) == 0 ) {
885+ $ uploadedEmptyLines ++;
860886 continue ;
861887 }
862888 $ hash = $ line ;
@@ -867,8 +893,12 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
867893 $ hash = substr ($ line , 0 , $ pos );
868894 $ salt = substr ($ line , $ pos + 1 );
869895 }
896+ else {
897+ $ uploadedValidHashesWithoutExpectedSalt ++;
898+ }
870899 }
871900 if (strlen ($ hash ) == 0 ) {
901+ $ uploadedEmptyLines ++;
872902 continue ;
873903 }
874904 //TODO: check hash length here
@@ -885,14 +915,18 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
885915 }
886916 }
887917 }
918+
888919 if ($ found == null ) {
889920 $ values [] = new Hash (null , $ hashlist ->getId (), $ hash , $ salt , "" , 0 , null , 0 , 0 );
890921 }
891922 else {
892923 $ values [] = new Hash (null , $ hashlist ->getId (), $ hash , $ salt , $ found ->getPlaintext (), time (), null , 1 , 0 );
893924 $ preFound ++;
894925 }
926+
895927 $ bufferCount ++;
928+ $ uploadedValidHashes ++;
929+
896930 if ($ bufferCount >= 10000 ) {
897931 $ result = Factory::getHashFactory ()->massSave ($ values );
898932 $ added += $ result ->rowCount ();
@@ -902,28 +936,43 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
902936 $ bufferCount = 0 ;
903937 }
904938 }
939+
905940 if (sizeof ($ values ) > 0 ) {
906941 $ result = Factory::getHashFactory ()->massSave ($ values );
907942 $ added += $ result ->rowCount ();
908943 }
944+
909945 fclose ($ file );
910946 unlink ($ tmpfile );
911- Factory::getHashlistFactory ()->mset ($ hashlist , [Hashlist::HASH_COUNT => $ added , Hashlist::CRACKED => $ preFound ]);
947+
948+ if ($ added === 0 ) {
949+ Factory::getAgentFactory ()->getDB ()->rollback ();
950+ Factory::getHashlistFactory ()->delete ($ hashlist );
951+ Factory::getAgentFactory ()->getDB ()->commit ();
952+ throw new HttpError ("No valid hashes found! Hashlist not created. " );
953+ }
954+
955+ Factory::getHashlistFactory ()->mset ($ hashlist , [Hashlist::HASH_COUNT => $ added , Hashlist::CRACKED => $ preFound , Hashlist::UPLOADED_TOTAL_LINES => $ uploadedTotalLines , Hashlist::UPLOADED_EMPTY_LINES => $ uploadedEmptyLines , Hashlist::UPLOADED_VALID_HASHES => $ uploadedValidHashes , Hashlist::UPLOADED_VALID_HASHES_WITHOUT_EXPECTED_SALT => $ uploadedValidHashesWithoutExpectedSalt , Hashlist::UPLOADED_VALID_HASHES => $ uploadedValidHashes ]);
912956 Factory::getAgentFactory ()->getDB ()->commit ();
913- Util::createLogEntry ("User " , $ user ->getId (), DLogEntry::INFO , "New Hashlist created: " . $ hashlist ->getHashlistName ());
957+ Util::createLogEntry ("User " , $ user ->getId (), DLogEntry::INFO , "New Hashlist created: " . $ hashlist ->getHashlistName () . " . Total lines: " . $ uploadedTotalLines . " Empty lines: " . $ uploadedEmptyLines . " Valid hashes: " . $ uploadedValidHashes . " Valid hashes without expected salt: " . $ uploadedValidHashesWithoutExpectedSalt . " Invalid hashes: " . $ uploadedInvalidHashes );
914958
915959 NotificationHandler::checkNotifications (DNotificationType::NEW_HASHLIST , new DataSet (array (DPayloadKeys::HASHLIST => $ hashlist )));
916960 break ;
917961 case DHashlistFormat::WPA :
918962 $ added = 0 ;
919963 $ values = [];
964+
920965 while (!feof ($ file )) {
966+ $ uploadedTotalLines ++;
967+
921968 if ($ hashlist ->getHashTypeId () == 2500 ) { // HCCAPX hashes
922969 $ data = fread ($ file , 393 );
923970 if (strlen ($ data ) == 0 ) {
971+ $ uploadedInvalidHashes ++;
924972 break ;
925973 }
926974 if (strlen ($ data ) != 393 ) {
975+ $ uploadedInvalidHashes ++;
927976 UI ::printError ("ERROR " , "Data file only contains " . strlen ($ data ) . " bytes! " );
928977 }
929978 // get the SSID
@@ -951,11 +1000,13 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
9511000 $ mac_cli = Util::bintohex ($ mac_cli );
9521001 $ hash = new HashBinary (null , $ hashlist ->getId (), $ mac_ap . SConfig::getInstance ()->getVal (DConfig::FIELD_SEPARATOR ) . $ mac_cli . SConfig::getInstance ()->getVal (DConfig::FIELD_SEPARATOR ) . Util::bintohex ($ network ), Util::bintohex ($ data ), null , 0 , null , 0 , 0 );
9531002 Factory::getHashBinaryFactory ()->save ($ hash );
1003+ $ uploadedValidHashes ++;
9541004 $ added ++;
9551005 }
9561006 else { // PMKID hashes
9571007 $ line = trim (fgets ($ file ));
9581008 if (strlen ($ line ) == 0 ) {
1009+ $ uploadedEmptyLines ++;
9591010 continue ;
9601011 }
9611012 if (strpos ($ line , "* " ) !== false ) {
@@ -974,14 +1025,15 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
9741025 }
9751026 $ hash = new HashBinary (null , $ hashlist ->getId (), $ identification , Util::bintohex ($ line . "\n" ), null , 0 , null , 0 , 0 );
9761027 Factory::getHashBinaryFactory ()->save ($ hash );
1028+ $ uploadedValidHashes ++;
9771029 $ added ++;
9781030 }
9791031 }
9801032 fclose ($ file );
9811033 unlink ($ tmpfile );
9821034
983- Factory::getHashlistFactory ()->set ($ hashlist , Hashlist::HASH_COUNT , $ added );
984- Util::createLogEntry ("User " , $ user ->getId (), DLogEntry::INFO , "New Hashlist created: " . $ hashlist ->getHashlistName ());
1035+ Factory::getHashlistFactory ()->mset ($ hashlist , [ Hashlist::HASH_COUNT => $ added, Hashlist:: UPLOADED_TOTAL_LINES => $ uploadedTotalLines , Hashlist:: UPLOADED_EMPTY_LINES => $ uploadedEmptyLines , Hashlist:: UPLOADED_VALID_HASHES => $ uploadedValidHashes , Hashlist:: UPLOADED_VALID_HASHES_WITHOUT_EXPECTED_SALT => $ uploadedValidHashesWithoutExpectedSalt , Hashlist:: UPLOADED_VALID_HASHES => $ uploadedValidHashes ] );
1036+ Util::createLogEntry ("User " , $ user ->getId (), DLogEntry::INFO , "New Hashlist created: " . $ hashlist ->getHashlistName () . " . Total lines: " . $ uploadedTotalLines . " Empty lines: " . $ uploadedEmptyLines . " Valid hashes: " . $ uploadedValidHashes . " Valid hashes without expected salt: " . $ uploadedValidHashesWithoutExpectedSalt . " Invalid hashes: " . $ uploadedInvalidHashes );
9851037
9861038 NotificationHandler::checkNotifications (DNotificationType::NEW_HASHLIST , new DataSet (array (DPayloadKeys::HASHLIST => $ hashlist )));
9871039 break ;
@@ -990,11 +1042,14 @@ public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted,
9901042 $ data = fread ($ file , Util::filesize ($ tmpfile ));
9911043 $ hash = new HashBinary (null , $ hashlist ->getId (), "" , Util::bintohex ($ data ), "" , 0 , null , 0 , 0 );
9921044 Factory::getHashBinaryFactory ()->save ($ hash );
1045+ $ uploadedValidHashes ++;
9931046 }
1047+
9941048 fclose ($ file );
9951049 unlink ($ tmpfile );
996- Factory::getHashlistFactory ()->set ($ hashlist , Hashlist::HASH_COUNT , 1 );
997- Util::createLogEntry ("User " , $ user ->getId (), DLogEntry::INFO , "New Hashlist created: " . $ hashlist ->getHashlistName ());
1050+
1051+ Factory::getHashlistFactory ()->mset ($ hashlist , [Hashlist::HASH_COUNT => 1 , Hashlist::UPLOADED_TOTAL_LINES => $ uploadedTotalLines , Hashlist::UPLOADED_EMPTY_LINES => $ uploadedEmptyLines , Hashlist::UPLOADED_VALID_HASHES => $ uploadedValidHashes , Hashlist::UPLOADED_VALID_HASHES_WITHOUT_EXPECTED_SALT => $ uploadedValidHashesWithoutExpectedSalt , Hashlist::UPLOADED_VALID_HASHES => $ uploadedValidHashes ]);
1052+ Util::createLogEntry ("User " , $ user ->getId (), DLogEntry::INFO , "New Hashlist created: " . $ hashlist ->getHashlistName () . ". Total lines: " . $ uploadedTotalLines . " Empty lines: " . $ uploadedEmptyLines . " Valid hashes: " . $ uploadedValidHashes . " Valid hashes without expected salt: " . $ uploadedValidHashesWithoutExpectedSalt . " Invalid hashes: " . $ uploadedInvalidHashes );
9981053
9991054 NotificationHandler::checkNotifications (DNotificationType::NEW_HASHLIST , new DataSet (array (DPayloadKeys::HASHLIST => $ hashlist )));
10001055 break ;
0 commit comments