GithubHelp home page GithubHelp logo

anthrax3 / sgn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 0x00-0x00/sgn

0.0 0.0 0.0 825 KB

Shikata ga nai (仕方がない) encoder ported into go with several improvements

License: MIT License

Go 91.93% Makefile 0.13% Shell 7.94%

sgn's Introduction

BANNER

Go Report Card Open Issues License Twitter

SGN is a polymorphic binary encoder for offensive security purposes such as generating statically undetecable binary payloads. It uses a additive feedback loop to encode given binary instructions similar to LSFR. This project is the reimplementation of the original Shikata ga nai in golang with many improvements.

How? & Why?

For offensive security community, the original implementation of shikata ga nai encoder is considered to be the best shellcode encoder(until now). But over the years security researchers found several pitfalls for statically detecing the encoder(related work FireEye article). The main motive for this project was to create a better encoder that encodes the given binary to the point it is identical with totally random data and not possible to detect the presence of a decoder. With the help of keystone assembler library following improvments are implemented.

  • 64 bit support. Finally properly encoded x64 shellcodes !
  • New smaller decoder stub. LFSR key reduced to 1 byte
  • Encoded stub with pseudo random schema. Decoder stub is also encoded with a psudo random schema
  • No visible loop condition Stub decodes itself WITHOUT using any loop conditions !!
  • Decoder stub obfuscation. Random garbage instruction generator added with keystone
  • Safe register option. Non of the registers are clobbered (optional preable, may reduce polimorphism)

Install

Dependencies:

Only dependencies required is keystone and capstone libraries. For easily installing capstone libarary check the table;

OS Install Command
Ubuntu/Debian sudo apt-get install libcapstone-dev
Mac brew install capstone
FreeBSD pkg install capstone
OpenBSD sudo pkg_add capstone
Windows/All Other... CHECK HERE

Installation of keystone library can be little tricky in some cases. Check here for keystone library installation guides.

Then just go get it ツ

go get github.com/egebalci/sgn

Usage

-h is pretty self explanatory use -v if you want to see what's going on behind the scenes ( ͡° ͜ʖ ͡°)_/¯

       __   _ __        __                               _ 
  ___ / /  (_) /_____ _/ /____ _  ___ ____ _  ___  ___ _(_)
 (_-</ _ \/ /  '_/ _ `/ __/ _ `/ / _ `/ _ `/ / _ \/ _ `/ / 
/___/_//_/_/_/\_\\_,_/\__/\_,_/  \_, /\_,_/ /_//_/\_,_/_/  
========[Author:-Ege-Balcı-]====/___/=======v2.0.0=========  
    ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻           (ノ ゜Д゜)ノ ︵ 仕方がない

Usage: sgn [OPTIONS] <FILE>
  -a int
    	Binary architecture (32/64) (default 32)
  -asci
    	Generates a full ASCI printable payload (takes very long time to bruteforce)
  -badchars string
    	Don't use specified bad characters given in hex format (\x00\x01\x02...)
  -c int
    	Number of times to encode the binary (increases overall size) (default 1)
  -h	Print help
  -max int
    	Maximum number of bytes for obfuscation (default 50)
  -o string
    	Encoded output binary name
  -plain-decoder
    	Do not encode the decoder stub
  -safe
    	Do not modify and register values
  -v	More verbose output

Using As Library

Warning !! SGN package is still under development for better performance and several improvements. Most of the functions are subject to change.

package main

import (
	"encoding/hex"
	"fmt"
	"io/ioutil"

	sgn "github.com/egebalci/sgn/lib"
)

func main() {
	// First open some file
	file, err := ioutil.ReadFile("myfile.bin")
	if err != nil { // check error
		fmt.Println(err)
		return
	}
	// Create a new SGN encoder
	encoder := sgn.NewEncoder()
	// Set the proper architecture
	encoder.SetArchitecture(64)
	// Encode the binary
	encodedBinary, err := encoder.Encode(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	// Print out the hex dump of the encoded binary
	fmt.Println(hex.Dump(encodedBinary))

}

Execution Flow

The following image is a basic workflow diagram for the encoder. But keep in mind that the sizes, locations and orders will change for garbage instructions, decoders and schema decoders on each iteration.

LFSR itself is pretty powerful in terms of probability space. For even more polimorphism garbage instructions are appended at the begining of the unencoded raw payload. Below image shows the the companion matrix of the characteristic polynomial of the LFSR and denoting the seed as a column vector, the state of the register in Fibonacci configuration after k steps.

Challenge

Considering the probability space of this encoder I personally don't think that any rule based static detection mechanism can detect the binaries that are encoded with SGN. In fact I am willing to give out the donation money for this project as a symbolic prize if anyone can write a YARA rule that can detect every encoded output. Check out HERE for the guidelines and rules for claiming the donation money.

Current Donation Amount

QR

If you tried and failed please consider donating [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]

sgn's People

Contributors

egebalci avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.