Skip to content

Commit

Permalink
Gottern v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joanbono committed Feb 13, 2020
1 parent 493cb64 commit f74589e
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 79 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ build/*

# rsrc syso output
*.syso
go.mod
go.mod
go.sum
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BINARY=gottern
APPNAME=GOTTERN
TARGET=all
VERSION=`git tag --list | head -1`
VERSION=`git tag --list | tail -1`

# Build stuff
BUILD_TIME=`date +%FT%T%z`
Expand Down
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GitHub Issues](https://img.shields.io/github/issues/joanbono/gottern.svg)](https://github.com/joanbono/gottern/issues)
[![GitHub tag](https://img.shields.io/github/tag/joanbono/gottern.svg)](https://github.com/joanbono/gottern/tags)
[![Go Version](https://img.shields.io/badge/go-1.11-blue.svg?logo=go)](https://golang.org/dl/)
[![Go Version](https://img.shields.io/badge/go-1.13.7-blue.svg?logo=go)](https://golang.org/dl/)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Go Report Card](https://goreportcard.com/badge/github.com/joanbono/gottern)](https://goreportcard.com/report/github.com/joanbono/gottern)

Expand All @@ -13,43 +13,83 @@ Based on [`haxpattern`](https://github.com/DharmaOfCode/haxpattern)
## Usage

```bash
$ gottern -h
Usage of gottern:
-b Big Endian
-c int pattern_create
-o string pattern_offset
$ gottern help
Pattern Offset Seeker and Pattern Creator

Usage:
Gottern [command]

Available Commands:
create Create the pattern
help Help about any command
offset Search for an offset
version Prints current Gottern version

Flags:
-h, --help help for Gottern

Use "Gottern [command] --help" for more information about a command.
```

### Create a pattern

Create a pattern using the `-c` flag with the size of the pattern to be created.
Create a pattern using the `create` flag with the size (`-l`) of the pattern to be created.

```bash
$ gottern -c 200
Aa0Aa1Aa2Aa3Aa4[...]Ag1Ag2Ag3Ag4Ag5Ag
$ gottern create -h
Create the pattern

Usage:
Gottern create [flags]

Flags:
-h, --help help for create
-l, --length int Lenght of the string to be created

$ gottern create -l 200
Aa0Aa1Aa2Aa3Aa4A[...]g1Ag2Ag3Ag4Ag5Ag
```

### Look for an offset

Search an offset using the `offset` flag with the query to perform (`-q`) of the pattern to be created. Use `-b` for big endian search.

```bash
$ gottern offset -h
Search for an offset

Usage:
Gottern offset [flags]

Flags:
-b, --bigendian Search for Big Endian Offset
-h, --help help for offset
-q, --query string Query the following pattern. Minimum 4 bytes.
```

Examples:

```bash
# ASCII
$ gottern -o 6Aj7
$ gottern offset -q 6Aj7
[*] 290
# Plain HEX
$ gottern -o 0x36416a37
$ gottern offset -q 0x36416a37
[*] 290
# Little Endian HEX
$ gottern -o 376a4136
$ gottern offset -q 376a4136
[*] 290
# Big Endian HEX
$ gottern -o 36416a37 -b
$ gottern offset -q 36416a37 -b
[*] 290
```

***

## Benchmarks

Some benchmarks using [`hyperfine`](https://github.com/sharkdp/hyperfine).

### Create a Pattern

![](img/benchmark_create.png)
Expand Down
75 changes: 75 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

package cmd

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
)

// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create the pattern",
Run: func(cmd *cobra.Command, args []string) {
Length, err := cmd.Flags().GetInt("length")
CheckErr(err)
if Length == 0 {
fmt.Printf("\n[i] ./gottern create -h for help\n\n")
os.Exit(0)
}
fmt.Printf("%v\n", PatternCreate(Length))
},
}

func init() {
rootCmd.AddCommand(createCmd)
createCmd.PersistentFlags().IntP("length", "l", 0, "Lenght of the string to be created")
createCmd.MarkFlagRequired("length")
}

// PatterCreate will just create the Pattern
// with [A-Za-z0-9]
func PatternCreate(length int) string {
UpperCase := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LowerCase := "abcdefghijklmnopqrstuvwxyz"
Numbers := "0123456789"

var pattern []string
for len(pattern) < length {
for _, A0 := range UpperCase {
for _, a0 := range LowerCase {
for _, n0 := range Numbers {
if len(pattern) < length {
pattern = append(pattern, string(A0))
}
if len(pattern) < length {
pattern = append(pattern, string(a0))
}
if len(pattern) < length {
pattern = append(pattern, string(n0))
}
}
}
}
}
return strings.Join(pattern, "")
}
94 changes: 30 additions & 64 deletions main.go → cmd/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,48 @@
under the License.
*/

package main
package cmd

import (
"encoding/hex"
"flag"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
)

var offset string
var create int
var bigendian bool
// offsetCmd represents the offset command
var offsetCmd = &cobra.Command{
Use: "offset",
Short: "Search for an offset",
Run: func(cmd *cobra.Command, args []string) {
offset, err := cmd.Flags().GetString("query")
CheckErr(err)
bigendian, err := cmd.Flags().GetBool("bigendian")
CheckErr(err)

func init() {
flag.IntVar(&create, "c", 0, "pattern_create")
flag.StringVar(&offset, "o", "", "pattern_offset")
flag.BoolVar(&bigendian, "b", false, "Big Endian")
if len(offset) < 4 || (len(offset) < 10 && offset[:2] == "0x") {
fmt.Printf("\n[i] ./gottern offset -h for help\n\n")
os.Exit(0)
} else if offset[:2] == "0x" {
PatternOffsetHex(offset)
} else {
PatternOffset(offset, bigendian)
}
},
}

flag.Parse()
func init() {
rootCmd.AddCommand(offsetCmd)
offsetCmd.PersistentFlags().StringP("query", "q", "", "Query the following pattern. Minimum 4 bytes.")
offsetCmd.PersistentFlags().BoolP("bigendian", "b", false, "Search for Big Endian Offset")
offsetCmd.MarkFlagRequired("length")
}

// PatternOffset looks for ASCII string
// inside the pattern
func PatternOffset(offset string) {
func PatternOffset(offset string, bigendian bool) {
var maxPattern string
maxPattern = PatternCreate(20280)
i := strings.Index(maxPattern, offset)
Expand All @@ -47,7 +65,7 @@ func PatternOffset(offset string) {
} else if i == -1 && bigendian == true {
PatternOffsetHex(offset)
} else {
println("[*]", i)
fmt.Printf("[*] %v\n", i)
}
}

Expand Down Expand Up @@ -89,55 +107,3 @@ func PatternOffsetHex(offset string) {
}
}
}

// PatterCreate will just create the Pattern
// with [A-Za-z0-9]
func PatternCreate(length int) string {
UpperCase := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LowerCase := "abcdefghijklmnopqrstuvwxyz"
Numbers := "0123456789"

var pattern []string
for len(pattern) < length {
for _, A0 := range UpperCase {
for _, a0 := range LowerCase {
for _, n0 := range Numbers {
if len(pattern) < length {
pattern = append(pattern, string(A0))
}
if len(pattern) < length {
pattern = append(pattern, string(a0))
}
if len(pattern) < length {
pattern = append(pattern, string(n0))
}
}
}
}
}
return strings.Join(pattern, "")
}

// main function to execute the program
func main() {

if (offset == "" && create == 0) || (offset != "" && create != 0) {
println("[i] ./gottern -h for help")
os.Exit(0)
} else if offset == "" && create > 0 {
var patternCreated = PatternCreate(create)
println(patternCreated)
} else if offset != "" && create == 0 {
if len(offset) < 4 || (len(offset) < 10 && offset[:2] == "0x") {
println("[!] Offset should be at least 4 bytes")
os.Exit(0)
} else if offset[:2] == "0x" {
PatternOffsetHex(offset)
} else {
PatternOffset(offset)
}
} else {
println("[i] ./gottern -h for help")
os.Exit(0)
}
}
46 changes: 46 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "Gottern",
Short: "Pattern Offset Seeker and Pattern Creator",
}

// Execute adds all child commands to the root command and sets flags appropriately.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

// CheckErr will handle errors
func CheckErr(err error) {
if err != nil {
fmt.Printf("Error: %v\n", err)
}
}
Loading

0 comments on commit f74589e

Please sign in to comment.