Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created January 17, 2019 13:57
Show Gist options
  • Save kohnakagawa/2cefc29c8e30095bb6a1e1f17d750b01 to your computer and use it in GitHub Desktop.
Save kohnakagawa/2cefc29c8e30095bb6a1e1f17d750b01 to your computer and use it in GitHub Desktop.
tlsh example in Go lang
package main
import (
tlsh "github.com/glaslos/tlsh"
"fmt"
"os"
"io/ioutil"
)
func readBinary(fname string) ([]byte, error) {
file, err := os.Open(fname)
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(file)
if err != nil{
return nil, err
}
return bytes, nil
}
func main() {
bytes0, err := readBinary("notepad.exe")
if err != nil {
fmt.Println(err.Error())
}
bytes1, err := readBinary("calc.exe")
if err != nil {
fmt.Println(err.Error())
}
tlsh0, err := tlsh.HashBytes(bytes0)
if err != nil {
fmt.Println(err.Error())
}
tlshStr0 := tlsh0.String()
tlsh1, err := tlsh.HashBytes(bytes1)
if err != nil {
fmt.Println(err.Error())
}
tlshStr1 := tlsh1.String()
fmt.Println(tlshStr0)
fmt.Println(tlshStr1)
}
@kohnakagawa
Copy link
Author

string -> tlsh.TLSH に変換するための関数がないので、それだけは自作する必要がありそう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment