@@ -15,6 +15,7 @@ import (
1515 "os"
1616 "regexp"
1717 "strings"
18+ "syscall"
1819
1920 "github.com/yeka/zip"
2021)
@@ -580,7 +581,7 @@ func polyswarm(uri string, api string, hash Hash) (bool, string) {
580581}
581582
582583func polyswarmDownload (uri string , api string , hash Hash ) (bool , string ) {
583- query := "/download/" + url .PathEscape (hash .HashType .String ()) + "/" + url .PathEscape (hash .Hash )
584+ query := "/consumer/ download/" + url .PathEscape (hash .HashType .String ()) + "/" + url .PathEscape (hash .Hash )
584585
585586 _ , error := url .ParseQuery (query )
586587 if error != nil {
@@ -620,7 +621,7 @@ func polyswarmDownload(uri string, api string, hash Hash) (bool, string) {
620621 }
621622}
622623
623- func hybridAnlysis (uri string , api string , hash Hash , doNotExtract bool ) (bool , string ) {
624+ func hybridAnalysis (uri string , api string , hash Hash ) (bool , string ) {
624625 if api == "" {
625626 fmt .Println (" [!] !! Missing Key !!" )
626627 return false , ""
@@ -672,12 +673,12 @@ func hybridAnlysis(uri string, api string, hash Hash, doNotExtract bool) (bool,
672673 }
673674
674675 if hash .HashType == sha256 {
675- return hybridAnlysisDownload (uri , api , hash , doNotExtract )
676+ return hybridAnalysisDownload (uri , api , hash )
676677 }
677678 return false , ""
678679}
679680
680- func hybridAnlysisDownload (uri string , api string , hash Hash , extract bool ) (bool , string ) {
681+ func hybridAnalysisDownload (uri string , api string , hash Hash ) (bool , string ) {
681682 request , error := http .NewRequest ("GET" , uri + "/overview/" + url .PathEscape (hash .Hash )+ "/sample" , nil )
682683
683684 request .Header .Set ("accept" , "application/gzip" )
@@ -699,6 +700,9 @@ func hybridAnlysisDownload(uri string, api string, hash Hash, extract bool) (boo
699700 if response .StatusCode == http .StatusForbidden {
700701 fmt .Printf (" [!] Not authorized. Check the URL and APIKey in the config.\n Could also be that the sample is not allowed to be downloaded.\n " )
701702 return false , ""
703+ } else if response .StatusCode == http .StatusNotFound {
704+ fmt .Printf (" [!] Hash not found" )
705+ return false , ""
702706 } else if response .StatusCode != http .StatusOK {
703707 return false , ""
704708 }
@@ -812,52 +816,18 @@ func traigeDownload(uri string, api string, sampleId string, hash Hash) (bool, s
812816 fmt .Println (error )
813817 return false , ""
814818 }
815- // Triage will download an archive file that contians the hash in question sometimes versus the actual sample being requested
816- hashMatch , _ := hash .ValidateFile (hash .Hash )
819+ // Triage will download the sample directly - no password protected zip file.
820+ hashMatch , dhash := hash .ValidateFile (hash .Hash )
817821 if ! hashMatch {
818- files , err := extractPwdZip (hash .Hash , "" , false , hash )
819- if err != nil {
820- fmt .Println (error )
821- return false , ""
822- }
822+ fmt .Printf (" [!] Sample ID %s (%s)\n contains the file in question, further processing of the sample is needed to get the hash requested.\n " , sampleId , dhash )
823+ //ok := YesNoPrompt(fmt.Sprintf(" [?] Keep the file %s or delete it and continue looking for sample?", dhash), false)
824+ //if ok {
825+ return true , hash .Hash
826+ // } else {
827+ //return false, ""
828+ //}
823829
824- found := false
825-
826- fmt .Printf (" [-] The downloaded file appears to be a zip file in which the requested file should be located.\n " )
827- for _ , f := range files {
828- fmt .Printf (" [-] Checking file: %s\n " , f .Name )
829- hashMatch , _ = hash .ValidateFile (f .Name )
830- if ! hashMatch {
831- err = os .Remove (f .Name )
832- if err != nil {
833- fmt .Println (" [!] Error when deleting file: " , f .Name )
834- fmt .Println (err )
835- }
836- } else {
837- fmt .Printf (" [+] %s is hash %s\n " , f .Name , hash .Hash )
838- err = os .Rename (f .Name , hash .Hash )
839- if err != nil {
840- fmt .Println (" [!] Error when renaming file: " , f .Name )
841- fmt .Println (err )
842- } else {
843- found = true
844- }
845- }
846- }
847- if ! found {
848- fmt .Printf (" [!] Hash %s not found\n " , hash .Hash )
849- err = os .Remove (hash .Hash )
850- if err != nil {
851- fmt .Println (" [!] Error when deleting file: " , hash .Hash )
852- fmt .Println (err )
853- }
854- return false , ""
855- } else {
856- fmt .Printf (" [+] Found %s\n " , hash .Hash )
857- return true , hash .Hash
858- }
859830 } else {
860- fmt .Printf (" [+] Downloaded %s\n " , hash .Hash )
861831 return true , hash .Hash
862832 }
863833}
@@ -905,7 +875,7 @@ func malshareDownload(uri string, api string, hash Hash) (bool, string) {
905875 }
906876}
907877
908- func malwareBazaar (uri string , hash Hash , doNotExtract bool , password string ) (bool , string ) {
878+ func malwareBazaar (uri string , api string , hash Hash , doNotExtract bool , password string ) (bool , string ) {
909879 if hash .HashType != sha256 {
910880 fmt .Printf (" [-] Looking up sha256 hash for %s\n " , hash .Hash )
911881
@@ -949,19 +919,26 @@ func malwareBazaar(uri string, hash Hash, doNotExtract bool, password string) (b
949919 }
950920
951921 if hash .HashType == sha256 {
952- return malwareBazaarDownload (uri , hash , doNotExtract , password )
922+ return malwareBazaarDownload (uri , api , hash , doNotExtract , password )
953923 }
954924 return false , ""
955925}
956926
957- func malwareBazaarDownload (uri string , hash Hash , doNotExtract bool , password string ) (bool , string ) {
927+ func malwareBazaarDownload (uri string , api string , hash Hash , doNotExtract bool , password string ) (bool , string ) {
958928 query := "query=get_file&sha256_hash=" + hash .Hash
959- values , err := url .ParseQuery (query )
960- if err != nil {
961- fmt .Println (err )
929+ values , error := url .ParseQuery (query )
930+ if error != nil {
931+ fmt .Println (error )
962932 return false , ""
963933 }
964934
935+ request , error := http .NewRequest ("POST" , uri , nil )
936+ if error != nil {
937+ fmt .Println (error )
938+ return false , ""
939+ }
940+
941+ request .Header .Set ("Auth-Key" , api )
965942 client := & http.Client {}
966943
967944 response , err := client .PostForm (uri , values )
@@ -976,14 +953,13 @@ func malwareBazaarDownload(uri string, hash Hash, doNotExtract bool, password st
976953 if response .StatusCode == http .StatusMethodNotAllowed {
977954 if ! strings .HasSuffix (uri , "/" ) {
978955 fmt .Printf (" [!] Trying again with a trailing slash: %s/\n " , uri )
979- return malwareBazaarDownload (uri + "/" , hash , doNotExtract , password )
956+ return malwareBazaarDownload (uri + "/" , api , hash , doNotExtract , password )
980957 } else {
981958 fmt .Printf (" [!] Normally the response code: %s means that the provided URL %s needs a trailing slash (to avoid the redirect), but this already has a trailing slash.\n Please file a bug report at https://github.com/xorhex/mlget/issues\n " , response .Status , uri )
982959 }
983960 } else {
984961 fmt .Printf (" [!] %s\n " , response .Status )
985962 }
986- return false , ""
987963 }
988964
989965 err = writeToFile (response .Body , hash .Hash + ".zip" )
@@ -1108,6 +1084,9 @@ func vxsharedownload(uri string, api string, hash Hash, doNotExtract bool, passw
11081084
11091085 if response .StatusCode == 404 {
11101086 return false , ""
1087+ } else if response .StatusCode == http .StatusInternalServerError {
1088+ fmt .Printf (" [!] Internal service error. Skipping.\n " )
1089+ return false , ""
11111090 } else if response .StatusCode == 204 {
11121091 fmt .Printf (" [!] Request rate limit exceeded. You are making more requests than are allowed or have exceeded your quota.\n " )
11131092 return false , ""
@@ -1361,8 +1340,13 @@ func assemblyline(uri string, user string, api string, ignoretlserrors bool, has
13611340 client := & http.Client {Transport : tr }
13621341 response , error := client .Do (request )
13631342 if error != nil {
1364- fmt .Println (error )
1365- return false , ""
1343+ if errors .Is (error , syscall .ECONNREFUSED ) {
1344+ fmt .Println (" [!] Connection Refused. Is the service online?" )
1345+ return false , ""
1346+ } else {
1347+ fmt .Println (error )
1348+ return false , ""
1349+ }
13661350 }
13671351 defer response .Body .Close ()
13681352
@@ -1519,6 +1503,7 @@ func virusexchangeDownload(uri string, hash Hash) (bool, string) {
15191503 defer response .Body .Close ()
15201504
15211505 if response .StatusCode == http .StatusNotFound {
1506+ fmt .Printf (" [!] Invalid download link returned by the API.\n " )
15221507 return false , ""
15231508 } else if response .StatusCode == http .StatusForbidden {
15241509 fmt .Printf (" [!] Not authorized for some reason.\n " )
0 commit comments