├── .github └── workflows │ └── codeql-analysis.yml ├── .idea ├── .gitignore ├── cryptopayload.iml ├── misc.xml ├── modules.xml └── vcs.xml ├── README.MD └── cryptopayload.go /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '34 1 * * 3' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: [ 'go' ] 32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 33 | # Learn more: 34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 35 | 36 | steps: 37 | - name: Checkout repository 38 | uses: actions/checkout@v2 39 | 40 | # Initializes the CodeQL tools for scanning. 41 | - name: Initialize CodeQL 42 | uses: github/codeql-action/init@v1 43 | with: 44 | languages: ${{ matrix.language }} 45 | # If you wish to specify custom queries, you can do so here or in a config file. 46 | # By default, queries listed here will override any specified in a config file. 47 | # Prefix the list here with "+" to use these queries and those in the config file. 48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 49 | 50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 51 | # If this step fails, then you should remove it and run the build manually (see below) 52 | - name: Autobuild 53 | uses: github/codeql-action/autobuild@v1 54 | 55 | # ℹ️ Command-line programs to run using the OS shell. 56 | # 📚 https://git.io/JvXDl 57 | 58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 59 | # and modify them (or add more) to build your code if your project 60 | # uses a compiled language 61 | 62 | #- run: | 63 | # make bootstrap 64 | # make release 65 | 66 | - name: Perform CodeQL Analysis 67 | uses: github/codeql-action/analyze@v1 68 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/cryptopayload.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | [![CodeQL](https://github.com/sourcefrenchy/cryptopayload/actions/workflows/codeql-analysis.yml/badge.svg?branch=master)](https://github.com/sourcefrenchy/cryptopayload/actions/workflows/codeql-analysis.yml) 2 | 3 | # Exfiltration fun using X509 digital certificates 4 | 5 | ## Overview 6 | 7 | I spend a ton of time on exfiltration topics and mitigation techniques. This is my very first attempt to try to learn Go by having a quick way to convert a payload (reading a file) and building it as part as a custom x509 digital certificate. 8 | 9 | Certexfil has a client and a listener and a module for encoding/encrypting (long term). 10 | 11 | More info at https://medium.com/@jeanmichel.amblat/abusing-certificates-for-data-exfiltration-d6bff2533cd0 12 | 13 | 14 | ## Todo 15 | 16 | * Actually have crypto in cryptopayload module 17 | 18 | 19 | ## Contact 20 | 21 | @Sourcefrenchy 22 | 23 | -------------------------------------------------------------------------------- /cryptopayload.go: -------------------------------------------------------------------------------- 1 | // Package cryptopayload provides functions to prepare the payload 2 | // and to retrieve the payload from within the custom client certificate. 3 | // Nothing fancy for now, b64enc(compress(payload)) and reverse. 4 | // @Sourcefrenchy 5 | package cryptopayload 6 | 7 | import ( 8 | "bytes" 9 | "compress/gzip" 10 | "encoding/base64" 11 | "io" 12 | "io/ioutil" 13 | "log" 14 | ) 15 | 16 | // DEBUG is used for verbose logging 17 | var DEBUG = false 18 | 19 | // Prepare takes care of compressing and encoding a string (payload) 20 | func Prepare(payloadDat string) string { 21 | var buf bytes.Buffer 22 | err := compress(&buf, []byte(payloadDat)) 23 | if err != nil { 24 | log.Fatal(err) 25 | } 26 | if DEBUG { 27 | log.Printf("Payload --> %.*s...\t(%d bytes)", 10, payloadDat, len(payloadDat)) 28 | log.Printf("PayloadPrepared --> %.*s...\t\t(%d bytes)", 10, buf.String(), len(buf.String())) 29 | } 30 | return base64.StdEncoding.EncodeToString([]byte(buf.String())) 31 | } 32 | 33 | // Retrieve takes care of retrieving and decoding a string (payload) 34 | func Retrieve(payloadDat string) []byte { 35 | decoded, _ := base64.StdEncoding.DecodeString(payloadDat) 36 | var buf bytes.Buffer 37 | err := decompress(&buf, decoded) 38 | if err != nil { 39 | log.Fatal(err) 40 | } 41 | if DEBUG { 42 | log.Printf("PayloadRetrieved -->\n%s<--", buf.String()) 43 | } 44 | return []byte(buf.String()) 45 | } 46 | 47 | func compress(w io.Writer, data []byte) error { 48 | gw, err := gzip.NewWriterLevel(w, gzip.BestCompression) 49 | defer gw.Close() 50 | gw.Write(data) 51 | return err 52 | } 53 | 54 | func decompress(w io.Writer, data []byte) error { 55 | gr, err := gzip.NewReader(bytes.NewBuffer(data)) 56 | defer gr.Close() 57 | data, err = ioutil.ReadAll(gr) 58 | if err != nil { 59 | return err 60 | } 61 | w.Write(data) 62 | return nil 63 | } 64 | --------------------------------------------------------------------------------