
PE est un package GO pour analyser le format de fichier exécutable portable. Ce package a été conçu avec une analyse de logiciels malveillants à l'esprit et résisté aux malformations de PE.
L'utilisation de ce package GO est facile. Tout d'abord, utilisez go get pour installer la dernière version de la bibliothèque. Cette commande installera le pedumper Exécutable avec la bibliothèque et ses dépendances:
go get -u github.com/saferwall/pe
Ensuite, incluez le package pe dans votre application:
import "github.com/saferwall/pe" package main
import (
peparser "github.com/saferwall/pe"
)
func main () {
filename := "C: \ Binaries \ notepad.exe"
pe , err := peparser . New ( filename , & peparser. Options {})
if err != nil {
log . Fatalf ( "Error while opening file: %s, reason: %v" , filename , err )
}
err = pe . Parse ()
if err != nil {
log . Fatalf ( "Error while parsing file: %s, reason: %v" , filename , err )
}
} Commencez par instancier un objet PE par appelé la méthode New() , qui emmène le chemin de fichier vers le fichier à analyser et certaines options facultatives.
Ensuite, un appel à la méthode Parse() vous donnera accès à toutes les différentes parties du format PE, directement accessibles pour être utilisés. Voici la définition de la structure:
type File struct {
DOSHeader ImageDOSHeader `json:"dos_header,omitempty"`
RichHeader RichHeader `json:"rich_header,omitempty"`
NtHeader ImageNtHeader `json:"nt_header,omitempty"`
COFF COFF `json:"coff,omitempty"`
Sections [] Section `json:"sections,omitempty"`
Imports [] Import `json:"imports,omitempty"`
Export Export `json:"export,omitempty"`
Debugs [] DebugEntry `json:"debugs,omitempty"`
Relocations [] Relocation `json:"relocations,omitempty"`
Resources ResourceDirectory `json:"resources,omitempty"`
TLS TLSDirectory `json:"tls,omitempty"`
LoadConfig LoadConfig `json:"load_config,omitempty"`
Exceptions [] Exception `json:"exceptions,omitempty"`
Certificates CertificateSection `json:"certificates,omitempty"`
DelayImports [] DelayImport `json:"delay_imports,omitempty"`
BoundImports [] BoundImportDescriptorData `json:"bound_imports,omitempty"`
GlobalPtr uint32 `json:"global_ptr,omitempty"`
CLR CLRData `json:"clr,omitempty"`
IAT [] IATEntry `json:"iat,omitempty"`
Anomalies [] string `json:"anomalies,omitempty"`
Header [] byte
data mmap. MMap
FileInfo
size uint32
OverlayOffset int64
f * os. File
opts * Options
logger * log. Helper
} Comme mentionné précédemment, tous les membres de la structure sont directement (pas de getters) accessibles, en outre, les types de champs ont été conservés comme la spécification les définit, cela signifie que si vous devez afficher la version Pretifified d'un type int , vous devez appeler la fonction d'assistance correspondante.
fmt . Printf ( "Magic is: 0x%x n " , pe . DOSHeader . Magic )
fmt . Printf ( "Signature is: 0x%x n " , pe . NtHeader . Signature )
fmt . Printf ( "Machine is: 0x%x, Meaning: %s n " , pe . NtHeader . FileHeader . Machine , pe . NtHeader . FileHeader . Machine . String ())Sortir:
Magic is: 0x5a4d
Signature is: 0x4550
Machine is: 0x8664, Meaning: x64
Exemple:
richHeader , _ := json . Marshal ( pe . RichHeader )
fmt . Print ( prettyPrint ( richHeader ))Sortir:
{
"XorKey" : 2796214951 ,
"CompIDs" : [
{
"MinorCV" : 27412 ,
"ProdID" : 257 ,
"Count" : 4 ,
"Unmasked" : 16870164
},
{
"MinorCV" : 30729 ,
"ProdID" : 147 ,
"Count" : 193 ,
"Unmasked" : 9664521
},
{
"MinorCV" : 0 ,
"ProdID" : 1 ,
"Count" : 1325 ,
"Unmasked" : 65536
},
{
"MinorCV" : 27412 ,
"ProdID" : 260 ,
"Count" : 9 ,
"Unmasked" : 17066772
},
{
"MinorCV" : 27412 ,
"ProdID" : 259 ,
"Count" : 3 ,
"Unmasked" : 17001236
},
{
"MinorCV" : 27412 ,
"ProdID" : 256 ,
"Count" : 1 ,
"Unmasked" : 16804628
},
{
"MinorCV" : 27412 ,
"ProdID" : 269 ,
"Count" : 209 ,
"Unmasked" : 17656596
},
{
"MinorCV" : 27412 ,
"ProdID" : 255 ,
"Count" : 1 ,
"Unmasked" : 16739092
},
{
"MinorCV" : 27412 ,
"ProdID" : 258 ,
"Count" : 1 ,
"Unmasked" : 16935700
}
],
"DansOffset" : 128 ,
"Raw" : " 47vE9afaqqan2qqmp9qqprOxq6ej2qqmrqI5pmbaqqan2qumit+qprOxrqeu2qqms7Gpp6TaqqazsaqnptqqprOxp6d22qqms7FVpqbaqqazsainptqqplJpY2in2qqm "
}
for _ , sec := range pe . Sections {
fmt . Printf ( "Section Name : %s n " , sec . NameString ())
fmt . Printf ( "Section VirtualSize : %x n " , sec . Header . VirtualSize )
fmt . Printf ( "Section Flags : %x, Meaning: %v n n " ,
sec . Header . Characteristics , sec . PrettySectionFlags ())
}Sortir:
Section Name : .text
Section VirtualSize : 2ea58
Section Flags : 60500060, Meaning: [Align8Bytes Readable Align16Bytes Executable Contains Code Initialized Data Align1Bytes]
Section Name : .data
Section VirtualSize : 58
Section Flags : c0500040, Meaning: [Readable Initialized Data Writable Align1Bytes Align16Bytes Align8Bytes]
Section Name : .rdata
Section VirtualSize : 18d0
Section Flags : 40600040, Meaning: [Align2Bytes Align8Bytes Readable Initialized Data Align32Bytes]
...
Pour valider l'analyseur, nous utilisons le go-fuzz et un corpus de fichiers PE malformés et délicats connus de Corkami.

Fibratus Un outil moderne pour l'exploration et le traçage du noyau Windows en mettant l'accent sur la sécurité.