pe
v1.5.0

PEは、ポータブル実行可能ファイル形式を解析するためのGOパッケージです。このパッケージは、マルウェア分析を念頭に置いて設計され、PE奇形に抵抗しています。
このGOパッケージを使用するのは簡単です。まず、最新バージョンのライブラリをインストールgo get 。このコマンドは、ライブラリとその依存関係とともにpedumper実行可能ファイルをインストールします。
go get -u github.com/saferwall/pe
次に、アプリケーションにpeパッケージを含めます。
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 )
}
} PEオブジェクトをNew()メソッドと呼ばれることでPEオブジェクトをインスタンス化することから始めます。これにより、ファイルパスを解析するファイルパスとオプションのオプションがあります。
その後、 Parse()メソッドへの呼び出しにより、PE形式のすべての異なる部分にアクセスできるようになり、使用できるように直接アクセスできます。構造の定義は次のとおりです。
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
}前述のように、structのすべてのメンバーは直接(ゲッターなし)アクセス可能であり、さらに、SPECが定義するようにフィールドタイプが保存されています。つまり、 intタイプの事後バージョンを表示する必要がある場合は、対応するヘルパー関数を呼び出す必要があります。
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 ())出力:
Magic is: 0x5a4d
Signature is: 0x4550
Machine is: 0x8664, Meaning: x64
例:
richHeader , _ := json . Marshal ( pe . RichHeader )
fmt . Print ( prettyPrint ( richHeader ))出力:
{
"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 ())
}出力:
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]
...
パーサーを検証するには、コルカミからの既知の奇形およびトリッキーなPEファイルのGo-FuzzとCorpusを使用します。

Fibratus Windowsカーネルの探索とセキュリティに焦点を当てたトレース用の最新のツール。