• Stars
    star
    952
  • Rank 48,013 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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


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 LFSR. 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

You can get the pre-compiled binaries HERE. For building from source follow the steps bellow.

Dependencies:

The only dependency for building the source is the keystone engine, follow these instructions for installing the library. Once libkeystone is installed on the system, simply just go get it ツ

go install github.com/EgeBalci/sgn@latest

DOCKER INSTALL

Docker

docker pull egee/sgn
docker run -it egee/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 20)
  -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

Docker Usage

docker run -it -v /tmp/:/tmp/ sgn /tmp/shellcode

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 [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]

More Repositories

1

amber

Reflective PE packer.
Go
979
star
2

HERCULES

HERCULES is a special payload generator that can bypass antivirus softwares.
Go
592
star
3

EGESPLOIT

EGESPLOIT is a golang library for malware development
Go
329
star
4

deoptimizer

Evasion by machine code de-optimization.
Rust
327
star
5

ARCANUS

ARCANUS is a customized payload generator/handler.
Go
143
star
6

Cminer

Cminer is a tool for enumerating the code caves in PE files.
C++
131
star
7

Keylogger

Simple C++ Keylogger...
C++
128
star
8

WSAAcceptBackdoor

Winsock accept() Backdoor Implant.
C
111
star
9

Mass-Hacker-Arsenal

Massive arsenal of hacker tools...
Shell
75
star
10

Hook_API

Assembly block for hooking windows API functions.
Assembly
72
star
11

IAT_API

Assembly block for finding and calling the windows API functions inside import address table(IAT) of the running PE file.
Assembly
64
star
12

The-Eye

Simple security surveillance script for linux distributions.
Go
53
star
13

MapPE

PE file mapping and manipulation package.
Go
37
star
14

syscall_api

Assembly
36
star
15

Ticketbleed

This is a tool for exploiting Ticketbleed (CVE-2016-9244) vulnerability.
Go
28
star
16

zippo

Zippo is a archive payload generator for testing XSS, (Zip/Tar/Gzip) slip vulnerabilities.
Go
26
star
17

SelfDefense

Several self-defense shellcodes
Assembly
22
star
18

MSF-Self-Defence

Self defense post module for metasploit
Ruby
18
star
19

meterpreter

Basic multi platform meterpreter loader module.
Go
17
star
20

MSF-Telegram-Notify

Telegram notification for metasploit sessions.
Ruby
15
star
21

BitBender

BitBender is a byte manipulation tool
Go
15
star
22

AzorultDecryptor

Brute-force script for finding azorult XOR key.
Go
15
star
23

crc32_api

Assembly API block that uses CRC32 for resolving Windows API function addresses
Assembly
14
star
24

KPOT-Decryptor

Tool for finding KPOT XOR key using known-plaintext attack.
Go
14
star
25

sub7

Clone of https://gitlab.com/illwill/sub7 repo.
Pascal
14
star
26

Injector

Simple shellcode injector.
C++
14
star
27

CryptAPI

Ransomware Using CryptoAPI
C
13
star
28

keystone-go

Keystone binding for golang
C
11
star
29

CVE-2022-29154

HIP2022 presentation materials.
10
star
30

urlscan-go

URLScan Go API client
Go
8
star
31

ARMBot_RCE

ARM Bot RCE Exploit.
Ruby
6
star
32

egebalci

6
star
33

CVE-2018-8065

Flexense HTTP Server <= 10.6.24 - Denial Of Service Exploit
Ruby
6
star
34

cracklord-docker

Experimental docker image for http://jmmcatee.github.io/cracklord/
Dockerfile
4
star
35

LG-Smart-IP-Device-Backup-Download

Exploit for downloading backup files from LG Smart IP Devices.
Python
4
star
36

Baldr_Exploit

Baldr remote code execution exploit for versions <= v3
Ruby
4
star
37

Sync_Breeze_Enterprise_10_6_24_-DOS

Sync Breeze Enterprise 10.6.24 - Denial Of Service Vulnerability
Ruby
2
star
38

AdvertisementBot

An advertisement bot for twitter.
JavaScript
2
star
39

conpty-go

Go
1
star
40

dotfiles

My dotfiles
1
star